[PATCH] D83609: [NewPM][CodeGen] Support printing machine functions from StandardInstrumentation
Yuanfang Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 10 19:22:09 PDT 2020
ychen created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D83609
Files:
llvm/lib/Passes/StandardInstrumentations.cpp
Index: llvm/lib/Passes/StandardInstrumentations.cpp
===================================================================
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ 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<const MachineFunction *>(IR)) {
+ const MachineFunction *MF = any_cast<const MachineFunction *>(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<const LazyCallGraph::SCC *>(IR)) {
const LazyCallGraph::SCC *C = any_cast<const LazyCallGraph::SCC *>(IR);
for (const LazyCallGraph::Node &N : *C) {
@@ -109,6 +120,13 @@
llvm::printLoop(const_cast<Loop &>(*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<const MachineFunction *>(IR)) {
+ const MachineFunction *MF = any_cast<const MachineFunction *>(IR);
+ assert(MF && "machine function should be valid for printing");
+ printIR(MF, Banner);
+ return;
+ }
+
llvm_unreachable("Unknown wrapped IR type");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83609.277202.patch
Type: text/x-patch
Size: 2057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200711/94ffde28/attachment.bin>
More information about the llvm-commits
mailing list