summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MIRPrinter.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-06-22 17:02:30 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-06-22 17:02:30 +0000
commit8e0a1b4857faf0ea9504ec254020dc22cd4f6cc1 (patch)
tree8f7b6b2153ae6936a7a9e32282fda87e95c5a5fe /llvm/lib/CodeGen/MIRPrinter.cpp
parent7f09a98ab138886454dfdf123a9fe9811ac20fb3 (diff)
downloadbcm5719-llvm-8e0a1b4857faf0ea9504ec254020dc22cd4f6cc1.tar.gz
bcm5719-llvm-8e0a1b4857faf0ea9504ec254020dc22cd4f6cc1.zip
MIR Serialization: Serialize machine instruction names.
This commit implements initial machine instruction serialization. It serializes machine instruction names. The instructions are represented using a YAML sequence of string literals and are a part of machine basic block YAML mapping. This commit introduces a class called 'MIParser' which will be used to parse the machine instructions and operands. Reviewers: Duncan P. N. Exon Smith Differential Revision: http://reviews.llvm.org/D10481 llvm-svn: 240295
Diffstat (limited to 'llvm/lib/CodeGen/MIRPrinter.cpp')
-rw-r--r--llvm/lib/CodeGen/MIRPrinter.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index bbf163a759e..7aa1b69a78b 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -21,6 +21,8 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
using namespace llvm;
@@ -39,6 +41,17 @@ public:
void convert(yaml::MachineBasicBlock &YamlMBB, const MachineBasicBlock &MBB);
};
+/// This class prints out the machine instructions using the MIR serialization
+/// format.
+class MIPrinter {
+ raw_ostream &OS;
+
+public:
+ MIPrinter(raw_ostream &OS) : OS(OS) {}
+
+ void print(const MachineInstr &MI);
+};
+
} // end anonymous namespace
namespace llvm {
@@ -83,6 +96,25 @@ void MIRPrinter::convert(yaml::MachineBasicBlock &YamlMBB,
YamlMBB.Alignment = MBB.getAlignment();
YamlMBB.AddressTaken = MBB.hasAddressTaken();
YamlMBB.IsLandingPad = MBB.isLandingPad();
+
+ // Print the machine instructions.
+ YamlMBB.Instructions.reserve(MBB.size());
+ std::string Str;
+ for (const auto &MI : MBB) {
+ raw_string_ostream StrOS(Str);
+ MIPrinter(StrOS).print(MI);
+ YamlMBB.Instructions.push_back(StrOS.str());
+ Str.clear();
+ }
+}
+
+void MIPrinter::print(const MachineInstr &MI) {
+ const auto &SubTarget = MI.getParent()->getParent()->getSubtarget();
+ const auto *TII = SubTarget.getInstrInfo();
+ assert(TII && "Expected target instruction info");
+
+ OS << TII->getName(MI.getOpcode());
+ // TODO: Print the instruction flags, machine operands, machine mem operands.
}
void llvm::printMIR(raw_ostream &OS, const Module &M) {
OpenPOWER on IntegriCloud