Browse Source

checkpoitn

Jeff Noyle 5 years ago
parent
commit
0f075532c1
1 changed files with 23 additions and 18 deletions
  1. 23 18
      lib/DxilPIXPasses/DxilDebugInstrumentation.cpp

+ 23 - 18
lib/DxilPIXPasses/DxilDebugInstrumentation.cpp

@@ -950,7 +950,7 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
 
   auto Fn = DM.GetEntryFunction();
   auto &Blocks = Fn->getBasicBlockList();
-  for (auto &block : Blocks) {
+  for (auto &CurrentBlock : Blocks) {
     struct ValueAndPhi {
       Value *Val;
       PHINode *Phi;
@@ -959,12 +959,12 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
 
     std::map<BasicBlock *, std::vector<ValueAndPhi>> InsertableEdges;
 
-    auto &Is = block.getInstList();
+    auto &Is = CurrentBlock.getInstList();
     for (auto &Inst : Is) {
       if (Inst.getOpcode() != Instruction::OtherOps::PHI) {
         break;
       }
-      PHINode &PN = cast<PHINode>(Inst);
+      PHINode &PN = llvm::cast<PHINode>(Inst);
       for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
         BasicBlock *PhiBB = PN.getIncomingBlock(i);
         Value *PhiVal = PN.getIncomingValue(i);
@@ -978,19 +978,25 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
       IRBuilder<> Builder(NewBlock);
 
       auto *PreviousBlock = InsertableEdge.first;
-      for (auto &ValueNPhi : InsertableEdge.second) {
-        TerminatorInst *terminator = PreviousBlock->getTerminator();
-        unsigned NumSuccessors = terminator->getNumSuccessors();
-        for (unsigned SuccessorIndex = 0; SuccessorIndex < NumSuccessors;
-             ++SuccessorIndex) {
-          auto *CurrentSuccessor = terminator->getSuccessor(SuccessorIndex);
-          if (CurrentSuccessor == PreviousBlock) {
-            terminator->setSuccessor(SuccessorIndex, NewBlock);
-            break;
-          }
+
+      // Modify all successor operands of the terminator in the previous block
+      // that match the current block to point to the new block:
+      TerminatorInst *terminator = PreviousBlock->getTerminator();
+      unsigned NumSuccessors = terminator->getNumSuccessors();
+      for (unsigned SuccessorIndex = 0; SuccessorIndex < NumSuccessors;
+           ++SuccessorIndex) {
+        auto *CurrentSuccessor = terminator->getSuccessor(SuccessorIndex);
+        if (CurrentSuccessor == &CurrentBlock) {
+          terminator->setSuccessor(SuccessorIndex, NewBlock);
         }
+      }
+
+      // Modify the Phis and add debug instrumentation
+      for (auto &ValueNPhi : InsertableEdge.second) {
+        // Modify the phi to refer to the new block:
         ValueNPhi.Phi->setIncomingBlock(ValueNPhi.Index, NewBlock);
 
+        // Add instrumentation to the new block
         std::uint32_t RegNum;
         if (!pix_dxil::PixDxilReg::FromInst(ValueNPhi.Phi, &RegNum)) {
           continue;
@@ -1005,12 +1011,11 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
         addStepDebugEntryValue(BC, InstNum, ValueNPhi.Val, RegNum,
                                BC.Builder.getInt32(0));
       }
-      Builder.CreateBr(&block);
 
-      for (auto &ValueNPhi : InsertableEdge.second) {
-        auto *CurrentBlock = ValueNPhi.Phi->getParent();
-        CurrentBlock->removePredecessor(PreviousBlock);
-      }
+      // Add a branch to the new block to point to the current block
+      Builder.CreateBr(&CurrentBlock);
+
+      //CurrentBlock.removePredecessor(PreviousBlock);
     }
   }