[PATCH] D83607: [NewPM][CodeGen] Port MIRPrinter to NewPM
Yuanfang Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 10 19:17:11 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/D83607
Files:
llvm/include/llvm/CodeGen/MIRPrinter.h
llvm/lib/CodeGen/MIRPrintingPass.cpp
Index: llvm/lib/CodeGen/MIRPrintingPass.cpp
===================================================================
--- llvm/lib/CodeGen/MIRPrintingPass.cpp
+++ llvm/lib/CodeGen/MIRPrintingPass.cpp
@@ -16,10 +16,29 @@
#include "llvm/CodeGen/Passes.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
+PreservedAnalyses PrintMIRPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &) {
+ std::string Str;
+ raw_string_ostream StrOS(Str);
+ printMIR(StrOS, MF);
+ MachineFunctions.append(StrOS.str());
+ return PreservedAnalyses::all();
+}
+
+Error PrintMIRPass::doFinalization(Module &M,
+ MachineFunctionAnalysisManager &) {
+ printMIR(OS, M);
+ OS << MachineFunctions;
+ return Error::success();
+}
+
+AnalysisKey PrintMIRPass::Key;
+
namespace {
/// This pass prints out the LLVM IR to an output stream using the MIR
Index: llvm/include/llvm/CodeGen/MIRPrinter.h
===================================================================
--- llvm/include/llvm/CodeGen/MIRPrinter.h
+++ llvm/include/llvm/CodeGen/MIRPrinter.h
@@ -14,6 +14,8 @@
#ifndef LLVM_LIB_CODEGEN_MIRPRINTER_H
#define LLVM_LIB_CODEGEN_MIRPRINTER_H
+#include "llvm/CodeGen/MachinePassManager.h"
+
namespace llvm {
class MachineBasicBlock;
@@ -22,6 +24,20 @@
class raw_ostream;
template <typename T> class SmallVectorImpl;
+class PrintMIRPass : public PassInfoMixin<PrintMIRPass> {
+ raw_ostream &OS;
+ std::string MachineFunctions;
+
+public:
+ PrintMIRPass() : OS(dbgs()) {}
+ PrintMIRPass(raw_ostream &OS) : OS(OS) {}
+
+ PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &);
+ Error doFinalization(Module &M, MachineFunctionAnalysisManager &);
+
+ static AnalysisKey Key;
+};
+
/// Print LLVM IR using the MIR serialization format to the given output stream.
void printMIR(raw_ostream &OS, const Module &M);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83607.277198.patch
Type: text/x-patch
Size: 2030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200711/2d47e4f2/attachment.bin>
More information about the llvm-commits
mailing list