diff options
author | Mircea Trofin <mtrofin@google.com> | 2018-12-21 22:48:50 +0000 |
---|---|---|
committer | Mircea Trofin <mtrofin@google.com> | 2018-12-21 22:48:50 +0000 |
commit | b53eeb6f4c824fcdfcb93dd9325a603c005660a7 (patch) | |
tree | 584b0989c4d54efc27f9a41e0c3430741f39fd7d /llvm/lib/Transforms | |
parent | 8d20cfdfc6c26533a87c525cb6e8dbc50a65e036 (diff) | |
download | bcm5719-llvm-b53eeb6f4c824fcdfcb93dd9325a603c005660a7.tar.gz bcm5719-llvm-b53eeb6f4c824fcdfcb93dd9325a603c005660a7.zip |
[llvm] API for encoding/decoding DWARF discriminators.
Summary:
Added a pair of APIs for encoding/decoding the 3 components of a DWARF discriminator described in http://lists.llvm.org/pipermail/llvm-dev/2016-October/106532.html: the base discriminator, the duplication factor (useful in profile-guided optimization) and the copy index (used to identify copies of code in cases like loop unrolling)
The encoding packs 3 unsigned values in 32 bits. This CL addresses 2 issues:
- communicates overflow back to the user
- supports encoding all 3 components together. Current APIs assume a sequencing of events. For example, creating a new discriminator based on an existing one by changing the base discriminator was not supported.
Reviewers: davidxl, danielcdh, wmi, dblaikie
Reviewed By: dblaikie
Subscribers: zzheng, dmgreen, aprantl, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D55681
llvm-svn: 349973
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Utils/AddDiscriminators.cpp | 29 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnroll.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 11 |
4 files changed, 50 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Utils/AddDiscriminators.cpp b/llvm/lib/Transforms/Utils/AddDiscriminators.cpp index e3ef4236222..1e0fd5588ca 100644 --- a/llvm/lib/Transforms/Utils/AddDiscriminators.cpp +++ b/llvm/lib/Transforms/Utils/AddDiscriminators.cpp @@ -209,10 +209,18 @@ static bool addDiscriminators(Function &F) { // Only the lowest 7 bits are used to represent a discriminator to fit // it in 1 byte ULEB128 representation. unsigned Discriminator = R.second ? ++LDM[L] : LDM[L]; - I.setDebugLoc(DIL->setBaseDiscriminator(Discriminator)); - LLVM_DEBUG(dbgs() << DIL->getFilename() << ":" << DIL->getLine() << ":" - << DIL->getColumn() << ":" << Discriminator << " " << I - << "\n"); + auto NewDIL = DIL->setBaseDiscriminator(Discriminator); + if (!NewDIL) { + LLVM_DEBUG(dbgs() << "Could not encode discriminator: " + << DIL->getFilename() << ":" << DIL->getLine() << ":" + << DIL->getColumn() << ":" << Discriminator << " " + << I << "\n"); + } else { + I.setDebugLoc(NewDIL.getValue()); + LLVM_DEBUG(dbgs() << DIL->getFilename() << ":" << DIL->getLine() << ":" + << DIL->getColumn() << ":" << Discriminator << " " << I + << "\n"); + } Changed = true; } } @@ -239,8 +247,17 @@ static bool addDiscriminators(Function &F) { std::make_pair(CurrentDIL->getFilename(), CurrentDIL->getLine()); if (!CallLocations.insert(L).second) { unsigned Discriminator = ++LDM[L]; - Current->setDebugLoc(CurrentDIL->setBaseDiscriminator(Discriminator)); - Changed = true; + auto NewDIL = CurrentDIL->setBaseDiscriminator(Discriminator); + if (!NewDIL) { + LLVM_DEBUG(dbgs() + << "Could not encode discriminator: " + << CurrentDIL->getFilename() << ":" + << CurrentDIL->getLine() << ":" << CurrentDIL->getColumn() + << ":" << Discriminator << " " << I << "\n"); + } else { + Current->setDebugLoc(NewDIL.getValue()); + Changed = true; + } } } } diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index 0ed4038cc3e..da7ed2bd165 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -598,8 +598,15 @@ LoopUnrollResult llvm::UnrollLoop( for (BasicBlock *BB : L->getBlocks()) for (Instruction &I : *BB) if (!isa<DbgInfoIntrinsic>(&I)) - if (const DILocation *DIL = I.getDebugLoc()) - I.setDebugLoc(DIL->cloneWithDuplicationFactor(Count)); + if (const DILocation *DIL = I.getDebugLoc()) { + auto NewDIL = DIL->cloneWithDuplicationFactor(Count); + if (NewDIL) + I.setDebugLoc(NewDIL.getValue()); + else + LLVM_DEBUG(dbgs() + << "Failed to create new discriminator: " + << DIL->getFilename() << " Line: " << DIL->getLine()); + } for (unsigned It = 1; It != Count; ++It) { std::vector<BasicBlock*> NewBlocks; diff --git a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp index b5d80f669fb..e26762639c1 100644 --- a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp @@ -300,8 +300,15 @@ LoopUnrollResult llvm::UnrollAndJamLoop( for (BasicBlock *BB : L->getBlocks()) for (Instruction &I : *BB) if (!isa<DbgInfoIntrinsic>(&I)) - if (const DILocation *DIL = I.getDebugLoc()) - I.setDebugLoc(DIL->cloneWithDuplicationFactor(Count)); + if (const DILocation *DIL = I.getDebugLoc()) { + auto NewDIL = DIL->cloneWithDuplicationFactor(Count); + if (NewDIL) + I.setDebugLoc(NewDIL.getValue()); + else + LLVM_DEBUG(dbgs() + << "Failed to create new discriminator: " + << DIL->getFilename() << " Line: " << DIL->getLine()); + } // Copy all blocks for (unsigned It = 1; It != Count; ++It) { diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index c74352cf703..c45dee590b8 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -759,8 +759,15 @@ void InnerLoopVectorizer::setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr) if (const Instruction *Inst = dyn_cast_or_null<Instruction>(Ptr)) { const DILocation *DIL = Inst->getDebugLoc(); if (DIL && Inst->getFunction()->isDebugInfoForProfiling() && - !isa<DbgInfoIntrinsic>(Inst)) - B.SetCurrentDebugLocation(DIL->cloneWithDuplicationFactor(UF * VF)); + !isa<DbgInfoIntrinsic>(Inst)) { + auto NewDIL = DIL->cloneWithDuplicationFactor(UF * VF); + if (NewDIL) + B.SetCurrentDebugLocation(NewDIL.getValue()); + else + LLVM_DEBUG(dbgs() + << "Failed to create new discriminator: " + << DIL->getFilename() << " Line: " << DIL->getLine()); + } else B.SetCurrentDebugLocation(DIL); } else |