Browse Source

[spirv] Emit OpLine for if/while/do/for conditions (#1462)

Lei Zhang 7 years ago
parent
commit
ba6eb6f2ef

+ 6 - 0
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -1486,6 +1486,7 @@ void SPIRVEmitter::doDoStmt(const DoStmt *theDoStmt,
   theBuilder.setInsertPoint(continueBB);
   theBuilder.setInsertPoint(continueBB);
   uint32_t condition = 0;
   uint32_t condition = 0;
   if (const Expr *check = theDoStmt->getCond()) {
   if (const Expr *check = theDoStmt->getCond()) {
+    emitDebugLine(check->getLocStart());
     condition = doExpr(check);
     condition = doExpr(check);
   } else {
   } else {
     condition = theBuilder.getConstantBool(true);
     condition = theBuilder.getConstantBool(true);
@@ -1585,6 +1586,7 @@ void SPIRVEmitter::doWhileStmt(const WhileStmt *whileStmt,
 
 
   uint32_t condition = 0;
   uint32_t condition = 0;
   if (const Expr *check = whileStmt->getCond()) {
   if (const Expr *check = whileStmt->getCond()) {
+    emitDebugLine(check->getLocStart());
     condition = doExpr(check);
     condition = doExpr(check);
   } else {
   } else {
     condition = theBuilder.getConstantBool(true);
     condition = theBuilder.getConstantBool(true);
@@ -1676,6 +1678,7 @@ void SPIRVEmitter::doForStmt(const ForStmt *forStmt,
 
 
   // Process the <init> block
   // Process the <init> block
   if (const Stmt *initStmt = forStmt->getInit()) {
   if (const Stmt *initStmt = forStmt->getInit()) {
+    emitDebugLine(initStmt->getLocStart());
     doStmt(initStmt);
     doStmt(initStmt);
   }
   }
   theBuilder.createBranch(checkBB);
   theBuilder.createBranch(checkBB);
@@ -1685,6 +1688,7 @@ void SPIRVEmitter::doForStmt(const ForStmt *forStmt,
   theBuilder.setInsertPoint(checkBB);
   theBuilder.setInsertPoint(checkBB);
   uint32_t condition;
   uint32_t condition;
   if (const Expr *check = forStmt->getCond()) {
   if (const Expr *check = forStmt->getCond()) {
+    emitDebugLine(check->getLocStart());
     condition = doExpr(check);
     condition = doExpr(check);
   } else {
   } else {
     condition = theBuilder.getConstantBool(true);
     condition = theBuilder.getConstantBool(true);
@@ -1713,6 +1717,7 @@ void SPIRVEmitter::doForStmt(const ForStmt *forStmt,
   // Process the <continue> block
   // Process the <continue> block
   theBuilder.setInsertPoint(continueBB);
   theBuilder.setInsertPoint(continueBB);
   if (const Expr *cont = forStmt->getInc()) {
   if (const Expr *cont = forStmt->getInc()) {
+    emitDebugLine(cont->getLocStart());
     doExpr(cont);
     doExpr(cont);
   }
   }
   theBuilder.createBranch(checkBB); // <continue> should jump back to header
   theBuilder.createBranch(checkBB); // <continue> should jump back to header
@@ -1786,6 +1791,7 @@ void SPIRVEmitter::doIfStmt(const IfStmt *ifStmt,
   if (const auto *declStmt = ifStmt->getConditionVariableDeclStmt())
   if (const auto *declStmt = ifStmt->getConditionVariableDeclStmt())
     doDeclStmt(declStmt);
     doDeclStmt(declStmt);
 
 
+  emitDebugLine(ifStmt->getCond()->getLocStart());
   // First emit the instruction for evaluating the condition.
   // First emit the instruction for evaluating the condition.
   const uint32_t condition = doExpr(ifStmt->getCond());
   const uint32_t condition = doExpr(ifStmt->getCond());
 
 

+ 35 - 0
tools/clang/test/CodeGenSPIRV/spirv.debug.opline.hlsl

@@ -29,5 +29,40 @@ float4 main(uint val : A) : SV_Target {
   // CHECK-NEXT: OpLoad %type_2d_image %MyTexture
   // CHECK-NEXT: OpLoad %type_2d_image %MyTexture
   float4 c = MyTexture.Sample(MySampler, float2(0.1, 0.2));
   float4 c = MyTexture.Sample(MySampler, float2(0.1, 0.2));
 
 
+  // CHECK:      OpLine [[file]] 36 7
+  // CHECK-NEXT: OpLoad %uint %val
+  // CHECK-NEXT: OpUGreaterThan
+  if (val > 10) {
+    a = 5;
+  } else {
+    a = 6;
+  }
+
+  for (
+  // CHECK:      OpLine [[file]] 45 7
+  // CHECK-NEXT: OpStore %b %uint_0
+      b = 0;
+  // CHECK:      OpLine [[file]] 49 7
+  // CHECK-NEXT: OpLoad %uint %b
+  // CHECK-NEXT: OpULessThan
+      b < 10;
+  // CHECK:      OpLine [[file]] 53 7
+  // CHECK-NEXT: OpLoad %uint %b
+  // CHECK-NEXT: OpIAdd
+      ++b) {
+    a += 1;
+  }
+
+  // CHECK:      OpLine [[file]] 60 10
+  // CHECK-NEXT: OpLoad %uint %b
+  // CHECK-NEXT: OpISub
+  while (--b > 0);
+
+  do {
+    c++;
+  // CHECK:      OpLine [[file]] 66 12
+  // CHECK-NEXT: OpAccessChain %_ptr_Function_float %c %int_0
+  } while (c.x < 10);
+
   return b * c;
   return b * c;
 }
 }