Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions llvm/include/llvm/CodeGen/DebugHandlerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ class DebugHandlerBase : public AsmPrinterHandler {
static bool isUnsignedDIType(const DIType *Ty);

const InstructionOrdering &getInstOrdering() const { return InstOrdering; }

const LexicalScopes &getLexicalScopes() const { return LScopes; }
};

} // namespace llvm
Expand Down
20 changes: 3 additions & 17 deletions llvm/include/llvm/CodeGen/LexicalScopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,12 @@ class LexicalScopes {
public:
LexicalScopes() = default;

/// Scan module to build subprogram-to-function map.
LLVM_ABI void initialize(const Module &);

/// Scan machine function and constuct lexical scope nest, resets
/// the instance if necessary.
LLVM_ABI void scanFunction(const MachineFunction &);

/// Reset the instance so that it's prepared for another module.
LLVM_ABI void resetModule();
LLVM_ABI void initialize(const MachineFunction &);

/// Reset the instance so that it's prepared for another function.
LLVM_ABI void resetFunction();
/// Release memory.
LLVM_ABI void reset();

/// Return true if there is any lexical scope information available.
bool empty() { return CurrentFnLexicalScope == nullptr; }
Expand Down Expand Up @@ -202,11 +196,6 @@ class LexicalScopes {
/// Find or create an abstract lexical scope.
LLVM_ABI LexicalScope *getOrCreateAbstractScope(const DILocalScope *Scope);

/// Get function to which the given subprogram is attached, if exists.
const Function *getFunction(const DISubprogram *SP) const {
return FunctionMap.lookup(SP);
}

private:
/// Find lexical scope for the given Scope/IA. If not available
/// then create new lexical scope.
Expand Down Expand Up @@ -236,9 +225,6 @@ class LexicalScopes {

const MachineFunction *MF = nullptr;

/// Mapping between DISubprograms and IR functions.
DenseMap<const DISubprogram *, const Function *> FunctionMap;

/// Tracks the scopes in the current function.
// Use an unordered_map to ensure value pointer validity over insertion.
std::unordered_map<const DILocalScope *, LexicalScope> LexicalScopeMap;
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ DebugHandlerBase::~DebugHandlerBase() = default;
void DebugHandlerBase::beginModule(Module *M) {
if (M->debug_compile_units().empty())
Asm = nullptr;
else
LScopes.initialize(*M);
}

// Each LexicalScope has first instruction and last instruction to mark
Expand Down Expand Up @@ -271,7 +269,7 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {

// Grab the lexical scopes for the function, if we don't have any of those
// then we're not going to be able to do anything.
LScopes.scanFunction(*MF);
LScopes.initialize(*MF);
if (LScopes.empty()) {
beginFunctionImpl(MF);
return;
Expand Down
103 changes: 33 additions & 70 deletions llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,8 @@ void DwarfCompileUnit::addWasmRelocBaseGlobal(DIELoc *Loc, StringRef GlobalName,
// and DW_AT_high_pc attributes. If there are global variables in this
// scope then create and insert DIEs for these variables.
DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP,
const Function &F,
MCSymbol *LineTableSym) {
DIE *SPDie = getOrCreateSubprogramDIE(SP, &F, includeMinimalInlineScopes());
DIE *SPDie = getOrCreateSubprogramDIE(SP, includeMinimalInlineScopes());
SmallVector<RangeSpan, 2> BB_List;
// If basic block sections are on, ranges for each basic block section has
// to be emitted separately.
Expand Down Expand Up @@ -1123,10 +1122,9 @@ sortLocalVars(SmallVectorImpl<DbgVariable *> &Input) {
}

DIE &DwarfCompileUnit::constructSubprogramScopeDIE(const DISubprogram *Sub,
const Function &F,
LexicalScope *Scope,
MCSymbol *LineTableSym) {
DIE &ScopeDIE = updateSubprogramScopeDIE(Sub, F, LineTableSym);
DIE &ScopeDIE = updateSubprogramScopeDIE(Sub, LineTableSym);

if (Scope) {
assert(!Scope->getInlinedAt());
Expand Down Expand Up @@ -1200,17 +1198,32 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
return ObjectPointer;
}

DIE &DwarfCompileUnit::getOrCreateAbstractSubprogramDIE(
const DISubprogram *SP) {
if (auto *AbsDef = getAbstractScopeDIEs().lookup(SP))
return *AbsDef;
void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
LexicalScope *Scope) {
auto *SP = cast<DISubprogram>(Scope->getScopeNode());
if (getAbstractScopeDIEs().count(SP))
return;

auto [ContextDIE, ContextCU] = getOrCreateAbstractSubprogramContextDIE(SP);
return createAbstractSubprogramDIE(SP, ContextDIE, ContextCU);
}
DIE *ContextDIE;
DwarfCompileUnit *ContextCU = this;

if (includeMinimalInlineScopes())
ContextDIE = &getUnitDie();
// Some of this is duplicated from DwarfUnit::getOrCreateSubprogramDIE, with
// the important distinction that the debug node is not associated with the
// DIE (since the debug node will be associated with the concrete DIE, if
// any). It could be refactored to some common utility function.
else if (auto *SPDecl = SP->getDeclaration()) {
ContextDIE = &getUnitDie();
getOrCreateSubprogramDIE(SPDecl);
} else {
ContextDIE = getOrCreateContextDIE(SP->getScope());
// The scope may be shared with a subprogram that has already been
// constructed in another CU, in which case we need to construct this
// subprogram in the same CU.
ContextCU = DD->lookupCU(ContextDIE->getUnitDie());
}

DIE &DwarfCompileUnit::createAbstractSubprogramDIE(
const DISubprogram *SP, DIE *ContextDIE, DwarfCompileUnit *ContextCU) {
// Passing null as the associated node because the abstract definition
// shouldn't be found by lookup.
DIE &AbsDef = ContextCU->createAndAddDIE(dwarf::DW_TAG_subprogram,
Expand All @@ -1224,45 +1237,8 @@ DIE &DwarfCompileUnit::createAbstractSubprogramDIE(
DD->getDwarfVersion() <= 4 ? std::optional<dwarf::Form>()
: dwarf::DW_FORM_implicit_const,
dwarf::DW_INL_inlined);

return AbsDef;
}

std::pair<DIE *, DwarfCompileUnit *>
DwarfCompileUnit::getOrCreateAbstractSubprogramContextDIE(
const DISubprogram *SP) {
bool Minimal = includeMinimalInlineScopes();
bool IgnoreScope = shouldPlaceInUnitDIE(SP, Minimal);
DIE *ContextDIE = getOrCreateSubprogramContextDIE(SP, IgnoreScope);

if (auto *SPDecl = SP->getDeclaration())
if (!Minimal)
getOrCreateSubprogramDIE(SPDecl, nullptr);

// The scope may be shared with a subprogram that has already been
// constructed in another CU, in which case we need to construct this
// subprogram in the same CU.
auto *ContextCU = IgnoreScope ? this : DD->lookupCU(ContextDIE->getUnitDie());

return std::make_pair(ContextDIE, ContextCU);
}

void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
LexicalScope *Scope) {
auto *SP = cast<DISubprogram>(Scope->getScopeNode());

// Populate subprogram DIE only once.
if (!getFinalizedAbstractSubprograms().insert(SP).second)
return;

auto [ContextDIE, ContextCU] = getOrCreateAbstractSubprogramContextDIE(SP);
DIE *AbsDef = getAbstractScopeDIEs().lookup(SP);
if (!AbsDef)
AbsDef = &createAbstractSubprogramDIE(SP, ContextDIE, ContextCU);

if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, *AbsDef))
ContextCU->addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer,
*ObjectPointer);
if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, AbsDef))
ContextCU->addDIEEntry(AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
}

bool DwarfCompileUnit::useGNUAnalogForDwarf5Feature() const {
Expand Down Expand Up @@ -1317,9 +1293,9 @@ DwarfCompileUnit::getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const {
}

DIE &DwarfCompileUnit::constructCallSiteEntryDIE(
DIE &ScopeDIE, const DISubprogram *CalleeSP, const Function *CalleeF,
bool IsTail, const MCSymbol *PCAddr, const MCSymbol *CallAddr,
unsigned CallReg, DIType *AllocSiteTy) {
DIE &ScopeDIE, const DISubprogram *CalleeSP, bool IsTail,
const MCSymbol *PCAddr, const MCSymbol *CallAddr, unsigned CallReg,
DIType *AllocSiteTy) {
// Insert a call site entry DIE within ScopeDIE.
DIE &CallSiteDIE = createAndAddDIE(getDwarf5OrGNUTag(dwarf::DW_TAG_call_site),
ScopeDIE, nullptr);
Expand All @@ -1329,7 +1305,7 @@ DIE &DwarfCompileUnit::constructCallSiteEntryDIE(
addAddress(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_target),
MachineLocation(CallReg));
} else if (CalleeSP) {
DIE *CalleeDIE = getOrCreateSubprogramDIE(CalleeSP, CalleeF);
DIE *CalleeDIE = getOrCreateSubprogramDIE(CalleeSP);
assert(CalleeDIE && "Could not create DIE for call site entry origin");
if (AddLinkageNamesToDeclCallOriginsForTuning(DD) &&
!CalleeSP->isDefinition() &&
Expand Down Expand Up @@ -1420,7 +1396,7 @@ DIE *DwarfCompileUnit::constructImportedEntityDIE(
if (auto *AbsSPDie = getAbstractScopeDIEs().lookup(SP))
EntityDie = AbsSPDie;
else
EntityDie = getOrCreateSubprogramDIE(SP, nullptr);
EntityDie = getOrCreateSubprogramDIE(SP);
} else if (auto *T = dyn_cast<DIType>(Entity))
EntityDie = getOrCreateTypeDIE(T);
else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
Expand Down Expand Up @@ -1829,16 +1805,3 @@ DIE *DwarfCompileUnit::getOrCreateContextDIE(const DIScope *Context) {
}
return DwarfUnit::getOrCreateContextDIE(Context);
}

DIE *DwarfCompileUnit::getOrCreateSubprogramDIE(const DISubprogram *SP,
const Function *F,
bool Minimal) {
if (!F && SP->isDefinition()) {
F = DD->getLexicalScopes().getFunction(SP);

if (!F)
return &getCU().getOrCreateAbstractSubprogramDIE(SP);
}

return DwarfUnit::getOrCreateSubprogramDIE(SP, F, Minimal);
}
35 changes: 5 additions & 30 deletions llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class DwarfCompileUnit final : public DwarfUnit {

// List of abstract local scopes (either DISubprogram or DILexicalBlock).
DenseMap<const DILocalScope *, DIE *> AbstractLocalScopeDIEs;
SmallPtrSet<const DISubprogram *, 8> FinalizedAbstractSubprograms;

// List of inlined lexical block scopes that belong to subprograms within this
// CU.
Expand Down Expand Up @@ -138,28 +137,12 @@ class DwarfCompileUnit final : public DwarfUnit {
return DU->getAbstractEntities();
}

auto &getFinalizedAbstractSubprograms() {
if (isDwoUnit() && !DD->shareAcrossDWOCUs())
return FinalizedAbstractSubprograms;
return DU->getFinalizedAbstractSubprograms();
}

void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) override;

/// Add info for Wasm-global-based relocation.
void addWasmRelocBaseGlobal(DIELoc *Loc, StringRef GlobalName,
uint64_t GlobalIndex);

/// Create context DIE for abstract subprogram.
/// \returns The context DIE and the compile unit where abstract
/// DIE should be constructed.
std::pair<DIE *, DwarfCompileUnit *>
getOrCreateAbstractSubprogramContextDIE(const DISubprogram *SP);

/// Create new DIE for abstract subprogram.
DIE &createAbstractSubprogramDIE(const DISubprogram *SP, DIE *ContextDIE,
DwarfCompileUnit *ContextCU);

public:
DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A,
DwarfDebug *DW, DwarfFile *DWU,
Expand Down Expand Up @@ -233,8 +216,7 @@ class DwarfCompileUnit final : public DwarfUnit {
/// DW_AT_low_pc, DW_AT_high_pc and DW_AT_LLVM_stmt_sequence attributes.
/// If there are global variables in this scope then create and insert DIEs
/// for these variables.
DIE &updateSubprogramScopeDIE(const DISubprogram *SP, const Function &F,
MCSymbol *LineTableSym);
DIE &updateSubprogramScopeDIE(const DISubprogram *SP, MCSymbol *LineTableSym);

void constructScopeDIE(LexicalScope *Scope, DIE &ParentScopeDIE);

Expand Down Expand Up @@ -277,18 +259,12 @@ class DwarfCompileUnit final : public DwarfUnit {
/// This instance of 'getOrCreateContextDIE()' can handle DILocalScope.
DIE *getOrCreateContextDIE(const DIScope *Ty) override;

DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, const Function *F,
bool Minimal = false) override;

/// Construct a DIE for this subprogram scope.
DIE &constructSubprogramScopeDIE(const DISubprogram *Sub, const Function &F,
LexicalScope *Scope, MCSymbol *LineTableSym);
DIE &constructSubprogramScopeDIE(const DISubprogram *Sub, LexicalScope *Scope,
MCSymbol *LineTableSym);

DIE *createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE);

/// Create an abstract subprogram DIE, that should later be populated
/// by \ref constructAbstractSubprogramScopeDIE.
DIE &getOrCreateAbstractSubprogramDIE(const DISubprogram *SP);
void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);

/// Whether to use the GNU analog for a DWARF5 tag, attribute, or location
Expand All @@ -305,15 +281,14 @@ class DwarfCompileUnit final : public DwarfUnit {
dwarf::LocationAtom getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const;

/// Construct a call site entry DIE describing a call within \p Scope to a
/// callee described by \p CalleeSP and \p CalleeF.
/// callee described by \p CalleeSP.
/// \p IsTail specifies whether the call is a tail call.
/// \p PCAddr points to the PC value after the call instruction.
/// \p CallAddr points to the PC value at the call instruction (or is null).
/// \p CallReg is a register location for an indirect call. For direct calls
/// the \p CallReg is set to 0.
DIE &constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram *CalleeSP,
const Function *CalleeF, bool IsTail,
const MCSymbol *PCAddr,
bool IsTail, const MCSymbol *PCAddr,
const MCSymbol *CallAddr, unsigned CallReg,
DIType *AllocSiteTy);
/// Construct call site parameter DIEs for the \p CallSiteDIE. The \p Params
Expand Down
13 changes: 5 additions & 8 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,8 @@ void DwarfDebug::constructCallSiteEntryDIEs(const DISubprogram &SP,
->getName(CallReg)))
<< (IsTail ? " [IsTail]" : "") << "\n");

DIE &CallSiteDIE =
CU.constructCallSiteEntryDIE(ScopeDIE, CalleeSP, CalleeDecl, IsTail,
PCAddr, CallAddr, CallReg, AllocSiteTy);
DIE &CallSiteDIE = CU.constructCallSiteEntryDIE(
ScopeDIE, CalleeSP, IsTail, PCAddr, CallAddr, CallReg, AllocSiteTy);

// Optionally emit call-site-param debug info.
if (emitDebugEntryValues()) {
Expand Down Expand Up @@ -2708,8 +2707,7 @@ void DwarfDebug::skippedNonDebugFunction() {

// Gather and emit post-function debug information.
void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
const Function &F = MF->getFunction();
const DISubprogram *SP = F.getSubprogram();
const DISubprogram *SP = MF->getFunction().getSubprogram();

assert(CurFn == MF &&
"endFunction should be called with the same function as beginFunction");
Expand Down Expand Up @@ -2778,12 +2776,11 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {

ProcessedSPNodes.insert(SP);
DIE &ScopeDIE =
TheCU.constructSubprogramScopeDIE(SP, F, FnScope, FunctionLineTableLabel);
TheCU.constructSubprogramScopeDIE(SP, FnScope, FunctionLineTableLabel);
if (auto *SkelCU = TheCU.getSkeleton())
if (!LScopes.getAbstractScopesList().empty() &&
TheCU.getCUNode()->getSplitDebugInlining())
SkelCU->constructSubprogramScopeDIE(SP, F, FnScope,
FunctionLineTableLabel);
SkelCU->constructSubprogramScopeDIE(SP, FnScope, FunctionLineTableLabel);

FunctionLineTableLabel = nullptr;

Expand Down
9 changes: 0 additions & 9 deletions llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "DwarfStringPool.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/DIE.h"
Expand All @@ -28,7 +27,6 @@ class DbgVariable;
class DbgLabel;
class DINode;
class DILocalScope;
class DISubprogram;
class DwarfCompileUnit;
class DwarfUnit;
class LexicalScope;
Expand Down Expand Up @@ -96,9 +94,6 @@ class DwarfFile {
// Collection of abstract subprogram DIEs.
DenseMap<const DILocalScope *, DIE *> AbstractLocalScopeDIEs;
DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities;
/// Keeps track of abstract subprograms to populate them only once.
// FIXME: merge creation and population of abstract scopes.
SmallPtrSet<const DISubprogram *, 8> FinalizedAbstractSubprograms;

/// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
/// be shared across CUs, that is why we keep the map here instead
Expand Down Expand Up @@ -179,10 +174,6 @@ class DwarfFile {
return AbstractEntities;
}

auto &getFinalizedAbstractSubprograms() {
return FinalizedAbstractSubprograms;
}

void insertDIE(const MDNode *TypeMD, DIE *Die) {
DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
}
Expand Down
Loading
Loading