X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FTransforms%2FScalar%2FSampleProfile.cpp;h=594a7beb2e3965101584877514a9e88875a57a0c;hp=fedbcf3a7c003cbe9285c5ab8359c0c93de9aab3;hb=c128e5c8c203b0f58850cd01b8ba2e19fb4792dc;hpb=da45b2bdbd92af261ca8ff18069fb0a988e5963d diff --git a/lib/Transforms/Scalar/SampleProfile.cpp b/lib/Transforms/Scalar/SampleProfile.cpp index fedbcf3a7c0..594a7beb2e3 100644 --- a/lib/Transforms/Scalar/SampleProfile.cpp +++ b/lib/Transforms/Scalar/SampleProfile.cpp @@ -95,7 +95,7 @@ public: void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesCFG(); - AU.addRequired(); + AU.addRequired(); AU.addRequired(); AU.addRequired(); } @@ -217,13 +217,16 @@ void SampleProfileLoader::printBlockWeight(raw_ostream &OS, BasicBlock *BB) { /// \returns The profiled weight of I. unsigned SampleProfileLoader::getInstWeight(Instruction &Inst) { DebugLoc DLoc = Inst.getDebugLoc(); + if (!DLoc) + return 0; + unsigned Lineno = DLoc.getLine(); if (Lineno < HeaderLineno) return 0; - DILocation DIL(DLoc.getAsMDNode(*Ctx)); + const DILocation *DIL = DLoc; int LOffset = Lineno - HeaderLineno; - unsigned Discriminator = DIL.getDiscriminator(); + unsigned Discriminator = DIL->getDiscriminator(); unsigned Weight = Samples->samplesAt(LOffset, Discriminator); DEBUG(dbgs() << " " << Lineno << "." << Discriminator << ":" << Inst << " (line offset: " << LOffset << "." << Discriminator @@ -305,7 +308,7 @@ void SampleProfileLoader::findEquivalencesFor( for (auto *BB2 : Descendants) { bool IsDomParent = DomTree->dominates(BB2, BB1); bool IsInSameLoop = LI->getLoopFor(BB1) == LI->getLoopFor(BB2); - if (BB1 != BB2 && VisitedBlocks.insert(BB2) && IsDomParent && + if (BB1 != BB2 && VisitedBlocks.insert(BB2).second && IsDomParent && IsInSameLoop) { EquivalenceClass[BB2] = BB1; @@ -494,7 +497,7 @@ bool SampleProfileLoader::propagateThroughEdges(Function &F) { << " known. Set weight for block: "; printBlockWeight(dbgs(), BB);); } - if (VisitedBlocks.insert(BB)) + if (VisitedBlocks.insert(BB).second) Changed = true; } else if (NumUnknownEdges == 1 && VisitedBlocks.count(BB)) { // If there is a single unknown edge and the block has been @@ -540,7 +543,7 @@ void SampleProfileLoader::buildEdges(Function &F) { llvm_unreachable("Found a stale predecessors list in a basic block."); for (pred_iterator PI = pred_begin(B1), PE = pred_end(B1); PI != PE; ++PI) { BasicBlock *B2 = *PI; - if (Visited.insert(B2)) + if (Visited.insert(B2).second) Predecessors[B1].push_back(B2); } @@ -550,7 +553,7 @@ void SampleProfileLoader::buildEdges(Function &F) { llvm_unreachable("Found a stale successors list in a basic block."); for (succ_iterator SI = succ_begin(B1), SE = succ_end(B1); SI != SE; ++SI) { BasicBlock *B2 = *SI; - if (Visited.insert(B2)) + if (Visited.insert(B2).second) Successors[B1].push_back(B2); } } @@ -639,9 +642,8 @@ void SampleProfileLoader::propagateWeights(Function &F) { /// \returns the line number where \p F is defined. If it returns 0, /// it means that there is no debug information available for \p F. unsigned SampleProfileLoader::getFunctionLoc(Function &F) { - DISubprogram S = getDISubprogram(&F); - if (S.isSubprogram()) - return S.getLineNumber(); + if (DISubprogram *S = getDISubprogram(&F)) + return S->getLine(); // If could not find the start of \p F, emit a diagnostic to inform the user // about the missed opportunity. @@ -731,14 +733,20 @@ INITIALIZE_PASS_BEGIN(SampleProfileLoader, "sample-profile", "Sample Profile loader", false, false) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(PostDominatorTree) -INITIALIZE_PASS_DEPENDENCY(LoopInfo) +INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(AddDiscriminators) INITIALIZE_PASS_END(SampleProfileLoader, "sample-profile", "Sample Profile loader", false, false) bool SampleProfileLoader::doInitialization(Module &M) { - Reader.reset(new SampleProfileReader(M, Filename)); - ProfileIsValid = Reader->load(); + auto ReaderOrErr = SampleProfileReader::create(Filename, M.getContext()); + if (std::error_code EC = ReaderOrErr.getError()) { + std::string Msg = "Could not open profile: " + EC.message(); + M.getContext().diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg)); + return false; + } + Reader = std::move(ReaderOrErr.get()); + ProfileIsValid = (Reader->read() == sampleprof_error::success); return true; } @@ -756,7 +764,7 @@ bool SampleProfileLoader::runOnFunction(Function &F) { DT = &getAnalysis().getDomTree(); PDT = &getAnalysis(); - LI = &getAnalysis(); + LI = &getAnalysis().getLoopInfo(); Ctx = &F.getParent()->getContext(); Samples = Reader->getSamplesFor(F); if (!Samples->empty())