Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
llvm-epi
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roger Ferrer
llvm-epi
Commits
9eeada94
Commit
9eeada94
authored
17 years ago
by
Chris Lattner
Browse files
Options
Downloads
Patches
Plain Diff
Fix PR1434 and test/Linker/link-archive.ll, this is a regression from 1.9.
llvm-svn: 37204
parent
7aed8fcc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+82
-53
82 additions, 53 deletions
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.h
+9
-1
9 additions, 1 deletion
llvm/lib/Bitcode/Reader/BitcodeReader.h
with
91 additions
and
54 deletions
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+
82
−
53
View file @
9eeada94
...
@@ -24,8 +24,15 @@
...
@@ -24,8 +24,15 @@
#include
"llvm/Support/MemoryBuffer.h"
#include
"llvm/Support/MemoryBuffer.h"
using
namespace
llvm
;
using
namespace
llvm
;
BitcodeReader
::
~
BitcodeReader
()
{
void
BitcodeReader
::
FreeState
()
{
delete
Buffer
;
delete
Buffer
;
Buffer
=
0
;
std
::
vector
<
PATypeHolder
>
().
swap
(
TypeList
);
ValueList
.
clear
();
std
::
vector
<
const
ParamAttrsList
*>
().
swap
(
ParamAttrs
);
std
::
vector
<
BasicBlock
*>
().
swap
(
FunctionBBs
);
std
::
vector
<
Function
*>
().
swap
(
FunctionsWithBodies
);
DeferredFunctionInfo
.
clear
();
}
}
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
...
@@ -1102,53 +1109,6 @@ bool BitcodeReader::ParseBitcode() {
...
@@ -1102,53 +1109,6 @@ bool BitcodeReader::ParseBitcode() {
}
}
bool
BitcodeReader
::
materializeFunction
(
Function
*
F
,
std
::
string
*
ErrInfo
)
{
// If it already is material, ignore the request.
if
(
!
F
->
hasNotBeenReadFromBytecode
())
return
false
;
DenseMap
<
Function
*
,
std
::
pair
<
uint64_t
,
unsigned
>
>::
iterator
DFII
=
DeferredFunctionInfo
.
find
(
F
);
assert
(
DFII
!=
DeferredFunctionInfo
.
end
()
&&
"Deferred function not found!"
);
// Move the bit stream to the saved position of the deferred function body and
// restore the real linkage type for the function.
Stream
.
JumpToBit
(
DFII
->
second
.
first
);
F
->
setLinkage
((
GlobalValue
::
LinkageTypes
)
DFII
->
second
.
second
);
if
(
ParseFunctionBody
(
F
))
{
if
(
ErrInfo
)
*
ErrInfo
=
ErrorString
;
return
true
;
}
return
false
;
}
void
BitcodeReader
::
dematerializeFunction
(
Function
*
F
)
{
// If this function isn't materialized, or if it is a proto, this is a noop.
if
(
F
->
hasNotBeenReadFromBytecode
()
||
F
->
isDeclaration
())
return
;
assert
(
DeferredFunctionInfo
.
count
(
F
)
&&
"No info to read function later?"
);
// Just forget the function body, we can remat it later.
F
->
deleteBody
();
F
->
setLinkage
(
GlobalValue
::
GhostLinkage
);
}
Module
*
BitcodeReader
::
materializeModule
(
std
::
string
*
ErrInfo
)
{
for
(
DenseMap
<
Function
*
,
std
::
pair
<
uint64_t
,
unsigned
>
>::
iterator
I
=
DeferredFunctionInfo
.
begin
(),
E
=
DeferredFunctionInfo
.
end
();
I
!=
E
;
++
I
)
{
Function
*
F
=
I
->
first
;
if
(
F
->
hasNotBeenReadFromBytecode
()
&&
materializeFunction
(
F
,
ErrInfo
))
return
0
;
}
return
TheModule
;
}
/// ParseFunctionBody - Lazily parse the specified function body block.
/// ParseFunctionBody - Lazily parse the specified function body block.
bool
BitcodeReader
::
ParseFunctionBody
(
Function
*
F
)
{
bool
BitcodeReader
::
ParseFunctionBody
(
Function
*
F
)
{
if
(
Stream
.
EnterSubBlock
(
bitc
::
FUNCTION_BLOCK_ID
))
if
(
Stream
.
EnterSubBlock
(
bitc
::
FUNCTION_BLOCK_ID
))
...
@@ -1597,6 +1557,69 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
...
@@ -1597,6 +1557,69 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
return
false
;
return
false
;
}
}
//===----------------------------------------------------------------------===//
// ModuleProvider implementation
//===----------------------------------------------------------------------===//
bool
BitcodeReader
::
materializeFunction
(
Function
*
F
,
std
::
string
*
ErrInfo
)
{
// If it already is material, ignore the request.
if
(
!
F
->
hasNotBeenReadFromBytecode
())
return
false
;
DenseMap
<
Function
*
,
std
::
pair
<
uint64_t
,
unsigned
>
>::
iterator
DFII
=
DeferredFunctionInfo
.
find
(
F
);
assert
(
DFII
!=
DeferredFunctionInfo
.
end
()
&&
"Deferred function not found!"
);
// Move the bit stream to the saved position of the deferred function body and
// restore the real linkage type for the function.
Stream
.
JumpToBit
(
DFII
->
second
.
first
);
F
->
setLinkage
((
GlobalValue
::
LinkageTypes
)
DFII
->
second
.
second
);
if
(
ParseFunctionBody
(
F
))
{
if
(
ErrInfo
)
*
ErrInfo
=
ErrorString
;
return
true
;
}
return
false
;
}
void
BitcodeReader
::
dematerializeFunction
(
Function
*
F
)
{
// If this function isn't materialized, or if it is a proto, this is a noop.
if
(
F
->
hasNotBeenReadFromBytecode
()
||
F
->
isDeclaration
())
return
;
assert
(
DeferredFunctionInfo
.
count
(
F
)
&&
"No info to read function later?"
);
// Just forget the function body, we can remat it later.
F
->
deleteBody
();
F
->
setLinkage
(
GlobalValue
::
GhostLinkage
);
}
Module
*
BitcodeReader
::
materializeModule
(
std
::
string
*
ErrInfo
)
{
for
(
DenseMap
<
Function
*
,
std
::
pair
<
uint64_t
,
unsigned
>
>::
iterator
I
=
DeferredFunctionInfo
.
begin
(),
E
=
DeferredFunctionInfo
.
end
();
I
!=
E
;
++
I
)
{
Function
*
F
=
I
->
first
;
if
(
F
->
hasNotBeenReadFromBytecode
()
&&
materializeFunction
(
F
,
ErrInfo
))
return
0
;
}
return
TheModule
;
}
/// This method is provided by the parent ModuleProvde class and overriden
/// here. It simply releases the module from its provided and frees up our
/// state.
/// @brief Release our hold on the generated module
Module
*
BitcodeReader
::
releaseModule
(
std
::
string
*
ErrInfo
)
{
// Since we're losing control of this Module, we must hand it back complete
Module
*
M
=
ModuleProvider
::
releaseModule
(
ErrInfo
);
FreeState
();
return
M
;
}
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// External interface
// External interface
...
@@ -1626,12 +1649,18 @@ Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg){
...
@@ -1626,12 +1649,18 @@ Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg){
R
=
static_cast
<
BitcodeReader
*>
(
getBitcodeModuleProvider
(
Buffer
,
ErrMsg
));
R
=
static_cast
<
BitcodeReader
*>
(
getBitcodeModuleProvider
(
Buffer
,
ErrMsg
));
if
(
!
R
)
return
0
;
if
(
!
R
)
return
0
;
// Read the
whole module, get a pointer to it, tell ModuleProvider not to
// Read
in
the
entire module.
// delete it when its dtor is run.
Module
*
M
=
R
->
materializeModule
(
ErrMsg
);
Module
*
M
=
R
->
releaseModule
(
ErrMsg
);
// Don't let the BitcodeReader dtor delete 'Buffer', regardless of whether
//
Don't let the BitcodeReader dtor delete 'Buffer'
.
//
there was an error
.
R
->
releaseMemoryBuffer
();
R
->
releaseMemoryBuffer
();
// If there was no error, tell ModuleProvider not to delete it when its dtor
// is run.
if
(
M
)
M
=
R
->
releaseModule
(
ErrMsg
);
delete
R
;
delete
R
;
return
M
;
return
M
;
}
}
This diff is collapsed.
Click to expand it.
llvm/lib/Bitcode/Reader/BitcodeReader.h
+
9
−
1
View file @
9eeada94
...
@@ -39,6 +39,10 @@ public:
...
@@ -39,6 +39,10 @@ public:
++
NumOperands
;
++
NumOperands
;
}
}
void
clear
()
{
std
::
vector
<
Use
>
().
swap
(
Uses
);
}
Value
*
operator
[](
unsigned
i
)
const
{
return
getOperand
(
i
);
}
Value
*
operator
[](
unsigned
i
)
const
{
return
getOperand
(
i
);
}
Value
*
back
()
const
{
return
Uses
.
back
();
}
Value
*
back
()
const
{
return
Uses
.
back
();
}
...
@@ -111,8 +115,11 @@ public:
...
@@ -111,8 +115,11 @@ public:
BitcodeReader
(
MemoryBuffer
*
buffer
)
:
Buffer
(
buffer
),
ErrorString
(
0
)
{
BitcodeReader
(
MemoryBuffer
*
buffer
)
:
Buffer
(
buffer
),
ErrorString
(
0
)
{
HasReversedFunctionsWithBodies
=
false
;
HasReversedFunctionsWithBodies
=
false
;
}
}
~
BitcodeReader
();
~
BitcodeReader
()
{
FreeState
();
}
void
FreeState
();
/// releaseMemoryBuffer - This causes the reader to completely forget about
/// releaseMemoryBuffer - This causes the reader to completely forget about
/// the memory buffer it contains, which prevents the buffer from being
/// the memory buffer it contains, which prevents the buffer from being
...
@@ -124,6 +131,7 @@ public:
...
@@ -124,6 +131,7 @@ public:
virtual
bool
materializeFunction
(
Function
*
F
,
std
::
string
*
ErrInfo
=
0
);
virtual
bool
materializeFunction
(
Function
*
F
,
std
::
string
*
ErrInfo
=
0
);
virtual
Module
*
materializeModule
(
std
::
string
*
ErrInfo
=
0
);
virtual
Module
*
materializeModule
(
std
::
string
*
ErrInfo
=
0
);
virtual
void
dematerializeFunction
(
Function
*
F
);
virtual
void
dematerializeFunction
(
Function
*
F
);
virtual
Module
*
releaseModule
(
std
::
string
*
ErrInfo
=
0
);
bool
Error
(
const
char
*
Str
)
{
bool
Error
(
const
char
*
Str
)
{
ErrorString
=
Str
;
ErrorString
=
Str
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment