Skip to content

Commit bbe912f

Browse files
authored
[KeyInstr] Inline asm atoms (#149076)
1 parent b933f0c commit bbe912f

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

clang/lib/CodeGen/CGStmt.cpp

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

2679+
// Make inline-asm calls Key for the debug info feature Key Instructions.
2680+
CGF.addInstToNewSourceAtom(&Result, nullptr);
2681+
26792682
if (!NoConvergent && CGF.getLangOpts().assumeFunctionsAreConvergent())
26802683
// Conservatively, mark all inline asm blocks in CUDA or OpenCL as
26812684
// convergent (meaning, they may call an intrinsically convergent op, such
@@ -2754,14 +2757,16 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S,
27542757
}
27552758
}
27562759

2760+
ApplyAtomGroup Grp(CGF.getDebugInfo());
27572761
LValue Dest = ResultRegDests[i];
27582762
// ResultTypeRequiresCast elements correspond to the first
27592763
// ResultTypeRequiresCast.size() elements of RegResults.
27602764
if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
27612765
unsigned Size = CGF.getContext().getTypeSize(ResultRegQualTys[i]);
27622766
Address A = Dest.getAddress().withElementType(ResultRegTypes[i]);
27632767
if (CGF.getTargetHooks().isScalarizableAsmOperand(CGF, TruncTy)) {
2764-
Builder.CreateStore(Tmp, A);
2768+
llvm::StoreInst *S = Builder.CreateStore(Tmp, A);
2769+
CGF.addInstToCurrentSourceAtom(S, S->getValueOperand());
27652770
continue;
27662771
}
27672772

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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=line-tables-only -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: store ptr [[ADDR]], ptr [[ADDR_ADDR]], align 8
15+
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[OUTPUT_ADDR]], align 8, !dbg [[DBG9:![0-9]+]]
16+
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[ADDR_ADDR]], align 8, !dbg [[DBG9]]
17+
// CHECK-NEXT: [[TMP2:%.*]] = call i512 asm sideeffect "ld64b $0,[$1]", "=r,r,~{memory}"(ptr [[TMP1]]) #[[ATTR1:[0-9]+]], !dbg [[DBG10:![0-9]+]], !srcloc [[META11:![0-9]+]]
18+
// CHECK-NEXT: store i512 [[TMP2]], ptr [[TMP0]], align 8, !dbg [[DBG12:![0-9]+]]
19+
// CHECK-NEXT: ret void, !dbg [[DBG13:![0-9]+]]
20+
//
21+
void load(struct foo *output, void *addr) {
22+
__asm__ volatile ("ld64b %0,[%1]" : "=r" (*output) : "r" (addr) : "memory");
23+
}
24+
25+
// CHECK-LABEL: define dso_local void @load2(
26+
// CHECK-SAME: ptr noundef [[OUTPUT:%.*]], ptr noundef [[ADDR:%.*]]) #[[ATTR0]] !dbg [[DBG14:![0-9]+]] {
27+
// CHECK-NEXT: [[ENTRY:.*:]]
28+
// CHECK-NEXT: [[OUTPUT_ADDR:%.*]] = alloca ptr, align 8
29+
// CHECK-NEXT: [[ADDR_ADDR:%.*]] = alloca ptr, align 8
30+
// CHECK-NEXT: store ptr [[OUTPUT]], ptr [[OUTPUT_ADDR]], align 8
31+
// CHECK-NEXT: store ptr [[ADDR]], ptr [[ADDR_ADDR]], align 8
32+
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[OUTPUT_ADDR]], align 8, !dbg [[DBG15:![0-9]+]]
33+
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[ADDR_ADDR]], align 8, !dbg [[DBG15]]
34+
// CHECK-NEXT: [[TMP2:%.*]] = call i32 asm sideeffect "ld64b $0,[$1]", "=r,r,~{memory}"(ptr [[TMP1]]) #[[ATTR1]], !dbg [[DBG16:![0-9]+]], !srcloc [[META17:![0-9]+]]
35+
// CHECK-NEXT: store i32 [[TMP2]], ptr [[TMP0]], align 4, !dbg [[DBG18:![0-9]+]]
36+
// CHECK-NEXT: ret void, !dbg [[DBG19:![0-9]+]]
37+
//
38+
void load2(int *output, void *addr) {
39+
__asm__ volatile ("ld64b %0,[%1]" : "=r" (*output) : "r" (addr) : "memory");
40+
}
41+
//.
42+
// CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
43+
// CHECK: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
44+
// CHECK: [[DBG5]] = distinct !DISubprogram(name: "load", scope: [[META6:![0-9]+]], file: [[META6]], line: 21, type: [[META7:![0-9]+]], scopeLine: 21, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], keyInstructions: true)
45+
// CHECK: [[META6]] = !DIFile(filename: "{{.*}}asm.c", directory: {{.*}})
46+
// CHECK: [[META7]] = !DISubroutineType(types: [[META8:![0-9]+]])
47+
// CHECK: [[META8]] = !{}
48+
// CHECK: [[DBG9]] = !DILocation(line: 22, scope: [[DBG5]])
49+
// CHECK: [[DBG10]] = !DILocation(line: 22, scope: [[DBG5]], atomGroup: 1, atomRank: 1)
50+
// CHECK: [[META11]] = !{i64 1458}
51+
// CHECK: [[DBG12]] = !DILocation(line: 22, scope: [[DBG5]], atomGroup: 2, atomRank: 1)
52+
// CHECK: [[DBG13]] = !DILocation(line: 23, scope: [[DBG5]], atomGroup: 3, atomRank: 1)
53+
// CHECK: [[DBG14]] = distinct !DISubprogram(name: "load2", scope: [[META6]], file: [[META6]], line: 38, type: [[META7]], scopeLine: 38, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], keyInstructions: true)
54+
// CHECK: [[DBG15]] = !DILocation(line: 39, scope: [[DBG14]])
55+
// CHECK: [[DBG16]] = !DILocation(line: 39, scope: [[DBG14]], atomGroup: 1, atomRank: 1)
56+
// CHECK: [[META17]] = !{i64 2501}
57+
// CHECK: [[DBG18]] = !DILocation(line: 39, scope: [[DBG14]], atomGroup: 2, atomRank: 1)
58+
// CHECK: [[DBG19]] = !DILocation(line: 40, scope: [[DBG14]], atomGroup: 3, atomRank: 1)
59+
//.

0 commit comments

Comments
 (0)