Pass a reference to ValueEnumerator.

NFC. This will just make it easier to use std::unique_ptr in a caller.

llvm-svn: 222170
This commit is contained in:
Rafael Espindola 2014-11-17 20:06:27 +00:00
parent 55635cea27
commit 49e9bf8c74
3 changed files with 36 additions and 37 deletions

View File

@ -1877,7 +1877,7 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals); Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals);
// Analyze the module, enumerating globals, functions, etc. // Analyze the module, enumerating globals, functions, etc.
ValueEnumerator VE(M); ValueEnumerator VE(*M);
// Emit blockinfo, which defines the standard abbreviations etc. // Emit blockinfo, which defines the standard abbreviations etc.
WriteBlockInfo(VE, Stream); WriteBlockInfo(VE, Stream);

View File

@ -68,7 +68,7 @@ static void orderValue(const Value *V, OrderMap &OM) {
OM.index(V); 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() // This needs to match the order used by ValueEnumerator::ValueEnumerator()
// and ValueEnumerator::incorporateFunction(). // and ValueEnumerator::incorporateFunction().
OrderMap OM; OrderMap OM;
@ -78,14 +78,14 @@ static OrderMap orderModule(const Module *M) {
// directly in predictValueUseListOrderImpl(), just assign IDs to // directly in predictValueUseListOrderImpl(), just assign IDs to
// initializers of GlobalValues before GlobalValues themselves to model this // initializers of GlobalValues before GlobalValues themselves to model this
// implicitly. // implicitly.
for (const GlobalVariable &G : M->globals()) for (const GlobalVariable &G : M.globals())
if (G.hasInitializer()) if (G.hasInitializer())
if (!isa<GlobalValue>(G.getInitializer())) if (!isa<GlobalValue>(G.getInitializer()))
orderValue(G.getInitializer(), OM); orderValue(G.getInitializer(), OM);
for (const GlobalAlias &A : M->aliases()) for (const GlobalAlias &A : M.aliases())
if (!isa<GlobalValue>(A.getAliasee())) if (!isa<GlobalValue>(A.getAliasee()))
orderValue(A.getAliasee(), OM); orderValue(A.getAliasee(), OM);
for (const Function &F : *M) for (const Function &F : M)
if (F.hasPrefixData()) if (F.hasPrefixData())
if (!isa<GlobalValue>(F.getPrefixData())) if (!isa<GlobalValue>(F.getPrefixData()))
orderValue(F.getPrefixData(), OM); orderValue(F.getPrefixData(), OM);
@ -99,15 +99,15 @@ static OrderMap orderModule(const Module *M) {
// Since GlobalValues never reference each other directly (just through // Since GlobalValues never reference each other directly (just through
// initializers), their relative IDs only matter for determining order of // initializers), their relative IDs only matter for determining order of
// uses in their initializers. // uses in their initializers.
for (const Function &F : *M) for (const Function &F : M)
orderValue(&F, OM); orderValue(&F, OM);
for (const GlobalAlias &A : M->aliases()) for (const GlobalAlias &A : M.aliases())
orderValue(&A, OM); orderValue(&A, OM);
for (const GlobalVariable &G : M->globals()) for (const GlobalVariable &G : M.globals())
orderValue(&G, OM); orderValue(&G, OM);
OM.LastGlobalValueID = OM.size(); OM.LastGlobalValueID = OM.size();
for (const Function &F : *M) { for (const Function &F : M) {
if (F.isDeclaration()) if (F.isDeclaration())
continue; continue;
// Here we need to match the union of ValueEnumerator::incorporateFunction() // Here we need to match the union of ValueEnumerator::incorporateFunction()
@ -220,7 +220,7 @@ static void predictValueUseListOrder(const Value *V, const Function *F,
predictValueUseListOrder(Op, F, OM, Stack); predictValueUseListOrder(Op, F, OM, Stack);
} }
static UseListOrderStack predictUseListOrder(const Module *M) { static UseListOrderStack predictUseListOrder(const Module &M) {
OrderMap OM = orderModule(M); OrderMap OM = orderModule(M);
// Use-list orders need to be serialized after all the users have been added // Use-list orders need to be serialized after all the users have been added
@ -233,7 +233,7 @@ static UseListOrderStack predictUseListOrder(const Module *M) {
// We want to visit the functions backward now so we can list function-local // 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 // constants in the last Function they're used in. Module-level constants
// have already been visited above. // 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; const Function &F = *I;
if (F.isDeclaration()) if (F.isDeclaration())
continue; continue;
@ -253,18 +253,18 @@ static UseListOrderStack predictUseListOrder(const Module *M) {
// Visit globals last, since the module-level use-list block will be seen // Visit globals last, since the module-level use-list block will be seen
// before the function bodies are processed. // before the function bodies are processed.
for (const GlobalVariable &G : M->globals()) for (const GlobalVariable &G : M.globals())
predictValueUseListOrder(&G, nullptr, OM, Stack); predictValueUseListOrder(&G, nullptr, OM, Stack);
for (const Function &F : *M) for (const Function &F : M)
predictValueUseListOrder(&F, nullptr, OM, Stack); predictValueUseListOrder(&F, nullptr, OM, Stack);
for (const GlobalAlias &A : M->aliases()) for (const GlobalAlias &A : M.aliases())
predictValueUseListOrder(&A, nullptr, OM, Stack); predictValueUseListOrder(&A, nullptr, OM, Stack);
for (const GlobalVariable &G : M->globals()) for (const GlobalVariable &G : M.globals())
if (G.hasInitializer()) if (G.hasInitializer())
predictValueUseListOrder(G.getInitializer(), nullptr, OM, Stack); predictValueUseListOrder(G.getInitializer(), nullptr, OM, Stack);
for (const GlobalAlias &A : M->aliases()) for (const GlobalAlias &A : M.aliases())
predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack); predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack);
for (const Function &F : *M) for (const Function &F : M)
if (F.hasPrefixData()) if (F.hasPrefixData())
predictValueUseListOrder(F.getPrefixData(), nullptr, OM, Stack); predictValueUseListOrder(F.getPrefixData(), nullptr, OM, Stack);
@ -275,25 +275,23 @@ static bool isIntOrIntVectorValue(const std::pair<const Value*, unsigned> &V) {
return V.first->getType()->isIntOrIntVectorTy(); return V.first->getType()->isIntOrIntVectorTy();
} }
/// ValueEnumerator - Enumerate module-level information. ValueEnumerator::ValueEnumerator(const Module &M) {
ValueEnumerator::ValueEnumerator(const Module *M) {
if (shouldPreserveBitcodeUseListOrder()) if (shouldPreserveBitcodeUseListOrder())
UseListOrders = predictUseListOrder(M); UseListOrders = predictUseListOrder(M);
// Enumerate the global variables. // Enumerate the global variables.
for (Module::const_global_iterator I = M->global_begin(), for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
E = M->global_end(); I != E; ++I)
EnumerateValue(I); EnumerateValue(I);
// Enumerate the functions. // 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); EnumerateValue(I);
EnumerateAttributes(cast<Function>(I)->getAttributes()); EnumerateAttributes(cast<Function>(I)->getAttributes());
} }
// Enumerate the aliases. // 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) I != E; ++I)
EnumerateValue(I); EnumerateValue(I);
@ -301,30 +299,30 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
unsigned FirstConstant = Values.size(); unsigned FirstConstant = Values.size();
// Enumerate the global variable initializers. // Enumerate the global variable initializers.
for (Module::const_global_iterator I = M->global_begin(), for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
E = M->global_end(); I != E; ++I) I != E; ++I)
if (I->hasInitializer()) if (I->hasInitializer())
EnumerateValue(I->getInitializer()); EnumerateValue(I->getInitializer());
// Enumerate the aliasees. // 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) I != E; ++I)
EnumerateValue(I->getAliasee()); EnumerateValue(I->getAliasee());
// Enumerate the prefix data constants. // 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()) if (I->hasPrefixData())
EnumerateValue(I->getPrefixData()); EnumerateValue(I->getPrefixData());
// Insert constants and metadata that are named at module level into the slot // Insert constants and metadata that are named at module level into the slot
// pool so that the module symbol table can refer to them... // pool so that the module symbol table can refer to them...
EnumerateValueSymbolTable(M->getValueSymbolTable()); EnumerateValueSymbolTable(M.getValueSymbolTable());
EnumerateNamedMetadata(M); EnumerateNamedMetadata(M);
SmallVector<std::pair<unsigned, MDNode *>, 8> MDs; SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;
// Enumerate types used by function bodies and argument lists. // 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()) for (const Argument &A : F.args())
EnumerateType(A.getType()); EnumerateType(A.getType());
@ -465,11 +463,12 @@ void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) {
EnumerateValue(VI->getValue()); EnumerateValue(VI->getValue());
} }
/// EnumerateNamedMetadata - Insert all of the values referenced by /// Insert all of the values referenced by named metadata in the specified
/// named metadata in the specified module. /// module.
void ValueEnumerator::EnumerateNamedMetadata(const Module *M) { void ValueEnumerator::EnumerateNamedMetadata(const Module &M) {
for (Module::const_named_metadata_iterator I = M->named_metadata_begin(), for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
E = M->named_metadata_end(); I != E; ++I) E = M.named_metadata_end();
I != E; ++I)
EnumerateNamedMDNode(I); EnumerateNamedMDNode(I);
} }

View File

@ -96,7 +96,7 @@ private:
ValueEnumerator(const ValueEnumerator &) LLVM_DELETED_FUNCTION; ValueEnumerator(const ValueEnumerator &) LLVM_DELETED_FUNCTION;
void operator=(const ValueEnumerator &) LLVM_DELETED_FUNCTION; void operator=(const ValueEnumerator &) LLVM_DELETED_FUNCTION;
public: public:
ValueEnumerator(const Module *M); ValueEnumerator(const Module &M);
void dump() const; void dump() const;
void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const; void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
@ -176,7 +176,7 @@ private:
void EnumerateAttributes(AttributeSet PAL); void EnumerateAttributes(AttributeSet PAL);
void EnumerateValueSymbolTable(const ValueSymbolTable &ST); void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
void EnumerateNamedMetadata(const Module *M); void EnumerateNamedMetadata(const Module &M);
}; };
} // End llvm namespace } // End llvm namespace