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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240295 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz
2015-06-22 17:02:30 +00:00
parent 39befc6ca8
commit 2f801faafb
9 changed files with 236 additions and 4 deletions

View File

@@ -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) {