19
19
#include " llvm/Analysis/CallGraphSCCPass.h"
20
20
#include " llvm/Analysis/LazyCallGraph.h"
21
21
#include " llvm/Analysis/LoopInfo.h"
22
+ #include " llvm/CodeGen/MIRPrinter.h"
22
23
#include " llvm/CodeGen/MachineFunction.h"
24
+ #include " llvm/CodeGen/MachineModuleInfo.h"
23
25
#include " llvm/IR/Constants.h"
24
26
#include " llvm/IR/Function.h"
25
27
#include " llvm/IR/Module.h"
@@ -180,6 +182,12 @@ const Module *unwrapModule(Any IR, bool Force = false) {
180
182
return F->getParent ();
181
183
}
182
184
185
+ if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
186
+ if (!Force && !isFunctionInPrintList (MF->getName ()))
187
+ return nullptr ;
188
+ return MF->getFunction ().getParent ();
189
+ }
190
+
183
191
llvm_unreachable (" Unknown IR unit" );
184
192
}
185
193
@@ -215,6 +223,12 @@ void printIR(raw_ostream &OS, const Loop *L) {
215
223
printLoop (const_cast <Loop &>(*L), OS);
216
224
}
217
225
226
+ void printIR (raw_ostream &OS, const MachineFunction *MF) {
227
+ if (!isFunctionInPrintList (MF->getName ()))
228
+ return ;
229
+ MF->print (OS);
230
+ }
231
+
218
232
std::string getIRName (Any IR) {
219
233
if (unwrapIR<Module>(IR))
220
234
return " [module]" ;
@@ -262,6 +276,9 @@ bool shouldPrintIR(Any IR) {
262
276
263
277
if (const auto *L = unwrapIR<Loop>(IR))
264
278
return isFunctionInPrintList (L->getHeader ()->getParent ()->getName ());
279
+
280
+ if (const auto *MF = unwrapIR<MachineFunction>(IR))
281
+ return isFunctionInPrintList (MF->getName ());
265
282
llvm_unreachable (" Unknown wrapped IR type" );
266
283
}
267
284
@@ -275,6 +292,14 @@ void unwrapAndPrint(raw_ostream &OS, Any IR) {
275
292
auto *M = unwrapModule (IR);
276
293
assert (M && " should have unwrapped module" );
277
294
printIR (OS, M);
295
+
296
+ if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
297
+ auto &MMI = MF->getMMI ();
298
+ for (const auto &F : *M) {
299
+ if (auto *MF = MMI.getMachineFunction (F))
300
+ MF->print (OS);
301
+ }
302
+ }
278
303
return ;
279
304
}
280
305
@@ -297,6 +322,11 @@ void unwrapAndPrint(raw_ostream &OS, Any IR) {
297
322
printIR (OS, L);
298
323
return ;
299
324
}
325
+
326
+ if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
327
+ printIR (OS, MF);
328
+ return ;
329
+ }
300
330
llvm_unreachable (" Unknown wrapped IR type" );
301
331
}
302
332
@@ -305,7 +335,8 @@ bool isIgnored(StringRef PassID) {
305
335
return isSpecialPass (PassID,
306
336
{" PassManager" , " PassAdaptor" , " AnalysisManagerProxy" ,
307
337
" DevirtSCCRepeatedPass" , " ModuleInlinerWrapperPass" ,
308
- " VerifierPass" , " PrintModulePass" });
338
+ " VerifierPass" , " PrintModulePass" , " PrintMIRPass" ,
339
+ " PrintMIRPreparePass" });
309
340
}
310
341
311
342
std::string makeHTMLReady (StringRef SR) {
@@ -664,20 +695,38 @@ template <typename T> void IRComparer<T>::analyzeIR(Any IR, IRDataT<T> &Data) {
664
695
return ;
665
696
}
666
697
667
- const auto *F = unwrapIR<Function>(IR);
668
- if (!F) {
669
- const auto *L = unwrapIR<Loop>(IR);
670
- assert (L && " Unknown IR unit." );
671
- F = L->getHeader ()->getParent ();
698
+ if (const auto *F = unwrapIR<Function>(IR)) {
699
+ generateFunctionData (Data, *F);
700
+ return ;
701
+ }
702
+
703
+ if (const auto *L = unwrapIR<Loop>(IR)) {
704
+ auto *F = L->getHeader ()->getParent ();
705
+ generateFunctionData (Data, *F);
706
+ return ;
672
707
}
673
- assert (F && " Unknown IR unit." );
674
- generateFunctionData (Data, *F);
708
+
709
+ if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
710
+ generateFunctionData (Data, *MF);
711
+ return ;
712
+ }
713
+
714
+ llvm_unreachable (" Unknown IR unit" );
715
+ }
716
+
717
+ static bool shouldGenerateData (const Function &F) {
718
+ return !F.isDeclaration () && isFunctionInPrintList (F.getName ());
719
+ }
720
+
721
+ static bool shouldGenerateData (const MachineFunction &MF) {
722
+ return isFunctionInPrintList (MF.getName ());
675
723
}
676
724
677
725
template <typename T>
678
- bool IRComparer<T>::generateFunctionData(IRDataT<T> &Data, const Function &F) {
679
- if (!F.isDeclaration () && isFunctionInPrintList (F.getName ())) {
680
- FuncDataT<T> FD (F.getEntryBlock ().getName ().str ());
726
+ template <typename FunctionT>
727
+ bool IRComparer<T>::generateFunctionData(IRDataT<T> &Data, const FunctionT &F) {
728
+ if (shouldGenerateData (F)) {
729
+ FuncDataT<T> FD (F.front ().getName ().str ());
681
730
int I = 0 ;
682
731
for (const auto &B : F) {
683
732
std::string BBName = B.getName ().str ();
@@ -722,6 +771,12 @@ static SmallString<32> getIRFileDisplayName(Any IR) {
722
771
ResultStream << " -loop-" ;
723
772
stable_hash LoopNameHash = stable_hash_combine_string (L->getName ());
724
773
write_hex (ResultStream, LoopNameHash, HexPrintStyle::Lower, MaxHashWidth);
774
+ } else if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
775
+ ResultStream << " -machine-function-" ;
776
+ stable_hash MachineFunctionNameHash =
777
+ stable_hash_combine_string (MF->getName ());
778
+ write_hex (ResultStream, MachineFunctionNameHash, HexPrintStyle::Lower,
779
+ MaxHashWidth);
725
780
} else {
726
781
llvm_unreachable (" Unknown wrapped IR type" );
727
782
}
@@ -2122,6 +2177,11 @@ DCData::DCData(const BasicBlock &B) {
2122
2177
addSuccessorLabel (Succ->getName ().str (), " " );
2123
2178
}
2124
2179
2180
+ DCData::DCData (const MachineBasicBlock &B) {
2181
+ for (const MachineBasicBlock *Succ : successors (&B))
2182
+ addSuccessorLabel (Succ->getName ().str (), " " );
2183
+ }
2184
+
2125
2185
DotCfgChangeReporter::DotCfgChangeReporter (bool Verbose)
2126
2186
: ChangeReporter<IRDataT<DCData>>(Verbose) {}
2127
2187
0 commit comments