aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LexicalScopes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/LexicalScopes.cpp')
-rw-r--r--llvm/lib/CodeGen/LexicalScopes.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/LexicalScopes.cpp b/llvm/lib/CodeGen/LexicalScopes.cpp
index 5916f61..9fc9ac9 100644
--- a/llvm/lib/CodeGen/LexicalScopes.cpp
+++ b/llvm/lib/CodeGen/LexicalScopes.cpp
@@ -23,6 +23,7 @@
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
@@ -36,8 +37,16 @@ using namespace llvm;
#define DEBUG_TYPE "lexicalscopes"
-/// reset - Reset the instance so that it's prepared for another function.
-void LexicalScopes::reset() {
+static bool skipUnit(const DICompileUnit *CU) {
+ return CU->getEmissionKind() == DICompileUnit::NoDebug;
+}
+
+void LexicalScopes::resetModule() {
+ FunctionMap.clear();
+ resetFunction();
+}
+
+void LexicalScopes::resetFunction() {
MF = nullptr;
CurrentFnLexicalScope = nullptr;
LexicalScopeMap.clear();
@@ -47,12 +56,19 @@ void LexicalScopes::reset() {
DominatedBlocks.clear();
}
-/// initialize - Scan machine function and constuct lexical scope nest.
-void LexicalScopes::initialize(const MachineFunction &Fn) {
- reset();
+void LexicalScopes::initialize(const Module &M) {
+ resetModule();
+ for (const Function &F : M) {
+ DISubprogram *SP = F.getSubprogram();
+ if (SP && (!SP->getUnit() || !skipUnit(SP->getUnit())))
+ FunctionMap[SP] = &F;
+ }
+}
+
+void LexicalScopes::scanFunction(const MachineFunction &Fn) {
+ resetFunction();
// Don't attempt any lexical scope creation for a NoDebug compile unit.
- if (Fn.getFunction().getSubprogram()->getUnit()->getEmissionKind() ==
- DICompileUnit::NoDebug)
+ if (skipUnit(Fn.getFunction().getSubprogram()->getUnit()))
return;
MF = &Fn;
SmallVector<InsnRange, 4> MIRanges;
@@ -143,8 +159,7 @@ LexicalScope *LexicalScopes::getOrCreateLexicalScope(const DILocalScope *Scope,
const DILocation *IA) {
if (IA) {
// Skip scopes inlined from a NoDebug compile unit.
- if (Scope->getSubprogram()->getUnit()->getEmissionKind() ==
- DICompileUnit::NoDebug)
+ if (skipUnit(Scope->getSubprogram()->getUnit()))
return getOrCreateLexicalScope(IA);
// Create an abstract scope for inlined function.
getOrCreateAbstractScope(Scope);