Skip to content

Commit 78664df

Browse files
authored
merge amd-debug into amd-staging (llvm#2511)
2 parents c906d0e + 1a0c4b6 commit 78664df

File tree

20 files changed

+1653
-42
lines changed

20 files changed

+1653
-42
lines changed

.github/workflows/buildbot-psdb-trigger.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99
jobs:
1010
trigger-build:
1111
if: github.event.pull_request.draft == false
12-
runs-on: self-hosted
12+
runs-on:
13+
group: compiler-generic-runners
1314
env:
1415
PR_SHA: ${{ github.event.pull_request.head.sha != '' && github.event.pull_request.head.sha || github.sha }}
1516
PR_NUMBER: ${{ github.event.pull_request.number != '' && github.event.pull_request.number || 0 }}

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,12 @@ class DIDerivedType : public DIType {
12621262

12631263
TempDIDerivedType clone() const { return cloneImpl(); }
12641264

1265+
TempDIDerivedType cloneWithAddressSpace(unsigned DWARFAddrSpace) const {
1266+
auto Tmp = clone();
1267+
Tmp->DWARFAddressSpace = DWARFAddrSpace;
1268+
return Tmp;
1269+
}
1270+
12651271
/// Get the base type this is derived from.
12661272
DIType *getBaseType() const { return cast_or_null<DIType>(getRawBaseType()); }
12671273
Metadata *getRawBaseType() const { return getOperand(3); }
@@ -3705,6 +3711,19 @@ class DIExpression : public MDNode {
37053711
element_iterator elements_begin() const { return getElements().begin(); }
37063712
element_iterator elements_end() const { return getElements().end(); }
37073713

3714+
/// Returns the pointer address space this DIOp-based DIExpression produces.
3715+
/// Note that this may diverge from the the pointer address space of the
3716+
/// result type. When there is a divergent address space, the DIExpression
3717+
/// must produce a generic pointer whose value can be proven to belong to a
3718+
/// more specific address space. For instance in this expression, this
3719+
/// function returns 4:
3720+
///
3721+
/// !DIExpression(DIOpArg(0, ptr addrspace(4)), DIOpConvert(ptr))
3722+
///
3723+
/// A divergent address space can be created by a DIOpConvert, and is
3724+
/// preserved across DIOpReinterpret.
3725+
std::optional<unsigned> getNewDivergentAddrSpace() const;
3726+
37083727
/// A lightweight wrapper around an expression operand.
37093728
///
37103729
/// TODO: Store arguments directly and change \a DIExpression to store a

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ Value *salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
366366
/// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
367367
/// or deleted. Returns true if any debug users were updated.
368368
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint,
369-
DominatorTree &DT);
369+
const DominatorTree &DT);
370370

371371
/// If a terminator in an unreachable basic block has an operand of type
372372
/// Instruction, transform it into poison. Return true if any operands

llvm/lib/CodeGen/AsmPrinter/DebugLocStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ void DebugLocStream::finalizeEntry() {
4040
DebugLocStream::ListBuilder::~ListBuilder() {
4141
if (!Locs.finalizeList(Asm))
4242
return;
43-
V.emplace<Loc::Multi>(ListIndex, TagOffset);
43+
V.emplace<Loc::Multi>(ListIndex, TagOffset, CommonAddrSpace);
4444
}

llvm/lib/CodeGen/AsmPrinter/DebugLocStream.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class DebugLocStream::ListBuilder {
157157
DbgVariable &V;
158158
size_t ListIndex;
159159
std::optional<uint8_t> TagOffset;
160+
std::optional<unsigned> CommonAddrSpace;
160161

161162
public:
162163
ListBuilder(DebugLocStream &Locs, DwarfCompileUnit &CU, AsmPrinter &Asm,
@@ -168,6 +169,11 @@ class DebugLocStream::ListBuilder {
168169
TagOffset = TO;
169170
}
170171

172+
void setCommonDivergentAddrSpace(unsigned AS) { CommonAddrSpace = AS; }
173+
bool hasCommonDivergentAddrSpace() const {
174+
return CommonAddrSpace != std::nullopt;
175+
}
176+
171177
/// Finalize the list.
172178
///
173179
/// If the list is empty, delete it. Otherwise, finalize it by creating a

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,8 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
891891

892892
if (Expr) {
893893
if (auto NewElementsRef = Expr->getNewElementsRef()) {
894+
if (DV.isDivergentAddrSpaceCompatible())
895+
DwarfExpr.permitDivergentAddrSpace();
894896
DwarfExpr.addExpression(*NewElementsRef, DVal->getLocEntries(), &TRI);
895897
addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
896898
return;
@@ -973,6 +975,8 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(const Loc::MMI &MMI,
973975
addBlock(VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
974976
return;
975977
}
978+
if (DV.isDivergentAddrSpaceCompatible())
979+
DwarfExpr.permitDivergentAddrSpace();
976980
for (const auto &Fragment : MMI.getFrameIndexExprs()) {
977981
Register FrameReg;
978982
const DIExpression *Expr = Fragment.Expr;
@@ -1758,7 +1762,19 @@ void DwarfCompileUnit::applyCommonDbgVariableAttributes(const DbgVariable &Var,
17581762
}
17591763

17601764
addSourceLine(VariableDie, DIVar);
1761-
addType(VariableDie, Var.getType());
1765+
1766+
const DIType *VarTy = Var.getType();
1767+
if (Var.isDivergentAddrSpaceCompatible()) {
1768+
if (std::optional<unsigned> EntityAS = Var.getCommonDivergentAddrSpace()) {
1769+
if (auto DwarfAS = getAsmPrinter()->TM.mapToDWARFAddrSpace(*EntityAS)) {
1770+
TempDIDerivedType Tmp =
1771+
cast<DIDerivedType>(VarTy)->cloneWithAddressSpace(*DwarfAS);
1772+
VarTy = MDNode::replaceWithUniqued(std::move(Tmp));
1773+
}
1774+
}
1775+
}
1776+
1777+
addType(VariableDie, VarTy);
17621778
if (Var.isArtificial())
17631779
addFlag(VariableDie, dwarf::DW_AT_artificial);
17641780
}

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,63 @@ void DebugLocDwarfExpression::commitTemporaryBuffer() {
233233
TmpBuf->Comments.clear();
234234
}
235235

236+
namespace {
237+
/// Utility class for finding the common divergent address space of all the
238+
/// DIExpressions that describe the location of a variable, if such an address
239+
/// space exists.
240+
class CommonDivergentAddrSpaceFinder {
241+
std::optional<unsigned> CommonAS;
242+
bool HasCommonAddrSpace = true;
243+
244+
public:
245+
void addSubExpr(const DIExpression *Expr) {
246+
if (!Expr || !HasCommonAddrSpace)
247+
return;
248+
std::optional<unsigned> ExprAS = Expr->getNewDivergentAddrSpace();
249+
if (!ExprAS)
250+
HasCommonAddrSpace = false;
251+
else if (!CommonAS)
252+
CommonAS = *ExprAS;
253+
else if (*CommonAS != *ExprAS)
254+
HasCommonAddrSpace = false;
255+
}
256+
257+
std::optional<unsigned> get() const {
258+
return HasCommonAddrSpace ? CommonAS : std::nullopt;
259+
}
260+
};
261+
} // namespace
262+
263+
std::optional<unsigned> DbgVariable::getCommonDivergentAddrSpace() const {
264+
const Loc::Variant *Loc = &asVariant();
265+
266+
if (auto *LM = std::get_if<Loc::Multi>(Loc))
267+
return LM->getCommonDivergentAddrSpace();
268+
269+
CommonDivergentAddrSpaceFinder Finder;
270+
if (auto *LS = std::get_if<Loc::Single>(Loc)) {
271+
Finder.addSubExpr(LS->getExpr());
272+
} else if (auto *MMI = std::get_if<Loc::MMI>(Loc)) {
273+
for (auto &FIE : MMI->getFrameIndexExprs())
274+
Finder.addSubExpr(FIE.Expr);
275+
} else if (auto *EV = std::get_if<Loc::EntryValue>(Loc)) {
276+
for (auto &Val : EV->EntryValues)
277+
Finder.addSubExpr(&Val.Expr);
278+
}
279+
280+
return Finder.get();
281+
}
282+
283+
bool DbgVariable::isDivergentAddrSpaceCompatible() const {
284+
if (auto *DT = dyn_cast<DIDerivedType>(getType()))
285+
return DT->getTag() == dwarf::DW_TAG_pointer_type ||
286+
DT->getTag() == dwarf::DW_TAG_reference_type ||
287+
DT->getTag() == dwarf::DW_TAG_rvalue_reference_type;
288+
// FIXME: We could support divergent address spaces on pointer/reference
289+
// fields of struct types.
290+
return false;
291+
}
292+
236293
const DIType *DbgVariable::getType() const {
237294
return getVariable()->getType();
238295
}
@@ -1952,6 +2009,18 @@ void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU,
19522009
continue;
19532010
}
19542011

2012+
// If all entries in the location list produce a consistent divergent
2013+
// address space we need to inform the expression emitter that it is
2014+
// permitted to produce divergent address spaces.
2015+
if (RegVar->isDivergentAddrSpaceCompatible()) {
2016+
CommonDivergentAddrSpaceFinder Finder;
2017+
for (const DebugLocEntry &DLE : Entries)
2018+
for (const DbgValueLoc &DVL : DLE.getValues())
2019+
Finder.addSubExpr(DVL.getExpression());
2020+
if (std::optional<unsigned> AS = Finder.get())
2021+
List.setCommonDivergentAddrSpace(*AS);
2022+
}
2023+
19552024
// If the variable has a DIBasicType, extract it. Basic types cannot have
19562025
// unique identifiers, so don't bother resolving the type with the
19572026
// identifier map.
@@ -3181,6 +3250,8 @@ void DebugLocEntry::finalize(const AsmPrinter &AP,
31813250
DebugLocStream::EntryBuilder Entry(List, Begin, End);
31823251
BufferByteStreamer Streamer = Entry.getStreamer();
31833252
DebugLocDwarfExpression DwarfExpr(AP, Streamer, TheCU);
3253+
if (List.hasCommonDivergentAddrSpace())
3254+
DwarfExpr.permitDivergentAddrSpace();
31843255
const DbgValueLoc &Value = Values[0];
31853256
if (Value.isFragment()) {
31863257
// Emit all fragments that belong to the same variable and range.

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,25 @@ class Multi {
145145
/// DW_OP_LLVM_tag_offset value from DebugLocs.
146146
std::optional<uint8_t> DebugLocListTagOffset;
147147

148+
/// In DIOp-DIExpressions, if this variable has pointer type and all entries
149+
/// in the loclist produce the same divergent address space, this is set to be
150+
/// the that address space.
151+
std::optional<unsigned> CommonAddrSpace;
152+
148153
public:
149154
explicit Multi(unsigned DebugLocListIndex,
150-
std::optional<uint8_t> DebugLocListTagOffset)
155+
std::optional<uint8_t> DebugLocListTagOffset,
156+
std::optional<unsigned> CommonAddrSpace = std::nullopt)
151157
: DebugLocListIndex(DebugLocListIndex),
152-
DebugLocListTagOffset(DebugLocListTagOffset) {}
158+
DebugLocListTagOffset(DebugLocListTagOffset),
159+
CommonAddrSpace(CommonAddrSpace) {}
153160
unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
154161
std::optional<uint8_t> getDebugLocListTagOffset() const {
155162
return DebugLocListTagOffset;
156163
}
164+
std::optional<unsigned> getCommonDivergentAddrSpace() const {
165+
return CommonAddrSpace;
166+
}
157167
};
158168
/// Single location defined by (potentially multiple) MMI entries.
159169
struct MMI {
@@ -277,6 +287,9 @@ class DbgVariable : public DbgEntity, public Loc::Variant {
277287

278288
const DIType *getType() const;
279289

290+
bool isDivergentAddrSpaceCompatible() const;
291+
std::optional<unsigned> getCommonDivergentAddrSpace() const;
292+
280293
static bool classof(const DbgEntity *N) {
281294
return N->getDbgEntityID() == DbgVariableKind;
282295
}

0 commit comments

Comments
 (0)