From c9093afce5e27b13fa6fad9a68b2d5595eed2916 Mon Sep 17 00:00:00 2001 From: RonxBulld <526677628@qq.com> Date: Sat, 26 Mar 2022 13:11:43 +0800 Subject: [PATCH] Provide a switch option 'newscope' to determine whether different BasicBlocks of the same Subprogram have different DIScopes. --- DebugIR.cpp | 13 ++++++++----- DebugIR.h | 4 ++++ Main.cpp | 8 +++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/DebugIR.cpp b/DebugIR.cpp index 2f9889494..56209d83c 100644 --- a/DebugIR.cpp +++ b/DebugIR.cpp @@ -126,7 +126,7 @@ class DIUpdater : public InstVisitor { int tempNameCounter; ValueMap SubprogramDescriptors; - ValueMap BlockDescriptors; + ValueMap ScopeDescriptors; DenseMap TypeDescriptors; public: @@ -296,9 +296,10 @@ class DIUpdater : public InstVisitor { } DIScope *getBlockScope(DIScope *ParentScope, const BasicBlock *B) { - auto BScope = BlockDescriptors.find(B); - if (BScope != BlockDescriptors.end()) { - return BScope->second; + auto S = BBAlwaysNewScope ? dyn_cast(B) : dyn_cast(B->getParent()); + auto ScopeIt = ScopeDescriptors.find(S); + if (ScopeIt != ScopeDescriptors.end()) { + return ScopeIt->second; } else { // Let's build a scope for this block. unsigned Line = 0; @@ -308,7 +309,7 @@ class DIUpdater : public InstVisitor { << B->getParent()->getName().str() << "\n"); } auto Scope = Builder.createLexicalBlock(ParentScope, FileNode, Line, 0); - BlockDescriptors[B] = Scope; + ScopeDescriptors[S] = Scope; return Scope; } } @@ -496,6 +497,8 @@ class DIUpdater : public InstVisitor { namespace llvm { +bool BBAlwaysNewScope = false; + std::unique_ptr createDebugInfo(Module &M, std::string Directory, std::string Filename) { diff --git a/DebugIR.h b/DebugIR.h index 1ebd4b215..4ab465c67 100644 --- a/DebugIR.h +++ b/DebugIR.h @@ -18,6 +18,10 @@ namespace llvm { +// Each BasicBlock uses a different DIScope. +// Default is false. +extern bool BBAlwaysNewScope; + // Attaches debug info to M, assuming it is parsed from Directory/Filename. // Returns a module for display in debugger devoid of any debug info. std::unique_ptr diff --git a/Main.cpp b/Main.cpp index 452de8db7..ead067c4b 100644 --- a/Main.cpp +++ b/Main.cpp @@ -32,12 +32,18 @@ using namespace llvm; namespace { // Command line arguments parsed using LLVM's command line parser. -cl::opt InputFile(cl::Positional, cl::desc(""), +cl::opt InputFile(cl::Positional, cl::desc(""), cl::Required); cl::opt RunInstNamer("instnamer", cl::desc("Run instnamer on input, prior to processing it")); +cl::opt + AlwaysNew("newscope", + cl::desc("Each BasicBlock uses a different DIScope."), + cl::location(BBAlwaysNewScope), + cl::init(false)); + void versionPrinter(llvm::raw_ostream &OS) { OS << "debugir: v0.1.0\n"; } ExitOnError ExitOnErr;