Skip to content

Commit a124bd2

Browse files
committed
[KeyInstr] Add fields to DILocation behind compile time flag
The definition EXPERIMENTAL_KEY_INSTRUCTIONS 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.
1 parent 133c1af commit a124bd2

File tree

9 files changed

+95
-27
lines changed

9 files changed

+95
-27
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,44 +2099,67 @@ class DISubprogram : public DILocalScope {
20992099
class DILocation : public MDNode {
21002100
friend class LLVMContextImpl;
21012101
friend class MDNode;
2102+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2103+
uint64_t AtomGroup : 61;
2104+
uint8_t AtomRank : 3;
2105+
#endif
21022106

21032107
DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
2104-
unsigned Column, ArrayRef<Metadata *> MDs, bool ImplicitCode);
2108+
unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
2109+
ArrayRef<Metadata *> MDs, bool ImplicitCode);
21052110
~DILocation() { dropAllReferences(); }
21062111

21072112
static DILocation *getImpl(LLVMContext &Context, unsigned Line,
21082113
unsigned Column, Metadata *Scope,
21092114
Metadata *InlinedAt, bool ImplicitCode,
2115+
uint64_t AtomGroup, uint8_t AtomRank,
21102116
StorageType Storage, bool ShouldCreate = true);
21112117
static DILocation *getImpl(LLVMContext &Context, unsigned Line,
21122118
unsigned Column, DILocalScope *Scope,
21132119
DILocation *InlinedAt, bool ImplicitCode,
2120+
uint64_t AtomGroup, uint8_t AtomRank,
21142121
StorageType Storage, bool ShouldCreate = true) {
21152122
return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
2116-
static_cast<Metadata *>(InlinedAt), ImplicitCode, Storage,
2117-
ShouldCreate);
2123+
static_cast<Metadata *>(InlinedAt), ImplicitCode, AtomGroup,
2124+
AtomRank, Storage, ShouldCreate);
21182125
}
21192126

21202127
TempDILocation cloneImpl() const {
21212128
// Get the raw scope/inlinedAt since it is possible to invoke this on
21222129
// a DILocation containing temporary metadata.
21232130
return getTemporary(getContext(), getLine(), getColumn(), getRawScope(),
2124-
getRawInlinedAt(), isImplicitCode());
2131+
getRawInlinedAt(), isImplicitCode(), getAtomGroup(),
2132+
getAtomRank());
21252133
}
2126-
21272134
public:
2135+
uint64_t getAtomGroup() const {
2136+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2137+
return AtomGroup;
2138+
#endif
2139+
return 0;
2140+
}
2141+
uint8_t getAtomRank() const {
2142+
#ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
2143+
return AtomRank;
2144+
#endif
2145+
return 0;
2146+
}
2147+
21282148
// Disallow replacing operands.
21292149
void replaceOperandWith(unsigned I, Metadata *New) = delete;
21302150

21312151
DEFINE_MDNODE_GET(DILocation,
21322152
(unsigned Line, unsigned Column, Metadata *Scope,
2133-
Metadata *InlinedAt = nullptr, bool ImplicitCode = false),
2134-
(Line, Column, Scope, InlinedAt, ImplicitCode))
2153+
Metadata *InlinedAt = nullptr, bool ImplicitCode = false,
2154+
uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2155+
(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2156+
AtomRank))
21352157
DEFINE_MDNODE_GET(DILocation,
21362158
(unsigned Line, unsigned Column, DILocalScope *Scope,
2137-
DILocation *InlinedAt = nullptr,
2138-
bool ImplicitCode = false),
2139-
(Line, Column, Scope, InlinedAt, ImplicitCode))
2159+
DILocation *InlinedAt = nullptr, bool ImplicitCode = false,
2160+
uint64_t AtomGroup = 0, uint8_t AtomRank = 0),
2161+
(Line, Column, Scope, InlinedAt, ImplicitCode, AtomGroup,
2162+
AtomRank))
21402163

21412164
/// Return a (temporary) clone of this.
21422165
TempDILocation clone() const { return cloneImpl(); }
@@ -2511,7 +2534,8 @@ DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
25112534
DILexicalBlockFile *NewScope =
25122535
DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
25132536
return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
2514-
getInlinedAt());
2537+
getInlinedAt(), isImplicitCode(), getAtomGroup(),
2538+
getAtomRank());
25152539
}
25162540

25172541
unsigned DILocation::getBaseDiscriminator() const {

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5312,13 +5312,15 @@ bool LLParser::parseDILocation(MDNode *&Result, bool IsDistinct) {
53125312
OPTIONAL(column, ColumnField, ); \
53135313
REQUIRED(scope, MDField, (/* AllowNull */ false)); \
53145314
OPTIONAL(inlinedAt, MDField, ); \
5315-
OPTIONAL(isImplicitCode, MDBoolField, (false));
5315+
OPTIONAL(isImplicitCode, MDBoolField, (false)); \
5316+
OPTIONAL(atomGroup, MDUnsignedField, (0, UINT64_MAX)); \
5317+
OPTIONAL(atomRank, MDUnsignedField, (0, UINT8_MAX));
53165318
PARSE_MD_FIELDS();
53175319
#undef VISIT_MD_FIELDS
53185320

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

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)