diff options
Diffstat (limited to 'contrib/llvm/lib/Transforms/Utils/AddDiscriminators.cpp')
| -rw-r--r-- | contrib/llvm/lib/Transforms/Utils/AddDiscriminators.cpp | 52 | 
1 files changed, 16 insertions, 36 deletions
diff --git a/contrib/llvm/lib/Transforms/Utils/AddDiscriminators.cpp b/contrib/llvm/lib/Transforms/Utils/AddDiscriminators.cpp index d034905b6572..2e95926c0b3f 100644 --- a/contrib/llvm/lib/Transforms/Utils/AddDiscriminators.cpp +++ b/contrib/llvm/lib/Transforms/Utils/AddDiscriminators.cpp @@ -57,12 +57,10 @@  #include "llvm/ADT/DenseSet.h"  #include "llvm/IR/BasicBlock.h"  #include "llvm/IR/Constants.h" -#include "llvm/IR/DIBuilder.h"  #include "llvm/IR/DebugInfo.h"  #include "llvm/IR/Instructions.h"  #include "llvm/IR/IntrinsicInst.h"  #include "llvm/IR/LLVMContext.h" -#include "llvm/IR/Module.h"  #include "llvm/Pass.h"  #include "llvm/Support/CommandLine.h"  #include "llvm/Support/Debug.h" @@ -159,20 +157,14 @@ static bool addDiscriminators(Function &F) {    // If the function has debug information, but the user has disabled    // discriminators, do nothing.    // Simlarly, if the function has no debug info, do nothing. -  // Finally, if this module is built with dwarf versions earlier than 4, -  // do nothing (discriminator support is a DWARF 4 feature). -  if (NoDiscriminators || !F.getSubprogram() || -      F.getParent()->getDwarfVersion() < 4) +  if (NoDiscriminators || !F.getSubprogram())      return false;    bool Changed = false; -  Module *M = F.getParent(); -  LLVMContext &Ctx = M->getContext(); -  DIBuilder Builder(*M, /*AllowUnresolved*/ false);    typedef std::pair<StringRef, unsigned> Location; -  typedef DenseMap<const BasicBlock *, Metadata *> BBScopeMap; -  typedef DenseMap<Location, BBScopeMap> LocationBBMap; +  typedef DenseSet<const BasicBlock *> BBSet; +  typedef DenseMap<Location, BBSet> LocationBBMap;    typedef DenseMap<Location, unsigned> LocationDiscriminatorMap;    typedef DenseSet<Location> LocationSet; @@ -184,32 +176,25 @@ static bool addDiscriminators(Function &F) {    // discriminator for this instruction.    for (BasicBlock &B : F) {      for (auto &I : B.getInstList()) { -      if (isa<DbgInfoIntrinsic>(&I)) +      if (isa<IntrinsicInst>(&I))          continue;        const DILocation *DIL = I.getDebugLoc();        if (!DIL)          continue;        Location L = std::make_pair(DIL->getFilename(), DIL->getLine());        auto &BBMap = LBM[L]; -      auto R = BBMap.insert(std::make_pair(&B, (Metadata *)nullptr)); +      auto R = BBMap.insert(&B);        if (BBMap.size() == 1)          continue; -      bool InsertSuccess = R.second; -      Metadata *&NewScope = R.first->second; -      // If we could insert a different block in the same location, a +      // If we could insert more than one block with the same line+file, a        // discriminator is needed to distinguish both instructions. -      if (InsertSuccess) { -        auto *Scope = DIL->getScope(); -        auto *File = -            Builder.createFile(DIL->getFilename(), Scope->getDirectory()); -        NewScope = Builder.createLexicalBlockFile(Scope, File, ++LDM[L]); -      } -      I.setDebugLoc(DILocation::get(Ctx, DIL->getLine(), DIL->getColumn(), -                                    NewScope, DIL->getInlinedAt())); +      // 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]) & 0x7f; +      I.setDebugLoc(DIL->cloneWithDiscriminator(Discriminator));        DEBUG(dbgs() << DIL->getFilename() << ":" << DIL->getLine() << ":" -                   << DIL->getColumn() << ":" -                   << dyn_cast<DILexicalBlockFile>(NewScope)->getDiscriminator() -                   << I << "\n"); +                   << DIL->getColumn() << ":" << Discriminator << " " << I +                   << "\n");        Changed = true;      }    } @@ -222,7 +207,7 @@ static bool addDiscriminators(Function &F) {      LocationSet CallLocations;      for (auto &I : B.getInstList()) {        CallInst *Current = dyn_cast<CallInst>(&I); -      if (!Current || isa<DbgInfoIntrinsic>(&I)) +      if (!Current || isa<IntrinsicInst>(&I))          continue;        DILocation *CurrentDIL = Current->getDebugLoc(); @@ -231,13 +216,8 @@ static bool addDiscriminators(Function &F) {        Location L =            std::make_pair(CurrentDIL->getFilename(), CurrentDIL->getLine());        if (!CallLocations.insert(L).second) { -        auto *Scope = CurrentDIL->getScope(); -        auto *File = Builder.createFile(CurrentDIL->getFilename(), -                                        Scope->getDirectory()); -        auto *NewScope = Builder.createLexicalBlockFile(Scope, File, ++LDM[L]); -        Current->setDebugLoc(DILocation::get(Ctx, CurrentDIL->getLine(), -                                             CurrentDIL->getColumn(), NewScope, -                                             CurrentDIL->getInlinedAt())); +        Current->setDebugLoc( +            CurrentDIL->cloneWithDiscriminator((++LDM[L]) & 0x7f));          Changed = true;        }      } @@ -249,7 +229,7 @@ bool AddDiscriminatorsLegacyPass::runOnFunction(Function &F) {    return addDiscriminators(F);  }  PreservedAnalyses AddDiscriminatorsPass::run(Function &F, -                                             AnalysisManager<Function> &AM) { +                                             FunctionAnalysisManager &AM) {    if (!addDiscriminators(F))      return PreservedAnalyses::all();  | 
