aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp')
-rw-r--r--contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp96
1 files changed, 35 insertions, 61 deletions
diff --git a/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
index 44dd604f8823..e07563b5a390 100644
--- a/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -87,15 +87,9 @@ static OrderMap orderModule(const Module &M) {
if (!isa<GlobalValue>(A.getAliasee()))
orderValue(A.getAliasee(), OM);
for (const Function &F : M) {
- if (F.hasPrefixData())
- if (!isa<GlobalValue>(F.getPrefixData()))
- orderValue(F.getPrefixData(), OM);
- if (F.hasPrologueData())
- if (!isa<GlobalValue>(F.getPrologueData()))
- orderValue(F.getPrologueData(), OM);
- if (F.hasPersonalityFn())
- if (!isa<GlobalValue>(F.getPersonalityFn()))
- orderValue(F.getPersonalityFn(), OM);
+ for (const Use &U : F.operands())
+ if (!isa<GlobalValue>(U.get()))
+ orderValue(U.get(), OM);
}
OM.LastGlobalConstantID = OM.size();
@@ -273,12 +267,8 @@ static UseListOrderStack predictUseListOrder(const Module &M) {
for (const GlobalAlias &A : M.aliases())
predictValueUseListOrder(A.getAliasee(), nullptr, OM, Stack);
for (const Function &F : M) {
- if (F.hasPrefixData())
- predictValueUseListOrder(F.getPrefixData(), nullptr, OM, Stack);
- if (F.hasPrologueData())
- predictValueUseListOrder(F.getPrologueData(), nullptr, OM, Stack);
- if (F.hasPersonalityFn())
- predictValueUseListOrder(F.getPersonalityFn(), nullptr, OM, Stack);
+ for (const Use &U : F.operands())
+ predictValueUseListOrder(U.get(), nullptr, OM, Stack);
}
return Stack;
@@ -321,20 +311,10 @@ ValueEnumerator::ValueEnumerator(const Module &M,
for (const GlobalAlias &GA : M.aliases())
EnumerateValue(GA.getAliasee());
- // Enumerate the prefix data constants.
+ // Enumerate any optional Function data.
for (const Function &F : M)
- if (F.hasPrefixData())
- EnumerateValue(F.getPrefixData());
-
- // Enumerate the prologue data constants.
- for (const Function &F : M)
- if (F.hasPrologueData())
- EnumerateValue(F.getPrologueData());
-
- // Enumerate the personality functions.
- for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
- if (I->hasPersonalityFn())
- EnumerateValue(I->getPersonalityFn());
+ for (const Use &U : F.operands())
+ EnumerateValue(U.get());
// Enumerate the metadata type.
//
@@ -425,7 +405,7 @@ unsigned ValueEnumerator::getValueID(const Value *V) const {
void ValueEnumerator::dump() const {
print(dbgs(), ValueMap, "Default");
dbgs() << '\n';
- print(dbgs(), MDValueMap, "MetaData");
+ print(dbgs(), MetadataMap, "MetaData");
dbgs() << '\n';
}
@@ -512,10 +492,8 @@ void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) {
/// 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);
+ for (const auto &I : M.named_metadata())
+ EnumerateNamedMDNode(&I);
}
void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
@@ -544,7 +522,7 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) {
// EnumerateMDNodeOperands() from re-visiting MD in a cyclic graph.
//
// Return early if there's already an ID.
- if (!MDValueMap.insert(std::make_pair(MD, 0)).second)
+ if (!MetadataMap.insert(std::make_pair(MD, 0)).second)
return;
// Visit operands first to minimize RAUW.
@@ -557,10 +535,10 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) {
HasDILocation |= isa<DILocation>(MD);
HasGenericDINode |= isa<GenericDINode>(MD);
- // Replace the dummy ID inserted above with the correct one. MDValueMap may
+ // Replace the dummy ID inserted above with the correct one. MetadataMap may
// have changed by inserting operands, so we need a fresh lookup here.
MDs.push_back(MD);
- MDValueMap[MD] = MDs.size();
+ MetadataMap[MD] = MDs.size();
}
/// EnumerateFunctionLocalMetadataa - Incorporate function-local metadata
@@ -568,12 +546,12 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) {
void ValueEnumerator::EnumerateFunctionLocalMetadata(
const LocalAsMetadata *Local) {
// Check to see if it's already in!
- unsigned &MDValueID = MDValueMap[Local];
- if (MDValueID)
+ unsigned &MetadataID = MetadataMap[Local];
+ if (MetadataID)
return;
MDs.push_back(Local);
- MDValueID = MDs.size();
+ MetadataID = MDs.size();
EnumerateValue(Local->getValue());
@@ -729,23 +707,20 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
NumModuleMDs = MDs.size();
// Adding function arguments to the value table.
- for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end();
- I != E; ++I)
- EnumerateValue(I);
+ for (const auto &I : F.args())
+ EnumerateValue(&I);
FirstFuncConstantID = Values.size();
// Add all function-level constants to the value table.
- for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
- for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I)
- for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
- OI != E; ++OI) {
- if ((isa<Constant>(*OI) && !isa<GlobalValue>(*OI)) ||
- isa<InlineAsm>(*OI))
- EnumerateValue(*OI);
+ for (const BasicBlock &BB : F) {
+ for (const Instruction &I : BB)
+ for (const Use &OI : I.operands()) {
+ if ((isa<Constant>(OI) && !isa<GlobalValue>(OI)) || isa<InlineAsm>(OI))
+ EnumerateValue(OI);
}
- BasicBlocks.push_back(BB);
- ValueMap[BB] = BasicBlocks.size();
+ BasicBlocks.push_back(&BB);
+ ValueMap[&BB] = BasicBlocks.size();
}
// Optimize the constant layout.
@@ -759,18 +734,17 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
SmallVector<LocalAsMetadata *, 8> FnLocalMDVector;
// Add all of the instructions.
- for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
- for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
- for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
- OI != E; ++OI) {
- if (auto *MD = dyn_cast<MetadataAsValue>(&*OI))
+ for (const BasicBlock &BB : F) {
+ for (const Instruction &I : BB) {
+ for (const Use &OI : I.operands()) {
+ if (auto *MD = dyn_cast<MetadataAsValue>(&OI))
if (auto *Local = dyn_cast<LocalAsMetadata>(MD->getMetadata()))
// Enumerate metadata after the instructions they might refer to.
FnLocalMDVector.push_back(Local);
}
- if (!I->getType()->isVoidTy())
- EnumerateValue(I);
+ if (!I.getType()->isVoidTy())
+ EnumerateValue(&I);
}
}
@@ -784,7 +758,7 @@ void ValueEnumerator::purgeFunction() {
for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
ValueMap.erase(Values[i].first);
for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i)
- MDValueMap.erase(MDs[i]);
+ MetadataMap.erase(MDs[i]);
for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
ValueMap.erase(BasicBlocks[i]);
@@ -797,8 +771,8 @@ void ValueEnumerator::purgeFunction() {
static void IncorporateFunctionInfoGlobalBBIDs(const Function *F,
DenseMap<const BasicBlock*, unsigned> &IDMap) {
unsigned Counter = 0;
- for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
- IDMap[BB] = ++Counter;
+ for (const BasicBlock &BB : *F)
+ IDMap[&BB] = ++Counter;
}
/// getGlobalBasicBlockID - This returns the function-specific ID for the