diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp --- a/llvm/lib/Passes/StandardInstrumentations.cpp +++ b/llvm/lib/Passes/StandardInstrumentations.cpp @@ -17,6 +17,8 @@ #include "llvm/Analysis/CallGraphSCCPass.h" #include "llvm/Analysis/LazyCallGraph.h" #include "llvm/Analysis/LoopInfo.h" +#include "llvm/CodeGen/MIRPrinter.h" +#include "llvm/CodeGen/MachineFunction.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/Module.h" @@ -43,6 +45,15 @@ return std::make_pair(M, formatv(" (function: {0})", F->getName()).str()); } + if (any_isa(IR)) { + const MachineFunction *MF = any_cast(IR); + if (!llvm::isFunctionInPrintList(MF->getName())) + return None; + const Module *M = MF->getFunction().getParent(); + return std::make_pair( + M, formatv(" (machine function: {0})", MF->getName()).str()); + } + if (any_isa(IR)) { const LazyCallGraph::SCC *C = any_cast(IR); for (const LazyCallGraph::Node &N : *C) { @@ -109,6 +120,13 @@ llvm::printLoop(const_cast(*L), dbgs(), std::string(Banner)); } +void printIR(const MachineFunction *MF, StringRef Banner, + StringRef Extra = StringRef()) { + if (!llvm::isFunctionInPrintList(MF->getName())) + return; + dbgs() << Banner << Extra << "\n"; + printMIR(dbgs(), *MF); +} /// Generic IR-printing helper that unpacks a pointer to IRUnit wrapped into /// llvm::Any and does actual print job. void unwrapAndPrint(Any IR, StringRef Banner, bool ForceModule = false) { @@ -146,6 +164,14 @@ printIR(L, Banner); return; } + + if (any_isa(IR)) { + const MachineFunction *MF = any_cast(IR); + assert(MF && "machine function should be valid for printing"); + printIR(MF, Banner); + return; + } + llvm_unreachable("Unknown wrapped IR type"); }