Index: include/llvm/IR/DiagnosticInfo.h =================================================================== --- include/llvm/IR/DiagnosticInfo.h +++ include/llvm/IR/DiagnosticInfo.h @@ -60,6 +60,7 @@ DK_OptimizationRemarkAnalysisAliasing, DK_OptimizationFailure, DK_MIRParser, + DK_PGOProfile, DK_FirstPluginKind }; @@ -250,6 +251,31 @@ const Twine &Msg; }; +/// Diagnostic information for the PGO profiler. +class DiagnosticInfoPGOProfile : public DiagnosticInfo { +public: + DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg, + DiagnosticSeverity Severity = DS_Error) + : DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {} + + /// \see DiagnosticInfo::print. + void print(DiagnosticPrinter &DP) const override; + + static bool classof(const DiagnosticInfo *DI) { + return DI->getKind() == DK_PGOProfile; + } + + const char *getFileName() const { return FileName; } + const Twine &getMsg() const { return Msg; } + +private: + /// Name of the input file associated with this diagnostic. + const char *FileName; + + /// Message to report. + const Twine &Msg; +}; + /// Common features for diagnostics dealing with optimization remarks. class DiagnosticInfoOptimizationBase : public DiagnosticInfo { public: Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -117,6 +117,8 @@ void initializeExpandPostRAPass(PassRegistry&); void initializeAAResultsWrapperPassPass(PassRegistry &); void initializeGCOVProfilerPass(PassRegistry&); +void initializePGOInstrumentationGenPass(PassRegistry&); +void initializePGOInstrumentationUsePass(PassRegistry&); void initializeInstrProfilingPass(PassRegistry&); void initializeAddressSanitizerPass(PassRegistry&); void initializeAddressSanitizerModulePass(PassRegistry&); Index: include/llvm/LinkAllPasses.h =================================================================== --- include/llvm/LinkAllPasses.h +++ include/llvm/LinkAllPasses.h @@ -85,6 +85,8 @@ (void) llvm::createDomOnlyViewerPass(); (void) llvm::createDomViewerPass(); (void) llvm::createGCOVProfilerPass(); + (void) llvm::createPGOInstrumentationGenPass(); + (void) llvm::createPGOInstrumentationUsePass(); (void) llvm::createInstrProfilingPass(); (void) llvm::createFunctionInliningPass(); (void) llvm::createAlwaysInlinerPass(); Index: include/llvm/Transforms/Instrumentation.h =================================================================== --- include/llvm/Transforms/Instrumentation.h +++ include/llvm/Transforms/Instrumentation.h @@ -79,6 +79,11 @@ ModulePass *createGCOVProfilerPass(const GCOVOptions &Options = GCOVOptions::getDefault()); +// PGO Instrumention +ModulePass *createPGOInstrumentationGenPass(); +ModulePass * +createPGOInstrumentationUsePass(StringRef Filename = StringRef("")); + /// Options for the frontend instrumentation based profiling pass. struct InstrProfOptions { InstrProfOptions() : NoRedZone(false) {} @@ -149,6 +154,29 @@ /// protect against stack-based overflow vulnerabilities. FunctionPass *createSafeStackPass(const TargetMachine *TM = nullptr); +/// \brief Calculate what to divide by to scale counts. +/// +/// Given the maximum count, calculate a divisor that will scale all the +/// weights to strictly less than UINT32_MAX. +static inline uint64_t calculateCountScale(uint64_t MaxCount) { + return MaxCount < UINT32_MAX ? 1 : MaxCount / UINT32_MAX + 1; +} + +/// \brief Scale an individual branch count (and add 1). +/// +/// Scale a 64-bit weight down to 32-bits using \c Scale. +/// +/// According to Laplace's Rule of Succession, it is better to compute the +/// count based on the count plus 1, so universally add 1 to the value. +/// +/// \pre \c Scale was calculated by \a calculateCountScale() with a count no +/// greater than \c Count. +static inline uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale) { + uint64_t Scaled = Count / Scale + 1; + assert(Scaled <= UINT32_MAX && "overflow 32-bits"); + return Scaled; +} + } // End llvm namespace #endif Index: lib/IR/DiagnosticInfo.cpp =================================================================== --- lib/IR/DiagnosticInfo.cpp +++ lib/IR/DiagnosticInfo.cpp @@ -132,6 +132,12 @@ DP << getMsg(); } +void DiagnosticInfoPGOProfile::print(DiagnosticPrinter &DP) const { + if (getFileName()) + DP << getFileName() << ": "; + DP << getMsg(); +} + bool DiagnosticInfoOptimizationBase::isLocationAvailable() const { return getDebugLoc(); } Index: lib/Transforms/IPO/LLVMBuild.txt =================================================================== --- lib/Transforms/IPO/LLVMBuild.txt +++ lib/Transforms/IPO/LLVMBuild.txt @@ -20,4 +20,4 @@ name = IPO parent = Transforms library_name = ipo -required_libraries = Analysis Core InstCombine ProfileData Scalar Support TransformUtils Vectorize +required_libraries = Analysis Core InstCombine ProfileData Scalar Support TransformUtils Vectorize Instrumentation Index: lib/Transforms/Instrumentation/CFGMST.h =================================================================== --- /dev/null +++ lib/Transforms/Instrumentation/CFGMST.h @@ -0,0 +1,210 @@ +//===-- CFGMST.h - Minimum Spanning Tree for CFG -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements Union-find algorithm to compute Minimum Spanning Tree +// for a given CFG. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/DenseMap.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/BranchProbability.h" +#include "llvm/Transforms/Utils/BasicBlockUtils.h" +#include "llvm/Analysis/CFG.h" +#include "llvm/Analysis/BranchProbabilityInfo.h" +#include "llvm/Analysis/BlockFrequencyInfo.h" +#include +#include +#include + +namespace llvm { + +#define DEBUG_TYPE "cfgmst" + +template class CFGMST { +public: + Function &F; + + // Store all the edges in CFG. It may contain some stale edges + // when Removed is set. + std::vector> AllEdges; + + // This map records the auxiliary information for each BB. + DenseMap> BBInfos; + + // Find the root group of the G and compress the path from G to the root. + BBInfo *findAndCompressGroup(BBInfo *G) { + if (G->Group != G) + G->Group = findAndCompressGroup(static_cast(G->Group)); + return static_cast(G->Group); + } + + // Union BB1 and BB2 into the same group and return true. + // Returns false if BB1 and BB2 are already in the same group. + bool unionGroups(const BasicBlock *BB1, const BasicBlock *BB2) { + BBInfo *BB1G = findAndCompressGroup(&getBBInfo(BB1)); + BBInfo *BB2G = findAndCompressGroup(&getBBInfo(BB2)); + + if (BB1G == BB2G) + return false; + + // Make the smaller rank tree a direct child or the root of high rank tree. + if (BB1G->Rank < BB2G->Rank) + BB1G->Group = BB2G; + else { + BB2G->Group = BB1G; + // If the ranks are the same, increment root of one tree by one. + if (BB1G->Rank == BB2G->Rank) + BB1G->Rank++; + } + return true; + } + + // Give BB, return the auxiliary information. + BBInfo &getBBInfo(const BasicBlock *BB) const { + auto It = BBInfos.find(BB); + assert(It->second.get() != nullptr); + return *It->second.get(); + } + + // Traverse the CFG using a stack. Find all the edges and assign the weight. + // Edges with large weight will be put into MST first so they are less likely + // to be instrumented. + void buildEdges() { + DEBUG(dbgs() << "Build Edge on " << F.getName() << "\n"); + + const BasicBlock *BB = &(F.getEntryBlock()); + // Add a fake edge to the entry. + addEdge(nullptr, BB, BFI->getEntryFreq()); + + // Special handling for single BB functions. + if (succ_empty(BB)) { + addEdge(BB, nullptr, BFI->getEntryFreq()); + return; + } + + static const uint32_t CriticalEdgeMultiplier = 1000; + + for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { + TerminatorInst *TI = BB->getTerminator(); + uint64_t BBWeight = BFI->getBlockFreq(&*BB).getFrequency(); + uint64_t Weight; + if (int successors = TI->getNumSuccessors()) { + for (uint32_t i = 0; i != successors; ++i) { + BasicBlock *TargetBB = TI->getSuccessor(i); + bool Critical = isCriticalEdge(TI, i); + uint64_t scaleFactor = BBWeight; + if (Critical) { + if (scaleFactor < UINT64_MAX / CriticalEdgeMultiplier) + scaleFactor *= CriticalEdgeMultiplier; + else + scaleFactor = UINT64_MAX; + } + Weight = BPI->getEdgeProbability(&*BB, TargetBB).scale(scaleFactor); + addEdge(&*BB, TargetBB, Weight).IsCritical = Critical; + DEBUG(dbgs() << " Edge: from " << BB->getName() << " to " + << TargetBB->getName() << " w=" << Weight << "\n"); + } + } else { + addEdge(&*BB, nullptr, BBWeight); + DEBUG(dbgs() << " Edge: from " << BB->getName() << " to exit" + << " w = " << BBWeight << "\n"); + } + } + } + + // Sort CFG edges based on its weight. + void sortEdgesByWeight() { + std::sort( + AllEdges.begin(), AllEdges.end(), + [](const std::unique_ptr &lhs, const std::unique_ptr &rhs) { + return lhs->Weight > rhs->Weight; + }); + } + + // Traverse all the edges and compute the Minimum Weight Spanning Tree + // using union-find algorithm. + void computeMinimumSpanningTree() { + // First, put all the critical edge with landing-pad as the Dest to MST. + // This works around the insufficient support of critical edges split + // when destination BB is a landing pad. + for (auto &Ei : AllEdges) { + if (Ei->Removed) + continue; + if (Ei->IsCritical) { + if (Ei->DestBB && Ei->DestBB->isLandingPad()) { + if (unionGroups(Ei->SrcBB, Ei->DestBB)) + Ei->InMST = true; + } + } + } + + for (auto &Ei : AllEdges) { + if (Ei->Removed) + continue; + if (unionGroups(Ei->SrcBB, Ei->DestBB)) + Ei->InMST = true; + } + } + + // Dump the Debug information about the instrumentation. + void dumpEdges(raw_ostream &OS, const StringRef Message = StringRef()) const { + if (!Message.empty()) + OS << Message << "\n"; + OS << " Number of Basic Blocks: " << BBInfos.size() << "\n"; + for (auto &BI : BBInfos) { + const BasicBlock *BB = BI.first; + OS << " BB: " << (BB == nullptr ? "FakeNode" : BB->getName()) << " " + << BI.second->infoString() << "\n"; + } + + OS << " Number of Edges: " << AllEdges.size() + << " (*: Instrument, C: CriticalEdge, -: Removed)\n"; + uint32_t Count = 0; + for (auto &EI : AllEdges) { + OS << " Edge " << Count++ << ": " << getBBInfo(EI->SrcBB).Index << "-->" + << getBBInfo(EI->DestBB).Index << EI->infoString() << "\n"; + }; + } + + // Add an edge to AllEdges with weight W. + Edge &addEdge(const BasicBlock *Src, const BasicBlock *Dest, uint64_t W) { + uint32_t Index = BBInfos.size(); + auto Iter = BBInfos.end(); + bool Inserted; + std::tie(Iter, Inserted) = BBInfos.insert(std::make_pair(Src, nullptr)); + if (Inserted) { + // Newly inserted, update the real info. + Iter->second = std::move(llvm::make_unique(Index)); + Index++; + } + std::tie(Iter, Inserted) = BBInfos.insert(std::make_pair(Dest, nullptr)); + if (Inserted) + // Newly inserted, update the real info. + Iter->second = std::move(llvm::make_unique(Index)); + AllEdges.emplace_back(new Edge(Src, Dest, W)); + return *AllEdges.back(); + } + + BranchProbabilityInfo *BPI; + BlockFrequencyInfo *BFI; + +public: + CFGMST(Function &Func, BranchProbabilityInfo *BPI_ = nullptr, + BlockFrequencyInfo *BFI_ = nullptr) + : F(Func), BPI(BPI_), BFI(BFI_) { + buildEdges(); + sortEdgesByWeight(); + computeMinimumSpanningTree(); + } +}; + +#undef DEBUG_TYPE // "cfgmst" +} // end namespace llvm Index: lib/Transforms/Instrumentation/CMakeLists.txt =================================================================== --- lib/Transforms/Instrumentation/CMakeLists.txt +++ lib/Transforms/Instrumentation/CMakeLists.txt @@ -6,6 +6,7 @@ MemorySanitizer.cpp Instrumentation.cpp InstrProfiling.cpp + PGOInstrumentation.cpp SafeStack.cpp SanitizerCoverage.cpp ThreadSanitizer.cpp Index: lib/Transforms/Instrumentation/Instrumentation.cpp =================================================================== --- lib/Transforms/Instrumentation/Instrumentation.cpp +++ lib/Transforms/Instrumentation/Instrumentation.cpp @@ -60,6 +60,8 @@ initializeAddressSanitizerModulePass(Registry); initializeBoundsCheckingPass(Registry); initializeGCOVProfilerPass(Registry); + initializePGOInstrumentationGenPass(Registry); + initializePGOInstrumentationUsePass(Registry); initializeInstrProfilingPass(Registry); initializeMemorySanitizerPass(Registry); initializeThreadSanitizerPass(Registry); Index: lib/Transforms/Instrumentation/LLVMBuild.txt =================================================================== --- lib/Transforms/Instrumentation/LLVMBuild.txt +++ lib/Transforms/Instrumentation/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Library name = Instrumentation parent = Transforms -required_libraries = Analysis Core MC Support TransformUtils +required_libraries = Analysis Core MC Support TransformUtils ProfileData Index: lib/Transforms/Instrumentation/PGOInstrumentation.cpp =================================================================== --- /dev/null +++ lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -0,0 +1,735 @@ +//===- PGOInstru.cpp - PGO Instrumentation --------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements PGO instrumentation using a minimum spanning tree based +// on the following paper. +// [1] Donald E. Knuth, Francis R. Stevenson. Optimal measurement of points +// for program frequency counts. BIT Numerical Mathematics 1973, Volume 13, +// Issue 3, pp 313-322 +// The idea of the algorithm based on the fact that for each node (except for +// the entry and exit), the sum of incoming edge counts equals the sum of +// outgoing edge counts. The count of edge on spanning tree can be derived from +// those edges not on the spanning tree. Knuth proves this method instruments +// the minimum number of edges. +// +// The minimal spanning tree here is actually a maximum weight tree -- on-tree +// edges have higher frequencies (most likely to execute). The idea is to +// instrument those less frequently executed edges which speeds up the +// instrumented binaries. +// +// This file contains two passes: +// (1) Pass PGOInstrumentationGen which instruments the IR to generate edge +// count profile, and +// (2) Pass PGOInstrumentationUse which reads the edge count profile and +// annotates the branch weight. +// These two passes are mutually exclusive, and they are called at the same +// compilation point (so they see the same IR). For PGOInstrumentationGen, +// the real work is done instrumentOneFunc(). For PGOInstrumentationUse, the +// real work in done in class PGOUseFunc and the profile is opened in module +// level and passed to each PGOUseFunc instance. +// The shared code for PGOInstrumentationGen and PGOInstrumentationUse is put +// in class FuncPGOInstrumentation. +// +// Class PGOEdge represents a CFG edge and some auxiliary information. Class +// BBInfo contains auxiliary information for a BB. These two classes are used +// in PGOGenFunc. Class PGOUseEdge and UseBBInfo are the derived class of +// PGOEdge and BBInfo, respectively. They contains extra data structure used +// in populating profile counters. +// The MST implementation is in Class CFGMST. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Transforms/Instrumentation.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/MDBuilder.h" +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/Pass.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/BranchProbability.h" +#include "llvm/Support/JamCRC.h" +#include "llvm/Transforms/Utils/BasicBlockUtils.h" +#include "llvm/ProfileData/InstrProfReader.h" +#include "llvm/Analysis/CFG.h" +#include "llvm/Analysis/BranchProbabilityInfo.h" +#include "llvm/Analysis/BlockFrequencyInfo.h" +#include +#include +#include +#include "CFGMST.h" + +using namespace llvm; + +#define DEBUG_TYPE "pgo-instr" + +STATISTIC(NumOfPGOInstrument, "Number of edges instrumented."); +STATISTIC(NumOfPGOEdge, "Number of edges."); +STATISTIC(NumOfPGOBB, "Number of basic-blocks."); +STATISTIC(NumOfPGOSplit, "Number of critical edge splits."); +STATISTIC(NumOfPGOFunc, "Number of functions having valid profile counts."); +STATISTIC(NumOfPGOMismatch, "Number of functions having mismatch profile."); +STATISTIC(NumOfPGOMissing, "Number of functions without profile."); + +static cl::opt + PGOProfileFile("pgo-profile-file", cl::init(""), cl::Hidden, + cl::value_desc("filename"), + cl::desc("Specify the path of profile data file")); + +namespace { +class PGOInstrumentationGen : public ModulePass { +public: + static char ID; + + PGOInstrumentationGen() : ModulePass(ID) { + initializePGOInstrumentationGenPass(*PassRegistry::getPassRegistry()); + } + + const char *getPassName() const override { + return "PGOInstrumentationGenPass"; + } + +private: + bool runOnModule(Module &M) override; + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired(); + AU.addRequired(); + } +}; + +class PGOInstrumentationUse : public ModulePass { +public: + static char ID; + + // Provide the profile filename as the parameter. + PGOInstrumentationUse(StringRef Filename = StringRef("")) + : ModulePass(ID), ProfileFileName(Filename) { + if (!PGOProfileFile.empty()) + ProfileFileName = StringRef(PGOProfileFile); + initializePGOInstrumentationUsePass(*PassRegistry::getPassRegistry()); + } + + const char *getPassName() const override { + return "PGOInstrumentationUsePass"; + } + +private: + StringRef ProfileFileName; + std::unique_ptr PGOReader; + bool runOnModule(Module &M) override; + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired(); + AU.addRequired(); + } +}; +} // end anonymous namespace + +char PGOInstrumentationGen::ID = 0; +INITIALIZE_PASS_BEGIN(PGOInstrumentationGen, "pgo-instr-gen", + "PGO instrumentation.", false, false) +INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass) +INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass) +INITIALIZE_PASS_END(PGOInstrumentationGen, "pgo-instr-gen", + "PGO instrumentation.", false, false) + +ModulePass *llvm::createPGOInstrumentationGenPass() { + return new PGOInstrumentationGen(); +} + +char PGOInstrumentationUse::ID = 0; +INITIALIZE_PASS_BEGIN(PGOInstrumentationUse, "pgo-instr-use", + "Read PGO instrumentation profile.", false, false) +INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass) +INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass) +INITIALIZE_PASS_END(PGOInstrumentationUse, "pgo-instr-use", + "Read PGO instrumentation profile.", false, false) + +ModulePass *llvm::createPGOInstrumentationUsePass(StringRef Filename) { + return new PGOInstrumentationUse(Filename); +} + +namespace { +/// \brief An MST based instrumentation for PGO +/// +/// Implements a Minimum Spanning Tree (MST) based instrumentation for PGO +/// in the function level. +// +// This class implements the CFG edges. Note the CFG can be a multi-graph. +struct PGOEdge { + const BasicBlock *SrcBB; + const BasicBlock *DestBB; + uint64_t Weight; + bool InMST; + bool Removed; + bool IsCritical; + PGOEdge(const BasicBlock *Src, const BasicBlock *Dest, unsigned W = 1) + : SrcBB(Src), DestBB(Dest), Weight(W), InMST(false), Removed(false), + IsCritical(false) {} + // Return the information string of an edge. + const std::string infoString() const { + std::string Str = (Removed ? "-" : " "); + Str += (InMST ? " " : "*"); + Str += (IsCritical ? "c" : " "); + Str += " W=" + std::to_string(Weight); + return Str; + } +}; + +// This class stores the auxiliary information for each BB. +struct BBInfo { + BBInfo *Group; + uint32_t Index; + uint32_t Rank; + + BBInfo(unsigned IX) : Group(this), Index(IX), Rank(0) {} + + // Return the information string of this object. + const std::string infoString() const { + return "Index=" + std::to_string(Index); + } +}; + +// This class implements the CFG edges. Note the CFG can be a multi-graph. +template class FuncPGOInstrumentation { +private: + Function &F; + void computeCFGHash(); + +public: + std::string FuncName; + GlobalVariable *FuncNameVar; + // CFG hash value for this function. + uint64_t FunctionHash; + + // The Minimum Spanning Tree of function CFG. + CFGMST MST; + + // Give an edge, find the BB that will be instrumented. + // Return nullptr if there is no BB to be instrumented. + BasicBlock *getInstrBB(Edge *E); + + // Return the auxiliary BB information. + BBInfo &getBBInfo(const BasicBlock *BB) const { return MST.getBBInfo(BB); } + + // Dump edges and BB information. + void dumpInfo(std::string Str = "") const { + std::string Message = "Dump Function " + FuncName + " Hash: " + + std::to_string(FunctionHash) + "\t" + Str; + MST.dumpEdges(dbgs(), Message); + } + + FuncPGOInstrumentation(Function &Func, bool CreateGlobalVar = false, + BranchProbabilityInfo *BPI_ = nullptr, + BlockFrequencyInfo *BFI_ = nullptr) + : F(Func), FunctionHash(0), MST(F, BPI_, BFI_) { + FuncName = getPGOFuncName(F); + computeCFGHash(); + DEBUG(dumpInfo("after CFGMST")); + + NumOfPGOBB += MST.BBInfos.size(); + for (auto &Ei : MST.AllEdges) { + if (Ei->Removed) + continue; + NumOfPGOEdge++; + if (!Ei->InMST) + NumOfPGOInstrument++; + } + + if (CreateGlobalVar) + FuncNameVar = createPGOFuncNameVar(F, FuncName); + }; +}; + +// Compute Hash value for the CFG: the lower 32 bits are CRC32 of the index +// value of each BB in the CFG. The higher 32 bits record the number of edges. +template +void FuncPGOInstrumentation::computeCFGHash() { + std::vector Indexes; + JamCRC JC; + for (auto &BB : F) { + const TerminatorInst *TI = BB.getTerminator(); + for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) { + BasicBlock *Succ = TI->getSuccessor(s); + uint32_t Index = getBBInfo(Succ).Index; + for (int i = 0; i < sizeof(uint32_t) / sizeof(char); i++) + Indexes.push_back((char)(Index >> (i * sizeof(char)))); + } + } + JC.update(Indexes); + FunctionHash = MST.AllEdges.size() << 32 | JC.getCRC(); +} + +template +BasicBlock *FuncPGOInstrumentation::getInstrBB(Edge *E) { + if (E->InMST || E->Removed) + return nullptr; + + BasicBlock *SrcBB = const_cast(E->SrcBB); + BasicBlock *DestBB = const_cast(E->DestBB); + // For a fake edge, instrument the real BB. + if (SrcBB == nullptr) + return DestBB; + if (DestBB == nullptr) + return SrcBB; + + // Instrument the SrcBB if it has a single successor, + // otherwise, the DestBB if this is not a critical edge. + TerminatorInst *TI = SrcBB->getTerminator(); + if (TI->getNumSuccessors() <= 1) + return SrcBB; + if (!E->IsCritical) + return DestBB; + + // For a critical edge, we have to split. Instrument the newly + // created BB. + NumOfPGOSplit++; + DEBUG(dbgs() << "Split critical edge: " << getBBInfo(SrcBB).Index << " --> " + << getBBInfo(DestBB).Index << "\n"); + unsigned SuccNum = GetSuccessorNumber(SrcBB, DestBB); + BasicBlock *InstrBB = SplitCriticalEdge(TI, SuccNum); + assert(InstrBB && "Critical edge is not split"); + + E->Removed = true; + return InstrBB; +} + +#if 0 +class PGOGenFunc { +private: + Module *M; + // This member stores the shared information with class PGOUseFunc. + FuncPGOInstrumentation FuncInfo; + +public: + PGOGenFunc(Function &Func, Module *Modu, BranchProbabilityInfo *BPI_, + BlockFrequencyInfo *BFI_) + : M(Modu), FuncInfo(Func, true, BPI_, BFI_) {} + + // Add the instrumentation intrinsic calls. +// void instrumentCFG(); +}; +#endif + +// Visit all edge and instrument the edges not in MST. +// Critical edges will be split. +static void instrumentOneFunc(Function &F, Module *M, + BranchProbabilityInfo *BPI, + BlockFrequencyInfo *BFI) { + unsigned NumCounters = 0; + FuncPGOInstrumentation FuncInfo(F, true, BPI, BFI); + for (auto &Ei : FuncInfo.MST.AllEdges) { + if (!Ei->InMST && !Ei->Removed) + NumCounters++; + } + + uint32_t j = 0; + for (auto &Ei : FuncInfo.MST.AllEdges) { + BasicBlock *InstrBB = FuncInfo.getInstrBB(Ei.get()); + if (!InstrBB) + continue; + + IRBuilder<> Builder(InstrBB, InstrBB->getFirstInsertionPt()); + assert(Builder.GetInsertPoint() != InstrBB->end() && + "Cannot get the Instrumentation point"); + auto *I8PtrTy = Type::getInt8PtrTy(M->getContext()); + Builder.CreateCall( + Intrinsic::getDeclaration(M, Intrinsic::instrprof_increment), + {llvm::ConstantExpr::getBitCast(FuncInfo.FuncNameVar, I8PtrTy), + Builder.getInt64(FuncInfo.FunctionHash), Builder.getInt32(NumCounters), + Builder.getInt32(j++)}); + } +} + +struct PGOUseEdge : public PGOEdge { + bool CountValid; + uint64_t CountValue; + PGOUseEdge(const BasicBlock *Src, const BasicBlock *Dest, unsigned W = 1) + : PGOEdge(Src, Dest, W), CountValid(false), CountValue(0) {} + + // Set edge count value + void setEdgeCount(uint64_t Value) { + CountValue = Value; + CountValid = true; + } + + // Return the information string for this object. + const std::string infoString() const { + if (!CountValid) + return PGOEdge::infoString(); + return PGOEdge::infoString() + " Count=" + std::to_string(CountValue); + } +}; + +typedef SmallVector DirectEdges; + +// This class stores the auxiliary information for each BB. +struct UseBBInfo : public BBInfo { + uint64_t CountValue; + bool CountValid; + int32_t UnknownCountInEdge; + int32_t UnknownCountOutEdge; + DirectEdges InEdges; + DirectEdges OutEdges; + UseBBInfo(unsigned IX) + : BBInfo(IX), CountValue(0), CountValid(false), UnknownCountInEdge(0), + UnknownCountOutEdge(0) {} + UseBBInfo(unsigned IX, uint64_t C) + : BBInfo(IX), CountValue(C), CountValid(true), UnknownCountInEdge(0), + UnknownCountOutEdge(0) {} + + // Set the profile count value for this BB. + void setBBInfoCount(uint64_t Value) { + CountValue = Value; + CountValid = true; + } + + // Return the information string of this object. + const std::string infoString() const { + if (!CountValid) + return BBInfo::infoString(); + return BBInfo::infoString() + " Count=" + std::to_string(CountValue); + } +}; + +// Sum up the count values for all the edges. +static uint64_t sumEdgeCount(const ArrayRef Edges) { + uint64_t Total = 0; + for (auto &Ei : Edges) { + if (Ei->Removed) + continue; + Total += Ei->CountValue; + } + return Total; +} + +class PGOUseFunc { +private: + Function &F; + Module *M; + // This member stores the shared information with class PGOGenFunc. + FuncPGOInstrumentation FuncInfo; + + // Return the auxiliary BB information. + UseBBInfo &getBBInfo(const BasicBlock *BB) const { + return FuncInfo.getBBInfo(BB); + } + + // The maximum count value in the profile. This is only used in PGO use + // compilation. + uint64_t ProgramMaxCount; + + // Find the Instrumented BB and set the value. + void setInstrumentedCounts(const std::vector &CountFromProfile); + + // Set the edge counter value for the unknown edge -- there should be only + // one unknown edge. + void setEdgeCount(DirectEdges &Edges, uint64_t Value); + + // Return FuncName string; + const std::string getFuncName() const { return FuncInfo.FuncName; } + + // Set the hot/cold inline hints based on the count values. + void applyFunctionAttributes(uint64_t EntryCount, uint64_t MaxCount) { + if (ProgramMaxCount == 0) + return; + // Threshold of the hot functions. + const BranchProbability HotFunctionThreshold(1, 100); + // Threshold of the cold functions. + const BranchProbability ColdFunctionThreshold(2, 10000); + if (EntryCount >= HotFunctionThreshold.scale(ProgramMaxCount)) + F.addFnAttr(llvm::Attribute::InlineHint); + else if (MaxCount <= ColdFunctionThreshold.scale(ProgramMaxCount)) + F.addFnAttr(llvm::Attribute::Cold); + } + +public: + PGOUseFunc(Function &Func, Module *Modu, + BranchProbabilityInfo *BPI_ = nullptr, + BlockFrequencyInfo *BFI_ = nullptr) + : F(Func), M(Modu), FuncInfo(Func, false, BPI_, BFI_) {} + + // Read counts for the instrumented BB from profile. + bool readCounters(IndexedInstrProfReader *PGOReader); + + // Populate the counts for all BBs. + void populateCounters(); + + // Set the branch weights based on the count values. + void setBranchWeights(); +}; + +// Visit all the edges and assign the count value for the instrumented +// edges and the BB. +void PGOUseFunc::setInstrumentedCounts( + const std::vector &CountFromProfile) { + + // Use a worklist as we will update the vector during the iteration. + std::vector WorkList; + for (auto &Ei : FuncInfo.MST.AllEdges) + WorkList.push_back(Ei.get()); + + uint32_t j = 0; + for (auto &Ei : WorkList) { + BasicBlock *InstrBB = FuncInfo.getInstrBB(Ei); + if (!InstrBB) + continue; + uint64_t CountValue = CountFromProfile[j++]; + if (!Ei->Removed) { + getBBInfo(InstrBB).setBBInfoCount(CountValue); + Ei->setEdgeCount(CountValue); + continue; + } + + // Need to add two new edges. + BasicBlock *SrcBB = const_cast(Ei->SrcBB); + BasicBlock *DestBB = const_cast(Ei->DestBB); + // Add new edge of SrcBB->InstrBB. + PGOUseEdge &NewEdge = FuncInfo.MST.addEdge(SrcBB, InstrBB, 0); + NewEdge.setEdgeCount(CountValue); + // Add new edge of InstrBB->DestBB. + PGOUseEdge &NewEdge1 = FuncInfo.MST.addEdge(InstrBB, DestBB, 0); + NewEdge1.setEdgeCount(CountValue); + NewEdge1.InMST = true; + getBBInfo(InstrBB).setBBInfoCount(CountValue); + } +} + +// Set the count value for the unknown edges. There should be one and only one +// unknown edge in Edges vector. +void PGOUseFunc::setEdgeCount(DirectEdges &Edges, uint64_t Value) { + for (auto &Ei : Edges) { + if (Ei->CountValid) + continue; + Ei->setEdgeCount(Value); + + getBBInfo(Ei->SrcBB).UnknownCountOutEdge--; + getBBInfo(Ei->DestBB).UnknownCountInEdge--; + return; + } + llvm_unreachable("Cannot find the unknown count edge"); +} + +// Read the profile from ProfileFileName and assign the value to the +// instrumented BB and the edges. This function also updates ProgramMaxCount. +// Return true if the profile are successfully read, and false on errors. +bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) { + auto &Ctx = M->getContext(); + ErrorOr Result = + PGOReader->getInstrProfRecord(FuncInfo.FuncName, FuncInfo.FunctionHash); + if (std::error_code EC = Result.getError()) { + if (EC == instrprof_error::unknown_function) + NumOfPGOMissing++; + else if (EC == instrprof_error::hash_mismatch || + EC == llvm::instrprof_error::malformed) + NumOfPGOMismatch++; + + std::string Msg = EC.message() + std::string(" ") + F.getName().str(); + Ctx.diagnose( + DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning)); + return false; + } + std::vector &CountFromProfile = Result.get().Counts; + + NumOfPGOFunc++; + DEBUG(dbgs() << CountFromProfile.size() << " counts\n"); + uint64_t ValueSum = 0; + for (unsigned i = 0, e = CountFromProfile.size(); i < e; i++) { + DEBUG(dbgs() << " " << i << ": " << CountFromProfile[i] << "\n"); + ValueSum += CountFromProfile[i]; + } + + DEBUG(dbgs() << "SUM = " << ValueSum << "\n"); + + getBBInfo(nullptr).UnknownCountOutEdge = 2; + getBBInfo(nullptr).UnknownCountInEdge = 2; + + setInstrumentedCounts(CountFromProfile); + ProgramMaxCount = PGOReader->getMaximumFunctionCount(); + return true; +} + +// Populate the counters from instrumented BBs to all BBs. +// In the end of this operation, all BBs should have a valid count value. +void PGOUseFunc::populateCounters() { + // First set up Count variable for all BBs. + for (auto &Ei : FuncInfo.MST.AllEdges) { + if (Ei->Removed) + continue; + + const BasicBlock *SrcBB = Ei->SrcBB; + const BasicBlock *DestBB = Ei->DestBB; + UseBBInfo &SrcInfo = getBBInfo(SrcBB); + UseBBInfo &DestInfo = getBBInfo(DestBB); + SrcInfo.OutEdges.push_back(Ei.get()); + DestInfo.InEdges.push_back(Ei.get()); + SrcInfo.UnknownCountOutEdge++; + DestInfo.UnknownCountInEdge++; + + if (!Ei->CountValid) + continue; + DestInfo.UnknownCountInEdge--; + SrcInfo.UnknownCountOutEdge--; + } + + bool Changes = true; + unsigned NumPasses = 0; + while (Changes) { + NumPasses++; + Changes = false; + + // For efficient traversal, it's better to start from the end as most + // of the instrumented edges are at the end. + for (auto &BB : reverse(F)) { + UseBBInfo &Count = getBBInfo(&BB); + if (!Count.CountValid) { + if (Count.UnknownCountOutEdge == 0) { + Count.CountValue = sumEdgeCount(Count.OutEdges); + Count.CountValid = true; + Changes = true; + } else if (Count.UnknownCountInEdge == 0) { + Count.CountValue = sumEdgeCount(Count.InEdges); + Count.CountValid = true; + Changes = true; + } + } + if (Count.CountValid) { + if (Count.UnknownCountOutEdge == 1) { + uint64_t Total = Count.CountValue - sumEdgeCount(Count.OutEdges); + setEdgeCount(Count.OutEdges, Total); + Changes = true; + } + if (Count.UnknownCountInEdge == 1) { + uint64_t Total = Count.CountValue - sumEdgeCount(Count.InEdges); + setEdgeCount(Count.InEdges, Total); + Changes = true; + } + } + } + } + + DEBUG(dbgs() << "Populate counts in " << NumPasses << " passes.\n"); + // Assert every BB has a valid counter. + uint64_t FuncEntryCount = getBBInfo(&*F.begin()).CountValue; + uint64_t FuncMaxCount = FuncEntryCount; + for (auto &BB : F) { + assert(getBBInfo(&BB).CountValid && "BB count is not valid"); + uint64_t Count = getBBInfo(&BB).CountValue; + if (Count > FuncMaxCount) + FuncMaxCount = Count; + } + applyFunctionAttributes(FuncEntryCount, FuncMaxCount); + + DEBUG(FuncInfo.dumpInfo("after reading profile.")); +} + +// Assign the scaled count values to the BB with multiple out edges. +void PGOUseFunc::setBranchWeights() { + // Generate MD_prof metadata for every branch instruction. + DEBUG(dbgs() << "\nSetting branch weights.\n"); + MDBuilder MDB(M->getContext()); + for (auto &BB : F) { + TerminatorInst *TI = BB.getTerminator(); + if (TI->getNumSuccessors() < 2) + continue; + if (!isa(TI) && !isa(TI)) + continue; + if (getBBInfo(&BB).CountValue == 0) + continue; + + // We have a non-zero Branch BB. + const UseBBInfo &BBCountInfo = getBBInfo(&BB); + unsigned Size = BBCountInfo.OutEdges.size(); + SmallVector EdgeCounts(Size, 0); + uint64_t MaxCount = 0; + for (unsigned s = 0; s < Size; s++) { + const PGOUseEdge *E = BBCountInfo.OutEdges[s]; + const BasicBlock *SrcBB = E->SrcBB; + const BasicBlock *DestBB = E->DestBB; + if (DestBB == 0) + continue; + unsigned SuccNum = GetSuccessorNumber(SrcBB, DestBB); + uint64_t EdgeCount = E->CountValue; + if (EdgeCount > MaxCount) + MaxCount = EdgeCount; + EdgeCounts[SuccNum] = EdgeCount; + } + assert(MaxCount > 0 && "Bad max count"); + uint64_t Scale = calculateCountScale(MaxCount); + SmallVector Weights; + for (const auto &ECI : EdgeCounts) + Weights.push_back(scaleBranchCount(ECI, Scale)); + + TI->setMetadata(llvm::LLVMContext::MD_prof, + MDB.createBranchWeights(Weights)); + DEBUG(dbgs() << "Weight is: "; for (const auto &W + : Weights) dbgs() + << W << " "; + dbgs() << "\n";); + } +} +} // end anonymous namespace + +bool PGOInstrumentationGen::runOnModule(Module &M) { + for (auto &F : M) { + if (F.isDeclaration()) + continue; + BranchProbabilityInfo *BPI = + &(getAnalysis(F).getBPI()); + BlockFrequencyInfo *BFI = + &(getAnalysis(F).getBFI()); + instrumentOneFunc(F, &M, BPI, BFI); + } + return true; +} + +static void setPGOCountOnFunc(PGOUseFunc &Func, + IndexedInstrProfReader *PGOReader) { + if (Func.readCounters(PGOReader)) { + Func.populateCounters(); + Func.setBranchWeights(); + } +} + +bool PGOInstrumentationUse::runOnModule(Module &M) { + DEBUG(dbgs() << "Read in profile counters: "); + auto &Ctx = M.getContext(); + // Read the counter array from file. + auto ReaderOrErr = IndexedInstrProfReader::create(ProfileFileName); + if (std::error_code EC = ReaderOrErr.getError()) { + Ctx.diagnose( + DiagnosticInfoPGOProfile(ProfileFileName.data(), EC.message())); + return false; + } + + PGOReader = std::move(ReaderOrErr.get()); + if (!PGOReader) { + Ctx.diagnose(DiagnosticInfoPGOProfile(ProfileFileName.data(), + "Cannot get PGOReader")); + return false; + } + + for (auto &F : M) { + if (F.isDeclaration()) + continue; + BranchProbabilityInfo *BPI = + &(getAnalysis(F).getBPI()); + BlockFrequencyInfo *BFI = + &(getAnalysis(F).getBFI()); + PGOUseFunc Func(F, &M, BPI, BFI); + setPGOCountOnFunc(Func, PGOReader.get()); + } + return true; +} Index: test/Transforms/PGOProfile/Inputs/bad.profdata =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/Inputs/bad.profdata @@ -0,0 +1 @@ +BAD Index: test/Transforms/PGOProfile/test_exception_gen.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_exception_gen.ll @@ -0,0 +1,165 @@ +; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@val = global i32 0, align 4 +@_ZTIi = external constant i8* +@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 +; CHECK: @__llvm_profile_name__Z3bari = private constant [7 x i8] c"_Z3bari" +; CHECK: @__llvm_profile_name__Z3fooi = private constant [7 x i8] c"_Z3fooi" +; CHECK: @__llvm_profile_name_main = private constant [4 x i8] c"main" + +; Function Attrs: noinline uwtable +define i32 @_Z3bari(i32 %i) #0 { +entry: + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %rem = srem i32 %tmp, 3 + %tobool = icmp ne i32 %rem, 0 + br i1 %tobool, label %if.then, label %if.end + +if.then: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3bari, i32 0, i32 0), i64 23319865734, i32 2, i32 1) + %exception = call i8* @__cxa_allocate_exception(i64 4) #4 + %tmp1 = bitcast i8* %exception to i32* + %tmp2 = load i32, i32* %i.addr, align 4 + store i32 %tmp2, i32* %tmp1, align 16 + call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #5 + unreachable + +if.end: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3bari, i32 0, i32 0), i64 23319865734, i32 2, i32 0) + ret i32 0 +} + +declare i8* @__cxa_allocate_exception(i64) + +declare void @__cxa_throw(i8*, i8*, i8*) + +; Function Attrs: noinline uwtable +define i32 @_Z3fooi(i32 %i) #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + %i.addr = alloca i32, align 4 + %exn.slot = alloca i8* + %ehselector.slot = alloca i32 + %e = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %rem = srem i32 %tmp, 2 + %tobool = icmp ne i32 %rem, 0 + br i1 %tobool, label %if.then, label %if.end + +if.then: ; preds = %entry + %tmp1 = load i32, i32* %i.addr, align 4 + %mul = mul nsw i32 %tmp1, 7 + %call = invoke i32 @_Z3bari(i32 %mul) + to label %invoke.cont unwind label %lpad + +invoke.cont: ; preds = %if.then +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3fooi, i32 0, i32 0), i64 57451243578, i32 4, i32 1) + br label %if.end + +lpad: ; preds = %if.then + %tmp2 = landingpad { i8*, i32 } + catch i8* bitcast (i8** @_ZTIi to i8*) + %tmp3 = extractvalue { i8*, i32 } %tmp2, 0 + store i8* %tmp3, i8** %exn.slot, align 8 + %tmp4 = extractvalue { i8*, i32 } %tmp2, 1 + store i32 %tmp4, i32* %ehselector.slot, align 4 + br label %catch.dispatch + +catch.dispatch: ; preds = %lpad + %sel = load i32, i32* %ehselector.slot, align 4 + %tmp5 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #4 + %matches = icmp eq i32 %sel, %tmp5 + br i1 %matches, label %catch, label %eh.resume + +catch: ; preds = %catch.dispatch +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3fooi, i32 0, i32 0), i64 57451243578, i32 4, i32 2) + %exn = load i8*, i8** %exn.slot, align 8 + %tmp6 = call i8* @__cxa_begin_catch(i8* %exn) #4 + %tmp7 = bitcast i8* %tmp6 to i32* + %tmp8 = load i32, i32* %tmp7, align 4 + store i32 %tmp8, i32* %e, align 4 + %tmp9 = load i32, i32* %e, align 4 + %tmp10 = load i32, i32* @val, align 4 + %sub = sub nsw i32 %tmp10, %tmp9 + store i32 %sub, i32* @val, align 4 + call void @__cxa_end_catch() #4 + br label %try.cont + +try.cont: ; preds = %if.end, %catch + ret i32 -1 + +if.end: ; preds = %invoke.cont, %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3fooi, i32 0, i32 0), i64 57451243578, i32 4, i32 0) + %tmp11 = load i32, i32* %i.addr, align 4 + %tmp12 = load i32, i32* @val, align 4 + %add = add nsw i32 %tmp12, %tmp11 + store i32 %add, i32* @val, align 4 + br label %try.cont + +eh.resume: ; preds = %catch.dispatch +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3fooi, i32 0, i32 0), i64 57451243578, i32 4, i32 3) + %exn.1 = load i8*, i8** %exn.slot, align 8 + %sel.2 = load i32, i32* %ehselector.slot, align 4 + %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn.1, 0 + %lpad.val.3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel.2, 1 + resume { i8*, i32 } %lpad.val.3 +} + +declare i32 @__gxx_personality_v0(...) + +; Function Attrs: nounwind readnone +declare i32 @llvm.eh.typeid.for(i8*) #1 + +declare i8* @__cxa_begin_catch(i8*) + +declare void @__cxa_end_catch() + +; Function Attrs: norecurse uwtable +define i32 @main() #2 { +entry: + %retval = alloca i32, align 4 + %i = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + store i32 1, i32* %i, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %tmp = load i32, i32* %i, align 4 + %cmp = icmp slt i32 %tmp, 6 + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + %tmp1 = load i32, i32* %i, align 4 + %call = call i32 @_Z3fooi(i32 %tmp1) + br label %for.inc + +for.inc: ; preds = %for.body +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 32052181608, i32 2, i32 0) + %tmp2 = load i32, i32* %i, align 4 + %inc = add nsw i32 %tmp2, 1 + store i32 %inc, i32* %i, align 4 + br label %for.cond + +for.end: ; preds = %for.cond +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 32052181608, i32 2, i32 1) + %tmp3 = load i32, i32* @val, align 4 + %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %tmp3) + ret i32 0 +} + +declare i32 @printf(i8*, ...) #3 + +attributes #0 = { noinline uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } +attributes #2 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #4 = { nounwind } +attributes #5 = { noreturn } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} Index: test/Transforms/PGOProfile/test_exception_use.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_exception_use.ll @@ -0,0 +1,162 @@ +; RUN: opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/test_exception.profdata -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@val = global i32 0, align 4 +@_ZTIi = external constant i8* +@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 + +; Function Attrs: noinline uwtable +define i32 @_Z3bari(i32 %i) #0 { +entry: + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %rem = srem i32 %tmp, 3 + %tobool = icmp ne i32 %rem, 0 + br i1 %tobool, label %if.then, label %if.end +; CHECK: !prof !1 + +if.then: ; preds = %entry + %exception = call i8* @__cxa_allocate_exception(i64 4) #4 + %tmp1 = bitcast i8* %exception to i32* + %tmp2 = load i32, i32* %i.addr, align 4 + store i32 %tmp2, i32* %tmp1, align 16 + call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #5 + unreachable + +if.end: ; preds = %entry + ret i32 0 +} + +declare i8* @__cxa_allocate_exception(i64) + +declare void @__cxa_throw(i8*, i8*, i8*) + +; Function Attrs: noinline uwtable +define i32 @_Z3fooi(i32 %i) #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + %i.addr = alloca i32, align 4 + %exn.slot = alloca i8* + %ehselector.slot = alloca i32 + %e = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %rem = srem i32 %tmp, 2 + %tobool = icmp ne i32 %rem, 0 + br i1 %tobool, label %if.then, label %if.end +; CHECK: !prof !2 + +if.then: ; preds = %entry + %tmp1 = load i32, i32* %i.addr, align 4 + %mul = mul nsw i32 %tmp1, 7 + %call = invoke i32 @_Z3bari(i32 %mul) + to label %invoke.cont unwind label %lpad + +invoke.cont: ; preds = %if.then + br label %if.end + +lpad: ; preds = %if.then + %tmp2 = landingpad { i8*, i32 } + catch i8* bitcast (i8** @_ZTIi to i8*) + %tmp3 = extractvalue { i8*, i32 } %tmp2, 0 + store i8* %tmp3, i8** %exn.slot, align 8 + %tmp4 = extractvalue { i8*, i32 } %tmp2, 1 + store i32 %tmp4, i32* %ehselector.slot, align 4 + br label %catch.dispatch + +catch.dispatch: ; preds = %lpad + %sel = load i32, i32* %ehselector.slot, align 4 + %tmp5 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #4 + %matches = icmp eq i32 %sel, %tmp5 + br i1 %matches, label %catch, label %eh.resume +; CHECK: !prof !3 + +catch: ; preds = %catch.dispatch + %exn = load i8*, i8** %exn.slot, align 8 + %tmp6 = call i8* @__cxa_begin_catch(i8* %exn) #4 + %tmp7 = bitcast i8* %tmp6 to i32* + %tmp8 = load i32, i32* %tmp7, align 4 + store i32 %tmp8, i32* %e, align 4 + %tmp9 = load i32, i32* %e, align 4 + %tmp10 = load i32, i32* @val, align 4 + %sub = sub nsw i32 %tmp10, %tmp9 + store i32 %sub, i32* @val, align 4 + call void @__cxa_end_catch() #4 + br label %try.cont + +try.cont: ; preds = %if.end, %catch + ret i32 -1 + +if.end: ; preds = %invoke.cont, %entry + %tmp11 = load i32, i32* %i.addr, align 4 + %tmp12 = load i32, i32* @val, align 4 + %add = add nsw i32 %tmp12, %tmp11 + store i32 %add, i32* @val, align 4 + br label %try.cont + +eh.resume: ; preds = %catch.dispatch + %exn.1 = load i8*, i8** %exn.slot, align 8 + %sel.2 = load i32, i32* %ehselector.slot, align 4 + %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn.1, 0 + %lpad.val.3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel.2, 1 + resume { i8*, i32 } %lpad.val.3 +} + +declare i32 @__gxx_personality_v0(...) + +; Function Attrs: nounwind readnone +declare i32 @llvm.eh.typeid.for(i8*) #1 + +declare i8* @__cxa_begin_catch(i8*) + +declare void @__cxa_end_catch() + +; Function Attrs: norecurse uwtable +define i32 @main() #2 { +entry: + %retval = alloca i32, align 4 + %i = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + store i32 1, i32* %i, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %tmp = load i32, i32* %i, align 4 + %cmp = icmp slt i32 %tmp, 6 + br i1 %cmp, label %for.body, label %for.end +; CHECK: !prof !4 + +for.body: ; preds = %for.cond + %tmp1 = load i32, i32* %i, align 4 + %call = call i32 @_Z3fooi(i32 %tmp1) + br label %for.inc + +for.inc: ; preds = %for.body + %tmp2 = load i32, i32* %i, align 4 + %inc = add nsw i32 %tmp2, 1 + store i32 %inc, i32* %i, align 4 + br label %for.cond + +for.end: ; preds = %for.cond + %tmp3 = load i32, i32* @val, align 4 + %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %tmp3) + ret i32 0 +} + +declare i32 @printf(i8*, ...) #3 + +attributes #0 = { noinline uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } +attributes #2 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #4 = { nounwind } +attributes #5 = { noreturn } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} +; CHECK: !1 = !{!"branch_weights", i32 3, i32 2} +; CHECK: !2 = !{!"branch_weights", i32 4, i32 3} +; CHECK: !3 = !{!"branch_weights", i32 3, i32 1} +; CHECK: !4 = !{!"branch_weights", i32 6, i32 2} Index: test/Transforms/PGOProfile/test_for_gen.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_for_gen.ll @@ -0,0 +1,271 @@ +; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str = private unnamed_addr constant [10 x i8] c"%d %d %d\0A\00", align 1 +; CHECK: @__llvm_profile_name__Z15test_simple_fori = private constant [20 x i8] c"_Z15test_simple_fori" +; CHECK: @__llvm_profile_name__Z13test_do_whilei = private constant [18 x i8] c"_Z13test_do_whilei" +; CHECK: @__llvm_profile_name__Z15test_nested_foriii = private constant [22 x i8] c"_Z15test_nested_foriii" +; CHECK: @__llvm_profile_name_main = private constant [4 x i8] c"main" + +; Function Attrs: nounwind uwtable +define i32 @_Z15test_simple_fori(i32 %n) #0 { +entry: + %n.addr = alloca i32, align 4 + %i = alloca i32, align 4 + %for_sum = alloca i32, align 4 + store i32 %n, i32* %n.addr, align 4 + store i32 1, i32* %for_sum, align 4 + store i32 0, i32* %i, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %tmp = load i32, i32* %i, align 4 + %tmp1 = load i32, i32* %n.addr, align 4 + %cmp = icmp slt i32 %tmp, %tmp1 + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + %tmp2 = load i32, i32* %for_sum, align 4 + %inc = add nsw i32 %tmp2, 1 + store i32 %inc, i32* %for_sum, align 4 + br label %for.inc + +for.inc: ; preds = %for.body +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__llvm_profile_name__Z15test_simple_fori, i32 0, i32 0), i64 32052181608, i32 2, i32 0) + %tmp3 = load i32, i32* %i, align 4 + %inc1 = add nsw i32 %tmp3, 1 + store i32 %inc1, i32* %i, align 4 + br label %for.cond + +for.end: ; preds = %for.cond +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__llvm_profile_name__Z15test_simple_fori, i32 0, i32 0), i64 32052181608, i32 2, i32 1) + %tmp4 = load i32, i32* %for_sum, align 4 + ret i32 %tmp4 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z13test_do_whilei(i32 %n) #0 { +entry: + %n.addr = alloca i32, align 4 + %i = alloca i32, align 4 + %while_sum = alloca i32, align 4 + store i32 %n, i32* %n.addr, align 4 + store i32 0, i32* %i, align 4 + store i32 1, i32* %while_sum, align 4 + br label %do.body + +do.body: ; preds = %do.cond, %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z13test_do_whilei, i32 0, i32 0), i64 29706172832, i32 2, i32 0) + %tmp = load i32, i32* %while_sum, align 4 + %inc = add nsw i32 %tmp, 1 + store i32 %inc, i32* %while_sum, align 4 + br label %do.cond + +do.cond: ; preds = %do.body + %tmp1 = load i32, i32* %i, align 4 + %inc1 = add nsw i32 %tmp1, 1 + store i32 %inc1, i32* %i, align 4 + %tmp2 = load i32, i32* %n.addr, align 4 + %cmp = icmp slt i32 %tmp1, %tmp2 + br i1 %cmp, label %do.body, label %do.end + +do.end: ; preds = %do.cond +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z13test_do_whilei, i32 0, i32 0), i64 29706172832, i32 2, i32 1) + %tmp3 = load i32, i32* %while_sum, align 4 + ret i32 %tmp3 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z15test_nested_foriii(i32 %r, i32 %s, i32 %t) #0 { +entry: +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__llvm_profile_name__Z15test_nested_foriii, i32 0, i32 0), i64 75296580464, i32 4, i32 3) + %r.addr = alloca i32, align 4 + %s.addr = alloca i32, align 4 + %t.addr = alloca i32, align 4 + %i = alloca i32, align 4 + %j = alloca i32, align 4 + %k = alloca i32, align 4 + %nested_for_sum = alloca i32, align 4 + store i32 %r, i32* %r.addr, align 4 + store i32 %s, i32* %s.addr, align 4 + store i32 %t, i32* %t.addr, align 4 + store i32 1, i32* %nested_for_sum, align 4 + store i32 0, i32* %i, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc.11, %entry + %tmp = load i32, i32* %i, align 4 + %tmp1 = load i32, i32* %r.addr, align 4 + %cmp = icmp slt i32 %tmp, %tmp1 + br i1 %cmp, label %for.body, label %for.end.13 + +for.body: ; preds = %for.cond + store i32 0, i32* %j, align 4 + br label %for.cond.1 + +for.cond.1: ; preds = %for.inc.8, %for.body + %tmp2 = load i32, i32* %j, align 4 + %tmp3 = load i32, i32* %s.addr, align 4 + %cmp2 = icmp slt i32 %tmp2, %tmp3 + br i1 %cmp2, label %for.body.3, label %for.end.10 + +for.body.3: ; preds = %for.cond.1 + store i32 0, i32* %k, align 4 + br label %for.cond.4 + +for.cond.4: ; preds = %for.inc, %for.body.3 + %tmp4 = load i32, i32* %k, align 4 + %tmp5 = load i32, i32* %t.addr, align 4 + %cmp5 = icmp slt i32 %tmp4, %tmp5 + br i1 %cmp5, label %for.body.6, label %for.end + +for.body.6: ; preds = %for.cond.4 + %tmp6 = load i32, i32* %nested_for_sum, align 4 + %inc = add nsw i32 %tmp6, 1 + store i32 %inc, i32* %nested_for_sum, align 4 + br label %for.inc + +for.inc: ; preds = %for.body.6 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__llvm_profile_name__Z15test_nested_foriii, i32 0, i32 0), i64 75296580464, i32 4, i32 0) + %tmp7 = load i32, i32* %k, align 4 + %inc7 = add nsw i32 %tmp7, 1 + store i32 %inc7, i32* %k, align 4 + br label %for.cond.4 + +for.end: ; preds = %for.cond.4 + br label %for.inc.8 + +for.inc.8: ; preds = %for.end +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__llvm_profile_name__Z15test_nested_foriii, i32 0, i32 0), i64 75296580464, i32 4, i32 1) + %tmp8 = load i32, i32* %j, align 4 + %inc9 = add nsw i32 %tmp8, 1 + store i32 %inc9, i32* %j, align 4 + br label %for.cond.1 + +for.end.10: ; preds = %for.cond.1 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @__llvm_profile_name__Z15test_nested_foriii, i32 0, i32 0), i64 75296580464, i32 4, i32 2) + br label %for.inc.11 + +for.inc.11: ; preds = %for.end.10 + %tmp9 = load i32, i32* %i, align 4 + %inc12 = add nsw i32 %tmp9, 1 + store i32 %inc12, i32* %i, align 4 + br label %for.cond + +for.end.13: ; preds = %for.cond + %tmp10 = load i32, i32* %nested_for_sum, align 4 + ret i32 %tmp10 +} + +; Function Attrs: norecurse uwtable +define i32 @main() #1 { +entry: + %retval = alloca i32, align 4 + %val1 = alloca i32, align 4 + %val2 = alloca i32, align 4 + %val3 = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + store i32 0, i32* %val1, align 4 + store i32 0, i32* %val2, align 4 + store i32 0, i32* %val3, align 4 + %call = call i32 @_Z15test_simple_fori(i32 0) + %tmp = load i32, i32* %val1, align 4 + %add = add nsw i32 %tmp, %call + store i32 %add, i32* %val1, align 4 + %call1 = call i32 @_Z15test_simple_fori(i32 1) + %tmp1 = load i32, i32* %val1, align 4 + %add2 = add nsw i32 %tmp1, %call1 + store i32 %add2, i32* %val1, align 4 + %call3 = call i32 @_Z15test_simple_fori(i32 23) + %tmp2 = load i32, i32* %val1, align 4 + %add4 = add nsw i32 %tmp2, %call3 + store i32 %add4, i32* %val1, align 4 + %call5 = call i32 @_Z15test_simple_fori(i32 72) + %tmp3 = load i32, i32* %val1, align 4 + %add6 = add nsw i32 %tmp3, %call5 + store i32 %add6, i32* %val1, align 4 + %call7 = call i32 @_Z13test_do_whilei(i32 -1) + %tmp4 = load i32, i32* %val2, align 4 + %add8 = add nsw i32 %tmp4, %call7 + store i32 %add8, i32* %val2, align 4 + %call9 = call i32 @_Z13test_do_whilei(i32 0) + %tmp5 = load i32, i32* %val2, align 4 + %add10 = add nsw i32 %tmp5, %call9 + store i32 %add10, i32* %val2, align 4 + %call11 = call i32 @_Z13test_do_whilei(i32 1) + %tmp6 = load i32, i32* %val2, align 4 + %add12 = add nsw i32 %tmp6, %call11 + store i32 %add12, i32* %val2, align 4 + %call13 = call i32 @_Z13test_do_whilei(i32 91) + %tmp7 = load i32, i32* %val2, align 4 + %add14 = add nsw i32 %tmp7, %call13 + store i32 %add14, i32* %val2, align 4 + %call15 = call i32 @_Z15test_nested_foriii(i32 0, i32 0, i32 0) + %tmp8 = load i32, i32* %val3, align 4 + %add16 = add nsw i32 %tmp8, %call15 + store i32 %add16, i32* %val3, align 4 + %call17 = call i32 @_Z15test_nested_foriii(i32 1, i32 0, i32 0) + %tmp9 = load i32, i32* %val3, align 4 + %add18 = add nsw i32 %tmp9, %call17 + store i32 %add18, i32* %val3, align 4 + %call19 = call i32 @_Z15test_nested_foriii(i32 1, i32 3, i32 0) + %tmp10 = load i32, i32* %val3, align 4 + %add20 = add nsw i32 %tmp10, %call19 + store i32 %add20, i32* %val3, align 4 + %call21 = call i32 @_Z15test_nested_foriii(i32 1, i32 3, i32 1) + %tmp11 = load i32, i32* %val3, align 4 + %add22 = add nsw i32 %tmp11, %call21 + store i32 %add22, i32* %val3, align 4 + %call23 = call i32 @_Z15test_nested_foriii(i32 3, i32 1, i32 5) + %tmp12 = load i32, i32* %val3, align 4 + %add24 = add nsw i32 %tmp12, %call23 + store i32 %add24, i32* %val3, align 4 + %call25 = call i32 @_Z15test_nested_foriii(i32 4, i32 6, i32 7) + %tmp13 = load i32, i32* %val3, align 4 + %add26 = add nsw i32 %tmp13, %call25 + store i32 %add26, i32* %val3, align 4 + %tmp14 = load i32, i32* %val1, align 4 + %tmp15 = load i32, i32* %val2, align 4 + %tmp16 = load i32, i32* %val3, align 4 + %call27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i32 %tmp14, i32 %tmp15, i32 %tmp16) + %tmp17 = load i32, i32* %val1, align 4 + %cmp = icmp ne i32 %tmp17, 100 + br i1 %cmp, label %if.then, label %lor.lhs.false + +lor.lhs.false: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 43897415037, i32 4, i32 1) + %tmp18 = load i32, i32* %val2, align 4 + %cmp28 = icmp ne i32 %tmp18, 100 + br i1 %cmp28, label %if.then, label %lor.lhs.false.29 + +lor.lhs.false.29: ; preds = %lor.lhs.false +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 43897415037, i32 4, i32 2) + %tmp19 = load i32, i32* %val3, align 4 + %cmp30 = icmp ne i32 %tmp19, 192 + br i1 %cmp30, label %if.then, label %if.end + +if.then: ; preds = %lor.lhs.false.29, %lor.lhs.false, %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 43897415037, i32 4, i32 0) + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %lor.lhs.false.29 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 43897415037, i32 4, i32 3) + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp20 = load i32, i32* %retval, align 4 + ret i32 %tmp20 +} + +declare i32 @printf(i8*, ...) #2 + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} Index: test/Transforms/PGOProfile/test_for_use.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_for_use.ll @@ -0,0 +1,269 @@ +; RUN: opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/test_for.profdata -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str = private unnamed_addr constant [10 x i8] c"%d %d %d\0A\00", align 1 + +; Function Attrs: nounwind uwtable +define i32 @_Z15test_simple_fori(i32 %n) #0 { +entry: + %n.addr = alloca i32, align 4 + %i = alloca i32, align 4 + %for_sum = alloca i32, align 4 + store i32 %n, i32* %n.addr, align 4 + store i32 1, i32* %for_sum, align 4 + store i32 0, i32* %i, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %tmp = load i32, i32* %i, align 4 + %tmp1 = load i32, i32* %n.addr, align 4 + %cmp = icmp slt i32 %tmp, %tmp1 + br i1 %cmp, label %for.body, label %for.end +; CHECK: !prof !1 + +for.body: ; preds = %for.cond + %tmp2 = load i32, i32* %for_sum, align 4 + %inc = add nsw i32 %tmp2, 1 + store i32 %inc, i32* %for_sum, align 4 + br label %for.inc + +for.inc: ; preds = %for.body + %tmp3 = load i32, i32* %i, align 4 + %inc1 = add nsw i32 %tmp3, 1 + store i32 %inc1, i32* %i, align 4 + br label %for.cond + +for.end: ; preds = %for.cond + %tmp4 = load i32, i32* %for_sum, align 4 + ret i32 %tmp4 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z13test_do_whilei(i32 %n) #0 { +entry: + %n.addr = alloca i32, align 4 + %i = alloca i32, align 4 + %while_sum = alloca i32, align 4 + store i32 %n, i32* %n.addr, align 4 + store i32 0, i32* %i, align 4 + store i32 1, i32* %while_sum, align 4 + br label %do.body + +do.body: ; preds = %do.cond, %entry + %tmp = load i32, i32* %while_sum, align 4 + %inc = add nsw i32 %tmp, 1 + store i32 %inc, i32* %while_sum, align 4 + br label %do.cond + +do.cond: ; preds = %do.body + %tmp1 = load i32, i32* %i, align 4 + %inc1 = add nsw i32 %tmp1, 1 + store i32 %inc1, i32* %i, align 4 + %tmp2 = load i32, i32* %n.addr, align 4 + %cmp = icmp slt i32 %tmp1, %tmp2 + br i1 %cmp, label %do.body, label %do.end +; CHECK: !prof !2 + +do.end: ; preds = %do.cond + %tmp3 = load i32, i32* %while_sum, align 4 + ret i32 %tmp3 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z15test_nested_foriii(i32 %r, i32 %s, i32 %t) #0 { +entry: + %r.addr = alloca i32, align 4 + %s.addr = alloca i32, align 4 + %t.addr = alloca i32, align 4 + %i = alloca i32, align 4 + %j = alloca i32, align 4 + %k = alloca i32, align 4 + %nested_for_sum = alloca i32, align 4 + store i32 %r, i32* %r.addr, align 4 + store i32 %s, i32* %s.addr, align 4 + store i32 %t, i32* %t.addr, align 4 + store i32 1, i32* %nested_for_sum, align 4 + store i32 0, i32* %i, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc.11, %entry + %tmp = load i32, i32* %i, align 4 + %tmp1 = load i32, i32* %r.addr, align 4 + %cmp = icmp slt i32 %tmp, %tmp1 + br i1 %cmp, label %for.body, label %for.end.13 +; CHECK: !prof !3 + +for.body: ; preds = %for.cond + store i32 0, i32* %j, align 4 + br label %for.cond.1 + +for.cond.1: ; preds = %for.inc.8, %for.body + %tmp2 = load i32, i32* %j, align 4 + %tmp3 = load i32, i32* %s.addr, align 4 + %cmp2 = icmp slt i32 %tmp2, %tmp3 + br i1 %cmp2, label %for.body.3, label %for.end.10 +; CHECK: !prof !4 + +for.body.3: ; preds = %for.cond.1 + store i32 0, i32* %k, align 4 + br label %for.cond.4 + +for.cond.4: ; preds = %for.inc, %for.body.3 + %tmp4 = load i32, i32* %k, align 4 + %tmp5 = load i32, i32* %t.addr, align 4 + %cmp5 = icmp slt i32 %tmp4, %tmp5 + br i1 %cmp5, label %for.body.6, label %for.end +; CHECK: !prof !5 + +for.body.6: ; preds = %for.cond.4 + %tmp6 = load i32, i32* %nested_for_sum, align 4 + %inc = add nsw i32 %tmp6, 1 + store i32 %inc, i32* %nested_for_sum, align 4 + br label %for.inc + +for.inc: ; preds = %for.body.6 + %tmp7 = load i32, i32* %k, align 4 + %inc7 = add nsw i32 %tmp7, 1 + store i32 %inc7, i32* %k, align 4 + br label %for.cond.4 + +for.end: ; preds = %for.cond.4 + br label %for.inc.8 + +for.inc.8: ; preds = %for.end + %tmp8 = load i32, i32* %j, align 4 + %inc9 = add nsw i32 %tmp8, 1 + store i32 %inc9, i32* %j, align 4 + br label %for.cond.1 + +for.end.10: ; preds = %for.cond.1 + br label %for.inc.11 + +for.inc.11: ; preds = %for.end.10 + %tmp9 = load i32, i32* %i, align 4 + %inc12 = add nsw i32 %tmp9, 1 + store i32 %inc12, i32* %i, align 4 + br label %for.cond + +for.end.13: ; preds = %for.cond + %tmp10 = load i32, i32* %nested_for_sum, align 4 + ret i32 %tmp10 +} + +; Function Attrs: norecurse uwtable +define i32 @main() #1 { +entry: + %retval = alloca i32, align 4 + %val1 = alloca i32, align 4 + %val2 = alloca i32, align 4 + %val3 = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + store i32 0, i32* %val1, align 4 + store i32 0, i32* %val2, align 4 + store i32 0, i32* %val3, align 4 + %call = call i32 @_Z15test_simple_fori(i32 0) + %tmp = load i32, i32* %val1, align 4 + %add = add nsw i32 %tmp, %call + store i32 %add, i32* %val1, align 4 + %call1 = call i32 @_Z15test_simple_fori(i32 1) + %tmp1 = load i32, i32* %val1, align 4 + %add2 = add nsw i32 %tmp1, %call1 + store i32 %add2, i32* %val1, align 4 + %call3 = call i32 @_Z15test_simple_fori(i32 23) + %tmp2 = load i32, i32* %val1, align 4 + %add4 = add nsw i32 %tmp2, %call3 + store i32 %add4, i32* %val1, align 4 + %call5 = call i32 @_Z15test_simple_fori(i32 72) + %tmp3 = load i32, i32* %val1, align 4 + %add6 = add nsw i32 %tmp3, %call5 + store i32 %add6, i32* %val1, align 4 + %call7 = call i32 @_Z13test_do_whilei(i32 -1) + %tmp4 = load i32, i32* %val2, align 4 + %add8 = add nsw i32 %tmp4, %call7 + store i32 %add8, i32* %val2, align 4 + %call9 = call i32 @_Z13test_do_whilei(i32 0) + %tmp5 = load i32, i32* %val2, align 4 + %add10 = add nsw i32 %tmp5, %call9 + store i32 %add10, i32* %val2, align 4 + %call11 = call i32 @_Z13test_do_whilei(i32 1) + %tmp6 = load i32, i32* %val2, align 4 + %add12 = add nsw i32 %tmp6, %call11 + store i32 %add12, i32* %val2, align 4 + %call13 = call i32 @_Z13test_do_whilei(i32 91) + %tmp7 = load i32, i32* %val2, align 4 + %add14 = add nsw i32 %tmp7, %call13 + store i32 %add14, i32* %val2, align 4 + %call15 = call i32 @_Z15test_nested_foriii(i32 0, i32 0, i32 0) + %tmp8 = load i32, i32* %val3, align 4 + %add16 = add nsw i32 %tmp8, %call15 + store i32 %add16, i32* %val3, align 4 + %call17 = call i32 @_Z15test_nested_foriii(i32 1, i32 0, i32 0) + %tmp9 = load i32, i32* %val3, align 4 + %add18 = add nsw i32 %tmp9, %call17 + store i32 %add18, i32* %val3, align 4 + %call19 = call i32 @_Z15test_nested_foriii(i32 1, i32 3, i32 0) + %tmp10 = load i32, i32* %val3, align 4 + %add20 = add nsw i32 %tmp10, %call19 + store i32 %add20, i32* %val3, align 4 + %call21 = call i32 @_Z15test_nested_foriii(i32 1, i32 3, i32 1) + %tmp11 = load i32, i32* %val3, align 4 + %add22 = add nsw i32 %tmp11, %call21 + store i32 %add22, i32* %val3, align 4 + %call23 = call i32 @_Z15test_nested_foriii(i32 3, i32 1, i32 5) + %tmp12 = load i32, i32* %val3, align 4 + %add24 = add nsw i32 %tmp12, %call23 + store i32 %add24, i32* %val3, align 4 + %call25 = call i32 @_Z15test_nested_foriii(i32 4, i32 6, i32 7) + %tmp13 = load i32, i32* %val3, align 4 + %add26 = add nsw i32 %tmp13, %call25 + store i32 %add26, i32* %val3, align 4 + %tmp14 = load i32, i32* %val1, align 4 + %tmp15 = load i32, i32* %val2, align 4 + %tmp16 = load i32, i32* %val3, align 4 + %call27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i32 %tmp14, i32 %tmp15, i32 %tmp16) + %tmp17 = load i32, i32* %val1, align 4 + %cmp = icmp ne i32 %tmp17, 100 + br i1 %cmp, label %if.then, label %lor.lhs.false +; CHECK: !prof !6 + +lor.lhs.false: ; preds = %entry + %tmp18 = load i32, i32* %val2, align 4 + %cmp28 = icmp ne i32 %tmp18, 100 + br i1 %cmp28, label %if.then, label %lor.lhs.false.29 +; CHECK: !prof !6 + +lor.lhs.false.29: ; preds = %lor.lhs.false + %tmp19 = load i32, i32* %val3, align 4 + %cmp30 = icmp ne i32 %tmp19, 192 + br i1 %cmp30, label %if.then, label %if.end +; CHECK: !prof !6 + +if.then: ; preds = %lor.lhs.false.29, %lor.lhs.false, %entry + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %lor.lhs.false.29 + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp20 = load i32, i32* %retval, align 4 + ret i32 %tmp20 +} + +declare i32 @printf(i8*, ...) #2 + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} +; CHECK: !1 = !{!"branch_weights", i32 97, i32 5} +; CHECK: !2 = !{!"branch_weights", i32 93, i32 5} +; CHECK: !3 = !{!"branch_weights", i32 11, i32 7} +; CHECK: !4 = !{!"branch_weights", i32 34, i32 11} +; CHECK: !5 = !{!"branch_weights", i32 187, i32 34} +; CHECK: !6 = !{!"branch_weights", i32 1, i32 2} Index: test/Transforms/PGOProfile/test_gen.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_gen.ll @@ -0,0 +1,91 @@ +; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@val = global i32 0, align 4 +; CHECK: @__llvm_profile_name__Z3foov = private constant [7 x i8] c"_Z3foov" +; CHECK: @"__llvm_profile_name_:_ZL8uncalledii" = private constant [22 x i8] c":_ZL8uncalledii" +; CHECK: @"__llvm_profile_name_:_ZL6calledii" = private constant [20 x i8] c":_ZL6calledii" +; CHECK: @__llvm_profile_name_main = private constant [4 x i8] c"main" + +; Function Attrs: uwtable +define void @_Z3foov() #0 { +entry: + %tmp = load i32, i32* @val, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.then, label %if.end + +if.then: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3foov, i32 0, i32 0), i64 23925403969, i32 2, i32 1) + %call = call i32 @_ZL8uncalledii(i32 1, i32 2) + store i32 %call, i32* @val, align 4 + br label %if.end + +if.end: ; preds = %if.then, %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3foov, i32 0, i32 0), i64 23925403969, i32 2, i32 0) + %tmp1 = load i32, i32* @val, align 4 + %call1 = call i32 @_ZL6calledii(i32 %tmp1, i32 4) + store i32 %call1, i32* @val, align 4 + ret void +} + +; Function Attrs: inlinehint nounwind uwtable +define internal i32 @_ZL8uncalledii(i32 %i, i32 %j) #1 { +entry: +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @"__llvm_profile_name_:_ZL8uncalledii", i32 0, i32 0), i64 12884901887, i32 1, i32 0) + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %mul = mul nsw i32 %tmp, %tmp1 + ret i32 %mul +} + +; Function Attrs: inlinehint nounwind uwtable +define internal i32 @_ZL6calledii(i32 %i, i32 %j) #1 { +entry: +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @"__llvm_profile_name_:_ZL6calledii", i32 0, i32 0), i64 12884901887, i32 1, i32 0) + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %add = add nsw i32 %tmp, %tmp1 + ret i32 %add +} + +; Function Attrs: norecurse uwtable +define i32 @main() #2 { +entry: + %retval = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + call void @_Z3foov() + %tmp = load i32, i32* @val, align 4 + %cmp = icmp ne i32 %tmp, 4 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 29368252703, i32 2, i32 0) + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 29368252703, i32 2, i32 1) + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp1 = load i32, i32* %retval, align 4 + ret i32 %tmp1 +} + +attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { inlinehint nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} Index: test/Transforms/PGOProfile/test_goto_gen.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_goto_gen.ll @@ -0,0 +1,166 @@ +; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: @__llvm_profile_name__Z9test_gotoi = private constant [13 x i8] c"_Z9test_gotoi" +; CHECK: @__llvm_profile_name__Z13test_for_gotoiii = private constant [20 x i8] c"_Z13test_for_gotoiii" +; CHECK: @__llvm_profile_name_main = private constant [4 x i8] c"main" + +; Function Attrs: nounwind uwtable +define i32 @_Z9test_gotoi(i32 %f) #0 { +entry: + %retval = alloca i32, align 4 + %f.addr = alloca i32, align 4 + store i32 %f, i32* %f.addr, align 4 + %tmp = load i32, i32* %f.addr, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.then, label %if.end + +if.then: ; preds = %entry + br label %lab1 + +if.end: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__llvm_profile_name__Z9test_gotoi, i32 0, i32 0), i64 41409848182, i32 2, i32 1) + br label %lab2 + +lab1: ; preds = %if.then + br label %lab3 + +lab2: ; preds = %if.end + store i32 1, i32* %retval, align 4 + br label %return + +lab3: ; preds = %lab1 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @__llvm_profile_name__Z9test_gotoi, i32 0, i32 0), i64 41409848182, i32 2, i32 0) + store i32 3, i32* %retval, align 4 + br label %return + +return: ; preds = %lab3, %lab2 + %tmp1 = load i32, i32* %retval, align 4 + ret i32 %tmp1 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z13test_for_gotoiii(i32 %n, i32 %f, i32 %m) #0 { +entry: + %retval = alloca i32, align 4 + %n.addr = alloca i32, align 4 + %f.addr = alloca i32, align 4 + %m.addr = alloca i32, align 4 + %i = alloca i32, align 4 + store i32 %n, i32* %n.addr, align 4 + store i32 %f, i32* %f.addr, align 4 + store i32 %m, i32* %m.addr, align 4 + store i32 0, i32* %i, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %tmp = load i32, i32* %i, align 4 + %tmp1 = load i32, i32* %n.addr, align 4 + %cmp = icmp slt i32 %tmp, %tmp1 + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + %tmp2 = load i32, i32* %i, align 4 + %tmp3 = load i32, i32* %f.addr, align 4 + %cmp1 = icmp eq i32 %tmp2, %tmp3 + br i1 %cmp1, label %if.then, label %if.end + +if.then: ; preds = %for.body + br label %lab2 + +if.end: ; preds = %for.body + %tmp4 = load i32, i32* %i, align 4 + %tmp5 = load i32, i32* %m.addr, align 4 + %cmp2 = icmp sgt i32 %tmp4, %tmp5 + br i1 %cmp2, label %if.then.3, label %if.end.4 + +if.then.3: ; preds = %if.end +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__llvm_profile_name__Z13test_for_gotoiii, i32 0, i32 0), i64 67827622839, i32 4, i32 3) + br label %for.end + +if.end.4: ; preds = %if.end + br label %for.inc + +for.inc: ; preds = %if.end.4 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__llvm_profile_name__Z13test_for_gotoiii, i32 0, i32 0), i64 67827622839, i32 4, i32 0) + %tmp6 = load i32, i32* %i, align 4 + %inc = add nsw i32 %tmp6, 1 + store i32 %inc, i32* %i, align 4 + br label %for.cond + +for.end: ; preds = %if.then.3, %for.cond +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__llvm_profile_name__Z13test_for_gotoiii, i32 0, i32 0), i64 67827622839, i32 4, i32 1) + store i32 5, i32* %retval, align 4 + br label %return + +lab2: ; preds = %if.then +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__llvm_profile_name__Z13test_for_gotoiii, i32 0, i32 0), i64 67827622839, i32 4, i32 2) + store i32 -10, i32* %retval, align 4 + br label %return + +return: ; preds = %lab2, %for.end + %tmp7 = load i32, i32* %retval, align 4 + ret i32 %tmp7 +} + +; Function Attrs: norecurse nounwind uwtable +define i32 @main() #1 { +entry: + %retval = alloca i32, align 4 + %val = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + store i32 0, i32* %val, align 4 + %call = call i32 @_Z9test_gotoi(i32 0) + %tmp = load i32, i32* %val, align 4 + %add = add nsw i32 %tmp, %call + store i32 %add, i32* %val, align 4 + %call1 = call i32 @_Z9test_gotoi(i32 1) + %tmp1 = load i32, i32* %val, align 4 + %add2 = add nsw i32 %tmp1, %call1 + store i32 %add2, i32* %val, align 4 + %call3 = call i32 @_Z9test_gotoi(i32 100) + %tmp2 = load i32, i32* %val, align 4 + %add4 = add nsw i32 %tmp2, %call3 + store i32 %add4, i32* %val, align 4 + %call5 = call i32 @_Z13test_for_gotoiii(i32 10, i32 3, i32 25) + %tmp3 = load i32, i32* %val, align 4 + %add6 = add nsw i32 %tmp3, %call5 + store i32 %add6, i32* %val, align 4 + %call7 = call i32 @_Z13test_for_gotoiii(i32 40, i32 30, i32 25) + %tmp4 = load i32, i32* %val, align 4 + %add8 = add nsw i32 %tmp4, %call7 + store i32 %add8, i32* %val, align 4 + %call9 = call i32 @_Z13test_for_gotoiii(i32 20, i32 3, i32 12) + %tmp5 = load i32, i32* %val, align 4 + %add10 = add nsw i32 %tmp5, %call9 + store i32 %add10, i32* %val, align 4 + %call11 = call i32 @_Z13test_for_gotoiii(i32 20, i32 -3, i32 20) + %tmp6 = load i32, i32* %val, align 4 + %add12 = add nsw i32 %tmp6, %call11 + store i32 %add12, i32* %val, align 4 + %tmp7 = load i32, i32* %val, align 4 + %cmp = icmp ne i32 %tmp7, -3 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 29368252703, i32 2, i32 0) + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 29368252703, i32 2, i32 1) + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp8 = load i32, i32* %retval, align 4 + ret i32 %tmp8 +} + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} Index: test/Transforms/PGOProfile/test_goto_use.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_goto_use.ll @@ -0,0 +1,164 @@ +; RUN: opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/test_goto.profdata -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind uwtable +define i32 @_Z9test_gotoi(i32 %f) #0 { +entry: + %retval = alloca i32, align 4 + %f.addr = alloca i32, align 4 + store i32 %f, i32* %f.addr, align 4 + %tmp = load i32, i32* %f.addr, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.then, label %if.end +; CHECK: !prof !1 + +if.then: ; preds = %entry + br label %lab1 + +if.end: ; preds = %entry + br label %lab2 + +lab1: ; preds = %if.then + br label %lab3 + +lab2: ; preds = %if.end + store i32 1, i32* %retval, align 4 + br label %return + +lab3: ; preds = %lab1 + store i32 3, i32* %retval, align 4 + br label %return + +return: ; preds = %lab3, %lab2 + %tmp1 = load i32, i32* %retval, align 4 + ret i32 %tmp1 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z13test_for_gotoiii(i32 %n, i32 %f, i32 %m) #0 { +entry: + %retval = alloca i32, align 4 + %n.addr = alloca i32, align 4 + %f.addr = alloca i32, align 4 + %m.addr = alloca i32, align 4 + %i = alloca i32, align 4 + store i32 %n, i32* %n.addr, align 4 + store i32 %f, i32* %f.addr, align 4 + store i32 %m, i32* %m.addr, align 4 + store i32 0, i32* %i, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %tmp = load i32, i32* %i, align 4 + %tmp1 = load i32, i32* %n.addr, align 4 + %cmp = icmp slt i32 %tmp, %tmp1 + br i1 %cmp, label %for.body, label %for.end +; CHECK: !prof !2 + +for.body: ; preds = %for.cond + %tmp2 = load i32, i32* %i, align 4 + %tmp3 = load i32, i32* %f.addr, align 4 + %cmp1 = icmp eq i32 %tmp2, %tmp3 + br i1 %cmp1, label %if.then, label %if.end +; CHECK: !prof !3 + +if.then: ; preds = %for.body + br label %lab2 + +if.end: ; preds = %for.body + %tmp4 = load i32, i32* %i, align 4 + %tmp5 = load i32, i32* %m.addr, align 4 + %cmp2 = icmp sgt i32 %tmp4, %tmp5 + br i1 %cmp2, label %if.then.3, label %if.end.4 +; CHECK: !prof !4 + +if.then.3: ; preds = %if.end + br label %for.end + +if.end.4: ; preds = %if.end + br label %for.inc + +for.inc: ; preds = %if.end.4 + %tmp6 = load i32, i32* %i, align 4 + %inc = add nsw i32 %tmp6, 1 + store i32 %inc, i32* %i, align 4 + br label %for.cond + +for.end: ; preds = %if.then.3, %for.cond + store i32 5, i32* %retval, align 4 + br label %return + +lab2: ; preds = %if.then + store i32 -10, i32* %retval, align 4 + br label %return + +return: ; preds = %lab2, %for.end + %tmp7 = load i32, i32* %retval, align 4 + ret i32 %tmp7 +} + +; Function Attrs: norecurse nounwind uwtable +define i32 @main() #1 { +entry: + %retval = alloca i32, align 4 + %val = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + store i32 0, i32* %val, align 4 + %call = call i32 @_Z9test_gotoi(i32 0) + %tmp = load i32, i32* %val, align 4 + %add = add nsw i32 %tmp, %call + store i32 %add, i32* %val, align 4 + %call1 = call i32 @_Z9test_gotoi(i32 1) + %tmp1 = load i32, i32* %val, align 4 + %add2 = add nsw i32 %tmp1, %call1 + store i32 %add2, i32* %val, align 4 + %call3 = call i32 @_Z9test_gotoi(i32 100) + %tmp2 = load i32, i32* %val, align 4 + %add4 = add nsw i32 %tmp2, %call3 + store i32 %add4, i32* %val, align 4 + %call5 = call i32 @_Z13test_for_gotoiii(i32 10, i32 3, i32 25) + %tmp3 = load i32, i32* %val, align 4 + %add6 = add nsw i32 %tmp3, %call5 + store i32 %add6, i32* %val, align 4 + %call7 = call i32 @_Z13test_for_gotoiii(i32 40, i32 30, i32 25) + %tmp4 = load i32, i32* %val, align 4 + %add8 = add nsw i32 %tmp4, %call7 + store i32 %add8, i32* %val, align 4 + %call9 = call i32 @_Z13test_for_gotoiii(i32 20, i32 3, i32 12) + %tmp5 = load i32, i32* %val, align 4 + %add10 = add nsw i32 %tmp5, %call9 + store i32 %add10, i32* %val, align 4 + %call11 = call i32 @_Z13test_for_gotoiii(i32 20, i32 -3, i32 20) + %tmp6 = load i32, i32* %val, align 4 + %add12 = add nsw i32 %tmp6, %call11 + store i32 %add12, i32* %val, align 4 + %tmp7 = load i32, i32* %val, align 4 + %cmp = icmp ne i32 %tmp7, -3 + br i1 %cmp, label %if.then, label %if.end +; CHECK: !prof !5 + +if.then: ; preds = %entry + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp8 = load i32, i32* %retval, align 4 + ret i32 %tmp8 +} + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} +; CHECK: !1 = !{!"branch_weights", i32 3, i32 2} +; CHECK: !2 = !{!"branch_weights", i32 56, i32 2} +; CHECK: !3 = !{!"branch_weights", i32 3, i32 54} +; CHECK: !4 = !{!"branch_weights", i32 2, i32 53} +; CHECK: !5 = !{!"branch_weights", i32 1, i32 2} Index: test/Transforms/PGOProfile/test_ifelse_gen.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_ifelse_gen.ll @@ -0,0 +1,548 @@ +; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: @__llvm_profile_name__Z3bari = private constant [7 x i8] c"_Z3bari" +; CHECK: @__llvm_profile_name__Z12test_ifelse0ii = private constant [18 x i8] c"_Z12test_ifelse0ii" +; CHECK: @__llvm_profile_name__Z12test_ifelse1ii = private constant [18 x i8] c"_Z12test_ifelse1ii" +; CHECK: @__llvm_profile_name__Z12test_ifelse2i = private constant [17 x i8] c"_Z12test_ifelse2i" +; CHECK: @__llvm_profile_name__Z12test_ifelse3i = private constant [17 x i8] c"_Z12test_ifelse3i" +; CHECK: @__llvm_profile_name__Z12test_ifelse4ii = private constant [18 x i8] c"_Z12test_ifelse4ii" +; CHECK: @__llvm_profile_name_main = private constant [4 x i8] c"main" + +; Function Attrs: nounwind uwtable +define i32 @_Z3bari(i32 %i) #0 { +entry: +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3bari, i32 0, i32 0), i64 12884901887, i32 1, i32 0) + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + ret i32 %tmp +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse0ii(i32 %i, i32 %j) #0 { +entry: + %retval = alloca i32, align 4 + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %cmp = icmp sgt i32 %tmp, %tmp1 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse0ii, i32 0, i32 0), i64 29368252703, i32 2, i32 0) + %tmp2 = load i32, i32* %i.addr, align 4 + store i32 %tmp2, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse0ii, i32 0, i32 0), i64 29368252703, i32 2, i32 1) + %tmp3 = load i32, i32* %j.addr, align 4 + store i32 %tmp3, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp4 = load i32, i32* %retval, align 4 + ret i32 %tmp4 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse1ii(i32 %i, i32 %j) #0 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + store i32 0, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.then, label %if.else.4 + +if.then: ; preds = %entry + %tmp1 = load i32, i32* %j.addr, align 4 + %tobool1 = icmp ne i32 %tmp1, 0 + br i1 %tobool1, label %if.then.2, label %if.else + +if.then.2: ; preds = %if.then +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse1ii, i32 0, i32 0), i64 102363127235, i32 7, i32 2) + %call = call i32 @_Z3bari(i32 4) + store i32 %call, i32* %result, align 4 + br label %if.end + +if.else: ; preds = %if.then +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse1ii, i32 0, i32 0), i64 102363127235, i32 7, i32 5) + %call3 = call i32 @_Z3bari(i32 1024) + store i32 %call3, i32* %result, align 4 + br label %if.end + +if.end: ; preds = %if.else, %if.then.2 + br label %if.end.11 + +if.else.4: ; preds = %entry + %tmp2 = load i32, i32* %j.addr, align 4 + %tobool5 = icmp ne i32 %tmp2, 0 + br i1 %tobool5, label %if.then.6, label %if.else.8 + +if.then.6: ; preds = %if.else.4 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse1ii, i32 0, i32 0), i64 102363127235, i32 7, i32 4) + %call7 = call i32 @_Z3bari(i32 1) + store i32 %call7, i32* %result, align 4 + br label %if.end.10 + +if.else.8: ; preds = %if.else.4 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse1ii, i32 0, i32 0), i64 102363127235, i32 7, i32 6) + %call9 = call i32 @_Z3bari(i32 2) + store i32 %call9, i32* %result, align 4 + br label %if.end.10 + +if.end.10: ; preds = %if.else.8, %if.then.6 + br label %if.end.11 + +if.end.11: ; preds = %if.end.10, %if.end + %tmp3 = load i32, i32* %i.addr, align 4 + %tmp4 = load i32, i32* %j.addr, align 4 + %cmp = icmp sgt i32 %tmp3, %tmp4 + br i1 %cmp, label %if.then.12, label %if.end.14 + +if.then.12: ; preds = %if.end.11 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse1ii, i32 0, i32 0), i64 102363127235, i32 7, i32 0) + %tmp5 = load i32, i32* %result, align 4 + %mul = mul nsw i32 %tmp5, 2 + %call13 = call i32 @_Z3bari(i32 %mul) + store i32 %call13, i32* %result, align 4 + br label %if.end.14 + +if.end.14: ; preds = %if.then.12, %if.end.11 + %tmp6 = load i32, i32* %i.addr, align 4 + %cmp15 = icmp sgt i32 %tmp6, 10 + br i1 %cmp15, label %if.then.16, label %if.end.22 + +if.then.16: ; preds = %if.end.14 + %tmp7 = load i32, i32* %j.addr, align 4 + %cmp17 = icmp sgt i32 %tmp7, 10 + br i1 %cmp17, label %if.then.18, label %if.end.21 + +if.then.18: ; preds = %if.then.16 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse1ii, i32 0, i32 0), i64 102363127235, i32 7, i32 3) + %tmp8 = load i32, i32* %result, align 4 + %mul19 = mul nsw i32 %tmp8, 4 + %call20 = call i32 @_Z3bari(i32 %mul19) + store i32 %call20, i32* %result, align 4 + br label %if.end.21 + +if.end.21: ; preds = %if.then.18, %if.then.16 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse1ii, i32 0, i32 0), i64 102363127235, i32 7, i32 1) + br label %if.end.22 + +if.end.22: ; preds = %if.end.21, %if.end.14 + %tmp9 = load i32, i32* %result, align 4 + ret i32 %tmp9 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse2i(i32 %i) #0 { +entry: + %retval = alloca i32, align 4 + %i.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 0, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.end, label %if.then + +if.then: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse2i, i32 0, i32 0), i64 81440066539, i32 6, i32 3) + %call = call i32 @_Z3bari(i32 1) + store i32 %call, i32* %result, align 4 + br label %if.end + +if.end: ; preds = %if.then, %entry + %tmp1 = load i32, i32* %i.addr, align 4 + %cmp = icmp eq i32 %tmp1, 1 + br i1 %cmp, label %if.then.1, label %if.end.3 + +if.then.1: ; preds = %if.end +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse2i, i32 0, i32 0), i64 81440066539, i32 6, i32 0) + %call2 = call i32 @_Z3bari(i32 1024) + store i32 %call2, i32* %result, align 4 + br label %if.end.3 + +if.end.3: ; preds = %if.then.1, %if.end + %tmp2 = load i32, i32* %i.addr, align 4 + %cmp4 = icmp eq i32 %tmp2, 2 + br i1 %cmp4, label %if.then.5, label %if.end.7 + +if.then.5: ; preds = %if.end.3 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse2i, i32 0, i32 0), i64 81440066539, i32 6, i32 1) + %call6 = call i32 @_Z3bari(i32 2) + store i32 %call6, i32* %result, align 4 + br label %if.end.7 + +if.end.7: ; preds = %if.then.5, %if.end.3 + %tmp3 = load i32, i32* %i.addr, align 4 + %cmp8 = icmp eq i32 %tmp3, 3 + br i1 %cmp8, label %if.then.9, label %if.end.11 + +if.then.9: ; preds = %if.end.7 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse2i, i32 0, i32 0), i64 81440066539, i32 6, i32 2) + %call10 = call i32 @_Z3bari(i32 8) + store i32 %call10, i32* %retval, align 4 + br label %return + +if.end.11: ; preds = %if.end.7 + %tmp4 = load i32, i32* %i.addr, align 4 + %cmp12 = icmp eq i32 %tmp4, 4 + br i1 %cmp12, label %if.then.13, label %if.end.15 + +if.then.13: ; preds = %if.end.11 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse2i, i32 0, i32 0), i64 81440066539, i32 6, i32 4) + %call14 = call i32 @_Z3bari(i32 2048) + store i32 %call14, i32* %retval, align 4 + br label %return + +if.end.15: ; preds = %if.end.11 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse2i, i32 0, i32 0), i64 81440066539, i32 6, i32 5) + %tmp5 = load i32, i32* %result, align 4 + store i32 %tmp5, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end.15, %if.then.13, %if.then.9 + %tmp6 = load i32, i32* %retval, align 4 + ret i32 %tmp6 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse3i(i32 %i) #0 { +entry: + %retval = alloca i32, align 4 + %i.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 0, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.else, label %if.then + +if.then: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse3i, i32 0, i32 0), i64 95295964486, i32 6, i32 0) + %call = call i32 @_Z3bari(i32 1) + store i32 %call, i32* %result, align 4 + br label %if.end.18 + +if.else: ; preds = %entry + %tmp1 = load i32, i32* %i.addr, align 4 + %cmp = icmp eq i32 %tmp1, 1 + br i1 %cmp, label %if.then.1, label %if.else.3 + +if.then.1: ; preds = %if.else +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse3i, i32 0, i32 0), i64 95295964486, i32 6, i32 1) + %call2 = call i32 @_Z3bari(i32 1) + store i32 %call2, i32* %result, align 4 + br label %if.end.17 + +if.else.3: ; preds = %if.else + %tmp2 = load i32, i32* %i.addr, align 4 + %cmp4 = icmp eq i32 %tmp2, 2 + br i1 %cmp4, label %if.then.5, label %if.else.7 + +if.then.5: ; preds = %if.else.3 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse3i, i32 0, i32 0), i64 95295964486, i32 6, i32 2) + %call6 = call i32 @_Z3bari(i32 2) + store i32 %call6, i32* %result, align 4 + br label %if.end.16 + +if.else.7: ; preds = %if.else.3 + %tmp3 = load i32, i32* %i.addr, align 4 + %cmp8 = icmp eq i32 %tmp3, 3 + br i1 %cmp8, label %if.then.9, label %if.else.11 + +if.then.9: ; preds = %if.else.7 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse3i, i32 0, i32 0), i64 95295964486, i32 6, i32 3) + %call10 = call i32 @_Z3bari(i32 3) + store i32 %call10, i32* %retval, align 4 + br label %return + +if.else.11: ; preds = %if.else.7 + %tmp4 = load i32, i32* %i.addr, align 4 + %cmp12 = icmp eq i32 %tmp4, 4 + br i1 %cmp12, label %if.then.13, label %if.end + +if.then.13: ; preds = %if.else.11 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse3i, i32 0, i32 0), i64 95295964486, i32 6, i32 4) + %call14 = call i32 @_Z3bari(i32 4) + store i32 %call14, i32* %retval, align 4 + br label %return + +if.end: ; preds = %if.else.11 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z12test_ifelse3i, i32 0, i32 0), i64 95295964486, i32 6, i32 5) + br label %if.end.15 + +if.end.15: ; preds = %if.end + br label %if.end.16 + +if.end.16: ; preds = %if.end.15, %if.then.5 + br label %if.end.17 + +if.end.17: ; preds = %if.end.16, %if.then.1 + br label %if.end.18 + +if.end.18: ; preds = %if.end.17, %if.then + %tmp5 = load i32, i32* %result, align 4 + store i32 %tmp5, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end.18, %if.then.13, %if.then.9 + %tmp6 = load i32, i32* %retval, align 4 + ret i32 %tmp6 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse4ii(i32 %i, i32 %j) #0 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + store i32 1, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %cmp = icmp sgt i32 %tmp, 10 + br i1 %cmp, label %land.lhs.true, label %if.end + +land.lhs.true: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 2) + %tmp1 = load i32, i32* %j.addr, align 4 + %tmp2 = load i32, i32* %i.addr, align 4 + %cmp1 = icmp sgt i32 %tmp1, %tmp2 + br i1 %cmp1, label %land.lhs.true.2, label %if.end + +land.lhs.true.2: ; preds = %land.lhs.true +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 7) + %tmp3 = load i32, i32* %j.addr, align 4 + %cmp3 = icmp slt i32 %tmp3, 20 + br i1 %cmp3, label %if.then, label %if.end + +if.then: ; preds = %land.lhs.true.2 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 9) + %call = call i32 @_Z3bari(i32 16) + store i32 %call, i32* %result, align 4 + br label %if.end + +if.end: ; preds = %if.then, %land.lhs.true.2, %land.lhs.true, %entry + %tmp4 = load i32, i32* %i.addr, align 4 + %cmp4 = icmp sgt i32 %tmp4, 20 + br i1 %cmp4, label %if.then.5, label %if.end.13 + +if.then.5: ; preds = %if.end +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 4) + %tmp5 = load i32, i32* %j.addr, align 4 + %tmp6 = load i32, i32* %i.addr, align 4 + %cmp6 = icmp sgt i32 %tmp5, %tmp6 + br i1 %cmp6, label %if.then.7, label %if.end.12 + +if.then.7: ; preds = %if.then.5 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 5) + %tmp7 = load i32, i32* %j.addr, align 4 + %cmp8 = icmp slt i32 %tmp7, 30 + br i1 %cmp8, label %if.then.9, label %if.end.11 + +if.then.9: ; preds = %if.then.7 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 8) + %call10 = call i32 @_Z3bari(i32 32) + store i32 %call10, i32* %result, align 4 + br label %if.end.11 + +if.end.11: ; preds = %if.then.9, %if.then.7 + br label %if.end.12 + +if.end.12: ; preds = %if.end.11, %if.then.5 + br label %if.end.13 + +if.end.13: ; preds = %if.end.12, %if.end + %tmp8 = load i32, i32* %i.addr, align 4 + %cmp14 = icmp eq i32 %tmp8, 3 + br i1 %cmp14, label %if.then.18, label %lor.lhs.false + +lor.lhs.false: ; preds = %if.end.13 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 3) + %tmp9 = load i32, i32* %j.addr, align 4 + %cmp15 = icmp eq i32 %tmp9, 47 + br i1 %cmp15, label %if.then.18, label %lor.lhs.false.16 + +lor.lhs.false.16: ; preds = %lor.lhs.false +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 6) + %tmp10 = load i32, i32* %i.addr, align 4 + %tmp11 = load i32, i32* %j.addr, align 4 + %cmp17 = icmp eq i32 %tmp10, %tmp11 + br i1 %cmp17, label %if.then.18, label %if.end.20 + +if.then.18: ; preds = %lor.lhs.false.16, %lor.lhs.false, %if.end.13 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 1) + %call19 = call i32 @_Z3bari(i32 64) + store i32 %call19, i32* %result, align 4 + br label %if.end.20 + +if.end.20: ; preds = %if.then.18, %lor.lhs.false.16 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__llvm_profile_name__Z12test_ifelse4ii, i32 0, i32 0), i64 107534361351, i32 10, i32 0) + %tmp12 = load i32, i32* %result, align 4 + ret i32 %tmp12 +} + +; Function Attrs: norecurse nounwind uwtable +define i32 @main() #1 { +entry: + %retval = alloca i32, align 4 + %val1 = alloca i32, align 4 + %val2 = alloca i32, align 4 + %val3 = alloca i32, align 4 + %val4 = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + %call = call i32 @_Z12test_ifelse1ii(i32 0, i32 2) + store i32 %call, i32* %val1, align 4 + %call1 = call i32 @_Z12test_ifelse1ii(i32 0, i32 0) + %tmp = load i32, i32* %val1, align 4 + %add = add nsw i32 %tmp, %call1 + store i32 %add, i32* %val1, align 4 + %call2 = call i32 @_Z12test_ifelse1ii(i32 1, i32 2) + %tmp1 = load i32, i32* %val1, align 4 + %add3 = add nsw i32 %tmp1, %call2 + store i32 %add3, i32* %val1, align 4 + %call4 = call i32 @_Z12test_ifelse1ii(i32 10, i32 2) + %tmp2 = load i32, i32* %val1, align 4 + %add5 = add nsw i32 %tmp2, %call4 + store i32 %add5, i32* %val1, align 4 + %call6 = call i32 @_Z12test_ifelse1ii(i32 11, i32 11) + %tmp3 = load i32, i32* %val1, align 4 + %add7 = add nsw i32 %tmp3, %call6 + store i32 %add7, i32* %val1, align 4 + %call8 = call i32 @_Z12test_ifelse2i(i32 -1) + store i32 %call8, i32* %val2, align 4 + %call9 = call i32 @_Z12test_ifelse2i(i32 0) + %tmp4 = load i32, i32* %val2, align 4 + %add10 = add nsw i32 %tmp4, %call9 + store i32 %add10, i32* %val2, align 4 + %call11 = call i32 @_Z12test_ifelse2i(i32 2) + %tmp5 = load i32, i32* %val2, align 4 + %add12 = add nsw i32 %tmp5, %call11 + store i32 %add12, i32* %val2, align 4 + %call13 = call i32 @_Z12test_ifelse2i(i32 3) + %tmp6 = load i32, i32* %val2, align 4 + %add14 = add nsw i32 %tmp6, %call13 + store i32 %add14, i32* %val2, align 4 + %call15 = call i32 @_Z12test_ifelse2i(i32 2) + %tmp7 = load i32, i32* %val2, align 4 + %add16 = add nsw i32 %tmp7, %call15 + store i32 %add16, i32* %val2, align 4 + %call17 = call i32 @_Z12test_ifelse2i(i32 103) + %tmp8 = load i32, i32* %val2, align 4 + %add18 = add nsw i32 %tmp8, %call17 + store i32 %add18, i32* %val2, align 4 + %call19 = call i32 @_Z12test_ifelse3i(i32 -1) + store i32 %call19, i32* %val3, align 4 + %call20 = call i32 @_Z12test_ifelse3i(i32 0) + %tmp9 = load i32, i32* %val3, align 4 + %add21 = add nsw i32 %tmp9, %call20 + store i32 %add21, i32* %val3, align 4 + %call22 = call i32 @_Z12test_ifelse3i(i32 2) + %tmp10 = load i32, i32* %val3, align 4 + %add23 = add nsw i32 %tmp10, %call22 + store i32 %add23, i32* %val3, align 4 + %call24 = call i32 @_Z12test_ifelse3i(i32 3) + %tmp11 = load i32, i32* %val3, align 4 + %add25 = add nsw i32 %tmp11, %call24 + store i32 %add25, i32* %val3, align 4 + %call26 = call i32 @_Z12test_ifelse3i(i32 2) + %tmp12 = load i32, i32* %val3, align 4 + %add27 = add nsw i32 %tmp12, %call26 + store i32 %add27, i32* %val3, align 4 + %call28 = call i32 @_Z12test_ifelse3i(i32 4) + %tmp13 = load i32, i32* %val3, align 4 + %add29 = add nsw i32 %tmp13, %call28 + store i32 %add29, i32* %val3, align 4 + %call30 = call i32 @_Z12test_ifelse3i(i32 103) + %tmp14 = load i32, i32* %val3, align 4 + %add31 = add nsw i32 %tmp14, %call30 + store i32 %add31, i32* %val3, align 4 + %call32 = call i32 @_Z12test_ifelse4ii(i32 11, i32 19) + store i32 %call32, i32* %val4, align 4 + %call33 = call i32 @_Z12test_ifelse4ii(i32 25, i32 27) + %tmp15 = load i32, i32* %val4, align 4 + %add34 = add nsw i32 %tmp15, %call33 + store i32 %add34, i32* %val4, align 4 + %call35 = call i32 @_Z12test_ifelse4ii(i32 11, i32 22) + %tmp16 = load i32, i32* %val4, align 4 + %add36 = add nsw i32 %tmp16, %call35 + store i32 %add36, i32* %val4, align 4 + %call37 = call i32 @_Z12test_ifelse4ii(i32 21, i32 20) + %tmp17 = load i32, i32* %val4, align 4 + %add38 = add nsw i32 %tmp17, %call37 + store i32 %add38, i32* %val4, align 4 + %call39 = call i32 @_Z12test_ifelse4ii(i32 1, i32 2) + %tmp18 = load i32, i32* %val4, align 4 + %add40 = add nsw i32 %tmp18, %call39 + store i32 %add40, i32* %val4, align 4 + %call41 = call i32 @_Z12test_ifelse4ii(i32 32, i32 31) + %tmp19 = load i32, i32* %val4, align 4 + %add42 = add nsw i32 %tmp19, %call41 + store i32 %add42, i32* %val4, align 4 + %call43 = call i32 @_Z12test_ifelse4ii(i32 3, i32 0) + %tmp20 = load i32, i32* %val4, align 4 + %add44 = add nsw i32 %tmp20, %call43 + store i32 %add44, i32* %val4, align 4 + %call45 = call i32 @_Z12test_ifelse4ii(i32 0, i32 47) + %tmp21 = load i32, i32* %val4, align 4 + %add46 = add nsw i32 %tmp21, %call45 + store i32 %add46, i32* %val4, align 4 + %call47 = call i32 @_Z12test_ifelse4ii(i32 165, i32 65) + %tmp22 = load i32, i32* %val4, align 4 + %add48 = add nsw i32 %tmp22, %call47 + store i32 %add48, i32* %val4, align 4 + %tmp23 = load i32, i32* %val1, align 4 + %cmp = icmp ne i32 %tmp23, 31 + br i1 %cmp, label %if.then, label %lor.lhs.false + +lor.lhs.false: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 53141135803, i32 5, i32 1) + %tmp24 = load i32, i32* %val2, align 4 + %cmp49 = icmp ne i32 %tmp24, 13 + br i1 %cmp49, label %if.then, label %lor.lhs.false.50 + +lor.lhs.false.50: ; preds = %lor.lhs.false +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 53141135803, i32 5, i32 2) + %tmp25 = load i32, i32* %val3, align 4 + %cmp51 = icmp ne i32 %tmp25, 12 + br i1 %cmp51, label %if.then, label %lor.lhs.false.52 + +lor.lhs.false.52: ; preds = %lor.lhs.false.50 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 53141135803, i32 5, i32 3) + %tmp26 = load i32, i32* %val4, align 4 + %cmp53 = icmp ne i32 %tmp26, 181 + br i1 %cmp53, label %if.then, label %if.end + +if.then: ; preds = %lor.lhs.false.52, %lor.lhs.false.50, %lor.lhs.false, %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 53141135803, i32 5, i32 0) + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %lor.lhs.false.52 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 53141135803, i32 5, i32 4) + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp27 = load i32, i32* %retval, align 4 + ret i32 %tmp27 +} + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} Index: test/Transforms/PGOProfile/test_ifelse_use.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_ifelse_use.ll @@ -0,0 +1,552 @@ +; RUN: opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/test_if.profdata -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind uwtable +define i32 @_Z3bari(i32 %i) #0 { +entry: + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + ret i32 %tmp +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse0ii(i32 %i, i32 %j) #0 { +entry: + %retval = alloca i32, align 4 + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %cmp = icmp sgt i32 %tmp, %tmp1 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + %tmp2 = load i32, i32* %i.addr, align 4 + store i32 %tmp2, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry + %tmp3 = load i32, i32* %j.addr, align 4 + store i32 %tmp3, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp4 = load i32, i32* %retval, align 4 + ret i32 %tmp4 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse1ii(i32 %i, i32 %j) #0 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + store i32 0, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.then, label %if.else.4 +; CHECK: !prof !1 + +if.then: ; preds = %entry + %tmp1 = load i32, i32* %j.addr, align 4 + %tobool1 = icmp ne i32 %tmp1, 0 + br i1 %tobool1, label %if.then.2, label %if.else +; CHECK: !prof !2 + +if.then.2: ; preds = %if.then + %call = call i32 @_Z3bari(i32 4) + store i32 %call, i32* %result, align 4 + br label %if.end + +if.else: ; preds = %if.then + %call3 = call i32 @_Z3bari(i32 1024) + store i32 %call3, i32* %result, align 4 + br label %if.end + +if.end: ; preds = %if.else, %if.then.2 + br label %if.end.11 + +if.else.4: ; preds = %entry + %tmp2 = load i32, i32* %j.addr, align 4 + %tobool5 = icmp ne i32 %tmp2, 0 + br i1 %tobool5, label %if.then.6, label %if.else.8 +; CHECK: !prof !3 + +if.then.6: ; preds = %if.else.4 + %call7 = call i32 @_Z3bari(i32 1) + store i32 %call7, i32* %result, align 4 + br label %if.end.10 + +if.else.8: ; preds = %if.else.4 + %call9 = call i32 @_Z3bari(i32 2) + store i32 %call9, i32* %result, align 4 + br label %if.end.10 + +if.end.10: ; preds = %if.else.8, %if.then.6 + br label %if.end.11 + +if.end.11: ; preds = %if.end.10, %if.end + %tmp3 = load i32, i32* %i.addr, align 4 + %tmp4 = load i32, i32* %j.addr, align 4 + %cmp = icmp sgt i32 %tmp3, %tmp4 + br i1 %cmp, label %if.then.12, label %if.end.14 +; CHECK: !prof !4 + +if.then.12: ; preds = %if.end.11 + %tmp5 = load i32, i32* %result, align 4 + %mul = mul nsw i32 %tmp5, 2 + %call13 = call i32 @_Z3bari(i32 %mul) + store i32 %call13, i32* %result, align 4 + br label %if.end.14 + +if.end.14: ; preds = %if.then.12, %if.end.11 + %tmp6 = load i32, i32* %i.addr, align 4 + %cmp15 = icmp sgt i32 %tmp6, 10 + br i1 %cmp15, label %if.then.16, label %if.end.22 +; CHECK: !prof !4 + +if.then.16: ; preds = %if.end.14 + %tmp7 = load i32, i32* %j.addr, align 4 + %cmp17 = icmp sgt i32 %tmp7, 10 + br i1 %cmp17, label %if.then.18, label %if.end.21 +; CHECK: !prof !5 + +if.then.18: ; preds = %if.then.16 + %tmp8 = load i32, i32* %result, align 4 + %mul19 = mul nsw i32 %tmp8, 4 + %call20 = call i32 @_Z3bari(i32 %mul19) + store i32 %call20, i32* %result, align 4 + br label %if.end.21 + +if.end.21: ; preds = %if.then.18, %if.then.16 + br label %if.end.22 + +if.end.22: ; preds = %if.end.21, %if.end.14 + %tmp9 = load i32, i32* %result, align 4 + ret i32 %tmp9 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse2i(i32 %i) #0 { +entry: + %retval = alloca i32, align 4 + %i.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 0, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.end, label %if.then +; CHECK: !prof !6 + +if.then: ; preds = %entry + %call = call i32 @_Z3bari(i32 1) + store i32 %call, i32* %result, align 4 + br label %if.end + +if.end: ; preds = %if.then, %entry + %tmp1 = load i32, i32* %i.addr, align 4 + %cmp = icmp eq i32 %tmp1, 1 + br i1 %cmp, label %if.then.1, label %if.end.3 +; CHECK: !prof !7 + +if.then.1: ; preds = %if.end + %call2 = call i32 @_Z3bari(i32 1024) + store i32 %call2, i32* %result, align 4 + br label %if.end.3 + +if.end.3: ; preds = %if.then.1, %if.end + %tmp2 = load i32, i32* %i.addr, align 4 + %cmp4 = icmp eq i32 %tmp2, 2 + br i1 %cmp4, label %if.then.5, label %if.end.7 +; CHECK: !prof !8 + +if.then.5: ; preds = %if.end.3 + %call6 = call i32 @_Z3bari(i32 2) + store i32 %call6, i32* %result, align 4 + br label %if.end.7 + +if.end.7: ; preds = %if.then.5, %if.end.3 + %tmp3 = load i32, i32* %i.addr, align 4 + %cmp8 = icmp eq i32 %tmp3, 3 + br i1 %cmp8, label %if.then.9, label %if.end.11 +; CHECK: !prof !9 + +if.then.9: ; preds = %if.end.7 + %call10 = call i32 @_Z3bari(i32 8) + store i32 %call10, i32* %retval, align 4 + br label %return + +if.end.11: ; preds = %if.end.7 + %tmp4 = load i32, i32* %i.addr, align 4 + %cmp12 = icmp eq i32 %tmp4, 4 + br i1 %cmp12, label %if.then.13, label %if.end.15 +; CHECK: !prof !10 + +if.then.13: ; preds = %if.end.11 + %call14 = call i32 @_Z3bari(i32 2048) + store i32 %call14, i32* %retval, align 4 + br label %return + +if.end.15: ; preds = %if.end.11 + %tmp5 = load i32, i32* %result, align 4 + store i32 %tmp5, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end.15, %if.then.13, %if.then.9 + %tmp6 = load i32, i32* %retval, align 4 + ret i32 %tmp6 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse3i(i32 %i) #0 { +entry: + %retval = alloca i32, align 4 + %i.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 0, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.else, label %if.then +; CHECK: !prof !11 + +if.then: ; preds = %entry + %call = call i32 @_Z3bari(i32 1) + store i32 %call, i32* %result, align 4 + br label %if.end.18 + +if.else: ; preds = %entry + %tmp1 = load i32, i32* %i.addr, align 4 + %cmp = icmp eq i32 %tmp1, 1 + br i1 %cmp, label %if.then.1, label %if.else.3 +; CHECK: !prof !7 + +if.then.1: ; preds = %if.else + %call2 = call i32 @_Z3bari(i32 1) + store i32 %call2, i32* %result, align 4 + br label %if.end.17 + +if.else.3: ; preds = %if.else + %tmp2 = load i32, i32* %i.addr, align 4 + %cmp4 = icmp eq i32 %tmp2, 2 + br i1 %cmp4, label %if.then.5, label %if.else.7 +; CHECK: !prof !8 + +if.then.5: ; preds = %if.else.3 + %call6 = call i32 @_Z3bari(i32 2) + store i32 %call6, i32* %result, align 4 + br label %if.end.16 + +if.else.7: ; preds = %if.else.3 + %tmp3 = load i32, i32* %i.addr, align 4 + %cmp8 = icmp eq i32 %tmp3, 3 + br i1 %cmp8, label %if.then.9, label %if.else.11 +; CHECK: !prof !12 + +if.then.9: ; preds = %if.else.7 + %call10 = call i32 @_Z3bari(i32 3) + store i32 %call10, i32* %retval, align 4 + br label %return + +if.else.11: ; preds = %if.else.7 + %tmp4 = load i32, i32* %i.addr, align 4 + %cmp12 = icmp eq i32 %tmp4, 4 + br i1 %cmp12, label %if.then.13, label %if.end +; CHECK: !prof !13 + +if.then.13: ; preds = %if.else.11 + %call14 = call i32 @_Z3bari(i32 4) + store i32 %call14, i32* %retval, align 4 + br label %return + +if.end: ; preds = %if.else.11 + br label %if.end.15 + +if.end.15: ; preds = %if.end + br label %if.end.16 + +if.end.16: ; preds = %if.end.15, %if.then.5 + br label %if.end.17 + +if.end.17: ; preds = %if.end.16, %if.then.1 + br label %if.end.18 + +if.end.18: ; preds = %if.end.17, %if.then + %tmp5 = load i32, i32* %result, align 4 + store i32 %tmp5, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end.18, %if.then.13, %if.then.9 + %tmp6 = load i32, i32* %retval, align 4 + ret i32 %tmp6 +} + +; Function Attrs: nounwind uwtable +define i32 @_Z12test_ifelse4ii(i32 %i, i32 %j) #0 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + store i32 1, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %cmp = icmp sgt i32 %tmp, 10 + br i1 %cmp, label %land.lhs.true, label %if.end +; CHECK: !prof !14 + +land.lhs.true: ; preds = %entry + %tmp1 = load i32, i32* %j.addr, align 4 + %tmp2 = load i32, i32* %i.addr, align 4 + %cmp1 = icmp sgt i32 %tmp1, %tmp2 + br i1 %cmp1, label %land.lhs.true.2, label %if.end +; CHECK: !prof !15 + +land.lhs.true.2: ; preds = %land.lhs.true + %tmp3 = load i32, i32* %j.addr, align 4 + %cmp3 = icmp slt i32 %tmp3, 20 + br i1 %cmp3, label %if.then, label %if.end +; CHECK: !prof !13 + +if.then: ; preds = %land.lhs.true.2 + %call = call i32 @_Z3bari(i32 16) + store i32 %call, i32* %result, align 4 + br label %if.end + +if.end: ; preds = %if.then, %land.lhs.true.2, %land.lhs.true, %entry + %tmp4 = load i32, i32* %i.addr, align 4 + %cmp4 = icmp sgt i32 %tmp4, 20 + br i1 %cmp4, label %if.then.5, label %if.end.13 +; CHECK: !prof !16 + +if.then.5: ; preds = %if.end + %tmp5 = load i32, i32* %j.addr, align 4 + %tmp6 = load i32, i32* %i.addr, align 4 + %cmp6 = icmp sgt i32 %tmp5, %tmp6 + br i1 %cmp6, label %if.then.7, label %if.end.12 +; CHECK: !prof !12 + +if.then.7: ; preds = %if.then.5 + %tmp7 = load i32, i32* %j.addr, align 4 + %cmp8 = icmp slt i32 %tmp7, 30 + br i1 %cmp8, label %if.then.9, label %if.end.11 +; CHECK: !prof !5 + +if.then.9: ; preds = %if.then.7 + %call10 = call i32 @_Z3bari(i32 32) + store i32 %call10, i32* %result, align 4 + br label %if.end.11 + +if.end.11: ; preds = %if.then.9, %if.then.7 + br label %if.end.12 + +if.end.12: ; preds = %if.end.11, %if.then.5 + br label %if.end.13 + +if.end.13: ; preds = %if.end.12, %if.end + %tmp8 = load i32, i32* %i.addr, align 4 + %cmp14 = icmp eq i32 %tmp8, 3 + br i1 %cmp14, label %if.then.18, label %lor.lhs.false +; CHECK: !prof !17 + +lor.lhs.false: ; preds = %if.end.13 + %tmp9 = load i32, i32* %j.addr, align 4 + %cmp15 = icmp eq i32 %tmp9, 47 + br i1 %cmp15, label %if.then.18, label %lor.lhs.false.16 +; CHECK: !prof !18 + +lor.lhs.false.16: ; preds = %lor.lhs.false + %tmp10 = load i32, i32* %i.addr, align 4 + %tmp11 = load i32, i32* %j.addr, align 4 + %cmp17 = icmp eq i32 %tmp10, %tmp11 + br i1 %cmp17, label %if.then.18, label %if.end.20 +; CHECK: !prof !19 + +if.then.18: ; preds = %lor.lhs.false.16, %lor.lhs.false, %if.end.13 + %call19 = call i32 @_Z3bari(i32 64) + store i32 %call19, i32* %result, align 4 + br label %if.end.20 + +if.end.20: ; preds = %if.then.18, %lor.lhs.false.16 + %tmp12 = load i32, i32* %result, align 4 + ret i32 %tmp12 +} + +; Function Attrs: norecurse nounwind uwtable +define i32 @main() #1 { +entry: + %retval = alloca i32, align 4 + %val1 = alloca i32, align 4 + %val2 = alloca i32, align 4 + %val3 = alloca i32, align 4 + %val4 = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + %call = call i32 @_Z12test_ifelse1ii(i32 0, i32 2) + store i32 %call, i32* %val1, align 4 + %call1 = call i32 @_Z12test_ifelse1ii(i32 0, i32 0) + %tmp = load i32, i32* %val1, align 4 + %add = add nsw i32 %tmp, %call1 + store i32 %add, i32* %val1, align 4 + %call2 = call i32 @_Z12test_ifelse1ii(i32 1, i32 2) + %tmp1 = load i32, i32* %val1, align 4 + %add3 = add nsw i32 %tmp1, %call2 + store i32 %add3, i32* %val1, align 4 + %call4 = call i32 @_Z12test_ifelse1ii(i32 10, i32 2) + %tmp2 = load i32, i32* %val1, align 4 + %add5 = add nsw i32 %tmp2, %call4 + store i32 %add5, i32* %val1, align 4 + %call6 = call i32 @_Z12test_ifelse1ii(i32 11, i32 11) + %tmp3 = load i32, i32* %val1, align 4 + %add7 = add nsw i32 %tmp3, %call6 + store i32 %add7, i32* %val1, align 4 + %call8 = call i32 @_Z12test_ifelse2i(i32 -1) + store i32 %call8, i32* %val2, align 4 + %call9 = call i32 @_Z12test_ifelse2i(i32 0) + %tmp4 = load i32, i32* %val2, align 4 + %add10 = add nsw i32 %tmp4, %call9 + store i32 %add10, i32* %val2, align 4 + %call11 = call i32 @_Z12test_ifelse2i(i32 2) + %tmp5 = load i32, i32* %val2, align 4 + %add12 = add nsw i32 %tmp5, %call11 + store i32 %add12, i32* %val2, align 4 + %call13 = call i32 @_Z12test_ifelse2i(i32 3) + %tmp6 = load i32, i32* %val2, align 4 + %add14 = add nsw i32 %tmp6, %call13 + store i32 %add14, i32* %val2, align 4 + %call15 = call i32 @_Z12test_ifelse2i(i32 2) + %tmp7 = load i32, i32* %val2, align 4 + %add16 = add nsw i32 %tmp7, %call15 + store i32 %add16, i32* %val2, align 4 + %call17 = call i32 @_Z12test_ifelse2i(i32 103) + %tmp8 = load i32, i32* %val2, align 4 + %add18 = add nsw i32 %tmp8, %call17 + store i32 %add18, i32* %val2, align 4 + %call19 = call i32 @_Z12test_ifelse3i(i32 -1) + store i32 %call19, i32* %val3, align 4 + %call20 = call i32 @_Z12test_ifelse3i(i32 0) + %tmp9 = load i32, i32* %val3, align 4 + %add21 = add nsw i32 %tmp9, %call20 + store i32 %add21, i32* %val3, align 4 + %call22 = call i32 @_Z12test_ifelse3i(i32 2) + %tmp10 = load i32, i32* %val3, align 4 + %add23 = add nsw i32 %tmp10, %call22 + store i32 %add23, i32* %val3, align 4 + %call24 = call i32 @_Z12test_ifelse3i(i32 3) + %tmp11 = load i32, i32* %val3, align 4 + %add25 = add nsw i32 %tmp11, %call24 + store i32 %add25, i32* %val3, align 4 + %call26 = call i32 @_Z12test_ifelse3i(i32 2) + %tmp12 = load i32, i32* %val3, align 4 + %add27 = add nsw i32 %tmp12, %call26 + store i32 %add27, i32* %val3, align 4 + %call28 = call i32 @_Z12test_ifelse3i(i32 4) + %tmp13 = load i32, i32* %val3, align 4 + %add29 = add nsw i32 %tmp13, %call28 + store i32 %add29, i32* %val3, align 4 + %call30 = call i32 @_Z12test_ifelse3i(i32 103) + %tmp14 = load i32, i32* %val3, align 4 + %add31 = add nsw i32 %tmp14, %call30 + store i32 %add31, i32* %val3, align 4 + %call32 = call i32 @_Z12test_ifelse4ii(i32 11, i32 19) + store i32 %call32, i32* %val4, align 4 + %call33 = call i32 @_Z12test_ifelse4ii(i32 25, i32 27) + %tmp15 = load i32, i32* %val4, align 4 + %add34 = add nsw i32 %tmp15, %call33 + store i32 %add34, i32* %val4, align 4 + %call35 = call i32 @_Z12test_ifelse4ii(i32 11, i32 22) + %tmp16 = load i32, i32* %val4, align 4 + %add36 = add nsw i32 %tmp16, %call35 + store i32 %add36, i32* %val4, align 4 + %call37 = call i32 @_Z12test_ifelse4ii(i32 21, i32 20) + %tmp17 = load i32, i32* %val4, align 4 + %add38 = add nsw i32 %tmp17, %call37 + store i32 %add38, i32* %val4, align 4 + %call39 = call i32 @_Z12test_ifelse4ii(i32 1, i32 2) + %tmp18 = load i32, i32* %val4, align 4 + %add40 = add nsw i32 %tmp18, %call39 + store i32 %add40, i32* %val4, align 4 + %call41 = call i32 @_Z12test_ifelse4ii(i32 32, i32 31) + %tmp19 = load i32, i32* %val4, align 4 + %add42 = add nsw i32 %tmp19, %call41 + store i32 %add42, i32* %val4, align 4 + %call43 = call i32 @_Z12test_ifelse4ii(i32 3, i32 0) + %tmp20 = load i32, i32* %val4, align 4 + %add44 = add nsw i32 %tmp20, %call43 + store i32 %add44, i32* %val4, align 4 + %call45 = call i32 @_Z12test_ifelse4ii(i32 0, i32 47) + %tmp21 = load i32, i32* %val4, align 4 + %add46 = add nsw i32 %tmp21, %call45 + store i32 %add46, i32* %val4, align 4 + %call47 = call i32 @_Z12test_ifelse4ii(i32 165, i32 65) + %tmp22 = load i32, i32* %val4, align 4 + %add48 = add nsw i32 %tmp22, %call47 + store i32 %add48, i32* %val4, align 4 + %tmp23 = load i32, i32* %val1, align 4 + %cmp = icmp ne i32 %tmp23, 31 + br i1 %cmp, label %if.then, label %lor.lhs.false +; CHECK: !prof !20 + +lor.lhs.false: ; preds = %entry + %tmp24 = load i32, i32* %val2, align 4 + %cmp49 = icmp ne i32 %tmp24, 13 + br i1 %cmp49, label %if.then, label %lor.lhs.false.50 +; CHECK: !prof !20 + +lor.lhs.false.50: ; preds = %lor.lhs.false + %tmp25 = load i32, i32* %val3, align 4 + %cmp51 = icmp ne i32 %tmp25, 12 + br i1 %cmp51, label %if.then, label %lor.lhs.false.52 +; CHECK: !prof !20 + +lor.lhs.false.52: ; preds = %lor.lhs.false.50 + %tmp26 = load i32, i32* %val4, align 4 + %cmp53 = icmp ne i32 %tmp26, 181 + br i1 %cmp53, label %if.then, label %if.end +; CHECK: !prof !20 + +if.then: ; preds = %lor.lhs.false.52, %lor.lhs.false.50, %lor.lhs.false, %entry + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %lor.lhs.false.52 + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp27 = load i32, i32* %retval, align 4 + ret i32 %tmp27 +} + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} +; CHECK: !1 = !{!"branch_weights", i32 4, i32 3} +; CHECK: !2 = !{!"branch_weights", i32 4, i32 1} +; CHECK: !3 = !{!"branch_weights", i32 2, i32 2} +; CHECK: !4 = !{!"branch_weights", i32 2, i32 5} +; CHECK: !5 = !{!"branch_weights", i32 2, i32 1} +; CHECK: !6 = !{!"branch_weights", i32 6, i32 2} +; CHECK: !7 = !{!"branch_weights", i32 1, i32 7} +; CHECK: !8 = !{!"branch_weights", i32 3, i32 5} +; CHECK: !9 = !{!"branch_weights", i32 2, i32 6} +; CHECK: !10 = !{!"branch_weights", i32 1, i32 6} +; CHECK: !11 = !{!"branch_weights", i32 7, i32 2} +; CHECK: !12 = !{!"branch_weights", i32 2, i32 4} +; CHECK: !13 = !{!"branch_weights", i32 2, i32 3} +; CHECK: !14 = !{!"branch_weights", i32 7, i32 4} +; CHECK: !15 = !{!"branch_weights", i32 4, i32 4} +; CHECK: !16 = !{!"branch_weights", i32 5, i32 6} +; CHECK: !17 = !{!"branch_weights", i32 2, i32 9} +; CHECK: !18 = !{!"branch_weights", i32 2, i32 8} +; CHECK: !19 = !{!"branch_weights", i32 1, i32 8} +; CHECK: !20 = !{!"branch_weights", i32 1, i32 2} Index: test/Transforms/PGOProfile/test_missing.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_missing.ll @@ -0,0 +1,82 @@ +; RUN: not opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/none.profdata -S 2>&1 | grep 'none.profdata: No such file or directory' +; RUN: not opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/bad.profdata -S 2>&1 | grep 'Invalid instrumentation profile data (bad magic)' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@val = global i32 0, align 4 + +; Function Attrs: uwtable +define void @_Z3foov() #0 { +entry: + %tmp = load i32, i32* @val, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.then, label %if.end + +if.then: ; preds = %entry + %call = call i32 @_ZL8uncalledii(i32 1, i32 2) + store i32 %call, i32* @val, align 4 + br label %if.end + +if.end: ; preds = %if.then, %entry + %tmp1 = load i32, i32* @val, align 4 + %call1 = call i32 @_ZL6calledii(i32 %tmp1, i32 4) + store i32 %call1, i32* @val, align 4 + ret void +} + +; Function Attrs: inlinehint nounwind uwtable +define internal i32 @_ZL8uncalledii(i32 %i, i32 %j) #1 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %mul = mul nsw i32 %tmp, %tmp1 + ret i32 %mul +} + +; Function Attrs: inlinehint nounwind uwtable +define internal i32 @_ZL6calledii(i32 %i, i32 %j) #1 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %add = add nsw i32 %tmp, %tmp1 + ret i32 %add +} + +; Function Attrs: norecurse uwtable +define i32 @main() #2 { +entry: + %retval = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + call void @_Z3foov() + %tmp = load i32, i32* @val, align 4 + %cmp = icmp ne i32 %tmp, 4 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp1 = load i32, i32* %retval, align 4 + ret i32 %tmp1 +} + +attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { inlinehint nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} Index: test/Transforms/PGOProfile/test_switch_gen.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_switch_gen.ll @@ -0,0 +1,155 @@ +; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: @__llvm_profile_name__Z3bari = private constant [7 x i8] c"_Z3bari" +; CHECK: @__llvm_profile_name__Z11test_switchii = private constant [17 x i8] c"_Z11test_switchii" +; CHECK: @__llvm_profile_name_main = private constant [4 x i8] c"main" + +; Function Attrs: noinline nounwind uwtable +define i32 @_Z3bari(i32 %i) #0 { +entry: +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__llvm_profile_name__Z3bari, i32 0, i32 0), i64 12884901887, i32 1, i32 0) + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + ret i32 %tmp +} + +; Function Attrs: nounwind uwtable +define i32 @_Z11test_switchii(i32 %i, i32 %j) #1 { +entry: + %retval = alloca i32, align 4 + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + store i32 0, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + switch i32 %tmp, label %sw.default [ + i32 1, label %sw.bb + i32 2, label %sw.bb.1 + i32 3, label %sw.bb.3 + i32 4, label %sw.bb.3 + i32 5, label %sw.bb.3 + ] + +sw.bb: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z11test_switchii, i32 0, i32 0), i64 82348442248, i32 8, i32 5) + %call = call i32 @_Z3bari(i32 2) + store i32 %call, i32* %result, align 4 + br label %sw.epilog + +sw.bb.1: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z11test_switchii, i32 0, i32 0), i64 82348442248, i32 8, i32 4) + %call2 = call i32 @_Z3bari(i32 1024) + store i32 %call2, i32* %result, align 4 + br label %sw.epilog + +sw.bb.3: ; preds = %entry, %entry, %entry + %tmp1 = load i32, i32* %j.addr, align 4 + %cmp = icmp eq i32 %tmp1, 2 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %sw.bb.3 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z11test_switchii, i32 0, i32 0), i64 82348442248, i32 8, i32 2) + %call4 = call i32 @_Z3bari(i32 4) + store i32 %call4, i32* %retval, align 4 + br label %return + +if.end: ; preds = %sw.bb.3 +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z11test_switchii, i32 0, i32 0), i64 82348442248, i32 8, i32 3) + %call5 = call i32 @_Z3bari(i32 8) + store i32 %call5, i32* %result, align 4 + br label %sw.epilog + +sw.default: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z11test_switchii, i32 0, i32 0), i64 82348442248, i32 8, i32 6) + %call6 = call i32 @_Z3bari(i32 32) + store i32 %call6, i32* %result, align 4 + %tmp2 = load i32, i32* %j.addr, align 4 + %cmp7 = icmp sgt i32 %tmp2, 10 + br i1 %cmp7, label %if.then.8, label %if.end.9 + +if.then.8: ; preds = %sw.default +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__llvm_profile_name__Z11test_switchii, i32 0, i32 0), i64 82348442248, i32 8, i32 7) + %tmp3 = load i32, i32* %result, align 4 + %add = add nsw i32 %tmp3, 10 + store i32 %add, i32* %result, align 4 + br label %if.end.9 + +if.end.9: ; preds = %if.then.8, %sw.default + br label %sw.epilog + +sw.epilog: ; preds = %if.end.9, %if.end, %sw.bb.1, %sw.bb + %tmp4 = load i32, i32* %result, align 4 + store i32 %tmp4, i32* %retval, align 4 + br label %return + +return: ; preds = %sw.epilog, %if.then + %tmp5 = load i32, i32* %retval, align 4 + ret i32 %tmp5 +} + +; Function Attrs: norecurse nounwind uwtable +define i32 @main() #2 { +entry: + %retval = alloca i32, align 4 + %val = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + store i32 0, i32* %val, align 4 + %call = call i32 @_Z11test_switchii(i32 0, i32 100) + %tmp = load i32, i32* %val, align 4 + %add = add nsw i32 %tmp, %call + store i32 %add, i32* %val, align 4 + %call1 = call i32 @_Z11test_switchii(i32 1, i32 0) + %tmp1 = load i32, i32* %val, align 4 + %add2 = add nsw i32 %tmp1, %call1 + store i32 %add2, i32* %val, align 4 + %call3 = call i32 @_Z11test_switchii(i32 3, i32 0) + %tmp2 = load i32, i32* %val, align 4 + %add4 = add nsw i32 %tmp2, %call3 + store i32 %add4, i32* %val, align 4 + %call5 = call i32 @_Z11test_switchii(i32 3, i32 2) + %tmp3 = load i32, i32* %val, align 4 + %add6 = add nsw i32 %tmp3, %call5 + store i32 %add6, i32* %val, align 4 + %call7 = call i32 @_Z11test_switchii(i32 4, i32 0) + %tmp4 = load i32, i32* %val, align 4 + %add8 = add nsw i32 %tmp4, %call7 + store i32 %add8, i32* %val, align 4 + %call9 = call i32 @_Z11test_switchii(i32 5, i32 2) + %tmp5 = load i32, i32* %val, align 4 + %add10 = add nsw i32 %tmp5, %call9 + store i32 %add10, i32* %val, align 4 + %call11 = call i32 @_Z11test_switchii(i32 16, i32 0) + %tmp6 = load i32, i32* %val, align 4 + %add12 = add nsw i32 %tmp6, %call11 + store i32 %add12, i32* %val, align 4 + %tmp7 = load i32, i32* %val, align 4 + %cmp = icmp ne i32 %tmp7, 100 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 29368252703, i32 2, i32 0) + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry +; CHECK: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i64 29368252703, i32 2, i32 1) + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp8 = load i32, i32* %retval, align 4 + ret i32 %tmp8 +} + +attributes #0 = { noinline nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} Index: test/Transforms/PGOProfile/test_switch_use.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_switch_use.ll @@ -0,0 +1,150 @@ +; RUN: opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/test_switch.profdata -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: noinline nounwind uwtable +define i32 @_Z3bari(i32 %i) #0 { +entry: + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + ret i32 %tmp +} + +; Function Attrs: nounwind uwtable +define i32 @_Z11test_switchii(i32 %i, i32 %j) #1 { +entry: + %retval = alloca i32, align 4 + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + %result = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + store i32 0, i32* %result, align 4 + %tmp = load i32, i32* %i.addr, align 4 + switch i32 %tmp, label %sw.default [ + i32 1, label %sw.bb + i32 2, label %sw.bb.1 + i32 3, label %sw.bb.3 + i32 4, label %sw.bb.3 + i32 5, label %sw.bb.3 + ] +; CHECK: !prof !1 + +sw.bb: ; preds = %entry + %call = call i32 @_Z3bari(i32 2) + store i32 %call, i32* %result, align 4 + br label %sw.epilog + +sw.bb.1: ; preds = %entry + %call2 = call i32 @_Z3bari(i32 1024) + store i32 %call2, i32* %result, align 4 + br label %sw.epilog + +sw.bb.3: ; preds = %entry, %entry, %entry + %tmp1 = load i32, i32* %j.addr, align 4 + %cmp = icmp eq i32 %tmp1, 2 + br i1 %cmp, label %if.then, label %if.end +; CHECK: !prof !2 + +if.then: ; preds = %sw.bb.3 + %call4 = call i32 @_Z3bari(i32 4) + store i32 %call4, i32* %retval, align 4 + br label %return + +if.end: ; preds = %sw.bb.3 + %call5 = call i32 @_Z3bari(i32 8) + store i32 %call5, i32* %result, align 4 + br label %sw.epilog + +sw.default: ; preds = %entry + %call6 = call i32 @_Z3bari(i32 32) + store i32 %call6, i32* %result, align 4 + %tmp2 = load i32, i32* %j.addr, align 4 + %cmp7 = icmp sgt i32 %tmp2, 10 + br i1 %cmp7, label %if.then.8, label %if.end.9 +; CHECK: !prof !3 + +if.then.8: ; preds = %sw.default + %tmp3 = load i32, i32* %result, align 4 + %add = add nsw i32 %tmp3, 10 + store i32 %add, i32* %result, align 4 + br label %if.end.9 + +if.end.9: ; preds = %if.then.8, %sw.default + br label %sw.epilog + +sw.epilog: ; preds = %if.end.9, %if.end, %sw.bb.1, %sw.bb + %tmp4 = load i32, i32* %result, align 4 + store i32 %tmp4, i32* %retval, align 4 + br label %return + +return: ; preds = %sw.epilog, %if.then + %tmp5 = load i32, i32* %retval, align 4 + ret i32 %tmp5 +} + +; Function Attrs: norecurse nounwind uwtable +define i32 @main() #2 { +entry: + %retval = alloca i32, align 4 + %val = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + store i32 0, i32* %val, align 4 + %call = call i32 @_Z11test_switchii(i32 0, i32 100) + %tmp = load i32, i32* %val, align 4 + %add = add nsw i32 %tmp, %call + store i32 %add, i32* %val, align 4 + %call1 = call i32 @_Z11test_switchii(i32 1, i32 0) + %tmp1 = load i32, i32* %val, align 4 + %add2 = add nsw i32 %tmp1, %call1 + store i32 %add2, i32* %val, align 4 + %call3 = call i32 @_Z11test_switchii(i32 3, i32 0) + %tmp2 = load i32, i32* %val, align 4 + %add4 = add nsw i32 %tmp2, %call3 + store i32 %add4, i32* %val, align 4 + %call5 = call i32 @_Z11test_switchii(i32 3, i32 2) + %tmp3 = load i32, i32* %val, align 4 + %add6 = add nsw i32 %tmp3, %call5 + store i32 %add6, i32* %val, align 4 + %call7 = call i32 @_Z11test_switchii(i32 4, i32 0) + %tmp4 = load i32, i32* %val, align 4 + %add8 = add nsw i32 %tmp4, %call7 + store i32 %add8, i32* %val, align 4 + %call9 = call i32 @_Z11test_switchii(i32 5, i32 2) + %tmp5 = load i32, i32* %val, align 4 + %add10 = add nsw i32 %tmp5, %call9 + store i32 %add10, i32* %val, align 4 + %call11 = call i32 @_Z11test_switchii(i32 16, i32 0) + %tmp6 = load i32, i32* %val, align 4 + %add12 = add nsw i32 %tmp6, %call11 + store i32 %add12, i32* %val, align 4 + %tmp7 = load i32, i32* %val, align 4 + %cmp = icmp ne i32 %tmp7, 100 + br i1 %cmp, label %if.then, label %if.end +; CHECK: !prof !4 + +if.then: ; preds = %entry + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp8 = load i32, i32* %retval, align 4 + ret i32 %tmp8 +} + +attributes #0 = { noinline nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} +; CHECK: !1 = !{!"branch_weights", i32 3, i32 2, i32 1, i32 3, i32 2, i32 2} +; CHECK: !2 = !{!"branch_weights", i32 3, i32 3} +; CHECK: !3 = !{!"branch_weights", i32 2, i32 2} +; CHECK: !4 = !{!"branch_weights", i32 1, i32 2} Index: test/Transforms/PGOProfile/test_unmatch_use.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_unmatch_use.ll @@ -0,0 +1,88 @@ +; RUN: opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/test_if.profdata 2>& 1 | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: No profile data available for function _Z3foov +; CHECK: No profile data available for function _ZL6calledii +; CHECK: No profile data available for function _ZL8uncalledii +; CHECK: Function hash mismatch main + +@val = global i32 0, align 4 + +; Function Attrs: uwtable +define void @_Z3foov() #0 { +entry: + %call = call i32 @_ZL6calledii(i32 0, i32 0) + store i32 %call, i32* @val, align 4 + %tmp = load i32, i32* @val, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.then, label %if.end + +if.then: ; preds = %entry + %call1 = call i32 @_ZL8uncalledii(i32 1, i32 2) + store i32 %call1, i32* @val, align 4 + br label %if.end + +if.end: ; preds = %if.then, %entry + %tmp1 = load i32, i32* @val, align 4 + %call2 = call i32 @_ZL6calledii(i32 %tmp1, i32 4) + store i32 %call2, i32* @val, align 4 + ret void +} + +; Function Attrs: inlinehint nounwind uwtable +define internal i32 @_ZL6calledii(i32 %i, i32 %j) #1 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %add = add nsw i32 %tmp, %tmp1 + ret i32 %add +} + +; Function Attrs: inlinehint nounwind uwtable +define internal i32 @_ZL8uncalledii(i32 %i, i32 %j) #1 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %mul = mul nsw i32 %tmp, %tmp1 + ret i32 %mul +} + +; Function Attrs: norecurse uwtable +define i32 @main() #2 { +entry: + %retval = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + call void @_Z3foov() + %tmp = load i32, i32* @val, align 4 + %cmp = icmp ne i32 %tmp, 4 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp1 = load i32, i32* %retval, align 4 + ret i32 %tmp1 +} + +attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { inlinehint nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} Index: test/Transforms/PGOProfile/test_use.ll =================================================================== --- /dev/null +++ test/Transforms/PGOProfile/test_use.ll @@ -0,0 +1,84 @@ +; RUN: opt < %s -pgo-instr-use -pgo-profile-file=%S/Inputs/test.profdata -S | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@val = global i32 0, align 4 + +; Function Attrs: uwtable +define void @_Z3foov() #0 { +entry: + %tmp = load i32, i32* @val, align 4 + %tobool = icmp ne i32 %tmp, 0 + br i1 %tobool, label %if.then, label %if.end +; CHECK: !prof !1 + +if.then: ; preds = %entry + %call = call i32 @_ZL8uncalledii(i32 1, i32 2) + store i32 %call, i32* @val, align 4 + br label %if.end + +if.end: ; preds = %if.then, %entry + %tmp1 = load i32, i32* @val, align 4 + %call1 = call i32 @_ZL6calledii(i32 %tmp1, i32 4) + store i32 %call1, i32* @val, align 4 + ret void +} + +; Function Attrs: inlinehint nounwind uwtable +define internal i32 @_ZL8uncalledii(i32 %i, i32 %j) #1 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %mul = mul nsw i32 %tmp, %tmp1 + ret i32 %mul +} + +; Function Attrs: inlinehint nounwind uwtable +define internal i32 @_ZL6calledii(i32 %i, i32 %j) #1 { +entry: + %i.addr = alloca i32, align 4 + %j.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + store i32 %j, i32* %j.addr, align 4 + %tmp = load i32, i32* %i.addr, align 4 + %tmp1 = load i32, i32* %j.addr, align 4 + %add = add nsw i32 %tmp, %tmp1 + ret i32 %add +} + +; Function Attrs: norecurse uwtable +define i32 @main() #2 { +entry: + %retval = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + call void @_Z3foov() + %tmp = load i32, i32* @val, align 4 + %cmp = icmp ne i32 %tmp, 4 + br i1 %cmp, label %if.then, label %if.end +; CHECK: !prof !1 + +if.then: ; preds = %entry + store i32 -1, i32* %retval, align 4 + br label %return + +if.end: ; preds = %entry + store i32 0, i32* %retval, align 4 + br label %return + +return: ; preds = %if.end, %if.then + %tmp1 = load i32, i32* %retval, align 4 + ret i32 %tmp1 +} + +attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { inlinehint nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { norecurse uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = !{!"clang version 3.8.0 "} +; CHECK: !1 = !{!"branch_weights", i32 1, i32 2}