MIR Serialization: Initial serialization of machine constant pools.

This commit implements the initial serialization of machine constant pools and
the constant pool index machine operands. The constant pool is serialized using
a YAML sequence of YAML mappings that represent the constant values.
The target-specific constant pool items aren't serialized by this commit.

Reviewers: Duncan P. N. Exon Smith


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242707 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz
2015-07-20 20:51:18 +00:00
parent ca221d01d0
commit 0e4484f44d
10 changed files with 278 additions and 1 deletions

View File

@@ -20,6 +20,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/AsmParser/Parser.h"
#include "llvm/AsmParser/SlotMapping.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
@@ -113,6 +114,11 @@ public:
DenseMap<unsigned, int> &StackObjectSlots,
DenseMap<unsigned, int> &FixedStackObjectSlots);
bool initializeConstantPool(MachineConstantPool &ConstantPool,
const yaml::MachineFunction &YamlMF,
const MachineFunction &MF,
DenseMap<unsigned, unsigned> &ConstantPoolSlots);
bool initializeJumpTableInfo(MachineFunction &MF,
const yaml::MachineJumpTable &YamlJTI,
PerFunctionMIParsingState &PFS);
@@ -273,6 +279,13 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) {
if (initializeFrameInfo(*MF.getFunction(), *MF.getFrameInfo(), YamlMF,
PFS.StackObjectSlots, PFS.FixedStackObjectSlots))
return true;
if (!YamlMF.Constants.empty()) {
auto *ConstantPool = MF.getConstantPool();
assert(ConstantPool && "Constant pool must be created");
if (initializeConstantPool(*ConstantPool, YamlMF, MF,
PFS.ConstantPoolSlots))
return true;
}
const auto &F = *MF.getFunction();
for (const auto &YamlMBB : YamlMF.BasicBlocks) {
@@ -439,6 +452,28 @@ bool MIRParserImpl::initializeFrameInfo(
return false;
}
bool MIRParserImpl::initializeConstantPool(
MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF,
const MachineFunction &MF,
DenseMap<unsigned, unsigned> &ConstantPoolSlots) {
const auto &M = *MF.getFunction()->getParent();
SMDiagnostic Error;
for (const auto &YamlConstant : YamlMF.Constants) {
const Constant *Value = dyn_cast_or_null<Constant>(
parseConstantValue(YamlConstant.Value.Value, Error, M));
if (!Value)
return error(Error, YamlConstant.Value.SourceRange);
unsigned Alignment =
YamlConstant.Alignment
? YamlConstant.Alignment
: M.getDataLayout().getPrefTypeAlignment(Value->getType());
// TODO: Report an error when the same constant pool value ID is redefined.
ConstantPoolSlots.insert(std::make_pair(
YamlConstant.ID, ConstantPool.getConstantPoolIndex(Value, Alignment)));
}
return false;
}
bool MIRParserImpl::initializeJumpTableInfo(
MachineFunction &MF, const yaml::MachineJumpTable &YamlJTI,
PerFunctionMIParsingState &PFS) {