diff options
author | Xinliang David Li <davidxl@google.com> | 2016-09-18 18:34:07 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-09-18 18:34:07 +0000 |
commit | 4ca1733a06484bc97bca0835d3506b2939f8808f (patch) | |
tree | 451e61c60448f31a02992176cd3d0e75e554d347 /llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | |
parent | fbbe75b1fe7aa6d2678ba692d945f07fc335e611 (diff) | |
download | bcm5719-llvm-4ca1733a06484bc97bca0835d3506b2939f8808f.tar.gz bcm5719-llvm-4ca1733a06484bc97bca0835d3506b2939f8808f.zip |
[Profile] Implement select instruction instrumentation in IR PGO
Differential Revision: http://reviews.llvm.org/D23727
llvm-svn: 281858
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index 6ca49cf5985..4f71261a1ab 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -107,6 +107,13 @@ StringRef InstrProfiling::getCoverageSection() const { return getInstrProfCoverageSectionName(isMachO()); } +static InstrProfIncrementInst *castToIncrementInst(Instruction *Instr) { + InstrProfIncrementInst *Inc = dyn_cast<InstrProfIncrementInstStep>(Instr); + if (Inc) + return Inc; + return dyn_cast<InstrProfIncrementInst>(Instr); +} + bool InstrProfiling::run(Module &M) { bool MadeChange = false; @@ -138,7 +145,8 @@ bool InstrProfiling::run(Module &M) { for (BasicBlock &BB : F) for (auto I = BB.begin(), E = BB.end(); I != E;) { auto Instr = I++; - if (auto *Inc = dyn_cast<InstrProfIncrementInst>(Instr)) { + InstrProfIncrementInst *Inc = castToIncrementInst(&*Instr); + if (Inc) { lowerIncrement(Inc); MadeChange = true; } else if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(Instr)) { @@ -214,6 +222,14 @@ void InstrProfiling::lowerValueProfileInst(InstrProfValueProfileInst *Ind) { Ind->eraseFromParent(); } +static Value *getIncrementStep(InstrProfIncrementInst *Inc, + IRBuilder<> &Builder) { + auto *IncWithStep = dyn_cast<InstrProfIncrementInstStep>(Inc); + if (IncWithStep) + return IncWithStep->getStep(); + return Builder.getInt64(1); +} + void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) { GlobalVariable *Counters = getOrCreateRegionCounters(Inc); @@ -221,7 +237,7 @@ void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) { uint64_t Index = Inc->getIndex()->getZExtValue(); Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters, 0, Index); Value *Count = Builder.CreateLoad(Addr, "pgocount"); - Count = Builder.CreateAdd(Count, Builder.getInt64(1)); + Count = Builder.CreateAdd(Count, getIncrementStep(Inc, Builder)); Inc->replaceAllUsesWith(Builder.CreateStore(Count, Addr)); Inc->eraseFromParent(); } |