Skip to content

Commit 2f40963

Browse files
committed
[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 2d2645e commit 2f40963

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
@@ -2088,44 +2088,70 @@ class DISubprogram : public DILocalScope {
20882088
class DILocation : public MDNode {
20892089
friend class LLVMContextImpl;
20902090
friend class MDNode;
2091+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2092+
uint64_t AtomGroup : 61;
2093+
uint8_t AtomRank : 3;
2094+
#endif
20912095

20922096
DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2093-
unsigned Column, ArrayRef<Metadata *> MDs, bool ImplicitCode);
2097+
unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2098+
ArrayRef<Metadata *> MDs, bool ImplicitCode);
20942099
~DILocation() { dropAllReferences(); }
20952100

20962101
static DILocation *getImpl(LLVMContext &Context, unsigned Line,
20972102
unsigned Column, Metadata *Scope,
20982103
Metadata *InlinedAt, bool ImplicitCode,
2104+
uint64_t AtomGroup, uint8_t AtomRank,
20992105
StorageType Storage, bool ShouldCreate = true);
21002106
static DILocation *getImpl(LLVMContext &Context, unsigned Line,
21012107
unsigned Column, DILocalScope *Scope,
21022108
DILocation *InlinedAt, bool ImplicitCode,
2109+
uint64_t AtomGroup, uint8_t AtomRank,
21032110
StorageType Storage, bool ShouldCreate = true) {
21042111
return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2105-
static_cast<Metadata *>(InlinedAt), ImplicitCode, Storage,
2106-
ShouldCreate);
2112+
static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2113+
AtomRank, Storage, ShouldCreate);
21072114
}
21082115

21092116
TempDILocation cloneImpl() const {
21102117
// Get the raw scope/inlinedAt since it is possible to invoke this on
21112118
// a DILocation containing temporary metadata.
21122119
return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2113-
getRawInlinedAt(), isImplicitCode());
2120+
getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2121+
getAtomRank());
21142122
}
21152123

21162124
public:
2125+
uint64_t getAtomGroup() const {
2126+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2127+
return AtomGroup;
2128+
#else
2129+
return 0;
2130+
#endif
2131+
}
2132+
uint8_t getAtomRank() const {
2133+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2134+
return AtomRank;
2135+
#else
2136+
return 0;
2137+
#endif
2138+
}
2139+
21172140
// Disallow replacing operands.
21182141
void replaceOperandWith(unsigned I, Metadata *New) = delete;
21192142

21202143
DEFINE_MDNODE_GET(DILocation,
21212144
(unsigned Line, unsigned Column, Metadata *Scope,
2122-
Metadata *InlinedAt = nullptr, bool ImplicitCode = false),
2123-
(Line, Column, Scope, InlinedAt, ImplicitCode))
2145+
Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2146+
uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2147+
(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2148+
AtomRank))
21242149
DEFINE_MDNODE_GET(DILocation,
21252150
(unsigned Line, unsigned Column, DILocalScope *Scope,
2126-
DILocation *InlinedAt = nullptr,
2127-
bool ImplicitCode = false),
2128-
(Line, Column, Scope, InlinedAt, ImplicitCode))
2151+
DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2152+
uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2153+
(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2154+
AtomRank))
21292155

21302156
/// Return a (temporary) clone of this.
21312157
TempDILocation clone() const { return cloneImpl(); }
@@ -2500,7 +2526,8 @@ DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
25002526
DILexicalBlockFile *NewScope =
25012527
DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
25022528
return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2503-
getInlinedAt());
2529+
getInlinedAt(), isImplicitCode(), getAtomGroup(),
2530+
getAtomRank());
25042531
}
25052532

25062533
unsigned DILocation::getBaseDiscriminator() const {

llvm/lib/AsmParser/LLParser.cpp

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

53055305
/// parseDILocationFields:
53065306
/// ::= !DILocation(line: 43, column: 8, scope: !5, inlinedAt: !6,
5307-
/// isImplicitCode: true)
5307+
/// isImplicitCode: true, atomGroup: 1, atomRank: 1)
53085308
bool LLParser::parseDILocation(MDNode *&Result, bool IsDistinct) {
53095309
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
53105310
OPTIONAL(line, LineField, ); \
53115311
OPTIONAL(column, ColumnField, ); \
53125312
REQUIRED(scope, MDField, (/* AllowNull */ false)); \
53135313
OPTIONAL(inlinedAt, MDField, ); \
5314-
OPTIONAL(isImplicitCode, MDBoolField, (false));
5314+
OPTIONAL(isImplicitCode, MDBoolField, (false)); \
5315+
OPTIONAL(atomGroup, MDUnsignedField, (0, UINT64_MAX)); \
5316+
OPTIONAL(atomRank, MDUnsignedField, (0, UINT8_MAX));
53155317
PARSE_MD_FIELDS();
53165318
#undef VISIT_MD_FIELDS
53175319

5318-
Result =
5319-
GET_OR_DISTINCT(DILocation, (Context, line.Val, column.Val, scope.Val,
5320-
inlinedAt.Val, isImplicitCode.Val));
5320+
Result = GET_OR_DISTINCT(
5321+
DILocation, (Context, line.Val, column.Val, scope.Val, inlinedAt.Val,
5322+
isImplicitCode.Val, atomGroup.Val, atomRank.Val));
53215323
return false;
53225324
}
53235325

llvm/lib/IR/AsmWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,8 @@ static void writeDILocation(raw_ostream &Out, const DILocation *DL,
20732073
Printer.printMetadata("inlinedAt", DL->getRawInlinedAt());
20742074
Printer.printBool("isImplicitCode", DL->isImplicitCode(),
20752075
/* Default */ false);
2076+
Printer.printInt("atomGroup", DL->getAtomGroup());
2077+
Printer.printInt<unsigned>("atomRank", DL->getAtomRank());
20762078
Out << ")";
20772079
}
20782080

llvm/lib/IR/DebugInfoMetadata.cpp

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

5858
DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
59-
unsigned Column, ArrayRef<Metadata *> MDs,
60-
bool ImplicitCode)
61-
: MDNode(C, DILocationKind, Storage, MDs) {
59+
unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
60+
ArrayRef<Metadata *> MDs, bool ImplicitCode)
61+
: MDNode(C, DILocationKind, Storage, MDs)
62+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
63+
,
64+
AtomGroup(AtomGroup), AtomRank(AtomRank)
65+
#endif
66+
{
67+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
68+
assert(AtomRank <= 7 && "AtomRank number should fit in 3 bits");
69+
#endif
6270
assert((MDs.size() == 1 || MDs.size() == 2) &&
6371
"Expected a scope and optional inlined-at");
64-
6572
// Set line and column.
6673
assert(Column < (1u << 16) && "Expected 16-bit column");
6774

@@ -80,14 +87,16 @@ static void adjustColumn(unsigned &Column) {
8087
DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
8188
unsigned Column, Metadata *Scope,
8289
Metadata *InlinedAt, bool ImplicitCode,
90+
uint64_t AtomGroup, uint8_t AtomRank,
8391
StorageType Storage, bool ShouldCreate) {
8492
// Fixup column.
8593
adjustColumn(Column);
8694

8795
if (Storage == Uniqued) {
8896
if (auto *N = getUniqued(Context.pImpl->DILocations,
8997
DILocationInfo::KeyTy(Line, Column, Scope,
90-
InlinedAt, ImplicitCode)))
98+
InlinedAt, ImplicitCode,
99+
AtomGroup, AtomRank)))
91100
return N;
92101
if (!ShouldCreate)
93102
return nullptr;
@@ -99,8 +108,9 @@ DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
99108
Ops.push_back(Scope);
100109
if (InlinedAt)
101110
Ops.push_back(InlinedAt);
102-
return storeImpl(new (Ops.size(), Storage) DILocation(
103-
Context, Storage, Line, Column, Ops, ImplicitCode),
111+
return storeImpl(new (Ops.size(), Storage)
112+
DILocation(Context, Storage, Line, Column, AtomGroup,
113+
AtomRank, Ops, ImplicitCode),
104114
Storage, Context.pImpl->DILocations);
105115
}
106116

llvm/lib/IR/LLVMContextImpl.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,23 +319,30 @@ template <> struct MDNodeKeyImpl<DILocation> {
319319
Metadata *Scope;
320320
Metadata *InlinedAt;
321321
bool ImplicitCode;
322+
uint64_t AtomGroup : 61;
323+
uint8_t AtomRank : 3;
322324

323325
MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
324-
Metadata *InlinedAt, bool ImplicitCode)
326+
Metadata *InlinedAt, bool ImplicitCode, uint64_t AtomGroup,
327+
uint8_t AtomRank)
325328
: Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt),
326-
ImplicitCode(ImplicitCode) {}
329+
ImplicitCode(ImplicitCode), AtomGroup(AtomGroup), AtomRank(AtomRank) {}
330+
327331
MDNodeKeyImpl(const DILocation *L)
328332
: Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
329-
InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {}
333+
InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()),
334+
AtomGroup(L->getAtomGroup()), AtomRank(L->getAtomRank()) {}
330335

331336
bool isKeyOf(const DILocation *RHS) const {
332337
return Line == RHS->getLine() && Column == RHS->getColumn() &&
333338
Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() &&
334-
ImplicitCode == RHS->isImplicitCode();
339+
ImplicitCode == RHS->isImplicitCode() &&
340+
AtomGroup == RHS->getAtomGroup() && AtomRank == RHS->getAtomRank();
335341
}
336342

337343
unsigned getHashValue() const {
338-
return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
344+
return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
345+
AtomRank);
339346
}
340347
};
341348

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)