summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MIRPrintingPass.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-05-28 22:41:12 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-05-28 22:41:12 +0000
commit78d7831b0fa2bd7c20c94ba90968923b938c6112 (patch)
treead43e8371f2fed24837dbb391caf3a6df79d9dec /llvm/lib/CodeGen/MIRPrintingPass.cpp
parent75afbfd4a14a31772528918f9d284793e775272a (diff)
downloadbcm5719-llvm-78d7831b0fa2bd7c20c94ba90968923b938c6112.tar.gz
bcm5719-llvm-78d7831b0fa2bd7c20c94ba90968923b938c6112.zip
MIR Serialization: print and parse machine function names.
This commit introduces a serializable structure called 'llvm::yaml::MachineFunction' that stores the machine function's name. This structure will mirror the machine function's state in the future. This commit prints machine functions as YAML documents containing a YAML mapping that stores the state of a machine function. This commit also parses the YAML documents that contain the machine functions. Reviewers: Duncan P. N. Exon Smith Differential Revision: http://reviews.llvm.org/D9841 llvm-svn: 238519
Diffstat (limited to 'llvm/lib/CodeGen/MIRPrintingPass.cpp')
-rw-r--r--llvm/lib/CodeGen/MIRPrintingPass.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/MIRPrintingPass.cpp b/llvm/lib/CodeGen/MIRPrintingPass.cpp
index c66658cc977..5e0f4cdcbfd 100644
--- a/llvm/lib/CodeGen/MIRPrintingPass.cpp
+++ b/llvm/lib/CodeGen/MIRPrintingPass.cpp
@@ -15,6 +15,7 @@
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MIRYamlMapping.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -41,11 +42,30 @@ template <> struct BlockScalarTraits<Module> {
namespace {
+/// This class prints out the machine functions using the MIR serialization
+/// format.
+class MIRPrinter {
+ raw_ostream &OS;
+
+public:
+ MIRPrinter(raw_ostream &OS) : OS(OS) {}
+
+ void print(const MachineFunction &MF);
+};
+
+void MIRPrinter::print(const MachineFunction &MF) {
+ yaml::MachineFunction YamlMF;
+ YamlMF.Name = MF.getName();
+ yaml::Output Out(OS);
+ Out << YamlMF;
+}
+
/// This pass prints out the LLVM IR to an output stream using the MIR
/// serialization format.
struct MIRPrintingPass : public MachineFunctionPass {
static char ID;
raw_ostream &OS;
+ std::string MachineFunctions;
MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}
MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}
@@ -58,13 +78,17 @@ struct MIRPrintingPass : public MachineFunctionPass {
}
virtual bool runOnMachineFunction(MachineFunction &MF) override {
- // TODO: Print out the machine function.
+ std::string Str;
+ raw_string_ostream StrOS(Str);
+ MIRPrinter(StrOS).print(MF);
+ MachineFunctions.append(StrOS.str());
return false;
}
virtual bool doFinalization(Module &M) override {
yaml::Output Out(OS);
Out << M;
+ OS << MachineFunctions;
return false;
}
};
OpenPOWER on IntegriCloud