فهرست منبع

Fix debug info generated by scalarizer.

Fixes some bugs with how the scalarizer emitted debug info:

- It wrongly emitted a non-zero Offset argument, which would cause the intrinsic to get discarded by newer LLVM versions which removed that parameter. (and the offset value it emitted wasn't even correct).
- It didn't take into account the offset of any existing bit piece expressions on the vector.
Tristan Labelle 6 سال پیش
والد
کامیت
aa8eee2f9a
2فایلهای تغییر یافته به همراه27 افزوده شده و 6 حذف شده
  1. 6 6
      lib/Transforms/Scalar/Scalarizer.cpp
  2. 21 0
      tools/clang/test/CodeGenHLSL/debug/locals/scalarized_vector.hlsl

+ 6 - 6
lib/Transforms/Scalar/Scalarizer.cpp

@@ -694,23 +694,23 @@ bool Scalarizer::finish() {
           unsigned Count = Ty->getVectorNumElements();
           Type *EltTy = Ty->getVectorElementType();
           unsigned EltSizeInBits = DL.getTypeSizeInBits(EltTy);
-          for (User *U : DINode->users())
+          for (User *U : DINode->users()) {
             if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(U)) {
               DIBuilder DIB(M, /*AllowUnresolved*/ false);
               auto *VarInfo = DVI->getVariable();
               DebugLoc DbgLoc = DVI->getDebugLoc();
               unsigned OffsetInBits = 0;
+              if (DVI->getExpression()->isBitPiece())
+                OffsetInBits = DVI->getExpression()->getBitPieceOffset();
               for (unsigned I = 0; I < Count; ++I) {
-                // TODO: need to use DIExpression::createFragmentExpression for
-                // case DVI->getExpression is already bit piece.
                 DIExpression *EltExpr =
-                    DIB.createBitPieceExpression(OffsetInBits, EltSizeInBits);
+                  DIB.createBitPieceExpression(OffsetInBits, EltSizeInBits);
                 OffsetInBits += EltSizeInBits;
 
-                DIB.insertDbgValueIntrinsic(CV[I], OffsetInBits, VarInfo, EltExpr,
-                                            DbgLoc, DVI);
+                DIB.insertDbgValueIntrinsic(CV[I], 0, VarInfo, EltExpr, DbgLoc, DVI);
               }
             }
+          }
         }
       }
     }

+ 21 - 0
tools/clang/test/CodeGenHLSL/debug/locals/scalarized_vector.hlsl

@@ -0,0 +1,21 @@
+// RUN: %dxc -E main -T vs_6_0 -Zi %s | FileCheck %s
+
+// Test that the vector scalarizer preserves debug information.
+
+// CHECK: %[[x:.*]] = add i32
+// CHECK: %[[y:.*]] = add i32
+// CHECK-DAG: call void @llvm.dbg.value(metadata i32 %[[x]], i64 0, metadata ![[vec:.*]], metadata ![[xexp:.*]]), !dbg !46
+// CHECK-DAG: call void @llvm.dbg.value(metadata i32 %[[y]], i64 0, metadata ![[vec]], metadata ![[yexp:.*]]), !dbg !46
+
+// Exclude quoted source file (see readme)
+// CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
+
+// CHECK-DAG: ![[vec]] = !DILocalVariable(tag: DW_TAG_auto_variable, name: "vec"
+// CHECK-DAG: ![[xexp]] = !DIExpression(DW_OP_bit_piece, 0, 32)
+// CHECK-DAG: ![[yexp]] = !DIExpression(DW_OP_bit_piece, 32, 32)
+
+int2 main(int2 a : A, int2 b : B) : OUT
+{
+    int2 vec = a + b;
+    return vec;
+}