|
| 1 | +From 30be071a6dc51fae4865ba71214bd3a2144d44ac Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alexey Sotkin < [email protected]> |
| 3 | +Date: Fri, 21 Dec 2018 23:20:56 +0300 |
| 4 | +Subject: [PATCH] Preserve debug location attached to a builtin call. |
| 5 | + |
| 6 | +--- |
| 7 | + lib/SPIRV/SPIRVUtil.cpp | 2 ++ |
| 8 | + test/DebugInfo/BuiltinCallLocation.ll | 54 +++++++++++++++++++++++++++++++++++ |
| 9 | + 2 files changed, 56 insertions(+) |
| 10 | + create mode 100644 test/DebugInfo/BuiltinCallLocation.ll |
| 11 | + |
| 12 | +diff --git a/lib/SPIRV/SPIRVUtil.cpp b/lib/SPIRV/SPIRVUtil.cpp |
| 13 | +index 2f730db..4c25385 100644 |
| 14 | +--- a/lib/SPIRV/SPIRVUtil.cpp |
| 15 | ++++ b/lib/SPIRV/SPIRVUtil.cpp |
| 16 | +@@ -627,6 +627,7 @@ CallInst *mutateCallInst( |
| 17 | + } |
| 18 | + auto NewCI = addCallInst(M, NewName, CI->getType(), Args, Attrs, CI, Mangle, |
| 19 | + InstName, TakeFuncName); |
| 20 | ++ NewCI->setDebugLoc(CI->getDebugLoc()); |
| 21 | + LLVM_DEBUG(dbgs() << " => " << *NewCI << '\n'); |
| 22 | + CI->replaceAllUsesWith(NewCI); |
| 23 | + CI->eraseFromParent(); |
| 24 | +@@ -653,6 +654,7 @@ Instruction *mutateCallInst( |
| 25 | + InstName + ".tmp", TakeFuncName); |
| 26 | + auto NewI = RetMutate(NewCI); |
| 27 | + NewI->takeName(CI); |
| 28 | ++ NewI->setDebugLoc(CI->getDebugLoc()); |
| 29 | + LLVM_DEBUG(dbgs() << " => " << *NewI << '\n'); |
| 30 | + CI->replaceAllUsesWith(NewI); |
| 31 | + CI->eraseFromParent(); |
| 32 | +diff --git a/test/DebugInfo/BuiltinCallLocation.ll b/test/DebugInfo/BuiltinCallLocation.ll |
| 33 | +new file mode 100644 |
| 34 | +index 0000000..d4e6b7c |
| 35 | +--- /dev/null |
| 36 | ++++ b/test/DebugInfo/BuiltinCallLocation.ll |
| 37 | +@@ -0,0 +1,54 @@ |
| 38 | ++; Check that DebugLoc attached to a builtin call is preserverd after translation. |
| 39 | ++; Source: |
| 40 | ++; float f(float x) { |
| 41 | ++; return sin(x); |
| 42 | ++; } |
| 43 | ++; Command to get this IR: |
| 44 | ++; clang -cc1 -triple spir -finclude-default-header /tmp/tmp.cl -disable-llvm-passes -emit-llvm -o - -debug-info-kind=line-tables-only | opt -mem2reg -S -o test/DebugInfo/BuiltinCallLocation.ll |
| 45 | ++ |
| 46 | ++; RUN: llvm-as < %s > %t.bc |
| 47 | ++; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV |
| 48 | ++; RUN: llvm-spirv %t.bc -o %t.spv |
| 49 | ++; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM |
| 50 | ++ |
| 51 | ++target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" |
| 52 | ++target triple = "spir" |
| 53 | ++ |
| 54 | ++; Function Attrs: convergent nounwind |
| 55 | ++define spir_func float @f(float %x) #0 !dbg !8 { |
| 56 | ++entry: |
| 57 | ++; CHECK-SPIRV: Label |
| 58 | ++; CHECK-SPIRV: ExtInst {{.*}} DebugScope |
| 59 | ++; CHECK-SPIRV: ExtInst {{.*}} sin |
| 60 | ++ %call = call spir_func float @_Z3sinf(float %x) #2, !dbg !11 |
| 61 | ++; CHECK-LLVM: call spir_func float @_Z3sinf(float %x) {{.*}} !dbg ![[loc:[0-9]+]] |
| 62 | ++ ret float %call, !dbg !12 |
| 63 | ++} |
| 64 | ++ |
| 65 | ++; Function Attrs: convergent nounwind readnone |
| 66 | ++declare spir_func float @_Z3sinf(float) #1 |
| 67 | ++ |
| 68 | ++attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 69 | ++attributes #1 = { convergent nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 70 | ++attributes #2 = { convergent nounwind readnone } |
| 71 | ++ |
| 72 | ++!llvm.dbg.cu = !{!0} |
| 73 | ++!llvm.module.flags = !{!3, !4} |
| 74 | ++!opencl.ocl.version = !{!5} |
| 75 | ++!opencl.spir.version = !{!6} |
| 76 | ++!llvm.ident = !{!7} |
| 77 | ++ |
| 78 | ++!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2) |
| 79 | ++!1 = !DIFile(filename: "/tmp/<stdin>", directory: "/llvm/build") |
| 80 | ++!2 = !{} |
| 81 | ++!3 = !{i32 2, !"Debug Info Version", i32 3} |
| 82 | ++!4 = !{i32 1, !"wchar_size", i32 4} |
| 83 | ++!5 = !{i32 1, i32 0} |
| 84 | ++!6 = !{i32 1, i32 2} |
| 85 | ++!7 = !{!"clang version 8.0.0 "} |
| 86 | ++!8 = distinct !DISubprogram(name: "f", scope: !9, file: !9, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2) |
| 87 | ++!9 = !DIFile(filename: "/tmp/tmp.cl", directory: "/llvm/build") |
| 88 | ++!10 = !DISubroutineType(types: !2) |
| 89 | ++!11 = !DILocation(line: 2, column: 10, scope: !8) |
| 90 | ++;CHECK-LLVM: ![[loc]] = !DILocation(line: 2, column: 10, scope: !{{.*}}) |
| 91 | ++!12 = !DILocation(line: 2, column: 3, scope: !8) |
| 92 | +-- |
| 93 | +1.8.3.1 |
| 94 | + |
0 commit comments