Browse Source

Fixes for adding -Od (#3292)

A customer couldn't recompile their large shader with -Od for debugging in PIX.
-The symbol manager would quit early, so now it continues to discover other variables
-The value-to-declare pass was adding an incorrect debug location, which tripped up the verifier.
Jeff Noyle 4 years ago
parent
commit
ac5630e8e6

+ 4 - 2
lib/DxilDia/DxilDiaSymbolManager.cpp

@@ -1815,13 +1815,15 @@ HRESULT dxil_dia::hlsl_symbols::SymbolManagerInit::CreateLocalVariables() {
     auto *LS = llvm::dyn_cast_or_null<llvm::DILocalScope>(CI->getDebugLoc()->getInlinedAtScope());
     auto SymIt = m_ScopeToSym.find(LS);
     if (SymIt == m_ScopeToSym.end()) {
-      return E_FAIL;
+        continue;
     }
 
     auto *LocalNameMetadata = llvm::dyn_cast<llvm::MetadataAsValue>(CI->getArgOperand(1));
     if (auto *LV = llvm::dyn_cast<llvm::DILocalVariable>(LocalNameMetadata->getMetadata())) {
       const DWORD dwParentID = SymIt->second;
-      IFR(CreateLocalVariable(dwParentID, LV));
+      if (FAILED(CreateLocalVariable(dwParentID, LV))) {
+          continue;
+      }
     }
   }
 

+ 11 - 7
lib/DxilPIXPasses/DxilDbgValueToDbgDeclare.cpp

@@ -197,6 +197,7 @@ class VariableRegisters
 {
 public:
   VariableRegisters(
+      llvm::DebugLoc const &,
       llvm::DIVariable *Variable,
       llvm::Module *M
   );
@@ -233,7 +234,8 @@ private:
       OffsetInBits Offset
   ) const;
 
-  llvm::DIVariable* m_Variable = nullptr;
+  llvm::DebugLoc const &m_dbgLoc;
+  llvm::DIVariable *m_Variable = nullptr;
   llvm::IRBuilder<> m_B;
   llvm::Function *m_DbgDeclareFn = nullptr;
 
@@ -389,7 +391,7 @@ void DxilDbgValueToDbgDeclare::handleDbgValue(
   auto &Register = m_Registers[Variable];
   if (Register == nullptr)
   {
-    Register.reset(new VariableRegisters(Variable, &M));
+    Register.reset(new VariableRegisters(DbgValue->getDebugLoc(), Variable, &M));
   }
 
   // Convert the offset from DbgValue's expression to a packed
@@ -435,8 +437,8 @@ void DxilDbgValueToDbgDeclare::handleDbgValue(
 
     if (AllocaInst->getAllocatedType()->getArrayElementType() == VO.m_V->getType())
     {
-        auto* GEP = B.CreateGEP(AllocaInst, { Zero, Zero });
-        B.CreateStore(VO.m_V, GEP);
+      auto* GEP = B.CreateGEP(AllocaInst, { Zero, Zero });
+      B.CreateStore(VO.m_V, GEP);
     }
   }
 }
@@ -482,9 +484,11 @@ static llvm::DIType *DITypePeelTypeAlias(
 #endif // NDEBUG
 
 VariableRegisters::VariableRegisters(
+    llvm::DebugLoc const & dbgLoc,
     llvm::DIVariable *Variable,
-    llvm::Module *M
-) : m_Variable(Variable)
+    llvm::Module *M)
+  : m_dbgLoc(dbgLoc)
+  ,m_Variable(Variable)
   , m_B(M->GetOrCreateDxilModule().GetEntryFunction()->getEntryBlock().begin())
   , m_DbgDeclareFn(llvm::Intrinsic::getDeclaration(
       M, llvm::Intrinsic::dbg_declare))
@@ -617,7 +621,7 @@ void VariableRegisters::PopulateAllocaMap_BasicType(
   auto *DbgDeclare = m_B.CreateCall(
       m_DbgDeclareFn,
       {Storage, Variable, Expression});
-  DbgDeclare->setDebugLoc(GetVariableLocation());
+  DbgDeclare->setDebugLoc(m_dbgLoc);
 }
 
 static unsigned NumArrayElements(