Skip to content

Commit

Permalink
Pass a reference to ValueEnumerator.
Browse files Browse the repository at this point in the history
NFC. This will just make it easier to use std::unique_ptr in a caller.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222170 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Nov 17, 2014
1 parent 18db81a commit dfeee31
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals);

// Analyze the module, enumerating globals, functions, etc.
ValueEnumerator VE(M);
ValueEnumerator VE(*M);

// Emit blockinfo, which defines the standard abbreviations etc.
WriteBlockInfo(VE, Stream);
Expand Down
67 changes: 33 additions & 34 deletions lib/Bitcode/Writer/ValueEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void orderValue(const Value *V, OrderMap &OM) {
OM.index(V);
}

static OrderMap orderModule(const Module *M) {
static OrderMap orderModule(const Module &M) {
// This needs to match the order used by ValueEnumerator::ValueEnumerator()
// and ValueEnumerator::incorporateFunction().
OrderMap OM;
Expand All @@ -78,14 +78,14 @@ static OrderMap orderModule(const Module *M) {
// directly in predictValueUseListOrderImpl(), just assign IDs to
// initializers of GlobalValues before GlobalValues themselves to model this
// implicitly.
for (const GlobalVariable &G : M->globals())
for (const GlobalVariable &G : M.globals())
if (G.hasInitializer())
if (!isa<GlobalValue>(G.getInitializer()))
orderValue(G.getInitializer(), OM);
for (const GlobalAlias &A : M->aliases())
for (const GlobalAlias &A : M.aliases())
if (!isa<GlobalValue>(A.getAliasee()))
orderValue(A.getAliasee(), OM);
for (const Function &F : *M)
for (const Function &F : M)
if (F.hasPrefixData())
if (!isa<GlobalValue>(F.getPrefixData()))
orderValue(F.getPrefixData(), OM);
Expand All @@ -99,15 +99,15 @@ static OrderMap orderModule(const Module *M) {
// Since GlobalValues never reference each other directly (just through
// initializers), their relative IDs only matter for determining order of
// uses in their initializers.
for (const Function &F : *M)
for (const Function &F : M)
orderValue(&F, OM);
for (const GlobalAlias &A : M->aliases())
for (const GlobalAlias &A : M.aliases())
orderValue(&A, OM);
for (const GlobalVariable &G : M->globals())
for (const GlobalVariable &G : M.globals())
orderValue(&G, OM);
OM.LastGlobalValueID = OM.size();

for (const Function &F : *M) {
for (const Function &F : M) {
if (F.isDeclaration())
continue;
// Here we need to match the union of ValueEnumerator::incorporateFunction()
Expand Down Expand Up @@ -220,7 +220,7 @@ static void predictValueUseListOrder(const Value *V, const Function *F,
predictValueUseListOrder(Op, F, OM, Stack);
}

static UseListOrderStack predictUseListOrder(const Module *M) {
static UseListOrderStack predictUseListOrder(const Module &M) {
OrderMap OM = orderModule(M);

// Use-list orders need to be serialized after all the users have been added
Expand All @@ -233,7 +233,7 @@ static UseListOrderStack predictUseListOrder(const Module *M) {
// We want to visit the functions backward now so we can list function-local
// constants in the last Function they're used in. Module-level constants
// have already been visited above.
for (auto I = M->rbegin(), E = M->rend(); I != E; ++I) {
for (auto I = M.rbegin(), E = M.rend(); I != E; ++I) {
const Function &F = *I;
if (F.isDeclaration())
continue;
Expand All @@ -253,18 +253,18 @@ static UseListOrderStack predictUseListOrder(const Module *M) {

// Visit globals last, since the module-level use-list block will be seen
// before the function bodies are processed.
for (const GlobalVariable &G : M->globals())
for (const GlobalVariable &G : M.globals())
predictValueUseListOrder(&G, nullptr, OM, Stack);
for (const Function &F : *M)
for (const Function &F : M)
predictValueUseListOrder(&F, nullptr, OM, Stack);
for (const GlobalAlias &A : M->aliases())
for (const GlobalAlias &A : M.aliases())
predictValueUseListOrder(&A, nullptr, OM, Stack);
for (const GlobalVariable &G : M->globals())
for (const GlobalVariable &G : M.globals())
if (G.hasInitializer())
predictValueUseListOrder(G.getInitializer(), nullptr, OM, Stack);
for (const GlobalAlias &A : M->aliases())
for (const GlobalAlias &A : M.aliases())
predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack);
for (const Function &F : *M)
for (const Function &F : M)
if (F.hasPrefixData())
predictValueUseListOrder(F.getPrefixData(), nullptr, OM, Stack);

Expand All @@ -275,56 +275,54 @@ static bool isIntOrIntVectorValue(const std::pair<const Value*, unsigned> &V) {
return V.first->getType()->isIntOrIntVectorTy();
}

/// ValueEnumerator - Enumerate module-level information.
ValueEnumerator::ValueEnumerator(const Module *M) {
ValueEnumerator::ValueEnumerator(const Module &M) {
if (shouldPreserveBitcodeUseListOrder())
UseListOrders = predictUseListOrder(M);

// Enumerate the global variables.
for (Module::const_global_iterator I = M->global_begin(),

E = M->global_end(); I != E; ++I)
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
EnumerateValue(I);

// Enumerate the functions.
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
EnumerateValue(I);
EnumerateAttributes(cast<Function>(I)->getAttributes());
}

// Enumerate the aliases.
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
I != E; ++I)
EnumerateValue(I);

// Remember what is the cutoff between globalvalue's and other constants.
unsigned FirstConstant = Values.size();

// Enumerate the global variable initializers.
for (Module::const_global_iterator I = M->global_begin(),
E = M->global_end(); I != E; ++I)
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
if (I->hasInitializer())
EnumerateValue(I->getInitializer());

// Enumerate the aliasees.
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
I != E; ++I)
EnumerateValue(I->getAliasee());

// Enumerate the prefix data constants.
for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
if (I->hasPrefixData())
EnumerateValue(I->getPrefixData());

// Insert constants and metadata that are named at module level into the slot
// pool so that the module symbol table can refer to them...
EnumerateValueSymbolTable(M->getValueSymbolTable());
EnumerateValueSymbolTable(M.getValueSymbolTable());
EnumerateNamedMetadata(M);

SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;

// Enumerate types used by function bodies and argument lists.
for (const Function &F : *M) {
for (const Function &F : M) {
for (const Argument &A : F.args())
EnumerateType(A.getType());

Expand Down Expand Up @@ -465,11 +463,12 @@ void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) {
EnumerateValue(VI->getValue());
}

/// EnumerateNamedMetadata - Insert all of the values referenced by
/// named metadata in the specified module.
void ValueEnumerator::EnumerateNamedMetadata(const Module *M) {
for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
E = M->named_metadata_end(); I != E; ++I)
/// Insert all of the values referenced by named metadata in the specified
/// module.
void ValueEnumerator::EnumerateNamedMetadata(const Module &M) {
for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
E = M.named_metadata_end();
I != E; ++I)
EnumerateNamedMDNode(I);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Bitcode/Writer/ValueEnumerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ValueEnumerator {
ValueEnumerator(const ValueEnumerator &) LLVM_DELETED_FUNCTION;
void operator=(const ValueEnumerator &) LLVM_DELETED_FUNCTION;
public:
ValueEnumerator(const Module *M);
ValueEnumerator(const Module &M);

void dump() const;
void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
Expand Down Expand Up @@ -176,7 +176,7 @@ class ValueEnumerator {
void EnumerateAttributes(AttributeSet PAL);

void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
void EnumerateNamedMetadata(const Module *M);
void EnumerateNamedMetadata(const Module &M);
};

} // End llvm namespace
Expand Down

0 comments on commit dfeee31

Please sign in to comment.