|
@@ -950,7 +950,7 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
|
|
|
|
|
|
auto Fn = DM.GetEntryFunction();
|
|
auto Fn = DM.GetEntryFunction();
|
|
auto &Blocks = Fn->getBasicBlockList();
|
|
auto &Blocks = Fn->getBasicBlockList();
|
|
- for (auto &block : Blocks) {
|
|
|
|
|
|
+ for (auto &CurrentBlock : Blocks) {
|
|
struct ValueAndPhi {
|
|
struct ValueAndPhi {
|
|
Value *Val;
|
|
Value *Val;
|
|
PHINode *Phi;
|
|
PHINode *Phi;
|
|
@@ -959,12 +959,12 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
|
|
|
|
|
|
std::map<BasicBlock *, std::vector<ValueAndPhi>> InsertableEdges;
|
|
std::map<BasicBlock *, std::vector<ValueAndPhi>> InsertableEdges;
|
|
|
|
|
|
- auto &Is = block.getInstList();
|
|
|
|
|
|
+ auto &Is = CurrentBlock.getInstList();
|
|
for (auto &Inst : Is) {
|
|
for (auto &Inst : Is) {
|
|
if (Inst.getOpcode() != Instruction::OtherOps::PHI) {
|
|
if (Inst.getOpcode() != Instruction::OtherOps::PHI) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- PHINode &PN = cast<PHINode>(Inst);
|
|
|
|
|
|
+ PHINode &PN = llvm::cast<PHINode>(Inst);
|
|
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
|
|
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
|
|
BasicBlock *PhiBB = PN.getIncomingBlock(i);
|
|
BasicBlock *PhiBB = PN.getIncomingBlock(i);
|
|
Value *PhiVal = PN.getIncomingValue(i);
|
|
Value *PhiVal = PN.getIncomingValue(i);
|
|
@@ -978,19 +978,25 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
|
|
IRBuilder<> Builder(NewBlock);
|
|
IRBuilder<> Builder(NewBlock);
|
|
|
|
|
|
auto *PreviousBlock = InsertableEdge.first;
|
|
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);
|
|
ValueNPhi.Phi->setIncomingBlock(ValueNPhi.Index, NewBlock);
|
|
|
|
|
|
|
|
+ // Add instrumentation to the new block
|
|
std::uint32_t RegNum;
|
|
std::uint32_t RegNum;
|
|
if (!pix_dxil::PixDxilReg::FromInst(ValueNPhi.Phi, &RegNum)) {
|
|
if (!pix_dxil::PixDxilReg::FromInst(ValueNPhi.Phi, &RegNum)) {
|
|
continue;
|
|
continue;
|
|
@@ -1005,12 +1011,11 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
|
|
addStepDebugEntryValue(BC, InstNum, ValueNPhi.Val, RegNum,
|
|
addStepDebugEntryValue(BC, InstNum, ValueNPhi.Val, RegNum,
|
|
BC.Builder.getInt32(0));
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|