Skip to content

Commit 720ce66

Browse files
committed
[KeyInstr] Inline asm atoms
1 parent 9eb0fc8 commit 720ce66

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,9 @@ static void UpdateAsmCallInst(llvm::CallBase &Result, bool HasSideEffect,
26722672
llvm::ConstantAsMetadata::get(Loc)));
26732673
}
26742674

2675+
// Make inline-asm calls Key for the debug info feature Key Instructions.
2676+
CGF.addInstToNewSourceAtom(&Result, nullptr);
2677+
26752678
if (!NoConvergent && CGF.getLangOpts().assumeFunctionsAreConvergent())
26762679
// Conservatively, mark all inline asm blocks in CUDA or OpenCL as
26772680
// convergent (meaning, they may call an intrinsically convergent op, such
@@ -2750,14 +2753,16 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S,
27502753
}
27512754
}
27522755

2756+
ApplyAtomGroup Grp(CGF.getDebugInfo());
27532757
LValue Dest = ResultRegDests[i];
27542758
// ResultTypeRequiresCast elements correspond to the first
27552759
// ResultTypeRequiresCast.size() elements of RegResults.
27562760
if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
27572761
unsigned Size = CGF.getContext().getTypeSize(ResultRegQualTys[i]);
27582762
Address A = Dest.getAddress().withElementType(ResultRegTypes[i]);
27592763
if (CGF.getTargetHooks().isScalarizableAsmOperand(CGF, TruncTy)) {
2760-
Builder.CreateStore(Tmp, A);
2764+
llvm::StoreInst *S = Builder.CreateStore(Tmp, A);
2765+
CGF.addInstToCurrentSourceAtom(S, S->getValueOperand());
27612766
continue;
27622767
}
27632768

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// RUN: %clang_cc1 -triple aarch64 -target-feature +ls64 -O0 -emit-llvm -x c %s -o - -gkey-instructions -debug-info-kind=limited -gno-column-info | FileCheck %s
3+
// Partially copied from clang/test/CodeGen/AArch64/ls64-inline-asm.c
4+
5+
// Check the inline asm call and result store are Key and distinct atoms.
6+
7+
struct foo { unsigned long long x[8]; };
8+
// CHECK-LABEL: define dso_local void @load(
9+
// CHECK-SAME: ptr noundef [[OUTPUT:%.*]], ptr noundef [[ADDR:%.*]]) #[[ATTR0:[0-9]+]] !dbg [[DBG5:![0-9]+]] {
10+
// CHECK-NEXT: [[ENTRY:.*:]]
11+
// CHECK-NEXT: [[OUTPUT_ADDR:%.*]] = alloca ptr, align 8
12+
// CHECK-NEXT: [[ADDR_ADDR:%.*]] = alloca ptr, align 8
13+
// CHECK-NEXT: store ptr [[OUTPUT]], ptr [[OUTPUT_ADDR]], align 8
14+
// CHECK-NEXT: #dbg_declare(ptr [[OUTPUT_ADDR]], [[META19:![0-9]+]], !DIExpression(), [[META20:![0-9]+]])
15+
// CHECK-NEXT: store ptr [[ADDR]], ptr [[ADDR_ADDR]], align 8
16+
// CHECK-NEXT: #dbg_declare(ptr [[ADDR_ADDR]], [[META21:![0-9]+]], !DIExpression(), [[META20]])
17+
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[OUTPUT_ADDR]], align 8, !dbg [[DBG22:![0-9]+]]
18+
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[ADDR_ADDR]], align 8, !dbg [[DBG22]]
19+
// CHECK-NEXT: [[TMP2:%.*]] = call i512 asm sideeffect "ld64b $0,[$1]", "=r,r,~{memory}"(ptr [[TMP1]]) #[[ATTR1:[0-9]+]], !dbg [[DBG23:![0-9]+]], !srcloc [[META24:![0-9]+]]
20+
// CHECK-NEXT: store i512 [[TMP2]], ptr [[TMP0]], align 8, !dbg [[DBG25:![0-9]+]]
21+
// CHECK-NEXT: ret void, !dbg [[DBG26:![0-9]+]]
22+
//
23+
void load(struct foo *output, void *addr) {
24+
__asm__ volatile ("ld64b %0,[%1]" : "=r" (*output) : "r" (addr) : "memory");
25+
}
26+
27+
// CHECK-LABEL: define dso_local void @load2(
28+
// CHECK-SAME: ptr noundef [[OUTPUT:%.*]], ptr noundef [[ADDR:%.*]]) #[[ATTR0]] !dbg [[DBG27:![0-9]+]] {
29+
// CHECK-NEXT: [[ENTRY:.*:]]
30+
// CHECK-NEXT: [[OUTPUT_ADDR:%.*]] = alloca ptr, align 8
31+
// CHECK-NEXT: [[ADDR_ADDR:%.*]] = alloca ptr, align 8
32+
// CHECK-NEXT: store ptr [[OUTPUT]], ptr [[OUTPUT_ADDR]], align 8
33+
// CHECK-NEXT: #dbg_declare(ptr [[OUTPUT_ADDR]], [[META32:![0-9]+]], !DIExpression(), [[META33:![0-9]+]])
34+
// CHECK-NEXT: store ptr [[ADDR]], ptr [[ADDR_ADDR]], align 8
35+
// CHECK-NEXT: #dbg_declare(ptr [[ADDR_ADDR]], [[META34:![0-9]+]], !DIExpression(), [[META33]])
36+
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[OUTPUT_ADDR]], align 8, !dbg [[DBG35:![0-9]+]]
37+
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[ADDR_ADDR]], align 8, !dbg [[DBG35]]
38+
// CHECK-NEXT: [[TMP2:%.*]] = call i32 asm sideeffect "ld64b $0,[$1]", "=r,r,~{memory}"(ptr [[TMP1]]) #[[ATTR1]], !dbg [[DBG36:![0-9]+]], !srcloc [[META37:![0-9]+]]
39+
// CHECK-NEXT: store i32 [[TMP2]], ptr [[TMP0]], align 4, !dbg [[DBG38:![0-9]+]]
40+
// CHECK-NEXT: ret void, !dbg [[DBG39:![0-9]+]]
41+
//
42+
void load2(int *output, void *addr) {
43+
__asm__ volatile ("ld64b %0,[%1]" : "=r" (*output) : "r" (addr) : "memory");
44+
}
45+
//.
46+
// CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
47+
// CHECK: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
48+
// CHECK: [[DBG5]] = distinct !DISubprogram(name: "load", scope: [[META6:![0-9]+]], file: [[META6]], line: 23, type: [[META7:![0-9]+]], scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META18:![0-9]+]], keyInstructions: true)
49+
// CHECK: [[META6]] = !DIFile(filename: "{{.*}}asm.c", directory: {{.*}})
50+
// CHECK: [[META7]] = !DISubroutineType(types: [[META8:![0-9]+]])
51+
// CHECK: [[META8]] = !{null, [[META9:![0-9]+]], [[META17:![0-9]+]]}
52+
// CHECK: [[META9]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META10:![0-9]+]], size: 64)
53+
// CHECK: [[META10]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: [[META6]], line: 7, size: 512, elements: [[META11:![0-9]+]])
54+
// CHECK: [[META11]] = !{[[META12:![0-9]+]]}
55+
// CHECK: [[META12]] = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: [[META10]], file: [[META6]], line: 7, baseType: [[META13:![0-9]+]], size: 512)
56+
// CHECK: [[META13]] = !DICompositeType(tag: DW_TAG_array_type, baseType: [[META14:![0-9]+]], size: 512, elements: [[META15:![0-9]+]])
57+
// CHECK: [[META14]] = !DIBasicType(name: "unsigned long long", size: 64, encoding: DW_ATE_unsigned)
58+
// CHECK: [[META15]] = !{[[META16:![0-9]+]]}
59+
// CHECK: [[META16]] = !DISubrange(count: 8)
60+
// CHECK: [[META17]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
61+
// CHECK: [[META18]] = !{}
62+
// CHECK: [[META19]] = !DILocalVariable(name: "output", arg: 1, scope: [[DBG5]], file: [[META6]], line: 23, type: [[META9]])
63+
// CHECK: [[META20]] = !DILocation(line: 23, scope: [[DBG5]])
64+
// CHECK: [[META21]] = !DILocalVariable(name: "addr", arg: 2, scope: [[DBG5]], file: [[META6]], line: 23, type: [[META17]])
65+
// CHECK: [[DBG22]] = !DILocation(line: 24, scope: [[DBG5]])
66+
// CHECK: [[DBG23]] = !DILocation(line: 24, scope: [[DBG5]], atomGroup: 1, atomRank: 1)
67+
// CHECK: [[META24]] = !{i64 1663}
68+
// CHECK: [[DBG25]] = !DILocation(line: 24, scope: [[DBG5]], atomGroup: 2, atomRank: 1)
69+
// CHECK: [[DBG26]] = !DILocation(line: 25, scope: [[DBG5]], atomGroup: 3, atomRank: 1)
70+
// CHECK: [[DBG27]] = distinct !DISubprogram(name: "load2", scope: [[META6]], file: [[META6]], line: 42, type: [[META28:![0-9]+]], scopeLine: 42, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META18]], keyInstructions: true)
71+
// CHECK: [[META28]] = !DISubroutineType(types: [[META29:![0-9]+]])
72+
// CHECK: [[META29]] = !{null, [[META30:![0-9]+]], [[META17]]}
73+
// CHECK: [[META30]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META31:![0-9]+]], size: 64)
74+
// CHECK: [[META31]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
75+
// CHECK: [[META32]] = !DILocalVariable(name: "output", arg: 1, scope: [[DBG27]], file: [[META6]], line: 42, type: [[META30]])
76+
// CHECK: [[META33]] = !DILocation(line: 42, scope: [[DBG27]])
77+
// CHECK: [[META34]] = !DILocalVariable(name: "addr", arg: 2, scope: [[DBG27]], file: [[META6]], line: 42, type: [[META17]])
78+
// CHECK: [[DBG35]] = !DILocation(line: 43, scope: [[DBG27]])
79+
// CHECK: [[DBG36]] = !DILocation(line: 43, scope: [[DBG27]], atomGroup: 1, atomRank: 1)
80+
// CHECK: [[META37]] = !{i64 2918}
81+
// CHECK: [[DBG38]] = !DILocation(line: 43, scope: [[DBG27]], atomGroup: 2, atomRank: 1)
82+
// CHECK: [[DBG39]] = !DILocation(line: 44, scope: [[DBG27]], atomGroup: 3, atomRank: 1)
83+
//.

0 commit comments

Comments
 (0)