Skip to content

Commit a56148d

Browse files
sys-igcigcbot
authored andcommitted
[Autobackout][FunctionalRegression]Revert of change: 1fd886c: Implement DIGlobalVariable handling in DWARF part 1
Partially Implemented global variable handling in DWARF. Now global variables with type `DIGlobalVariable` and in global addrspace can be visible in debugger. This commit skips emmiting DW_AT_Location and DW_OP_addr.
1 parent dc8ab0b commit a56148d

File tree

4 files changed

+8
-191
lines changed

4 files changed

+8
-191
lines changed

IGC/DebugInfo/DwarfCompileUnit.cpp

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ void CompileUnit::addBlock(DIE *Die, dwarf::Attribute Attribute, IGC::DIEBlock *
386386
/// entry.
387387
void CompileUnit::addSourceLine(DIE *Die, DIScope *S, unsigned Line) {
388388
// If the line number is 0, don't add it.
389-
if (Line == 0 || !S)
389+
if (Line == 0)
390390
return;
391391

392392
unsigned FileID = DD->getOrCreateSourceID(S->getFilename(), S->getDirectory(), DD->getMD5AsBytes(S->getFile()),
@@ -444,16 +444,6 @@ void CompileUnit::addSourceLine(DIE *Die, DIType *Ty) {
444444
addSourceLine(Die, Ty, Ty->getLine());
445445
}
446446

447-
/// addSourceLine - Add location information to specified debug information
448-
/// entry.
449-
void CompileUnit::addSourceLine(DIE *Die, DIGlobalVariable *GV) {
450-
// Verify type.
451-
if (!isa<DIGlobalVariable>(GV))
452-
return;
453-
454-
addSourceLine(Die, GV->getScope(), GV->getLine());
455-
}
456-
457447
void CompileUnit::addRegOrConst(IGC::DIEBlock *TheDie, unsigned DWReg) {
458448
// TODO: Confirm if this function is correctly used.
459449
auto DWRegEncoded = GetEncodedRegNum<RegisterNumbering::GRFBase>(DWReg);
@@ -1515,6 +1505,10 @@ void CompileUnit::constructTemplateValueParameterDIE(DIE &Buffer, DITemplateValu
15151505
/// constructImportedEntityDIE - Create a DIE for DIImportedEntity.
15161506
IGC::DIE *CompileUnit::constructImportedEntityDIE(DIImportedEntity *Module) {
15171507
DINode *Entity = Module->getEntity();
1508+
if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
1509+
return nullptr; // Missing support for imported entity linked to a global
1510+
// variable
1511+
15181512
DIE *IMDie = new DIE(Module->getTag());
15191513
insertDIE(Module, IMDie);
15201514

@@ -1527,8 +1521,9 @@ IGC::DIE *CompileUnit::constructImportedEntityDIE(DIImportedEntity *Module) {
15271521
EntityDie = getOrCreateSubprogramDIE(SP);
15281522
else if (auto *T = dyn_cast<DIType>(Entity))
15291523
EntityDie = getOrCreateTypeDIE(T);
1530-
else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
1531-
EntityDie = getOrCreateGlobalVariableDIE(GV, {});
1524+
// else if (auto* GV = dyn_cast<DIGlobalVariable>(Entity)) // TODO missing
1525+
// support
1526+
// EntityDie = getOrCreateGlobalVariableDIE(GV, {});
15321527
else
15331528
EntityDie = getDIE(Entity);
15341529

@@ -1561,59 +1556,6 @@ IGC::DIE *CompileUnit::getOrCreateNameSpace(DINamespace *NS) {
15611556
return NDie;
15621557
}
15631558

1564-
IGC::DIE *CompileUnit::getOrCreateGlobalVariableDIE(DIGlobalVariable *GV, ArrayRef<GlobalExpr> GlobalExprs) {
1565-
// Check for pre-existence.
1566-
if (DIE *Die = getDIE(GV))
1567-
return Die;
1568-
1569-
auto *GVContext = GV->getScope();
1570-
DIType *GTy = GV->getType();
1571-
1572-
DIE *ContextDIE = getOrCreateContextDIE(GVContext);
1573-
1574-
// Add to map.
1575-
DIE *VariableDIE = createAndAddDIE(GV->getTag(), *ContextDIE, GV);
1576-
DIScope *DeclContext;
1577-
if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
1578-
DeclContext = SDMDecl->getScope();
1579-
assert(SDMDecl->isStaticMember() && "Expected static member decl");
1580-
assert(GV->isDefinition());
1581-
// We need the declaration DIE that is in the static member's class.
1582-
DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl);
1583-
addDIEEntry(VariableDIE, dwarf::DW_AT_specification, VariableSpecDIE);
1584-
// If the global variable's type is different from the one in the class
1585-
// member type, assume that it's more specific and also emit it.
1586-
if (GTy != SDMDecl->getBaseType())
1587-
addType(VariableDIE, GTy);
1588-
} else {
1589-
DeclContext = GV->getScope();
1590-
// Add name and type.
1591-
addString(VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
1592-
if (GTy)
1593-
addType(VariableDIE, GTy);
1594-
1595-
// Add scoping info.
1596-
if (!GV->isLocalToUnit())
1597-
addFlag(VariableDIE, dwarf::DW_AT_external);
1598-
1599-
// Add line number info.
1600-
addSourceLine(VariableDIE, GV);
1601-
}
1602-
1603-
if (!GV->isDefinition())
1604-
addFlag(VariableDIE, dwarf::DW_AT_declaration);
1605-
1606-
if (uint32_t AlignInBytes = GV->getAlignInBytes())
1607-
addUInt(VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata, AlignInBytes);
1608-
1609-
if (MDTuple *TP = GV->getTemplateParams())
1610-
addTemplateParams(*VariableDIE, DINodeArray(TP));
1611-
1612-
// TODO: Add location and relocation entry to Global Variable
1613-
// addLocationAttribute(VariableDIE, GV, GlobalExprs);
1614-
return VariableDIE;
1615-
}
1616-
16171559
/// getOrCreateSubprogramDIE - Create new DIE using SP.
16181560
IGC::DIE *CompileUnit::getOrCreateSubprogramDIE(DISubprogram *SP) {
16191561
// Construct the context before querying for the existence of the DIE in case

IGC/DebugInfo/DwarfCompileUnit.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ See LICENSE.TXT for details.
2424
#include "llvm/ADT/DenseMap.h"
2525
#include <llvmWrapper/ADT/Optional.h>
2626
#include "llvm/ADT/SmallVector.h"
27-
#include <llvm/ADT/ArrayRef.h>
2827
#include "llvm/ADT/StringMap.h"
2928
#include "llvm/ADT/StringRef.h"
3029
#include "llvm/Config/llvm-config.h"
@@ -162,12 +161,6 @@ class CompileUnit {
162161

163162
DIEBlock *getDIEBlock() { return new (DIEValueAllocator) DIEBlock(); }
164163

165-
/// A pair of GlobalVariable and DIExpression.
166-
struct GlobalExpr {
167-
const llvm::GlobalVariable *Var;
168-
const llvm::DIExpression *Expr;
169-
};
170-
171164
/// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug
172165
/// when the llvm::MDNode can be part of the type system, since DIEs for
173166
/// the type system can be shared across CUs and the mappings are
@@ -247,7 +240,6 @@ class CompileUnit {
247240
void addSourceLine(DIE *Die, llvm::DIVariable *V);
248241
void addSourceLine(DIE *Die, llvm::DISubprogram *SP);
249242
void addSourceLine(DIE *Die, llvm::DIType *Ty);
250-
void addSourceLine(DIE *Die, llvm::DIGlobalVariable *GV);
251243

252244
/// addConstantValue - Add constant value entry in variable DIE.
253245
void addConstantValue(DIE *Die, const llvm::ConstantInt *CI, bool Unsigned);
@@ -333,9 +325,6 @@ class CompileUnit {
333325
/// getOrCreateNameSpace - Create a DIE for DINameSpace.
334326
DIE *getOrCreateNameSpace(llvm::DINamespace *NS);
335327

336-
/// Get or create global variable DIE.
337-
DIE *getOrCreateGlobalVariableDIE(llvm::DIGlobalVariable *GV, llvm::ArrayRef<GlobalExpr> GlobalExprs);
338-
339328
/// getOrCreateSubprogramDIE - Create new DIE using SP.
340329
DIE *getOrCreateSubprogramDIE(llvm::DISubprogram *SP);
341330

IGC/DebugInfo/DwarfDebug.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,28 +1068,6 @@ IGCLLVM::optional<llvm::MD5::MD5Result> DwarfDebug::getMD5AsBytes(const llvm::DI
10681068
return CKMem;
10691069
}
10701070

1071-
/// Sort and unique GVEs by comparing their fragment offset.
1072-
static SmallVectorImpl<CompileUnit::GlobalExpr> &sortGlobalExprs(SmallVectorImpl<CompileUnit::GlobalExpr> &GVEs) {
1073-
llvm::sort(GVEs, [](CompileUnit::GlobalExpr A, CompileUnit::GlobalExpr B) {
1074-
// Sort order: first null exprs, then exprs without fragment
1075-
// info, then sort by fragment offset in bits.
1076-
// FIXME: Come up with a more comprehensive comparator so
1077-
// the sorting isn't non-deterministic, and so the following
1078-
// std::unique call works correctly.
1079-
if (!A.Expr || !B.Expr)
1080-
return !!B.Expr;
1081-
auto FragmentA = A.Expr->getFragmentInfo();
1082-
auto FragmentB = B.Expr->getFragmentInfo();
1083-
if (!FragmentA || !FragmentB)
1084-
return !!FragmentB;
1085-
return FragmentA->OffsetInBits < FragmentB->OffsetInBits;
1086-
});
1087-
GVEs.erase(std::unique(GVEs.begin(), GVEs.end(),
1088-
[](CompileUnit::GlobalExpr A, CompileUnit::GlobalExpr B) { return A.Expr == B.Expr; }),
1089-
GVEs.end());
1090-
return GVEs;
1091-
}
1092-
10931071
// Emit all Dwarf sections that should come prior to the content. Create
10941072
// global DIEs and emit initial debug info sections.
10951073
void DwarfDebug::beginModule() {
@@ -1099,14 +1077,6 @@ void DwarfDebug::beginModule() {
10991077
if (M->debug_compile_units().begin() == M->debug_compile_units().end())
11001078
return;
11011079

1102-
DenseMap<DIGlobalVariable *, SmallVector<CompileUnit::GlobalExpr, 1>> GVMap;
1103-
for (const GlobalVariable &Global : M->globals()) {
1104-
SmallVector<DIGlobalVariableExpression *, 1> GVs;
1105-
Global.getDebugInfo(GVs);
1106-
for (auto *GVE : GVs)
1107-
GVMap[GVE->getVariable()].push_back({&Global, GVE->getExpression()});
1108-
}
1109-
11101080
// discover DISubprogramNodes for all the registered visaModules
11111081
discoverDISPNodes();
11121082
// Emit initial sections so we can reference labels later.
@@ -1115,35 +1085,6 @@ void DwarfDebug::beginModule() {
11151085
DICompileUnit *CUNode = *M->debug_compile_units_begin();
11161086
CompileUnit *CU = constructCompileUnit(CUNode);
11171087

1118-
// Global Variables.
1119-
for (auto *GVE : CUNode->getGlobalVariables()) {
1120-
// Don't bother adding DIGlobalVariableExpressions listed in the CU if we
1121-
// already know about the variable and it isn't adding a constant
1122-
// expression.
1123-
auto &GVMapEntry = GVMap[GVE->getVariable()];
1124-
auto *Expr = GVE->getExpression();
1125-
if (!GVMapEntry.size() || (Expr && Expr->isConstant()))
1126-
GVMapEntry.push_back({nullptr, Expr});
1127-
}
1128-
1129-
DenseSet<DIGlobalVariable *> Processed;
1130-
for (auto *GVE : CUNode->getGlobalVariables()) {
1131-
DIGlobalVariable *GV = GVE->getVariable();
1132-
1133-
// Skip variables in different addrspaces than global,
1134-
// SLM globals and constants will be handled later. This
1135-
// will avoid duplication.
1136-
if (GVMap.find(GV) == GVMap.end())
1137-
continue;
1138-
1139-
bool AllInGlobalAS = llvm::all_of(GVMap.find(GV)->second, [](const CompileUnit::GlobalExpr &GE) {
1140-
return GE.Var && GE.Var->getAddressSpace() == ADDRESS_SPACE_GLOBAL;
1141-
});
1142-
1143-
if (Processed.insert(GV).second && AllInGlobalAS)
1144-
CU->getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV]));
1145-
}
1146-
11471088
for (auto *DISP : DISubprogramNodes)
11481089
constructSubprogramDIE(CU, DISP);
11491090

IGC/ocloc_tests/DebugInfo/Dwarf/generate_global_variable_dwarf.ll

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)