Mercurial > hg > CbC > CbC_llvm
diff lib/Bitcode/Writer/ValueEnumerator.cpp @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 7d135dc70f03 |
line wrap: on
line diff
--- a/lib/Bitcode/Writer/ValueEnumerator.cpp Wed Feb 18 14:56:07 2015 +0900 +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp Tue Oct 13 17:48:58 2015 +0900 @@ -93,6 +93,9 @@ if (F.hasPrologueData()) if (!isa<GlobalValue>(F.getPrologueData())) orderValue(F.getPrologueData(), OM); + if (F.hasPersonalityFn()) + if (!isa<GlobalValue>(F.getPersonalityFn())) + orderValue(F.getPersonalityFn(), OM); } OM.LastGlobalConstantID = OM.size(); @@ -274,6 +277,8 @@ predictValueUseListOrder(F.getPrefixData(), nullptr, OM, Stack); if (F.hasPrologueData()) predictValueUseListOrder(F.getPrologueData(), nullptr, OM, Stack); + if (F.hasPersonalityFn()) + predictValueUseListOrder(F.getPersonalityFn(), nullptr, OM, Stack); } return Stack; @@ -283,50 +288,53 @@ return V.first->getType()->isIntOrIntVectorTy(); } -ValueEnumerator::ValueEnumerator(const Module &M) - : HasMDString(false), HasMDLocation(false), HasGenericDebugNode(false) { - if (shouldPreserveBitcodeUseListOrder()) +ValueEnumerator::ValueEnumerator(const Module &M, + bool ShouldPreserveUseListOrder) + : HasMDString(false), HasDILocation(false), HasGenericDINode(false), + ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) { + if (ShouldPreserveUseListOrder) UseListOrders = predictUseListOrder(M); // Enumerate the global variables. - for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); - I != E; ++I) - EnumerateValue(I); + for (const GlobalVariable &GV : M.globals()) + EnumerateValue(&GV); // Enumerate the functions. - for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) { - EnumerateValue(I); - EnumerateAttributes(cast<Function>(I)->getAttributes()); + for (const Function & F : M) { + EnumerateValue(&F); + EnumerateAttributes(F.getAttributes()); } // Enumerate the aliases. - for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); - I != E; ++I) - EnumerateValue(I); + for (const GlobalAlias &GA : M.aliases()) + EnumerateValue(&GA); // 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) - if (I->hasInitializer()) - EnumerateValue(I->getInitializer()); + for (const GlobalVariable &GV : M.globals()) + if (GV.hasInitializer()) + EnumerateValue(GV.getInitializer()); // Enumerate the aliasees. - for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); - I != E; ++I) - EnumerateValue(I->getAliasee()); + for (const GlobalAlias &GA : M.aliases()) + EnumerateValue(GA.getAliasee()); // Enumerate the prefix data constants. - for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) - if (I->hasPrefixData()) - EnumerateValue(I->getPrefixData()); + 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->hasPrologueData()) - EnumerateValue(I->getPrologueData()); + if (I->hasPersonalityFn()) + EnumerateValue(I->getPersonalityFn()); // Enumerate the metadata type. // @@ -346,6 +354,11 @@ for (const Argument &A : F.args()) EnumerateType(A.getType()); + // Enumerate metadata attached to this function. + F.getAllMetadata(MDs); + for (const auto &I : MDs) + EnumerateMetadata(I.second); + for (const BasicBlock &BB : F) for (const Instruction &I : BB) { for (const Use &Op : I.operands()) { @@ -373,12 +386,10 @@ for (unsigned i = 0, e = MDs.size(); i != e; ++i) EnumerateMetadata(MDs[i].second); - if (!I.getDebugLoc().isUnknown()) { - MDNode *Scope, *IA; - I.getDebugLoc().getScopeAndInlinedAt(Scope, IA, I.getContext()); - if (Scope) EnumerateMetadata(Scope); - if (IA) EnumerateMetadata(IA); - } + // Don't enumerate the location directly -- it has a special record + // type -- but enumerate its operands. + if (DILocation *L = I.getDebugLoc()) + EnumerateMDNodeOperands(L); } } @@ -463,7 +474,7 @@ void ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned CstEnd) { if (CstStart == CstEnd || CstStart+1 == CstEnd) return; - if (shouldPreserveBitcodeUseListOrder()) + if (ShouldPreserveUseListOrder) // Optimizing constants makes the use-list order difficult to predict. // Disable it for now when trying to preserve the order. return; @@ -501,10 +512,8 @@ /// 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) { @@ -543,8 +552,8 @@ EnumerateValue(C->getValue()); HasMDString |= isa<MDString>(MD); - HasMDLocation |= isa<MDLocation>(MD); - HasGenericDebugNode |= isa<GenericDebugNode>(MD); + HasDILocation |= isa<DILocation>(MD); + HasGenericDINode |= isa<GenericDINode>(MD); // Replace the dummy ID inserted above with the correct one. MDValueMap may // have changed by inserting operands, so we need a fresh lookup here. @@ -680,9 +689,7 @@ // This constant may have operands, make sure to enumerate the types in // them. - for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) { - const Value *Op = C->getOperand(i); - + for (const Value *Op : C->operands()) { // Don't enumerate basic blocks here, this happens as operands to // blockaddress. if (isa<BasicBlock>(Op)) @@ -720,23 +727,20 @@ 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. @@ -750,18 +754,17 @@ 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); } } @@ -788,8 +791,8 @@ 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 @@ -803,3 +806,7 @@ IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs); return getGlobalBasicBlockID(BB); } + +uint64_t ValueEnumerator::computeBitsRequiredForTypeIndicies() const { + return Log2_32_Ceil(getTypes().size() + 1); +}