Skip to content

Commit b4433df

Browse files
OCHyamsGeorgeARM
authored andcommitted
[KeyInstr] Add fields to DILocation behind compile time flag (llvm#133477)
Add AtomGroup and AtomRank to DILocation behind compile time flag EXPERIMENTAL_KEY_INSTRUCTIONS which is controlled by cmake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS. Add IR read-write roundtrip test in a directory that is unsupported unless the CMake flag is enabled. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668
1 parent 125cde3 commit b4433df

File tree

9 files changed

+98
-27
lines changed

9 files changed

+98
-27
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,44 +2235,70 @@ class DISubprogram : public DILocalScope {
22352235
class DILocation : public MDNode {
22362236
friend class LLVMContextImpl;
22372237
friend class MDNode;
2238+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2239+
uint64_t AtomGroup : 61;
2240+
uint8_t AtomRank : 3;
2241+
#endif
22382242

22392243
DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2240-
unsigned Column, ArrayRef<Metadata *> MDs, bool ImplicitCode);
2244+
unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2245+
ArrayRef<Metadata *> MDs, bool ImplicitCode);
22412246
~DILocation() { dropAllReferences(); }
22422247

22432248
static DILocation *getImpl(LLVMContext &Context, unsigned Line,
22442249
unsigned Column, Metadata *Scope,
22452250
Metadata *InlinedAt, bool ImplicitCode,
2251+
uint64_t AtomGroup, uint8_t AtomRank,
22462252
StorageType Storage, bool ShouldCreate = true);
22472253
static DILocation *getImpl(LLVMContext &Context, unsigned Line,
22482254
unsigned Column, DILocalScope *Scope,
22492255
DILocation *InlinedAt, bool ImplicitCode,
2256+
uint64_t AtomGroup, uint8_t AtomRank,
22502257
StorageType Storage, bool ShouldCreate = true) {
22512258
return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2252-
static_cast<Metadata *>(InlinedAt), ImplicitCode, Storage,
2253-
ShouldCreate);
2259+
static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2260+
AtomRank, Storage, ShouldCreate);
22542261
}
22552262

22562263
TempDILocation cloneImpl() const {
22572264
// Get the raw scope/inlinedAt since it is possible to invoke this on
22582265
// a DILocation containing temporary metadata.
22592266
return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2260-
getRawInlinedAt(), isImplicitCode());
2267+
getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2268+
getAtomRank());
22612269
}
22622270

22632271
public:
2272+
uint64_t getAtomGroup() const {
2273+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2274+
return AtomGroup;
2275+
#else
2276+
return 0;
2277+
#endif
2278+
}
2279+
uint8_t getAtomRank() const {
2280+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2281+
return AtomRank;
2282+
#else
2283+
return 0;
2284+
#endif
2285+
}
2286+
22642287
// Disallow replacing operands.
22652288
void replaceOperandWith(unsigned I, Metadata *New) = delete;
22662289

22672290
DEFINE_MDNODE_GET(DILocation,
22682291
(unsigned Line, unsigned Column, Metadata *Scope,
2269-
Metadata *InlinedAt = nullptr, bool ImplicitCode = false),
2270-
(Line, Column, Scope, InlinedAt, ImplicitCode))
2292+
Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2293+
uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2294+
(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2295+
AtomRank))
22712296
DEFINE_MDNODE_GET(DILocation,
22722297
(unsigned Line, unsigned Column, DILocalScope *Scope,
2273-
DILocation *InlinedAt = nullptr,
2274-
bool ImplicitCode = false),
2275-
(Line, Column, Scope, InlinedAt, ImplicitCode))
2298+
DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2299+
uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2300+
(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2301+
AtomRank))
22762302

22772303
/// Return a (temporary) clone of this.
22782304
TempDILocation clone() const { return cloneImpl(); }
@@ -2647,7 +2673,8 @@ DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
26472673
DILexicalBlockFile *NewScope =
26482674
DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
26492675
return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2650-
getInlinedAt());
2676+
getInlinedAt(), isImplicitCode(), getAtomGroup(),
2677+
getAtomRank());
26512678
}
26522679

26532680
unsigned DILocation::getBaseDiscriminator() const {

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5321,20 +5321,22 @@ bool LLParser::parseSpecializedMDNode(MDNode *&N, bool IsDistinct) {
53215321

53225322
/// parseDILocationFields:
53235323
/// ::= !DILocation(line: 43, column: 8, scope: !5, inlinedAt: !6,
5324-
/// isImplicitCode: true)
5324+
/// isImplicitCode: true, atomGroup: 1, atomRank: 1)
53255325
bool LLParser::parseDILocation(MDNode *&Result, bool IsDistinct) {
53265326
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
53275327
OPTIONAL(line, LineField, ); \
53285328
OPTIONAL(column, ColumnField, ); \
53295329
REQUIRED(scope, MDField, (/* AllowNull */ false)); \
53305330
OPTIONAL(inlinedAt, MDField, ); \
5331-
OPTIONAL(isImplicitCode, MDBoolField, (false));
5331+
OPTIONAL(isImplicitCode, MDBoolField, (false)); \
5332+
OPTIONAL(atomGroup, MDUnsignedField, (0, UINT64_MAX)); \
5333+
OPTIONAL(atomRank, MDUnsignedField, (0, UINT8_MAX));
53325334
PARSE_MD_FIELDS();
53335335
#undef VISIT_MD_FIELDS
53345336

5335-
Result =
5336-
GET_OR_DISTINCT(DILocation, (Context, line.Val, column.Val, scope.Val,
5337-
inlinedAt.Val, isImplicitCode.Val));
5337+
Result = GET_OR_DISTINCT(
5338+
DILocation, (Context, line.Val, column.Val, scope.Val, inlinedAt.Val,
5339+
isImplicitCode.Val, atomGroup.Val, atomRank.Val));
53385340
return false;
53395341
}
53405342

llvm/lib/IR/AsmWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,8 @@ static void writeDILocation(raw_ostream &Out, const DILocation *DL,
21032103
Printer.printMetadata("inlinedAt", DL->getRawInlinedAt());
21042104
Printer.printBool("isImplicitCode", DL->isImplicitCode(),
21052105
/* Default */ false);
2106+
Printer.printInt("atomGroup", DL->getAtomGroup());
2107+
Printer.printInt<unsigned>("atomRank", DL->getAtomRank());
21062108
Out << ")";
21072109
}
21082110

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,19 @@ DebugVariableAggregate::DebugVariableAggregate(const DbgVariableIntrinsic *DVI)
6363
DVI->getDebugLoc()->getInlinedAt()) {}
6464

6565
DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
66-
unsigned Column, ArrayRef<Metadata *> MDs,
67-
bool ImplicitCode)
68-
: MDNode(C, DILocationKind, Storage, MDs) {
66+
unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
67+
ArrayRef<Metadata *> MDs, bool ImplicitCode)
68+
: MDNode(C, DILocationKind, Storage, MDs)
69+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
70+
,
71+
AtomGroup(AtomGroup), AtomRank(AtomRank)
72+
#endif
73+
{
74+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
75+
assert(AtomRank <= 7 && "AtomRank number should fit in 3 bits");
76+
#endif
6977
assert((MDs.size() == 1 || MDs.size() == 2) &&
7078
"Expected a scope and optional inlined-at");
71-
7279
// Set line and column.
7380
assert(Column < (1u << 16) && "Expected 16-bit column");
7481

@@ -87,14 +94,16 @@ static void adjustColumn(unsigned &Column) {
8794
DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
8895
unsigned Column, Metadata *Scope,
8996
Metadata *InlinedAt, bool ImplicitCode,
97+
uint64_t AtomGroup, uint8_t AtomRank,
9098
StorageType Storage, bool ShouldCreate) {
9199
// Fixup column.
92100
adjustColumn(Column);
93101

94102
if (Storage == Uniqued) {
95103
if (auto *N = getUniqued(Context.pImpl->DILocations,
96104
DILocationInfo::KeyTy(Line, Column, Scope,
97-
InlinedAt, ImplicitCode)))
105+
InlinedAt, ImplicitCode,
106+
AtomGroup, AtomRank)))
98107
return N;
99108
if (!ShouldCreate)
100109
return nullptr;
@@ -106,8 +115,9 @@ DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
106115
Ops.push_back(Scope);
107116
if (InlinedAt)
108117
Ops.push_back(InlinedAt);
109-
return storeImpl(new (Ops.size(), Storage) DILocation(
110-
Context, Storage, Line, Column, Ops, ImplicitCode),
118+
return storeImpl(new (Ops.size(), Storage)
119+
DILocation(Context, Storage, Line, Column, AtomGroup,
120+
AtomRank, Ops, ImplicitCode),
111121
Storage, Context.pImpl->DILocations);
112122
}
113123

llvm/lib/IR/LLVMContextImpl.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,30 @@ template <> struct MDNodeKeyImpl<DILocation> {
315315
Metadata *Scope;
316316
Metadata *InlinedAt;
317317
bool ImplicitCode;
318+
uint64_t AtomGroup : 61;
319+
uint8_t AtomRank : 3;
318320

319321
MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
320-
Metadata *InlinedAt, bool ImplicitCode)
322+
Metadata *InlinedAt, bool ImplicitCode, uint64_t AtomGroup,
323+
uint8_t AtomRank)
321324
: Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt),
322-
ImplicitCode(ImplicitCode) {}
325+
ImplicitCode(ImplicitCode), AtomGroup(AtomGroup), AtomRank(AtomRank) {}
326+
323327
MDNodeKeyImpl(const DILocation *L)
324328
: Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
325-
InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {}
329+
InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()),
330+
AtomGroup(L->getAtomGroup()), AtomRank(L->getAtomRank()) {}
326331

327332
bool isKeyOf(const DILocation *RHS) const {
328333
return Line == RHS->getLine() && Column == RHS->getColumn() &&
329334
Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() &&
330-
ImplicitCode == RHS->isImplicitCode();
335+
ImplicitCode == RHS->isImplicitCode() &&
336+
AtomGroup == RHS->getAtomGroup() && AtomRank == RHS->getAtomRank();
331337
}
332338

333339
unsigned getHashValue() const {
334-
return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
340+
return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
341+
AtomRank);
335342
}
336343
};
337344

llvm/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ llvm_canonicalize_cmake_booleans(
2929
LLVM_INCLUDE_SPIRV_TOOLS_TESTS
3030
LLVM_APPEND_VC_REV
3131
LLVM_HAS_LOGF128
32+
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS
3233
)
3334

3435
configure_lit_site_cfg(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: opt %s -o - -S| FileCheck %s
2+
3+
; CHECK: !DILocation(line: 1, column: 11, scope: ![[#]], atomGroup: 1, atomRank: 1)
4+
5+
define dso_local void @f() !dbg !10 {
6+
entry:
7+
ret void, !dbg !13
8+
}
9+
10+
!llvm.module.flags = !{!3}
11+
12+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 21.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
13+
!1 = !DIFile(filename: "test.cpp", directory: "/")
14+
!3 = !{i32 2, !"Debug Info Version", i32 3}
15+
!9 = !{!"clang version 21.0.0git"}
16+
!10 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
17+
!11 = !DISubroutineType(types: !12)
18+
!12 = !{null}
19+
!13 = !DILocation(line: 1, column: 11, scope: !10, atomGroup: 1, atomRank: 1)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not config.has_key_instructions:
2+
config.unsupported = True

llvm/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@
6565
config.have_vc_rev = @LLVM_APPEND_VC_REV@
6666
config.force_vc_rev = "@LLVM_FORCE_VC_REVISION@"
6767
config.has_logf128 = @LLVM_HAS_LOGF128@
68+
config.has_key_instructions = @LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS@
6869

6970
import lit.llvm
7071
lit.llvm.initialize(lit_config, config)

0 commit comments

Comments
 (0)