Skip to content

Commit 49d1724

Browse files
authored
Merge pull request #1143 from dcci/gisel-di-fixes
Cherry-pick GlobalISel debug info location fixes.
2 parents 71916c3 + b560a12 commit 49d1724

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class LegalizationArtifactCombiner {
5050
SmallVectorImpl<Register> &UpdatedDefs) {
5151
assert(MI.getOpcode() == TargetOpcode::G_ANYEXT);
5252

53-
Builder.setInstr(MI);
53+
Builder.setInstrAndDebugLoc(MI);
5454
Register DstReg = MI.getOperand(0).getReg();
5555
Register SrcReg = lookThroughCopyInstrs(MI.getOperand(1).getReg());
5656

@@ -99,7 +99,7 @@ class LegalizationArtifactCombiner {
9999
SmallVectorImpl<Register> &UpdatedDefs) {
100100
assert(MI.getOpcode() == TargetOpcode::G_ZEXT);
101101

102-
Builder.setInstr(MI);
102+
Builder.setInstrAndDebugLoc(MI);
103103
Register DstReg = MI.getOperand(0).getReg();
104104
Register SrcReg = lookThroughCopyInstrs(MI.getOperand(1).getReg());
105105

llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ MachineInstrBuilder MachineIRBuilder::buildConstant(const DstOp &Res,
290290
}
291291

292292
auto Const = buildInstr(TargetOpcode::G_CONSTANT);
293+
Const->setDebugLoc(DebugLoc());
293294
Res.addDefToMIB(*getMRI(), Const);
294295
Const.addCImm(&Val);
295296
return Const;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# RUN: llc -O0 -verify-machineinstrs -mtriple aarch64-- -run-pass=legalizer %s -o - | FileCheck %s
2+
3+
# Check that when we combine SEXT/ZEXT/ANYEXT we assign the correct location.
4+
# CHECK: !8 = !DILocation(line: 23, column: 5, scope: !4)
5+
# CHECK: G_AND %16, %15, debug-location !8
6+
7+
--- |
8+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
9+
target triple = "arm64-apple-ios13.0.0"
10+
11+
@.str = external dso_local unnamed_addr constant [4 x i8], align 1
12+
13+
define void @main() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !dbg !4 {
14+
entry:
15+
%tobool = trunc i8 undef to i1
16+
%conv = zext i1 %tobool to i32
17+
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %conv), !dbg !8
18+
%0 = load i32, i32* undef, align 4, !dbg !9
19+
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
20+
ret void
21+
}
22+
23+
declare void @printf(i8*, ...)
24+
declare i32 @__gxx_personality_v0(...)
25+
26+
!llvm.dbg.cu = !{!0}
27+
!llvm.module.flags = !{!2, !3}
28+
29+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, nameTableKind: None, sysroot: "/pata/tino", sdk: "iPhoneOS13.0.sdk")
30+
!1 = !DIFile(filename: "/pata/tino/main.cpp", directory: "/pata/tino")
31+
!2 = !{i32 2, !"Debug Info Version", i32 3}
32+
!3 = !{i32 7, !"PIC Level", i32 2}
33+
!4 = distinct !DISubprogram(name: "main", scope: !5, file: !5, line: 19, type: !6, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
34+
!5 = !DIFile(filename: "main.cpp", directory: "/pata/tino")
35+
!6 = !DISubroutineType(types: !7)
36+
!7 = !{}
37+
!8 = !DILocation(line: 23, column: 5, scope: !4)
38+
!9 = !DILocation(line: 36, column: 21, scope: !4)
39+
40+
...
41+
---
42+
name: main
43+
registers:
44+
- { id: 0, class: _, preferred-register: '' }
45+
- { id: 1, class: _, preferred-register: '' }
46+
- { id: 2, class: _, preferred-register: '' }
47+
- { id: 3, class: _, preferred-register: '' }
48+
- { id: 4, class: _, preferred-register: '' }
49+
- { id: 5, class: _, preferred-register: '' }
50+
- { id: 6, class: _, preferred-register: '' }
51+
- { id: 7, class: _, preferred-register: '' }
52+
- { id: 8, class: _, preferred-register: '' }
53+
- { id: 9, class: _, preferred-register: '' }
54+
body: |
55+
bb.1.entry:
56+
%0:_(s8) = G_IMPLICIT_DEF
57+
%4:_(p0) = G_GLOBAL_VALUE @.str, debug-location !DILocation(line: 0, scope: !4)
58+
%10:_(p0) = G_IMPLICIT_DEF debug-location !DILocation(line: 0, scope: !4)
59+
%1:_(s1) = G_TRUNC %0(s8)
60+
%2:_(s32) = G_ZEXT %1(s1)
61+
ADJCALLSTACKDOWN 8, 0, implicit-def $sp, implicit $sp, debug-location !8
62+
$x0 = COPY %4(p0), debug-location !8
63+
%5:_(p0) = COPY $sp, debug-location !8
64+
%6:_(s64) = G_CONSTANT i64 0
65+
%7:_(p0) = G_PTR_ADD %5, %6(s64), debug-location !8
66+
%8:_(s64) = G_ANYEXT %2(s32), debug-location !8
67+
G_STORE %8(s64), %7(p0), debug-location !8 :: (store 8 into stack, align 1)
68+
BL @printf, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $x0, debug-location !8
69+
ADJCALLSTACKUP 8, 0, implicit-def $sp, implicit $sp, debug-location !8
70+
%13:_(s64) = G_LOAD %10(p0), debug-location !9 :: (load 4 from `i32* undef`)
71+
ADJCALLSTACKDOWN 8, 0, implicit-def $sp, implicit $sp
72+
$x0 = COPY %4(p0)
73+
%11:_(p0) = COPY $sp
74+
%12:_(p0) = G_PTR_ADD %11, %6(s64)
75+
G_STORE %13(s64), %12(p0) :: (store 8 into stack, align 1)
76+
BL @printf, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $x0
77+
ADJCALLSTACKUP 8, 0, implicit-def $sp, implicit $sp
78+
RET_ReallyLR
79+
80+
...

llvm/test/CodeGen/AArch64/GlobalISel/constant-dbg-loc.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2-
; RUN: llc -mtriple aarch64 -O0 -stop-after=irtranslator -global-isel -verify-machineinstrs %s -o - 2>&1 | FileCheck %s
2+
; RUN: llc -mtriple aarch64 -O0 -stop-after=irtranslator -global-isel -verify-machineinstrs %s -o - 2>&1 | FileCheck --match-full-lines %s
33
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
44
target triple = "arm64-apple-ios5.0.0"
55

@@ -13,8 +13,8 @@ define i32 @main() #0 !dbg !14 {
1313
; CHECK: successors: %bb.2(0x40000000), %bb.3(0x40000000)
1414
; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
1515
; CHECK: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var1, debug-location !DILocation(line: 0, scope: !18)
16-
; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 0, scope: !18)
17-
; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 0, scope: !22)
16+
; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
17+
; CHECK: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
1818
; CHECK: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var2, debug-location !DILocation(line: 0, scope: !22)
1919
; CHECK: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0.retval
2020
; CHECK: G_STORE [[C]](s32), [[FRAME_INDEX]](p0) :: (store 4 into %ir.retval)

0 commit comments

Comments
 (0)