2015-06-16 07:52:35 +08:00
|
|
|
//===- MIRPrinter.cpp - MIR serialization format printer ------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the class that prints out the LLVM IR and machine
|
|
|
|
// functions using the MIR serialization format.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MIRPrinter.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2015-07-21 04:51:18 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2015-06-16 07:52:35 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
MIR Serialization: Serialize the simple MachineFrameInfo attributes.
This commit serializes the 13 scalar boolean and integer attributes from the
MachineFrameInfo class: IsFrameAddressTaken, IsReturnAddressTaken, HasStackMap,
HasPatchPoint, StackSize, OffsetAdjustment, MaxAlignment, AdjustsStack,
HasCalls, MaxCallFrameSize, HasOpaqueSPAdjustment, HasVAStart, and
HasMustTailInVarArgFunc. These attributes are serialized as part
of the frameInfo YAML mapping, which itself is a part of the machine function's
YAML mapping.
llvm-svn: 241844
2015-07-10 03:55:27 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2015-08-04 07:08:19 +08:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2015-07-22 06:28:27 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2015-06-25 03:56:10 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2015-06-16 07:52:35 +08:00
|
|
|
#include "llvm/CodeGen/MIRYamlMapping.h"
|
2015-06-20 01:43:07 +08:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
2015-07-29 01:28:03 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2015-07-16 06:14:49 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2015-07-22 00:59:53 +08:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2015-06-16 07:52:35 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2015-07-08 07:27:53 +08:00
|
|
|
#include "llvm/IR/ModuleSlotTracker.h"
|
2015-08-22 05:12:44 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2015-06-16 07:52:35 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
2015-06-23 01:02:30 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2015-06-16 07:52:35 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-07-17 07:37:45 +08:00
|
|
|
/// This structure describes how to print out stack object references.
|
|
|
|
struct FrameIndexOperand {
|
|
|
|
std::string Name;
|
|
|
|
unsigned ID;
|
|
|
|
bool IsFixed;
|
|
|
|
|
|
|
|
FrameIndexOperand(StringRef Name, unsigned ID, bool IsFixed)
|
|
|
|
: Name(Name.str()), ID(ID), IsFixed(IsFixed) {}
|
|
|
|
|
|
|
|
/// Return an ordinary stack object reference.
|
|
|
|
static FrameIndexOperand create(StringRef Name, unsigned ID) {
|
|
|
|
return FrameIndexOperand(Name, ID, /*IsFixed=*/false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return a fixed stack object reference.
|
|
|
|
static FrameIndexOperand createFixed(unsigned ID) {
|
|
|
|
return FrameIndexOperand("", ID, /*IsFixed=*/true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-31 00:54:38 +08:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-06-16 07:52:35 +08:00
|
|
|
/// This class prints out the machine functions using the MIR serialization
|
|
|
|
/// format.
|
|
|
|
class MIRPrinter {
|
|
|
|
raw_ostream &OS;
|
2015-06-30 00:57:06 +08:00
|
|
|
DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
|
2015-07-17 07:37:45 +08:00
|
|
|
/// Maps from stack object indices to operand indices which will be used when
|
|
|
|
/// printing frame index machine operands.
|
|
|
|
DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;
|
2015-06-16 07:52:35 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
MIRPrinter(raw_ostream &OS) : OS(OS) {}
|
|
|
|
|
|
|
|
void print(const MachineFunction &MF);
|
2015-06-20 01:43:07 +08:00
|
|
|
|
2015-07-10 06:23:13 +08:00
|
|
|
void convert(yaml::MachineFunction &MF, const MachineRegisterInfo &RegInfo,
|
|
|
|
const TargetRegisterInfo *TRI);
|
2015-07-30 05:09:09 +08:00
|
|
|
void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
|
|
|
|
const MachineFrameInfo &MFI);
|
2015-07-21 04:51:18 +08:00
|
|
|
void convert(yaml::MachineFunction &MF,
|
|
|
|
const MachineConstantPool &ConstantPool);
|
2015-07-16 07:31:07 +08:00
|
|
|
void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
|
|
|
|
const MachineJumpTableInfo &JTI);
|
2015-07-11 02:13:57 +08:00
|
|
|
void convertStackObjects(yaml::MachineFunction &MF,
|
2015-08-19 08:13:25 +08:00
|
|
|
const MachineFrameInfo &MFI, MachineModuleInfo &MMI,
|
|
|
|
ModuleSlotTracker &MST,
|
2015-07-25 06:22:50 +08:00
|
|
|
const TargetRegisterInfo *TRI);
|
2015-06-30 00:57:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void initRegisterMaskIds(const MachineFunction &MF);
|
2015-06-16 07:52:35 +08:00
|
|
|
};
|
|
|
|
|
2015-06-23 01:02:30 +08:00
|
|
|
/// This class prints out the machine instructions using the MIR serialization
|
|
|
|
/// format.
|
|
|
|
class MIPrinter {
|
|
|
|
raw_ostream &OS;
|
2015-07-08 07:27:53 +08:00
|
|
|
ModuleSlotTracker &MST;
|
2015-06-30 00:57:06 +08:00
|
|
|
const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds;
|
2015-07-17 07:37:45 +08:00
|
|
|
const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping;
|
2015-06-23 01:02:30 +08:00
|
|
|
|
|
|
|
public:
|
2015-07-08 07:27:53 +08:00
|
|
|
MIPrinter(raw_ostream &OS, ModuleSlotTracker &MST,
|
2015-07-17 07:37:45 +08:00
|
|
|
const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds,
|
|
|
|
const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping)
|
|
|
|
: OS(OS), MST(MST), RegisterMaskIds(RegisterMaskIds),
|
|
|
|
StackObjectOperandMapping(StackObjectOperandMapping) {}
|
2015-06-23 01:02:30 +08:00
|
|
|
|
2015-08-14 07:10:16 +08:00
|
|
|
void print(const MachineBasicBlock &MBB);
|
|
|
|
|
2015-06-23 01:02:30 +08:00
|
|
|
void print(const MachineInstr &MI);
|
2015-07-01 02:00:16 +08:00
|
|
|
void printMBBReference(const MachineBasicBlock &MBB);
|
2015-07-29 01:28:03 +08:00
|
|
|
void printIRBlockReference(const BasicBlock &BB);
|
2015-08-04 07:08:19 +08:00
|
|
|
void printIRValueReference(const Value &V);
|
2015-07-17 07:37:45 +08:00
|
|
|
void printStackObjectReference(int FrameIndex);
|
2015-08-06 06:26:15 +08:00
|
|
|
void printOffset(int64_t Offset);
|
2015-08-06 08:44:07 +08:00
|
|
|
void printTargetFlags(const MachineOperand &Op);
|
2015-08-20 02:55:47 +08:00
|
|
|
void print(const MachineOperand &Op, const TargetRegisterInfo *TRI,
|
2015-08-20 03:05:34 +08:00
|
|
|
unsigned I, bool ShouldPrintRegisterTies, bool IsDef = false);
|
2015-08-04 07:08:19 +08:00
|
|
|
void print(const MachineMemOperand &Op);
|
2015-07-22 06:28:27 +08:00
|
|
|
|
2015-07-24 07:09:07 +08:00
|
|
|
void print(const MCCFIInstruction &CFI, const TargetRegisterInfo *TRI);
|
2015-06-23 01:02:30 +08:00
|
|
|
};
|
|
|
|
|
2015-08-14 07:10:16 +08:00
|
|
|
} // end namespace llvm
|
2015-06-16 07:52:35 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace yaml {
|
|
|
|
|
|
|
|
/// This struct serializes the LLVM IR module.
|
|
|
|
template <> struct BlockScalarTraits<Module> {
|
|
|
|
static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
|
|
|
|
Mod.print(OS, nullptr);
|
|
|
|
}
|
|
|
|
static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
|
|
|
|
llvm_unreachable("LLVM Module is supposed to be parsed separately");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace yaml
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2015-07-15 05:18:25 +08:00
|
|
|
static void printReg(unsigned Reg, raw_ostream &OS,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
// TODO: Print Stack Slots.
|
|
|
|
if (!Reg)
|
|
|
|
OS << '_';
|
|
|
|
else if (TargetRegisterInfo::isVirtualRegister(Reg))
|
|
|
|
OS << '%' << TargetRegisterInfo::virtReg2Index(Reg);
|
|
|
|
else if (Reg < TRI->getNumRegs())
|
|
|
|
OS << '%' << StringRef(TRI->getName(Reg)).lower();
|
|
|
|
else
|
|
|
|
llvm_unreachable("Can't print this kind of register yet");
|
|
|
|
}
|
|
|
|
|
2015-07-25 04:35:40 +08:00
|
|
|
static void printReg(unsigned Reg, yaml::StringValue &Dest,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
raw_string_ostream OS(Dest.Value);
|
|
|
|
printReg(Reg, OS, TRI);
|
|
|
|
}
|
|
|
|
|
2015-06-16 07:52:35 +08:00
|
|
|
void MIRPrinter::print(const MachineFunction &MF) {
|
2015-06-30 00:57:06 +08:00
|
|
|
initRegisterMaskIds(MF);
|
|
|
|
|
2015-06-16 07:52:35 +08:00
|
|
|
yaml::MachineFunction YamlMF;
|
|
|
|
YamlMF.Name = MF.getName();
|
2015-06-16 08:10:47 +08:00
|
|
|
YamlMF.Alignment = MF.getAlignment();
|
|
|
|
YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice();
|
|
|
|
YamlMF.HasInlineAsm = MF.hasInlineAsm();
|
2015-07-10 06:23:13 +08:00
|
|
|
convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
|
2015-07-30 05:09:09 +08:00
|
|
|
ModuleSlotTracker MST(MF.getFunction()->getParent());
|
|
|
|
MST.incorporateFunction(*MF.getFunction());
|
|
|
|
convert(MST, YamlMF.FrameInfo, *MF.getFrameInfo());
|
2015-08-19 08:13:25 +08:00
|
|
|
convertStackObjects(YamlMF, *MF.getFrameInfo(), MF.getMMI(), MST,
|
2015-07-25 06:22:50 +08:00
|
|
|
MF.getSubtarget().getRegisterInfo());
|
2015-07-21 04:51:18 +08:00
|
|
|
if (const auto *ConstantPool = MF.getConstantPool())
|
|
|
|
convert(YamlMF, *ConstantPool);
|
2015-07-16 07:31:07 +08:00
|
|
|
if (const auto *JumpTableInfo = MF.getJumpTableInfo())
|
|
|
|
convert(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
|
2015-08-14 07:10:16 +08:00
|
|
|
raw_string_ostream StrOS(YamlMF.Body.Value.Value);
|
|
|
|
bool IsNewlineNeeded = false;
|
2015-06-20 01:43:07 +08:00
|
|
|
for (const auto &MBB : MF) {
|
2015-08-14 07:10:16 +08:00
|
|
|
if (IsNewlineNeeded)
|
|
|
|
StrOS << "\n";
|
|
|
|
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
|
|
|
|
.print(MBB);
|
|
|
|
IsNewlineNeeded = true;
|
2015-06-20 01:43:07 +08:00
|
|
|
}
|
2015-08-14 07:10:16 +08:00
|
|
|
StrOS.flush();
|
2015-06-16 07:52:35 +08:00
|
|
|
yaml::Output Out(OS);
|
|
|
|
Out << YamlMF;
|
|
|
|
}
|
|
|
|
|
2015-06-25 03:56:10 +08:00
|
|
|
void MIRPrinter::convert(yaml::MachineFunction &MF,
|
2015-07-10 06:23:13 +08:00
|
|
|
const MachineRegisterInfo &RegInfo,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
2015-06-25 03:56:10 +08:00
|
|
|
MF.IsSSA = RegInfo.isSSA();
|
|
|
|
MF.TracksRegLiveness = RegInfo.tracksLiveness();
|
|
|
|
MF.TracksSubRegLiveness = RegInfo.subRegLivenessEnabled();
|
2015-07-10 06:23:13 +08:00
|
|
|
|
|
|
|
// Print the virtual register definitions.
|
|
|
|
for (unsigned I = 0, E = RegInfo.getNumVirtRegs(); I < E; ++I) {
|
|
|
|
unsigned Reg = TargetRegisterInfo::index2VirtReg(I);
|
|
|
|
yaml::VirtualRegisterDefinition VReg;
|
|
|
|
VReg.ID = I;
|
|
|
|
VReg.Class =
|
|
|
|
StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
|
2015-07-25 04:35:40 +08:00
|
|
|
unsigned PreferredReg = RegInfo.getSimpleHint(Reg);
|
|
|
|
if (PreferredReg)
|
|
|
|
printReg(PreferredReg, VReg.PreferredRegister, TRI);
|
2015-07-10 06:23:13 +08:00
|
|
|
MF.VirtualRegisters.push_back(VReg);
|
|
|
|
}
|
2015-07-28 01:42:45 +08:00
|
|
|
|
|
|
|
// Print the live ins.
|
|
|
|
for (auto I = RegInfo.livein_begin(), E = RegInfo.livein_end(); I != E; ++I) {
|
|
|
|
yaml::MachineFunctionLiveIn LiveIn;
|
|
|
|
printReg(I->first, LiveIn.Register, TRI);
|
|
|
|
if (I->second)
|
|
|
|
printReg(I->second, LiveIn.VirtualRegister, TRI);
|
|
|
|
MF.LiveIns.push_back(LiveIn);
|
|
|
|
}
|
2015-08-11 08:32:49 +08:00
|
|
|
// The used physical register mask is printed as an inverted callee saved
|
|
|
|
// register mask.
|
|
|
|
const BitVector &UsedPhysRegMask = RegInfo.getUsedPhysRegsMask();
|
|
|
|
if (UsedPhysRegMask.none())
|
|
|
|
return;
|
|
|
|
std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
|
|
|
|
for (unsigned I = 0, E = UsedPhysRegMask.size(); I != E; ++I) {
|
|
|
|
if (!UsedPhysRegMask[I]) {
|
|
|
|
yaml::FlowStringValue Reg;
|
|
|
|
printReg(I, Reg, TRI);
|
|
|
|
CalleeSavedRegisters.push_back(Reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MF.CalleeSavedRegisters = CalleeSavedRegisters;
|
2015-06-25 03:56:10 +08:00
|
|
|
}
|
|
|
|
|
2015-07-30 05:09:09 +08:00
|
|
|
void MIRPrinter::convert(ModuleSlotTracker &MST,
|
|
|
|
yaml::MachineFrameInfo &YamlMFI,
|
MIR Serialization: Serialize the simple MachineFrameInfo attributes.
This commit serializes the 13 scalar boolean and integer attributes from the
MachineFrameInfo class: IsFrameAddressTaken, IsReturnAddressTaken, HasStackMap,
HasPatchPoint, StackSize, OffsetAdjustment, MaxAlignment, AdjustsStack,
HasCalls, MaxCallFrameSize, HasOpaqueSPAdjustment, HasVAStart, and
HasMustTailInVarArgFunc. These attributes are serialized as part
of the frameInfo YAML mapping, which itself is a part of the machine function's
YAML mapping.
llvm-svn: 241844
2015-07-10 03:55:27 +08:00
|
|
|
const MachineFrameInfo &MFI) {
|
|
|
|
YamlMFI.IsFrameAddressTaken = MFI.isFrameAddressTaken();
|
|
|
|
YamlMFI.IsReturnAddressTaken = MFI.isReturnAddressTaken();
|
|
|
|
YamlMFI.HasStackMap = MFI.hasStackMap();
|
|
|
|
YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
|
|
|
|
YamlMFI.StackSize = MFI.getStackSize();
|
|
|
|
YamlMFI.OffsetAdjustment = MFI.getOffsetAdjustment();
|
|
|
|
YamlMFI.MaxAlignment = MFI.getMaxAlignment();
|
|
|
|
YamlMFI.AdjustsStack = MFI.adjustsStack();
|
|
|
|
YamlMFI.HasCalls = MFI.hasCalls();
|
|
|
|
YamlMFI.MaxCallFrameSize = MFI.getMaxCallFrameSize();
|
|
|
|
YamlMFI.HasOpaqueSPAdjustment = MFI.hasOpaqueSPAdjustment();
|
|
|
|
YamlMFI.HasVAStart = MFI.hasVAStart();
|
|
|
|
YamlMFI.HasMustTailInVarArgFunc = MFI.hasMustTailInVarArgFunc();
|
2015-07-30 05:09:09 +08:00
|
|
|
if (MFI.getSavePoint()) {
|
|
|
|
raw_string_ostream StrOS(YamlMFI.SavePoint.Value);
|
|
|
|
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
|
|
|
|
.printMBBReference(*MFI.getSavePoint());
|
|
|
|
}
|
|
|
|
if (MFI.getRestorePoint()) {
|
|
|
|
raw_string_ostream StrOS(YamlMFI.RestorePoint.Value);
|
|
|
|
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
|
|
|
|
.printMBBReference(*MFI.getRestorePoint());
|
|
|
|
}
|
MIR Serialization: Serialize the simple MachineFrameInfo attributes.
This commit serializes the 13 scalar boolean and integer attributes from the
MachineFrameInfo class: IsFrameAddressTaken, IsReturnAddressTaken, HasStackMap,
HasPatchPoint, StackSize, OffsetAdjustment, MaxAlignment, AdjustsStack,
HasCalls, MaxCallFrameSize, HasOpaqueSPAdjustment, HasVAStart, and
HasMustTailInVarArgFunc. These attributes are serialized as part
of the frameInfo YAML mapping, which itself is a part of the machine function's
YAML mapping.
llvm-svn: 241844
2015-07-10 03:55:27 +08:00
|
|
|
}
|
|
|
|
|
2015-07-11 02:13:57 +08:00
|
|
|
void MIRPrinter::convertStackObjects(yaml::MachineFunction &MF,
|
2015-07-25 06:22:50 +08:00
|
|
|
const MachineFrameInfo &MFI,
|
2015-08-19 08:13:25 +08:00
|
|
|
MachineModuleInfo &MMI,
|
2015-08-19 06:26:26 +08:00
|
|
|
ModuleSlotTracker &MST,
|
2015-07-25 06:22:50 +08:00
|
|
|
const TargetRegisterInfo *TRI) {
|
2015-07-14 02:07:26 +08:00
|
|
|
// Process fixed stack objects.
|
2015-07-11 02:13:57 +08:00
|
|
|
unsigned ID = 0;
|
2015-07-14 02:07:26 +08:00
|
|
|
for (int I = MFI.getObjectIndexBegin(); I < 0; ++I) {
|
|
|
|
if (MFI.isDeadObjectIndex(I))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
yaml::FixedMachineStackObject YamlObject;
|
2015-07-17 07:37:45 +08:00
|
|
|
YamlObject.ID = ID;
|
2015-07-14 02:07:26 +08:00
|
|
|
YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
|
|
|
|
? yaml::FixedMachineStackObject::SpillSlot
|
|
|
|
: yaml::FixedMachineStackObject::DefaultType;
|
|
|
|
YamlObject.Offset = MFI.getObjectOffset(I);
|
|
|
|
YamlObject.Size = MFI.getObjectSize(I);
|
|
|
|
YamlObject.Alignment = MFI.getObjectAlignment(I);
|
|
|
|
YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
|
|
|
|
YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
|
|
|
|
MF.FixedStackObjects.push_back(YamlObject);
|
2015-07-17 07:37:45 +08:00
|
|
|
StackObjectOperandMapping.insert(
|
|
|
|
std::make_pair(I, FrameIndexOperand::createFixed(ID++)));
|
2015-07-14 02:07:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process ordinary stack objects.
|
|
|
|
ID = 0;
|
2015-07-11 02:13:57 +08:00
|
|
|
for (int I = 0, E = MFI.getObjectIndexEnd(); I < E; ++I) {
|
|
|
|
if (MFI.isDeadObjectIndex(I))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
yaml::MachineStackObject YamlObject;
|
2015-07-17 07:37:45 +08:00
|
|
|
YamlObject.ID = ID;
|
2015-07-16 06:14:49 +08:00
|
|
|
if (const auto *Alloca = MFI.getObjectAllocation(I))
|
|
|
|
YamlObject.Name.Value =
|
|
|
|
Alloca->hasName() ? Alloca->getName() : "<unnamed alloca>";
|
2015-07-11 02:13:57 +08:00
|
|
|
YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
|
|
|
|
? yaml::MachineStackObject::SpillSlot
|
2015-07-14 08:26:26 +08:00
|
|
|
: MFI.isVariableSizedObjectIndex(I)
|
|
|
|
? yaml::MachineStackObject::VariableSized
|
|
|
|
: yaml::MachineStackObject::DefaultType;
|
2015-07-11 02:13:57 +08:00
|
|
|
YamlObject.Offset = MFI.getObjectOffset(I);
|
|
|
|
YamlObject.Size = MFI.getObjectSize(I);
|
|
|
|
YamlObject.Alignment = MFI.getObjectAlignment(I);
|
|
|
|
|
|
|
|
MF.StackObjects.push_back(YamlObject);
|
2015-07-17 07:37:45 +08:00
|
|
|
StackObjectOperandMapping.insert(std::make_pair(
|
|
|
|
I, FrameIndexOperand::create(YamlObject.Name.Value, ID++)));
|
2015-07-11 02:13:57 +08:00
|
|
|
}
|
2015-07-25 06:22:50 +08:00
|
|
|
|
|
|
|
for (const auto &CSInfo : MFI.getCalleeSavedInfo()) {
|
|
|
|
yaml::StringValue Reg;
|
|
|
|
printReg(CSInfo.getReg(), Reg, TRI);
|
|
|
|
auto StackObjectInfo = StackObjectOperandMapping.find(CSInfo.getFrameIdx());
|
|
|
|
assert(StackObjectInfo != StackObjectOperandMapping.end() &&
|
|
|
|
"Invalid stack object index");
|
|
|
|
const FrameIndexOperand &StackObject = StackObjectInfo->second;
|
|
|
|
if (StackObject.IsFixed)
|
|
|
|
MF.FixedStackObjects[StackObject.ID].CalleeSavedRegister = Reg;
|
|
|
|
else
|
|
|
|
MF.StackObjects[StackObject.ID].CalleeSavedRegister = Reg;
|
|
|
|
}
|
2015-08-18 06:17:42 +08:00
|
|
|
for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) {
|
|
|
|
auto LocalObject = MFI.getLocalFrameObjectMap(I);
|
|
|
|
auto StackObjectInfo = StackObjectOperandMapping.find(LocalObject.first);
|
|
|
|
assert(StackObjectInfo != StackObjectOperandMapping.end() &&
|
|
|
|
"Invalid stack object index");
|
|
|
|
const FrameIndexOperand &StackObject = StackObjectInfo->second;
|
|
|
|
assert(!StackObject.IsFixed && "Expected a locally mapped stack object");
|
|
|
|
MF.StackObjects[StackObject.ID].LocalOffset = LocalObject.second;
|
|
|
|
}
|
2015-08-19 06:26:26 +08:00
|
|
|
|
|
|
|
// Print the stack object references in the frame information class after
|
|
|
|
// converting the stack objects.
|
|
|
|
if (MFI.hasStackProtectorIndex()) {
|
|
|
|
raw_string_ostream StrOS(MF.FrameInfo.StackProtector.Value);
|
|
|
|
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
|
|
|
|
.printStackObjectReference(MFI.getStackProtectorIndex());
|
|
|
|
}
|
2015-08-19 08:13:25 +08:00
|
|
|
|
|
|
|
// Print the debug variable information.
|
|
|
|
for (MachineModuleInfo::VariableDbgInfo &DebugVar :
|
|
|
|
MMI.getVariableDbgInfo()) {
|
|
|
|
auto StackObjectInfo = StackObjectOperandMapping.find(DebugVar.Slot);
|
|
|
|
assert(StackObjectInfo != StackObjectOperandMapping.end() &&
|
|
|
|
"Invalid stack object index");
|
|
|
|
const FrameIndexOperand &StackObject = StackObjectInfo->second;
|
|
|
|
assert(!StackObject.IsFixed && "Expected a non-fixed stack object");
|
|
|
|
auto &Object = MF.StackObjects[StackObject.ID];
|
|
|
|
{
|
|
|
|
raw_string_ostream StrOS(Object.DebugVar.Value);
|
|
|
|
DebugVar.Var->printAsOperand(StrOS, MST);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
raw_string_ostream StrOS(Object.DebugExpr.Value);
|
|
|
|
DebugVar.Expr->printAsOperand(StrOS, MST);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
raw_string_ostream StrOS(Object.DebugLoc.Value);
|
|
|
|
DebugVar.Loc->printAsOperand(StrOS, MST);
|
|
|
|
}
|
|
|
|
}
|
2015-07-11 02:13:57 +08:00
|
|
|
}
|
|
|
|
|
2015-07-21 04:51:18 +08:00
|
|
|
void MIRPrinter::convert(yaml::MachineFunction &MF,
|
|
|
|
const MachineConstantPool &ConstantPool) {
|
|
|
|
unsigned ID = 0;
|
|
|
|
for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
|
|
|
|
// TODO: Serialize target specific constant pool entries.
|
|
|
|
if (Constant.isMachineConstantPoolEntry())
|
|
|
|
llvm_unreachable("Can't print target specific constant pool entries yet");
|
|
|
|
|
|
|
|
yaml::MachineConstantPoolValue YamlConstant;
|
|
|
|
std::string Str;
|
|
|
|
raw_string_ostream StrOS(Str);
|
|
|
|
Constant.Val.ConstVal->printAsOperand(StrOS);
|
|
|
|
YamlConstant.ID = ID++;
|
|
|
|
YamlConstant.Value = StrOS.str();
|
|
|
|
YamlConstant.Alignment = Constant.getAlignment();
|
|
|
|
MF.Constants.push_back(YamlConstant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 07:31:07 +08:00
|
|
|
void MIRPrinter::convert(ModuleSlotTracker &MST,
|
|
|
|
yaml::MachineJumpTable &YamlJTI,
|
|
|
|
const MachineJumpTableInfo &JTI) {
|
|
|
|
YamlJTI.Kind = JTI.getEntryKind();
|
|
|
|
unsigned ID = 0;
|
|
|
|
for (const auto &Table : JTI.getJumpTables()) {
|
|
|
|
std::string Str;
|
|
|
|
yaml::MachineJumpTable::Entry Entry;
|
|
|
|
Entry.ID = ID++;
|
|
|
|
for (const auto *MBB : Table.MBBs) {
|
|
|
|
raw_string_ostream StrOS(Str);
|
2015-07-17 07:37:45 +08:00
|
|
|
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
|
|
|
|
.printMBBReference(*MBB);
|
2015-07-16 07:31:07 +08:00
|
|
|
Entry.Blocks.push_back(StrOS.str());
|
|
|
|
Str.clear();
|
|
|
|
}
|
|
|
|
YamlJTI.Entries.push_back(Entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 07:10:16 +08:00
|
|
|
void MIRPrinter::initRegisterMaskIds(const MachineFunction &MF) {
|
|
|
|
const auto *TRI = MF.getSubtarget().getRegisterInfo();
|
|
|
|
unsigned I = 0;
|
|
|
|
for (const uint32_t *Mask : TRI->getRegMasks())
|
|
|
|
RegisterMaskIds.insert(std::make_pair(Mask, I++));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MIPrinter::print(const MachineBasicBlock &MBB) {
|
2015-06-27 00:46:11 +08:00
|
|
|
assert(MBB.getNumber() >= 0 && "Invalid MBB number");
|
2015-08-14 07:10:16 +08:00
|
|
|
OS << "bb." << MBB.getNumber();
|
|
|
|
bool HasAttributes = false;
|
2015-07-28 06:42:41 +08:00
|
|
|
if (const auto *BB = MBB.getBasicBlock()) {
|
|
|
|
if (BB->hasName()) {
|
2015-08-14 07:10:16 +08:00
|
|
|
OS << "." << BB->getName();
|
2015-07-28 06:42:41 +08:00
|
|
|
} else {
|
2015-08-14 07:10:16 +08:00
|
|
|
HasAttributes = true;
|
|
|
|
OS << " (";
|
2015-07-28 06:42:41 +08:00
|
|
|
int Slot = MST.getLocalSlot(BB);
|
|
|
|
if (Slot == -1)
|
2015-08-14 07:10:16 +08:00
|
|
|
OS << "<ir-block badref>";
|
2015-07-28 06:42:41 +08:00
|
|
|
else
|
2015-08-14 07:10:16 +08:00
|
|
|
OS << (Twine("%ir-block.") + Twine(Slot)).str();
|
2015-07-28 06:42:41 +08:00
|
|
|
}
|
|
|
|
}
|
2015-08-14 07:10:16 +08:00
|
|
|
if (MBB.hasAddressTaken()) {
|
|
|
|
OS << (HasAttributes ? ", " : " (");
|
|
|
|
OS << "address-taken";
|
|
|
|
HasAttributes = true;
|
|
|
|
}
|
|
|
|
if (MBB.isLandingPad()) {
|
|
|
|
OS << (HasAttributes ? ", " : " (");
|
|
|
|
OS << "landing-pad";
|
|
|
|
HasAttributes = true;
|
2015-07-01 02:16:42 +08:00
|
|
|
}
|
2015-08-14 07:10:16 +08:00
|
|
|
if (MBB.getAlignment()) {
|
|
|
|
OS << (HasAttributes ? ", " : " (");
|
|
|
|
OS << "align " << MBB.getAlignment();
|
|
|
|
HasAttributes = true;
|
2015-07-31 00:54:38 +08:00
|
|
|
}
|
2015-08-14 07:10:16 +08:00
|
|
|
if (HasAttributes)
|
|
|
|
OS << ")";
|
|
|
|
OS << ":\n";
|
|
|
|
|
|
|
|
bool HasLineAttributes = false;
|
|
|
|
// Print the successors
|
|
|
|
if (!MBB.succ_empty()) {
|
|
|
|
OS.indent(2) << "successors: ";
|
|
|
|
for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
|
|
|
|
if (I != MBB.succ_begin())
|
|
|
|
OS << ", ";
|
|
|
|
printMBBReference(**I);
|
|
|
|
if (MBB.hasSuccessorWeights())
|
|
|
|
OS << '(' << MBB.getSuccWeight(I) << ')';
|
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
HasLineAttributes = true;
|
|
|
|
}
|
|
|
|
|
2015-07-15 05:24:41 +08:00
|
|
|
// Print the live in registers.
|
|
|
|
const auto *TRI = MBB.getParent()->getSubtarget().getRegisterInfo();
|
|
|
|
assert(TRI && "Expected target register info");
|
2015-08-14 07:10:16 +08:00
|
|
|
if (!MBB.livein_empty()) {
|
|
|
|
OS.indent(2) << "liveins: ";
|
|
|
|
for (auto I = MBB.livein_begin(), E = MBB.livein_end(); I != E; ++I) {
|
|
|
|
if (I != MBB.livein_begin())
|
|
|
|
OS << ", ";
|
|
|
|
printReg(*I, OS, TRI);
|
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
HasLineAttributes = true;
|
2015-07-15 05:24:41 +08:00
|
|
|
}
|
2015-08-14 07:10:16 +08:00
|
|
|
|
|
|
|
if (HasLineAttributes)
|
|
|
|
OS << "\n";
|
2015-08-15 02:57:24 +08:00
|
|
|
bool IsInBundle = false;
|
|
|
|
for (auto I = MBB.instr_begin(), E = MBB.instr_end(); I != E; ++I) {
|
|
|
|
const MachineInstr &MI = *I;
|
|
|
|
if (IsInBundle && !MI.isInsideBundle()) {
|
|
|
|
OS.indent(2) << "}\n";
|
|
|
|
IsInBundle = false;
|
|
|
|
}
|
|
|
|
OS.indent(IsInBundle ? 4 : 2);
|
2015-08-14 07:10:16 +08:00
|
|
|
print(MI);
|
2015-08-15 02:57:24 +08:00
|
|
|
if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
|
|
|
|
OS << " {";
|
|
|
|
IsInBundle = true;
|
|
|
|
}
|
2015-08-14 07:10:16 +08:00
|
|
|
OS << "\n";
|
2015-06-23 01:02:30 +08:00
|
|
|
}
|
2015-08-15 02:57:24 +08:00
|
|
|
if (IsInBundle)
|
|
|
|
OS.indent(2) << "}\n";
|
2015-06-23 01:02:30 +08:00
|
|
|
}
|
|
|
|
|
2015-08-20 03:05:34 +08:00
|
|
|
/// Return true when an instruction has tied register that can't be determined
|
|
|
|
/// by the instruction's descriptor.
|
|
|
|
static bool hasComplexRegisterTies(const MachineInstr &MI) {
|
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
|
|
|
for (unsigned I = 0, E = MI.getNumOperands(); I < E; ++I) {
|
|
|
|
const auto &Operand = MI.getOperand(I);
|
|
|
|
if (!Operand.isReg() || Operand.isDef())
|
|
|
|
// Ignore the defined registers as MCID marks only the uses as tied.
|
|
|
|
continue;
|
|
|
|
int ExpectedTiedIdx = MCID.getOperandConstraint(I, MCOI::TIED_TO);
|
|
|
|
int TiedIdx = Operand.isTied() ? int(MI.findTiedOperandIdx(I)) : -1;
|
|
|
|
if (ExpectedTiedIdx != TiedIdx)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-23 01:02:30 +08:00
|
|
|
void MIPrinter::print(const MachineInstr &MI) {
|
|
|
|
const auto &SubTarget = MI.getParent()->getParent()->getSubtarget();
|
2015-06-24 00:35:26 +08:00
|
|
|
const auto *TRI = SubTarget.getRegisterInfo();
|
|
|
|
assert(TRI && "Expected target register info");
|
2015-06-23 01:02:30 +08:00
|
|
|
const auto *TII = SubTarget.getInstrInfo();
|
|
|
|
assert(TII && "Expected target instruction info");
|
2015-07-22 06:28:27 +08:00
|
|
|
if (MI.isCFIInstruction())
|
|
|
|
assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
|
2015-06-23 01:02:30 +08:00
|
|
|
|
2015-08-20 03:05:34 +08:00
|
|
|
bool ShouldPrintRegisterTies = hasComplexRegisterTies(MI);
|
2015-06-24 00:35:26 +08:00
|
|
|
unsigned I = 0, E = MI.getNumOperands();
|
|
|
|
for (; I < E && MI.getOperand(I).isReg() && MI.getOperand(I).isDef() &&
|
|
|
|
!MI.getOperand(I).isImplicit();
|
|
|
|
++I) {
|
|
|
|
if (I)
|
|
|
|
OS << ", ";
|
2015-08-20 03:05:34 +08:00
|
|
|
print(MI.getOperand(I), TRI, I, ShouldPrintRegisterTies, /*IsDef=*/true);
|
2015-06-24 00:35:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (I)
|
|
|
|
OS << " = ";
|
2015-07-17 08:24:15 +08:00
|
|
|
if (MI.getFlag(MachineInstr::FrameSetup))
|
|
|
|
OS << "frame-setup ";
|
2015-06-23 01:02:30 +08:00
|
|
|
OS << TII->getName(MI.getOpcode());
|
2015-06-24 00:35:26 +08:00
|
|
|
if (I < E)
|
|
|
|
OS << ' ';
|
|
|
|
|
|
|
|
bool NeedComma = false;
|
|
|
|
for (; I < E; ++I) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ", ";
|
2015-08-20 03:05:34 +08:00
|
|
|
print(MI.getOperand(I), TRI, I, ShouldPrintRegisterTies);
|
2015-06-24 00:35:26 +08:00
|
|
|
NeedComma = true;
|
|
|
|
}
|
2015-07-23 05:15:11 +08:00
|
|
|
|
|
|
|
if (MI.getDebugLoc()) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ',';
|
|
|
|
OS << " debug-location ";
|
|
|
|
MI.getDebugLoc()->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-04 07:08:19 +08:00
|
|
|
|
|
|
|
if (!MI.memoperands_empty()) {
|
|
|
|
OS << " :: ";
|
|
|
|
bool NeedComma = false;
|
|
|
|
for (const auto *Op : MI.memoperands()) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ", ";
|
|
|
|
print(*Op);
|
|
|
|
NeedComma = true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 00:35:26 +08:00
|
|
|
}
|
|
|
|
|
2015-07-01 02:00:16 +08:00
|
|
|
void MIPrinter::printMBBReference(const MachineBasicBlock &MBB) {
|
|
|
|
OS << "%bb." << MBB.getNumber();
|
|
|
|
if (const auto *BB = MBB.getBasicBlock()) {
|
|
|
|
if (BB->hasName())
|
|
|
|
OS << '.' << BB->getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-20 07:24:37 +08:00
|
|
|
static void printIRSlotNumber(raw_ostream &OS, int Slot) {
|
|
|
|
if (Slot == -1)
|
|
|
|
OS << "<badref>";
|
|
|
|
else
|
|
|
|
OS << Slot;
|
|
|
|
}
|
|
|
|
|
2015-07-29 01:28:03 +08:00
|
|
|
void MIPrinter::printIRBlockReference(const BasicBlock &BB) {
|
|
|
|
OS << "%ir-block.";
|
|
|
|
if (BB.hasName()) {
|
|
|
|
printLLVMNameWithoutPrefix(OS, BB.getName());
|
|
|
|
return;
|
|
|
|
}
|
2015-08-07 07:57:04 +08:00
|
|
|
const Function *F = BB.getParent();
|
|
|
|
int Slot;
|
|
|
|
if (F == MST.getCurrentFunction()) {
|
|
|
|
Slot = MST.getLocalSlot(&BB);
|
|
|
|
} else {
|
|
|
|
ModuleSlotTracker CustomMST(F->getParent(),
|
|
|
|
/*ShouldInitializeAllMetadata=*/false);
|
|
|
|
CustomMST.incorporateFunction(*F);
|
|
|
|
Slot = CustomMST.getLocalSlot(&BB);
|
|
|
|
}
|
2015-08-20 07:24:37 +08:00
|
|
|
printIRSlotNumber(OS, Slot);
|
2015-07-29 01:28:03 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 07:08:19 +08:00
|
|
|
void MIPrinter::printIRValueReference(const Value &V) {
|
2015-08-20 08:20:03 +08:00
|
|
|
if (isa<GlobalValue>(V)) {
|
|
|
|
V.printAsOperand(OS, /*PrintType=*/false, MST);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-04 07:08:19 +08:00
|
|
|
OS << "%ir.";
|
|
|
|
if (V.hasName()) {
|
|
|
|
printLLVMNameWithoutPrefix(OS, V.getName());
|
|
|
|
return;
|
|
|
|
}
|
2015-08-20 07:56:37 +08:00
|
|
|
if (isa<Constant>(V)) {
|
|
|
|
// Machine memory operands can load/store to/from constant value pointers.
|
|
|
|
// TODO: Serialize the constant values.
|
|
|
|
OS << "<unserializable ir value>";
|
|
|
|
return;
|
|
|
|
}
|
2015-08-20 07:31:05 +08:00
|
|
|
printIRSlotNumber(OS, MST.getLocalSlot(&V));
|
2015-08-04 07:08:19 +08:00
|
|
|
}
|
|
|
|
|
2015-07-17 07:37:45 +08:00
|
|
|
void MIPrinter::printStackObjectReference(int FrameIndex) {
|
|
|
|
auto ObjectInfo = StackObjectOperandMapping.find(FrameIndex);
|
|
|
|
assert(ObjectInfo != StackObjectOperandMapping.end() &&
|
|
|
|
"Invalid frame index");
|
|
|
|
const FrameIndexOperand &Operand = ObjectInfo->second;
|
|
|
|
if (Operand.IsFixed) {
|
|
|
|
OS << "%fixed-stack." << Operand.ID;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OS << "%stack." << Operand.ID;
|
|
|
|
if (!Operand.Name.empty())
|
|
|
|
OS << '.' << Operand.Name;
|
|
|
|
}
|
|
|
|
|
2015-08-06 06:26:15 +08:00
|
|
|
void MIPrinter::printOffset(int64_t Offset) {
|
|
|
|
if (Offset == 0)
|
|
|
|
return;
|
|
|
|
if (Offset < 0) {
|
|
|
|
OS << " - " << -Offset;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OS << " + " << Offset;
|
|
|
|
}
|
|
|
|
|
2015-08-06 08:44:07 +08:00
|
|
|
static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) {
|
|
|
|
auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
|
|
|
|
for (const auto &I : Flags) {
|
|
|
|
if (I.first == TF) {
|
|
|
|
return I.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MIPrinter::printTargetFlags(const MachineOperand &Op) {
|
|
|
|
if (!Op.getTargetFlags())
|
|
|
|
return;
|
|
|
|
const auto *TII =
|
|
|
|
Op.getParent()->getParent()->getParent()->getSubtarget().getInstrInfo();
|
|
|
|
assert(TII && "expected instruction info");
|
|
|
|
auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags());
|
|
|
|
OS << "target-flags(";
|
2015-08-19 06:52:15 +08:00
|
|
|
const bool HasDirectFlags = Flags.first;
|
|
|
|
const bool HasBitmaskFlags = Flags.second;
|
|
|
|
if (!HasDirectFlags && !HasBitmaskFlags) {
|
|
|
|
OS << "<unknown>) ";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (HasDirectFlags) {
|
|
|
|
if (const auto *Name = getTargetFlagName(TII, Flags.first))
|
|
|
|
OS << Name;
|
|
|
|
else
|
|
|
|
OS << "<unknown target flag>";
|
|
|
|
}
|
|
|
|
if (!HasBitmaskFlags) {
|
|
|
|
OS << ") ";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool IsCommaNeeded = HasDirectFlags;
|
|
|
|
unsigned BitMask = Flags.second;
|
|
|
|
auto BitMasks = TII->getSerializableBitmaskMachineOperandTargetFlags();
|
|
|
|
for (const auto &Mask : BitMasks) {
|
|
|
|
// Check if the flag's bitmask has the bits of the current mask set.
|
|
|
|
if ((BitMask & Mask.first) == Mask.first) {
|
|
|
|
if (IsCommaNeeded)
|
|
|
|
OS << ", ";
|
|
|
|
IsCommaNeeded = true;
|
|
|
|
OS << Mask.second;
|
|
|
|
// Clear the bits which were serialized from the flag's bitmask.
|
|
|
|
BitMask &= ~(Mask.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (BitMask) {
|
|
|
|
// When the resulting flag's bitmask isn't zero, we know that we didn't
|
|
|
|
// serialize all of the bit flags.
|
|
|
|
if (IsCommaNeeded)
|
|
|
|
OS << ", ";
|
|
|
|
OS << "<unknown bitmask target flag>";
|
|
|
|
}
|
2015-08-06 08:44:07 +08:00
|
|
|
OS << ") ";
|
|
|
|
}
|
|
|
|
|
2015-07-29 07:02:45 +08:00
|
|
|
static const char *getTargetIndexName(const MachineFunction &MF, int Index) {
|
|
|
|
const auto *TII = MF.getSubtarget().getInstrInfo();
|
|
|
|
assert(TII && "expected instruction info");
|
|
|
|
auto Indices = TII->getSerializableTargetIndices();
|
|
|
|
for (const auto &I : Indices) {
|
|
|
|
if (I.first == Index) {
|
|
|
|
return I.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-08-20 02:55:47 +08:00
|
|
|
void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI,
|
2015-08-20 03:05:34 +08:00
|
|
|
unsigned I, bool ShouldPrintRegisterTies, bool IsDef) {
|
2015-08-06 08:44:07 +08:00
|
|
|
printTargetFlags(Op);
|
2015-06-24 00:35:26 +08:00
|
|
|
switch (Op.getType()) {
|
|
|
|
case MachineOperand::MO_Register:
|
2015-07-07 07:07:26 +08:00
|
|
|
if (Op.isImplicit())
|
|
|
|
OS << (Op.isDef() ? "implicit-def " : "implicit ");
|
2015-08-20 02:55:47 +08:00
|
|
|
else if (!IsDef && Op.isDef())
|
|
|
|
// Print the 'def' flag only when the operand is defined after '='.
|
|
|
|
OS << "def ";
|
2015-08-15 03:07:07 +08:00
|
|
|
if (Op.isInternalRead())
|
|
|
|
OS << "internal ";
|
2015-07-08 04:34:53 +08:00
|
|
|
if (Op.isDead())
|
|
|
|
OS << "dead ";
|
2015-07-09 05:23:34 +08:00
|
|
|
if (Op.isKill())
|
|
|
|
OS << "killed ";
|
2015-07-09 07:58:31 +08:00
|
|
|
if (Op.isUndef())
|
|
|
|
OS << "undef ";
|
2015-08-06 01:49:03 +08:00
|
|
|
if (Op.isEarlyClobber())
|
|
|
|
OS << "early-clobber ";
|
2015-08-06 01:41:17 +08:00
|
|
|
if (Op.isDebug())
|
|
|
|
OS << "debug-use ";
|
2015-06-24 00:35:26 +08:00
|
|
|
printReg(Op.getReg(), OS, TRI);
|
2015-07-14 07:24:34 +08:00
|
|
|
// Print the sub register.
|
|
|
|
if (Op.getSubReg() != 0)
|
|
|
|
OS << ':' << TRI->getSubRegIndexName(Op.getSubReg());
|
2015-08-20 03:05:34 +08:00
|
|
|
if (ShouldPrintRegisterTies && Op.isTied() && !Op.isDef())
|
|
|
|
OS << "(tied-def " << Op.getParent()->findTiedOperandIdx(I) << ")";
|
2015-06-24 00:35:26 +08:00
|
|
|
break;
|
2015-06-24 07:42:28 +08:00
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
OS << Op.getImm();
|
|
|
|
break;
|
2015-08-06 02:52:21 +08:00
|
|
|
case MachineOperand::MO_CImmediate:
|
|
|
|
Op.getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
|
|
|
|
break;
|
2015-08-01 04:49:21 +08:00
|
|
|
case MachineOperand::MO_FPImmediate:
|
|
|
|
Op.getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
|
|
|
|
break;
|
2015-06-27 00:46:11 +08:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2015-07-01 02:00:16 +08:00
|
|
|
printMBBReference(*Op.getMBB());
|
2015-06-27 00:46:11 +08:00
|
|
|
break;
|
2015-07-17 07:37:45 +08:00
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
printStackObjectReference(Op.getIndex());
|
|
|
|
break;
|
2015-07-21 04:51:18 +08:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
OS << "%const." << Op.getIndex();
|
2015-08-06 06:26:15 +08:00
|
|
|
printOffset(Op.getOffset());
|
2015-07-21 04:51:18 +08:00
|
|
|
break;
|
2015-07-29 07:02:45 +08:00
|
|
|
case MachineOperand::MO_TargetIndex: {
|
|
|
|
OS << "target-index(";
|
|
|
|
if (const auto *Name = getTargetIndexName(
|
|
|
|
*Op.getParent()->getParent()->getParent(), Op.getIndex()))
|
|
|
|
OS << Name;
|
|
|
|
else
|
|
|
|
OS << "<unknown>";
|
|
|
|
OS << ')';
|
2015-08-06 06:26:15 +08:00
|
|
|
printOffset(Op.getOffset());
|
2015-07-29 07:02:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-07-16 07:38:35 +08:00
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
OS << "%jump-table." << Op.getIndex();
|
|
|
|
break;
|
2015-07-22 00:59:53 +08:00
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
OS << '$';
|
|
|
|
printLLVMNameWithoutPrefix(OS, Op.getSymbolName());
|
2015-08-06 06:26:15 +08:00
|
|
|
printOffset(Op.getOffset());
|
2015-07-22 00:59:53 +08:00
|
|
|
break;
|
2015-06-27 06:56:48 +08:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2015-07-08 07:27:53 +08:00
|
|
|
Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
|
2015-08-06 06:26:15 +08:00
|
|
|
printOffset(Op.getOffset());
|
2015-06-27 06:56:48 +08:00
|
|
|
break;
|
2015-07-29 01:28:03 +08:00
|
|
|
case MachineOperand::MO_BlockAddress:
|
|
|
|
OS << "blockaddress(";
|
|
|
|
Op.getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
|
|
|
|
MST);
|
|
|
|
OS << ", ";
|
|
|
|
printIRBlockReference(*Op.getBlockAddress()->getBasicBlock());
|
|
|
|
OS << ')';
|
2015-08-06 06:26:15 +08:00
|
|
|
printOffset(Op.getOffset());
|
2015-07-29 01:28:03 +08:00
|
|
|
break;
|
2015-06-30 00:57:06 +08:00
|
|
|
case MachineOperand::MO_RegisterMask: {
|
|
|
|
auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
|
|
|
|
if (RegMaskInfo != RegisterMaskIds.end())
|
|
|
|
OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
|
|
|
|
else
|
|
|
|
llvm_unreachable("Can't print this machine register mask yet.");
|
|
|
|
break;
|
|
|
|
}
|
2015-08-11 07:24:42 +08:00
|
|
|
case MachineOperand::MO_RegisterLiveOut: {
|
|
|
|
const uint32_t *RegMask = Op.getRegLiveOut();
|
|
|
|
OS << "liveout(";
|
|
|
|
bool IsCommaNeeded = false;
|
|
|
|
for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
|
|
|
|
if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
|
|
|
|
if (IsCommaNeeded)
|
|
|
|
OS << ", ";
|
|
|
|
printReg(Reg, OS, TRI);
|
|
|
|
IsCommaNeeded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << ")";
|
|
|
|
break;
|
|
|
|
}
|
2015-07-23 01:58:46 +08:00
|
|
|
case MachineOperand::MO_Metadata:
|
|
|
|
Op.getMetadata()->printAsOperand(OS, MST);
|
|
|
|
break;
|
2015-08-22 05:12:44 +08:00
|
|
|
case MachineOperand::MO_MCSymbol:
|
|
|
|
OS << "<mcsymbol " << *Op.getMCSymbol() << ">";
|
|
|
|
break;
|
2015-07-22 06:28:27 +08:00
|
|
|
case MachineOperand::MO_CFIIndex: {
|
|
|
|
const auto &MMI = Op.getParent()->getParent()->getParent()->getMMI();
|
2015-07-24 07:09:07 +08:00
|
|
|
print(MMI.getFrameInstructions()[Op.getCFIIndex()], TRI);
|
2015-07-22 06:28:27 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-06-24 00:35:26 +08:00
|
|
|
}
|
2015-06-20 01:43:07 +08:00
|
|
|
}
|
|
|
|
|
2015-08-04 07:08:19 +08:00
|
|
|
void MIPrinter::print(const MachineMemOperand &Op) {
|
|
|
|
OS << '(';
|
2015-08-07 00:55:53 +08:00
|
|
|
// TODO: Print operand's target specific flags.
|
2015-08-04 08:24:45 +08:00
|
|
|
if (Op.isVolatile())
|
|
|
|
OS << "volatile ";
|
2015-08-07 00:49:30 +08:00
|
|
|
if (Op.isNonTemporal())
|
|
|
|
OS << "non-temporal ";
|
2015-08-07 00:55:53 +08:00
|
|
|
if (Op.isInvariant())
|
|
|
|
OS << "invariant ";
|
2015-08-04 07:08:19 +08:00
|
|
|
if (Op.isLoad())
|
|
|
|
OS << "load ";
|
|
|
|
else {
|
|
|
|
assert(Op.isStore() && "Non load machine operand must be a store");
|
|
|
|
OS << "store ";
|
|
|
|
}
|
|
|
|
OS << Op.getSize() << (Op.isLoad() ? " from " : " into ");
|
2015-08-13 04:33:26 +08:00
|
|
|
if (const Value *Val = Op.getValue()) {
|
2015-08-04 07:08:19 +08:00
|
|
|
printIRValueReference(*Val);
|
2015-08-13 04:33:26 +08:00
|
|
|
} else {
|
|
|
|
const PseudoSourceValue *PVal = Op.getPseudoValue();
|
|
|
|
assert(PVal && "Expected a pseudo source value");
|
|
|
|
switch (PVal->kind()) {
|
2015-08-13 04:44:16 +08:00
|
|
|
case PseudoSourceValue::Stack:
|
|
|
|
OS << "stack";
|
|
|
|
break;
|
2015-08-13 05:00:22 +08:00
|
|
|
case PseudoSourceValue::GOT:
|
|
|
|
OS << "got";
|
|
|
|
break;
|
2015-08-13 05:11:08 +08:00
|
|
|
case PseudoSourceValue::JumpTable:
|
|
|
|
OS << "jump-table";
|
|
|
|
break;
|
2015-08-13 04:33:26 +08:00
|
|
|
case PseudoSourceValue::ConstantPool:
|
|
|
|
OS << "constant-pool";
|
|
|
|
break;
|
2015-08-13 05:23:17 +08:00
|
|
|
case PseudoSourceValue::FixedStack:
|
|
|
|
printStackObjectReference(
|
|
|
|
cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex());
|
|
|
|
break;
|
2015-08-15 05:08:30 +08:00
|
|
|
case PseudoSourceValue::GlobalValueCallEntry:
|
2015-08-20 08:12:57 +08:00
|
|
|
OS << "call-entry ";
|
2015-08-15 05:08:30 +08:00
|
|
|
cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
|
|
|
|
OS, /*PrintType=*/false, MST);
|
|
|
|
break;
|
2015-08-15 05:14:50 +08:00
|
|
|
case PseudoSourceValue::ExternalSymbolCallEntry:
|
2015-08-20 08:12:57 +08:00
|
|
|
OS << "call-entry $";
|
2015-08-15 05:14:50 +08:00
|
|
|
printLLVMNameWithoutPrefix(
|
|
|
|
OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
|
2015-08-13 04:33:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-08 04:26:52 +08:00
|
|
|
printOffset(Op.getOffset());
|
2015-08-08 04:48:30 +08:00
|
|
|
if (Op.getBaseAlignment() != Op.getSize())
|
|
|
|
OS << ", align " << Op.getBaseAlignment();
|
2015-08-18 06:05:15 +08:00
|
|
|
auto AAInfo = Op.getAAInfo();
|
|
|
|
if (AAInfo.TBAA) {
|
|
|
|
OS << ", !tbaa ";
|
|
|
|
AAInfo.TBAA->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-18 06:06:40 +08:00
|
|
|
if (AAInfo.Scope) {
|
|
|
|
OS << ", !alias.scope ";
|
|
|
|
AAInfo.Scope->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-18 06:08:02 +08:00
|
|
|
if (AAInfo.NoAlias) {
|
|
|
|
OS << ", !noalias ";
|
|
|
|
AAInfo.NoAlias->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-18 06:09:52 +08:00
|
|
|
if (Op.getRanges()) {
|
|
|
|
OS << ", !range ";
|
|
|
|
Op.getRanges()->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-04 07:08:19 +08:00
|
|
|
OS << ')';
|
|
|
|
}
|
|
|
|
|
2015-07-24 07:09:07 +08:00
|
|
|
static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
int Reg = TRI->getLLVMRegNum(DwarfReg, true);
|
|
|
|
if (Reg == -1) {
|
|
|
|
OS << "<badreg>";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printReg(Reg, OS, TRI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MIPrinter::print(const MCCFIInstruction &CFI,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
2015-07-22 06:28:27 +08:00
|
|
|
switch (CFI.getOperation()) {
|
2015-08-15 05:55:58 +08:00
|
|
|
case MCCFIInstruction::OpSameValue:
|
|
|
|
OS << ".cfi_same_value ";
|
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
break;
|
2015-07-24 07:09:07 +08:00
|
|
|
case MCCFIInstruction::OpOffset:
|
|
|
|
OS << ".cfi_offset ";
|
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
OS << ", " << CFI.getOffset();
|
|
|
|
break;
|
2015-07-28 04:39:03 +08:00
|
|
|
case MCCFIInstruction::OpDefCfaRegister:
|
|
|
|
OS << ".cfi_def_cfa_register ";
|
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
break;
|
2015-07-22 06:28:27 +08:00
|
|
|
case MCCFIInstruction::OpDefCfaOffset:
|
|
|
|
OS << ".cfi_def_cfa_offset ";
|
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
OS << CFI.getOffset();
|
|
|
|
break;
|
2015-07-30 02:57:23 +08:00
|
|
|
case MCCFIInstruction::OpDefCfa:
|
|
|
|
OS << ".cfi_def_cfa ";
|
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
OS << ", " << CFI.getOffset();
|
|
|
|
break;
|
2015-07-22 06:28:27 +08:00
|
|
|
default:
|
|
|
|
// TODO: Print the other CFI Operations.
|
|
|
|
OS << "<unserializable cfi operation>";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 07:52:35 +08:00
|
|
|
void llvm::printMIR(raw_ostream &OS, const Module &M) {
|
|
|
|
yaml::Output Out(OS);
|
|
|
|
Out << const_cast<Module &>(M);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llvm::printMIR(raw_ostream &OS, const MachineFunction &MF) {
|
|
|
|
MIRPrinter Printer(OS);
|
|
|
|
Printer.print(MF);
|
|
|
|
}
|