@@ -104,6 +104,36 @@ IRTranslator::IRTranslator() : MachineFunctionPass(ID) {
104
104
initializeIRTranslatorPass (*PassRegistry::getPassRegistry ());
105
105
}
106
106
107
+ #ifndef NDEBUG
108
+ // / Verify that every instruction created has the same DILocation as the
109
+ // / instruction being translated.
110
+ class DILocationVerifier : MachineFunction::Delegate {
111
+ MachineFunction &MF;
112
+ const Instruction *CurrInst = nullptr ;
113
+
114
+ public:
115
+ DILocationVerifier (MachineFunction &MF) : MF(MF) { MF.setDelegate (this ); }
116
+ ~DILocationVerifier () { MF.resetDelegate (this ); }
117
+
118
+ const Instruction *getCurrentInst () const { return CurrInst; }
119
+ void setCurrentInst (const Instruction *Inst) { CurrInst = Inst; }
120
+
121
+ void MF_HandleInsertion (const MachineInstr &MI) override {
122
+ assert (getCurrentInst () && " Inserted instruction without a current MI" );
123
+
124
+ // Only print the check message if we're actually checking it.
125
+ #ifndef NDEBUG
126
+ LLVM_DEBUG (dbgs () << " Checking DILocation from " << *CurrInst
127
+ << " was copied to " << MI);
128
+ #endif
129
+ assert (CurrInst->getDebugLoc () == MI.getDebugLoc () &&
130
+ " Line info was not transferred to all instructions" );
131
+ }
132
+ void MF_HandleRemoval (const MachineInstr &MI) override {}
133
+ };
134
+ #endif // ifndef NDEBUG
135
+
136
+
107
137
void IRTranslator::getAnalysisUsage (AnalysisUsage &AU) const {
108
138
AU.addRequired <StackProtector>();
109
139
AU.addRequired <TargetPassConfig>();
@@ -1468,9 +1498,16 @@ bool IRTranslator::translateAtomicRMW(const User &U,
1468
1498
}
1469
1499
1470
1500
void IRTranslator::finishPendingPhis () {
1501
+ #ifndef NDEBUG
1502
+ DILocationVerifier Verifier (*MF);
1503
+ #endif // ifndef NDEBUG
1471
1504
for (auto &Phi : PendingPHIs) {
1472
1505
const PHINode *PI = Phi.first ;
1473
1506
ArrayRef<MachineInstr *> ComponentPHIs = Phi.second ;
1507
+ EntryBuilder.setDebugLoc (PI->getDebugLoc ());
1508
+ #ifndef NDEBUG
1509
+ Verifier.setCurrentInst (PI);
1510
+ #endif // ifndef NDEBUG
1474
1511
1475
1512
// All MachineBasicBlocks exist, add them to the PHI. We assume IRTranslator
1476
1513
// won't create extra control flow here, otherwise we need to find the
@@ -1509,6 +1546,7 @@ bool IRTranslator::valueIsSplit(const Value &V,
1509
1546
1510
1547
bool IRTranslator::translate (const Instruction &Inst) {
1511
1548
CurBuilder.setDebugLoc (Inst.getDebugLoc ());
1549
+ EntryBuilder.setDebugLoc (Inst.getDebugLoc ());
1512
1550
switch (Inst.getOpcode ()) {
1513
1551
#define HANDLE_INST (NUM, OPCODE, CLASS ) \
1514
1552
case Instruction::OPCODE: return translate##OPCODE (Inst, CurBuilder);
@@ -1684,31 +1722,39 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
1684
1722
}
1685
1723
1686
1724
// Need to visit defs before uses when translating instructions.
1687
- ReversePostOrderTraversal<const Function *> RPOT (&F);
1688
- for (const BasicBlock *BB : RPOT) {
1689
- MachineBasicBlock &MBB = getMBB (*BB);
1690
- // Set the insertion point of all the following translations to
1691
- // the end of this basic block.
1692
- CurBuilder.setMBB (MBB);
1693
-
1694
- for (const Instruction &Inst : *BB) {
1695
- if (translate (Inst))
1696
- continue ;
1697
-
1698
- OptimizationRemarkMissed R (" gisel-irtranslator" , " GISelFailure" ,
1699
- Inst.getDebugLoc (), BB);
1700
- R << " unable to translate instruction: " << ore::NV (" Opcode" , &Inst);
1701
-
1702
- if (ORE->allowExtraAnalysis (" gisel-irtranslator" )) {
1703
- std::string InstStrStorage;
1704
- raw_string_ostream InstStr (InstStrStorage);
1705
- InstStr << Inst;
1725
+ {
1726
+ ReversePostOrderTraversal<const Function *> RPOT (&F);
1727
+ #ifndef NDEBUG
1728
+ DILocationVerifier Verifier (*MF);
1729
+ #endif // ifndef NDEBUG
1730
+ for (const BasicBlock *BB : RPOT) {
1731
+ MachineBasicBlock &MBB = getMBB (*BB);
1732
+ // Set the insertion point of all the following translations to
1733
+ // the end of this basic block.
1734
+ CurBuilder.setMBB (MBB);
1735
+
1736
+ for (const Instruction &Inst : *BB) {
1737
+ #ifndef NDEBUG
1738
+ Verifier.setCurrentInst (&Inst);
1739
+ #endif // ifndef NDEBUG
1740
+ if (translate (Inst))
1741
+ continue ;
1742
+
1743
+ OptimizationRemarkMissed R (" gisel-irtranslator" , " GISelFailure" ,
1744
+ Inst.getDebugLoc (), BB);
1745
+ R << " unable to translate instruction: " << ore::NV (" Opcode" , &Inst);
1746
+
1747
+ if (ORE->allowExtraAnalysis (" gisel-irtranslator" )) {
1748
+ std::string InstStrStorage;
1749
+ raw_string_ostream InstStr (InstStrStorage);
1750
+ InstStr << Inst;
1751
+
1752
+ R << " : '" << InstStr.str () << " '" ;
1753
+ }
1706
1754
1707
- R << " : '" << InstStr.str () << " '" ;
1755
+ reportTranslationError (*MF, *TPC, *ORE, R);
1756
+ return false ;
1708
1757
}
1709
-
1710
- reportTranslationError (*MF, *TPC, *ORE, R);
1711
- return false ;
1712
1758
}
1713
1759
}
1714
1760
0 commit comments