2015-06-16 01:52:35 +02: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/None.h"
|
2016-09-12 13:20:10 +02:00
|
|
|
#include "llvm/ADT/SmallBitVector.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2016-04-08 18:26:22 +02:00
|
|
|
#include "llvm/CodeGen/GlobalISel/RegisterBank.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2015-07-20 22:51:18 +02:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.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-09 21:55:27 +02:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2016-04-08 18:26:22 +02:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2015-08-04 01:08:19 +02:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2015-06-24 21:56:10 +02:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/CodeGen/MIRPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MIRYamlMapping.h"
|
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2015-06-19 19:43:07 +02:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
2015-07-28 19:28:03 +02:00
|
|
|
#include "llvm/IR/Constants.h"
|
2016-04-14 20:29:59 +02:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/GlobalValue.h"
|
|
|
|
#include "llvm/IR/InstrTypes.h"
|
2016-04-08 18:26:22 +02:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2016-07-29 22:32:59 +02:00
|
|
|
#include "llvm/IR/Intrinsics.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2015-06-16 01:52:35 +02:00
|
|
|
#include "llvm/IR/Module.h"
|
2015-07-08 01:27:53 +02:00
|
|
|
#include "llvm/IR/ModuleSlotTracker.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/IR/Value.h"
|
|
|
|
#include "llvm/MC/LaneBitmask.h"
|
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2015-08-21 23:12:44 +02:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/Support/AtomicOrdering.h"
|
|
|
|
#include "llvm/Support/BranchProbability.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2016-11-18 20:37:24 +01:00
|
|
|
#include "llvm/Support/Format.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/Support/LowLevelTypeImpl.h"
|
2016-04-08 18:26:22 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
2015-06-22 19:02:30 +02:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2016-07-29 22:32:59 +02:00
|
|
|
#include "llvm/Target/TargetIntrinsicInfo.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2015-06-22 19:02:30 +02:00
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2017-06-07 00:22:41 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iterator>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2015-06-16 01:52:35 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-05-05 23:09:30 +02:00
|
|
|
static cl::opt<bool> SimplifyMIR("simplify-mir",
|
|
|
|
cl::desc("Leave out unnecessary information when printing MIR"));
|
|
|
|
|
2015-06-16 01:52:35 +02:00
|
|
|
namespace {
|
|
|
|
|
2015-07-17 01:37:45 +02: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-30 18:54:38 +02:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-06-16 01:52:35 +02:00
|
|
|
/// This class prints out the machine functions using the MIR serialization
|
|
|
|
/// format.
|
|
|
|
class MIRPrinter {
|
|
|
|
raw_ostream &OS;
|
2015-06-29 18:57:06 +02:00
|
|
|
DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
|
2015-07-17 01:37:45 +02: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 01:52:35 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
MIRPrinter(raw_ostream &OS) : OS(OS) {}
|
|
|
|
|
|
|
|
void print(const MachineFunction &MF);
|
2015-06-19 19:43:07 +02:00
|
|
|
|
2015-07-10 00:23:13 +02:00
|
|
|
void convert(yaml::MachineFunction &MF, const MachineRegisterInfo &RegInfo,
|
|
|
|
const TargetRegisterInfo *TRI);
|
2015-07-29 23:09:09 +02:00
|
|
|
void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
|
|
|
|
const MachineFrameInfo &MFI);
|
2015-07-20 22:51:18 +02:00
|
|
|
void convert(yaml::MachineFunction &MF,
|
|
|
|
const MachineConstantPool &ConstantPool);
|
2015-07-16 01:31:07 +02:00
|
|
|
void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
|
|
|
|
const MachineJumpTableInfo &JTI);
|
2016-12-01 00:48:50 +01:00
|
|
|
void convertStackObjects(yaml::MachineFunction &YMF,
|
|
|
|
const MachineFunction &MF, ModuleSlotTracker &MST);
|
2015-06-29 18:57:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void initRegisterMaskIds(const MachineFunction &MF);
|
2015-06-16 01:52:35 +02:00
|
|
|
};
|
|
|
|
|
2015-06-22 19:02:30 +02:00
|
|
|
/// This class prints out the machine instructions using the MIR serialization
|
|
|
|
/// format.
|
|
|
|
class MIPrinter {
|
|
|
|
raw_ostream &OS;
|
2015-07-08 01:27:53 +02:00
|
|
|
ModuleSlotTracker &MST;
|
2015-06-29 18:57:06 +02:00
|
|
|
const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds;
|
2015-07-17 01:37:45 +02:00
|
|
|
const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping;
|
2015-06-22 19:02:30 +02:00
|
|
|
|
2017-05-05 23:09:30 +02:00
|
|
|
bool canPredictBranchProbabilities(const MachineBasicBlock &MBB) const;
|
|
|
|
bool canPredictSuccessors(const MachineBasicBlock &MBB) const;
|
|
|
|
|
2015-06-22 19:02:30 +02:00
|
|
|
public:
|
2015-07-08 01:27:53 +02:00
|
|
|
MIPrinter(raw_ostream &OS, ModuleSlotTracker &MST,
|
2015-07-17 01:37:45 +02:00
|
|
|
const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds,
|
|
|
|
const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping)
|
|
|
|
: OS(OS), MST(MST), RegisterMaskIds(RegisterMaskIds),
|
|
|
|
StackObjectOperandMapping(StackObjectOperandMapping) {}
|
2015-06-22 19:02:30 +02:00
|
|
|
|
2015-08-14 01:10:16 +02:00
|
|
|
void print(const MachineBasicBlock &MBB);
|
|
|
|
|
2015-06-22 19:02:30 +02:00
|
|
|
void print(const MachineInstr &MI);
|
2015-06-30 20:00:16 +02:00
|
|
|
void printMBBReference(const MachineBasicBlock &MBB);
|
2015-07-28 19:28:03 +02:00
|
|
|
void printIRBlockReference(const BasicBlock &BB);
|
2015-08-04 01:08:19 +02:00
|
|
|
void printIRValueReference(const Value &V);
|
2015-07-17 01:37:45 +02:00
|
|
|
void printStackObjectReference(int FrameIndex);
|
2015-08-06 00:26:15 +02:00
|
|
|
void printOffset(int64_t Offset);
|
2015-08-06 02:44:07 +02:00
|
|
|
void printTargetFlags(const MachineOperand &Op);
|
2015-08-19 20:55:47 +02:00
|
|
|
void print(const MachineOperand &Op, const TargetRegisterInfo *TRI,
|
2016-03-07 22:57:52 +01:00
|
|
|
unsigned I, bool ShouldPrintRegisterTies,
|
2016-09-12 13:20:10 +02:00
|
|
|
LLT TypeToPrint, bool IsDef = false);
|
2015-08-04 01:08:19 +02:00
|
|
|
void print(const MachineMemOperand &Op);
|
2015-07-22 00:28:27 +02:00
|
|
|
|
2015-07-24 01:09:07 +02:00
|
|
|
void print(const MCCFIInstruction &CFI, const TargetRegisterInfo *TRI);
|
2015-06-22 19:02:30 +02:00
|
|
|
};
|
|
|
|
|
2015-08-14 01:10:16 +02:00
|
|
|
} // end namespace llvm
|
2015-06-16 01:52:35 +02: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);
|
|
|
|
}
|
2017-06-07 00:22:41 +02:00
|
|
|
|
2015-06-16 01:52:35 +02:00
|
|
|
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-14 23:18:25 +02: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-24 22:35:40 +02: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 01:52:35 +02:00
|
|
|
void MIRPrinter::print(const MachineFunction &MF) {
|
2015-06-29 18:57:06 +02:00
|
|
|
initRegisterMaskIds(MF);
|
|
|
|
|
2015-06-16 01:52:35 +02:00
|
|
|
yaml::MachineFunction YamlMF;
|
|
|
|
YamlMF.Name = MF.getName();
|
2015-06-16 02:10:47 +02:00
|
|
|
YamlMF.Alignment = MF.getAlignment();
|
|
|
|
YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice();
|
2016-03-28 19:05:30 +02:00
|
|
|
|
2016-08-02 17:10:25 +02:00
|
|
|
YamlMF.Legalized = MF.getProperties().hasProperty(
|
|
|
|
MachineFunctionProperties::Property::Legalized);
|
2016-08-02 18:17:10 +02:00
|
|
|
YamlMF.RegBankSelected = MF.getProperties().hasProperty(
|
|
|
|
MachineFunctionProperties::Property::RegBankSelected);
|
2016-08-02 18:49:19 +02:00
|
|
|
YamlMF.Selected = MF.getProperties().hasProperty(
|
|
|
|
MachineFunctionProperties::Property::Selected);
|
2016-08-02 17:10:25 +02:00
|
|
|
|
2015-07-10 00:23:13 +02:00
|
|
|
convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
|
2015-07-29 23:09:09 +02:00
|
|
|
ModuleSlotTracker MST(MF.getFunction()->getParent());
|
|
|
|
MST.incorporateFunction(*MF.getFunction());
|
2016-07-28 20:40:00 +02:00
|
|
|
convert(MST, YamlMF.FrameInfo, MF.getFrameInfo());
|
2016-12-01 00:48:50 +01:00
|
|
|
convertStackObjects(YamlMF, MF, MST);
|
2015-07-20 22:51:18 +02:00
|
|
|
if (const auto *ConstantPool = MF.getConstantPool())
|
|
|
|
convert(YamlMF, *ConstantPool);
|
2015-07-16 01:31:07 +02:00
|
|
|
if (const auto *JumpTableInfo = MF.getJumpTableInfo())
|
|
|
|
convert(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
|
2015-08-14 01:10:16 +02:00
|
|
|
raw_string_ostream StrOS(YamlMF.Body.Value.Value);
|
|
|
|
bool IsNewlineNeeded = false;
|
2015-06-19 19:43:07 +02:00
|
|
|
for (const auto &MBB : MF) {
|
2015-08-14 01:10:16 +02:00
|
|
|
if (IsNewlineNeeded)
|
|
|
|
StrOS << "\n";
|
|
|
|
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
|
|
|
|
.print(MBB);
|
|
|
|
IsNewlineNeeded = true;
|
2015-06-19 19:43:07 +02:00
|
|
|
}
|
2015-08-14 01:10:16 +02:00
|
|
|
StrOS.flush();
|
2015-06-16 01:52:35 +02:00
|
|
|
yaml::Output Out(OS);
|
2017-06-06 10:16:19 +02:00
|
|
|
if (!SimplifyMIR)
|
|
|
|
Out.setWriteDefaultValues(true);
|
2015-06-16 01:52:35 +02:00
|
|
|
Out << YamlMF;
|
|
|
|
}
|
|
|
|
|
2017-03-19 09:14:18 +01:00
|
|
|
static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
|
|
|
assert(RegMask && "Can't print an empty register mask");
|
|
|
|
OS << StringRef("CustomRegMask(");
|
|
|
|
|
|
|
|
bool IsRegInRegMaskFound = false;
|
|
|
|
for (int I = 0, E = TRI->getNumRegs(); I < E; I++) {
|
|
|
|
// Check whether the register is asserted in regmask.
|
|
|
|
if (RegMask[I / 32] & (1u << (I % 32))) {
|
|
|
|
if (IsRegInRegMaskFound)
|
|
|
|
OS << ',';
|
|
|
|
printReg(I, OS, TRI);
|
|
|
|
IsRegInRegMaskFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << ')';
|
|
|
|
}
|
|
|
|
|
2015-06-24 21:56:10 +02:00
|
|
|
void MIRPrinter::convert(yaml::MachineFunction &MF,
|
2015-07-10 00:23:13 +02:00
|
|
|
const MachineRegisterInfo &RegInfo,
|
|
|
|
const TargetRegisterInfo *TRI) {
|
2015-06-24 21:56:10 +02:00
|
|
|
MF.TracksRegLiveness = RegInfo.tracksLiveness();
|
2015-07-10 00:23:13 +02: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;
|
2016-04-08 18:26:22 +02:00
|
|
|
if (RegInfo.getRegClassOrNull(Reg))
|
2016-03-08 02:17:03 +01:00
|
|
|
VReg.Class =
|
|
|
|
StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
|
2016-04-08 18:26:22 +02:00
|
|
|
else if (RegInfo.getRegBankOrNull(Reg))
|
|
|
|
VReg.Class = StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).lower();
|
2016-03-08 02:17:03 +01:00
|
|
|
else {
|
|
|
|
VReg.Class = std::string("_");
|
2016-09-12 13:20:10 +02:00
|
|
|
assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
|
2016-09-09 13:46:34 +02:00
|
|
|
"Generic registers must have a valid type");
|
2016-03-08 02:17:03 +01:00
|
|
|
}
|
2015-07-24 22:35:40 +02:00
|
|
|
unsigned PreferredReg = RegInfo.getSimpleHint(Reg);
|
|
|
|
if (PreferredReg)
|
|
|
|
printReg(PreferredReg, VReg.PreferredRegister, TRI);
|
2015-07-10 00:23:13 +02:00
|
|
|
MF.VirtualRegisters.push_back(VReg);
|
|
|
|
}
|
2015-07-27 19:42:45 +02: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);
|
|
|
|
}
|
2017-03-19 09:14:18 +01:00
|
|
|
|
|
|
|
// Prints the callee saved registers.
|
|
|
|
if (RegInfo.isUpdatedCSRsInitialized()) {
|
|
|
|
const MCPhysReg *CalleeSavedRegs = RegInfo.getCalleeSavedRegs();
|
|
|
|
std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
|
|
|
|
for (const MCPhysReg *I = CalleeSavedRegs; *I; ++I) {
|
2015-08-11 02:32:49 +02:00
|
|
|
yaml::FlowStringValue Reg;
|
2017-03-19 09:14:18 +01:00
|
|
|
printReg(*I, Reg, TRI);
|
2015-08-11 02:32:49 +02:00
|
|
|
CalleeSavedRegisters.push_back(Reg);
|
|
|
|
}
|
2017-03-19 09:14:18 +01:00
|
|
|
MF.CalleeSavedRegisters = CalleeSavedRegisters;
|
2015-08-11 02:32:49 +02:00
|
|
|
}
|
2015-06-24 21:56:10 +02:00
|
|
|
}
|
|
|
|
|
2015-07-29 23:09:09 +02: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-09 21:55:27 +02: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();
|
2017-05-02 00:32:25 +02:00
|
|
|
YamlMFI.MaxCallFrameSize = MFI.isMaxCallFrameSizeComputed()
|
|
|
|
? MFI.getMaxCallFrameSize() : ~0u;
|
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-09 21:55:27 +02:00
|
|
|
YamlMFI.HasOpaqueSPAdjustment = MFI.hasOpaqueSPAdjustment();
|
|
|
|
YamlMFI.HasVAStart = MFI.hasVAStart();
|
|
|
|
YamlMFI.HasMustTailInVarArgFunc = MFI.hasMustTailInVarArgFunc();
|
2015-07-29 23:09:09 +02: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-09 21:55:27 +02:00
|
|
|
}
|
|
|
|
|
2016-12-01 00:48:50 +01:00
|
|
|
void MIRPrinter::convertStackObjects(yaml::MachineFunction &YMF,
|
|
|
|
const MachineFunction &MF,
|
|
|
|
ModuleSlotTracker &MST) {
|
|
|
|
const MachineFrameInfo &MFI = MF.getFrameInfo();
|
|
|
|
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
|
2015-07-13 20:07:26 +02:00
|
|
|
// Process fixed stack objects.
|
2015-07-10 20:13:57 +02:00
|
|
|
unsigned ID = 0;
|
2015-07-13 20:07:26 +02:00
|
|
|
for (int I = MFI.getObjectIndexBegin(); I < 0; ++I) {
|
|
|
|
if (MFI.isDeadObjectIndex(I))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
yaml::FixedMachineStackObject YamlObject;
|
2015-07-17 01:37:45 +02:00
|
|
|
YamlObject.ID = ID;
|
2015-07-13 20:07:26 +02: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);
|
2016-12-01 00:48:50 +01:00
|
|
|
YMF.FixedStackObjects.push_back(YamlObject);
|
2015-07-17 01:37:45 +02:00
|
|
|
StackObjectOperandMapping.insert(
|
|
|
|
std::make_pair(I, FrameIndexOperand::createFixed(ID++)));
|
2015-07-13 20:07:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process ordinary stack objects.
|
|
|
|
ID = 0;
|
2015-07-10 20:13:57 +02:00
|
|
|
for (int I = 0, E = MFI.getObjectIndexEnd(); I < E; ++I) {
|
|
|
|
if (MFI.isDeadObjectIndex(I))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
yaml::MachineStackObject YamlObject;
|
2015-07-17 01:37:45 +02:00
|
|
|
YamlObject.ID = ID;
|
2015-07-16 00:14:49 +02:00
|
|
|
if (const auto *Alloca = MFI.getObjectAllocation(I))
|
|
|
|
YamlObject.Name.Value =
|
|
|
|
Alloca->hasName() ? Alloca->getName() : "<unnamed alloca>";
|
2015-07-10 20:13:57 +02:00
|
|
|
YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
|
|
|
|
? yaml::MachineStackObject::SpillSlot
|
2015-07-14 02:26:26 +02:00
|
|
|
: MFI.isVariableSizedObjectIndex(I)
|
|
|
|
? yaml::MachineStackObject::VariableSized
|
|
|
|
: yaml::MachineStackObject::DefaultType;
|
2015-07-10 20:13:57 +02:00
|
|
|
YamlObject.Offset = MFI.getObjectOffset(I);
|
|
|
|
YamlObject.Size = MFI.getObjectSize(I);
|
|
|
|
YamlObject.Alignment = MFI.getObjectAlignment(I);
|
|
|
|
|
2016-12-01 00:48:50 +01:00
|
|
|
YMF.StackObjects.push_back(YamlObject);
|
2015-07-17 01:37:45 +02:00
|
|
|
StackObjectOperandMapping.insert(std::make_pair(
|
|
|
|
I, FrameIndexOperand::create(YamlObject.Name.Value, ID++)));
|
2015-07-10 20:13:57 +02:00
|
|
|
}
|
2015-07-25 00:22:50 +02: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)
|
2016-12-01 00:48:50 +01:00
|
|
|
YMF.FixedStackObjects[StackObject.ID].CalleeSavedRegister = Reg;
|
2015-07-25 00:22:50 +02:00
|
|
|
else
|
2016-12-01 00:48:50 +01:00
|
|
|
YMF.StackObjects[StackObject.ID].CalleeSavedRegister = Reg;
|
2015-07-25 00:22:50 +02:00
|
|
|
}
|
2015-08-18 00:17:42 +02: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");
|
2016-12-01 00:48:50 +01:00
|
|
|
YMF.StackObjects[StackObject.ID].LocalOffset = LocalObject.second;
|
2015-08-18 00:17:42 +02:00
|
|
|
}
|
2015-08-19 00:26:26 +02:00
|
|
|
|
|
|
|
// Print the stack object references in the frame information class after
|
|
|
|
// converting the stack objects.
|
|
|
|
if (MFI.hasStackProtectorIndex()) {
|
2016-12-01 00:48:50 +01:00
|
|
|
raw_string_ostream StrOS(YMF.FrameInfo.StackProtector.Value);
|
2015-08-19 00:26:26 +02:00
|
|
|
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
|
|
|
|
.printStackObjectReference(MFI.getStackProtectorIndex());
|
|
|
|
}
|
2015-08-19 02:13:25 +02:00
|
|
|
|
|
|
|
// Print the debug variable information.
|
2016-12-01 00:48:50 +01:00
|
|
|
for (const MachineFunction::VariableDbgInfo &DebugVar :
|
|
|
|
MF.getVariableDbgInfo()) {
|
2015-08-19 02:13:25 +02:00
|
|
|
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");
|
2016-12-01 00:48:50 +01:00
|
|
|
auto &Object = YMF.StackObjects[StackObject.ID];
|
2015-08-19 02:13:25 +02:00
|
|
|
{
|
|
|
|
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-10 20:13:57 +02:00
|
|
|
}
|
|
|
|
|
2015-07-20 22:51:18 +02: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 01:31:07 +02: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 01:37:45 +02:00
|
|
|
MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
|
|
|
|
.printMBBReference(*MBB);
|
2015-07-16 01:31:07 +02:00
|
|
|
Entry.Blocks.push_back(StrOS.str());
|
|
|
|
Str.clear();
|
|
|
|
}
|
|
|
|
YamlJTI.Entries.push_back(Entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 01:10:16 +02: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++));
|
|
|
|
}
|
|
|
|
|
2017-05-05 23:09:30 +02:00
|
|
|
void llvm::guessSuccessors(const MachineBasicBlock &MBB,
|
|
|
|
SmallVectorImpl<MachineBasicBlock*> &Result,
|
|
|
|
bool &IsFallthrough) {
|
|
|
|
SmallPtrSet<MachineBasicBlock*,8> Seen;
|
|
|
|
|
|
|
|
for (const MachineInstr &MI : MBB) {
|
|
|
|
if (MI.isPHI())
|
|
|
|
continue;
|
|
|
|
for (const MachineOperand &MO : MI.operands()) {
|
|
|
|
if (!MO.isMBB())
|
|
|
|
continue;
|
|
|
|
MachineBasicBlock *Succ = MO.getMBB();
|
|
|
|
auto RP = Seen.insert(Succ);
|
|
|
|
if (RP.second)
|
|
|
|
Result.push_back(Succ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr();
|
|
|
|
IsFallthrough = I == MBB.end() || !I->isBarrier();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MIPrinter::canPredictBranchProbabilities(const MachineBasicBlock &MBB) const {
|
|
|
|
if (MBB.succ_size() <= 1)
|
|
|
|
return true;
|
|
|
|
if (!MBB.hasSuccessorProbabilities())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
SmallVector<BranchProbability,8> Normalized(MBB.Probs.begin(),
|
|
|
|
MBB.Probs.end());
|
|
|
|
BranchProbability::normalizeProbabilities(Normalized.begin(),
|
|
|
|
Normalized.end());
|
|
|
|
SmallVector<BranchProbability,8> Equal(Normalized.size());
|
|
|
|
BranchProbability::normalizeProbabilities(Equal.begin(), Equal.end());
|
|
|
|
|
|
|
|
return std::equal(Normalized.begin(), Normalized.end(), Equal.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MIPrinter::canPredictSuccessors(const MachineBasicBlock &MBB) const {
|
|
|
|
SmallVector<MachineBasicBlock*,8> GuessedSuccs;
|
|
|
|
bool GuessedFallthrough;
|
|
|
|
guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough);
|
|
|
|
if (GuessedFallthrough) {
|
|
|
|
const MachineFunction &MF = *MBB.getParent();
|
|
|
|
MachineFunction::const_iterator NextI = std::next(MBB.getIterator());
|
|
|
|
if (NextI != MF.end()) {
|
|
|
|
MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI);
|
|
|
|
if (!is_contained(GuessedSuccs, Next))
|
|
|
|
GuessedSuccs.push_back(Next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (GuessedSuccs.size() != MBB.succ_size())
|
|
|
|
return false;
|
|
|
|
return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin());
|
|
|
|
}
|
|
|
|
|
2015-08-14 01:10:16 +02:00
|
|
|
void MIPrinter::print(const MachineBasicBlock &MBB) {
|
2015-06-26 18:46:11 +02:00
|
|
|
assert(MBB.getNumber() >= 0 && "Invalid MBB number");
|
2015-08-14 01:10:16 +02:00
|
|
|
OS << "bb." << MBB.getNumber();
|
|
|
|
bool HasAttributes = false;
|
2015-07-28 00:42:41 +02:00
|
|
|
if (const auto *BB = MBB.getBasicBlock()) {
|
|
|
|
if (BB->hasName()) {
|
2015-08-14 01:10:16 +02:00
|
|
|
OS << "." << BB->getName();
|
2015-07-28 00:42:41 +02:00
|
|
|
} else {
|
2015-08-14 01:10:16 +02:00
|
|
|
HasAttributes = true;
|
|
|
|
OS << " (";
|
2015-07-28 00:42:41 +02:00
|
|
|
int Slot = MST.getLocalSlot(BB);
|
|
|
|
if (Slot == -1)
|
2015-08-14 01:10:16 +02:00
|
|
|
OS << "<ir-block badref>";
|
2015-07-28 00:42:41 +02:00
|
|
|
else
|
2015-08-14 01:10:16 +02:00
|
|
|
OS << (Twine("%ir-block.") + Twine(Slot)).str();
|
2015-07-28 00:42:41 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-14 01:10:16 +02:00
|
|
|
if (MBB.hasAddressTaken()) {
|
|
|
|
OS << (HasAttributes ? ", " : " (");
|
|
|
|
OS << "address-taken";
|
|
|
|
HasAttributes = true;
|
|
|
|
}
|
2015-08-28 01:27:47 +02:00
|
|
|
if (MBB.isEHPad()) {
|
2015-08-14 01:10:16 +02:00
|
|
|
OS << (HasAttributes ? ", " : " (");
|
|
|
|
OS << "landing-pad";
|
|
|
|
HasAttributes = true;
|
2015-06-30 20:16:42 +02:00
|
|
|
}
|
2015-08-14 01:10:16 +02:00
|
|
|
if (MBB.getAlignment()) {
|
|
|
|
OS << (HasAttributes ? ", " : " (");
|
|
|
|
OS << "align " << MBB.getAlignment();
|
|
|
|
HasAttributes = true;
|
2015-07-30 18:54:38 +02:00
|
|
|
}
|
2015-08-14 01:10:16 +02:00
|
|
|
if (HasAttributes)
|
|
|
|
OS << ")";
|
|
|
|
OS << ":\n";
|
|
|
|
|
|
|
|
bool HasLineAttributes = false;
|
|
|
|
// Print the successors
|
2017-05-05 23:09:30 +02:00
|
|
|
bool canPredictProbs = canPredictBranchProbabilities(MBB);
|
|
|
|
if (!MBB.succ_empty() && (!SimplifyMIR || !canPredictProbs ||
|
|
|
|
!canPredictSuccessors(MBB))) {
|
2015-08-14 01:10:16 +02:00
|
|
|
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);
|
2017-05-05 23:09:30 +02:00
|
|
|
if (!SimplifyMIR || !canPredictProbs)
|
2016-11-18 20:37:24 +01:00
|
|
|
OS << '('
|
|
|
|
<< format("0x%08" PRIx32, MBB.getSuccProbability(I).getNumerator())
|
|
|
|
<< ')';
|
2015-08-14 01:10:16 +02:00
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
HasLineAttributes = true;
|
|
|
|
}
|
|
|
|
|
2015-07-14 23:24:41 +02:00
|
|
|
// Print the live in registers.
|
2017-01-05 21:01:19 +01:00
|
|
|
const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
|
|
|
|
if (MRI.tracksLiveness() && !MBB.livein_empty()) {
|
|
|
|
const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
|
2015-08-14 01:10:16 +02:00
|
|
|
OS.indent(2) << "liveins: ";
|
2015-08-25 00:59:52 +02:00
|
|
|
bool First = true;
|
2015-09-09 20:08:03 +02:00
|
|
|
for (const auto &LI : MBB.liveins()) {
|
2015-08-25 00:59:52 +02:00
|
|
|
if (!First)
|
2015-08-14 01:10:16 +02:00
|
|
|
OS << ", ";
|
2015-08-25 00:59:52 +02:00
|
|
|
First = false;
|
2017-01-05 21:01:19 +01:00
|
|
|
printReg(LI.PhysReg, OS, &TRI);
|
2016-12-15 15:36:06 +01:00
|
|
|
if (!LI.LaneMask.all())
|
2016-10-12 23:06:45 +02:00
|
|
|
OS << ":0x" << PrintLaneMask(LI.LaneMask);
|
2015-08-14 01:10:16 +02:00
|
|
|
}
|
|
|
|
OS << "\n";
|
|
|
|
HasLineAttributes = true;
|
2015-07-14 23:24:41 +02:00
|
|
|
}
|
2015-08-14 01:10:16 +02:00
|
|
|
|
|
|
|
if (HasLineAttributes)
|
|
|
|
OS << "\n";
|
2015-08-14 20:57:24 +02: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 01:10:16 +02:00
|
|
|
print(MI);
|
2015-08-14 20:57:24 +02:00
|
|
|
if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
|
|
|
|
OS << " {";
|
|
|
|
IsInBundle = true;
|
|
|
|
}
|
2015-08-14 01:10:16 +02:00
|
|
|
OS << "\n";
|
2015-06-22 19:02:30 +02:00
|
|
|
}
|
2015-08-14 20:57:24 +02:00
|
|
|
if (IsInBundle)
|
|
|
|
OS.indent(2) << "}\n";
|
2015-06-22 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 21:05:34 +02: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;
|
|
|
|
}
|
|
|
|
|
2016-09-12 13:20:10 +02:00
|
|
|
static LLT getTypeToPrint(const MachineInstr &MI, unsigned OpIdx,
|
|
|
|
SmallBitVector &PrintedTypes,
|
|
|
|
const MachineRegisterInfo &MRI) {
|
|
|
|
const MachineOperand &Op = MI.getOperand(OpIdx);
|
|
|
|
if (!Op.isReg())
|
|
|
|
return LLT{};
|
|
|
|
|
|
|
|
if (MI.isVariadic() || OpIdx >= MI.getNumExplicitOperands())
|
|
|
|
return MRI.getType(Op.getReg());
|
|
|
|
|
|
|
|
auto &OpInfo = MI.getDesc().OpInfo[OpIdx];
|
|
|
|
if (!OpInfo.isGenericType())
|
|
|
|
return MRI.getType(Op.getReg());
|
|
|
|
|
|
|
|
if (PrintedTypes[OpInfo.getGenericTypeIndex()])
|
|
|
|
return LLT{};
|
|
|
|
|
|
|
|
PrintedTypes.set(OpInfo.getGenericTypeIndex());
|
|
|
|
return MRI.getType(Op.getReg());
|
|
|
|
}
|
|
|
|
|
2015-06-22 19:02:30 +02:00
|
|
|
void MIPrinter::print(const MachineInstr &MI) {
|
2016-03-07 22:57:52 +01:00
|
|
|
const auto *MF = MI.getParent()->getParent();
|
|
|
|
const auto &MRI = MF->getRegInfo();
|
|
|
|
const auto &SubTarget = MF->getSubtarget();
|
2015-06-23 18:35:26 +02:00
|
|
|
const auto *TRI = SubTarget.getRegisterInfo();
|
|
|
|
assert(TRI && "Expected target register info");
|
2015-06-22 19:02:30 +02:00
|
|
|
const auto *TII = SubTarget.getInstrInfo();
|
|
|
|
assert(TII && "Expected target instruction info");
|
2015-07-22 00:28:27 +02:00
|
|
|
if (MI.isCFIInstruction())
|
|
|
|
assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
|
2015-06-22 19:02:30 +02:00
|
|
|
|
2016-09-12 13:20:10 +02:00
|
|
|
SmallBitVector PrintedTypes(8);
|
2015-08-19 21:05:34 +02:00
|
|
|
bool ShouldPrintRegisterTies = hasComplexRegisterTies(MI);
|
2015-06-23 18:35:26 +02: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 << ", ";
|
2016-09-12 13:20:10 +02:00
|
|
|
print(MI.getOperand(I), TRI, I, ShouldPrintRegisterTies,
|
|
|
|
getTypeToPrint(MI, I, PrintedTypes, MRI),
|
2016-03-07 22:57:52 +01:00
|
|
|
/*IsDef=*/true);
|
2015-06-23 18:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (I)
|
|
|
|
OS << " = ";
|
2015-07-17 02:24:15 +02:00
|
|
|
if (MI.getFlag(MachineInstr::FrameSetup))
|
|
|
|
OS << "frame-setup ";
|
2015-06-22 19:02:30 +02:00
|
|
|
OS << TII->getName(MI.getOpcode());
|
2015-06-23 18:35:26 +02:00
|
|
|
if (I < E)
|
|
|
|
OS << ' ';
|
|
|
|
|
|
|
|
bool NeedComma = false;
|
|
|
|
for (; I < E; ++I) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ", ";
|
2016-09-12 13:20:10 +02:00
|
|
|
print(MI.getOperand(I), TRI, I, ShouldPrintRegisterTies,
|
|
|
|
getTypeToPrint(MI, I, PrintedTypes, MRI));
|
2015-06-23 18:35:26 +02:00
|
|
|
NeedComma = true;
|
|
|
|
}
|
2015-07-22 23:15:11 +02:00
|
|
|
|
|
|
|
if (MI.getDebugLoc()) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ',';
|
|
|
|
OS << " debug-location ";
|
|
|
|
MI.getDebugLoc()->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-04 01:08:19 +02:00
|
|
|
|
|
|
|
if (!MI.memoperands_empty()) {
|
|
|
|
OS << " :: ";
|
|
|
|
bool NeedComma = false;
|
|
|
|
for (const auto *Op : MI.memoperands()) {
|
|
|
|
if (NeedComma)
|
|
|
|
OS << ", ";
|
|
|
|
print(*Op);
|
|
|
|
NeedComma = true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 18:35:26 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 20:00:16 +02: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 01:24:37 +02:00
|
|
|
static void printIRSlotNumber(raw_ostream &OS, int Slot) {
|
|
|
|
if (Slot == -1)
|
|
|
|
OS << "<badref>";
|
|
|
|
else
|
|
|
|
OS << Slot;
|
|
|
|
}
|
|
|
|
|
2015-07-28 19:28:03 +02:00
|
|
|
void MIPrinter::printIRBlockReference(const BasicBlock &BB) {
|
|
|
|
OS << "%ir-block.";
|
|
|
|
if (BB.hasName()) {
|
|
|
|
printLLVMNameWithoutPrefix(OS, BB.getName());
|
|
|
|
return;
|
|
|
|
}
|
2015-08-07 01:57:04 +02: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 01:24:37 +02:00
|
|
|
printIRSlotNumber(OS, Slot);
|
2015-07-28 19:28:03 +02:00
|
|
|
}
|
|
|
|
|
2015-08-04 01:08:19 +02:00
|
|
|
void MIPrinter::printIRValueReference(const Value &V) {
|
2015-08-20 02:20:03 +02:00
|
|
|
if (isa<GlobalValue>(V)) {
|
|
|
|
V.printAsOperand(OS, /*PrintType=*/false, MST);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-21 23:54:12 +02:00
|
|
|
if (isa<Constant>(V)) {
|
|
|
|
// Machine memory operands can load/store to/from constant value pointers.
|
|
|
|
OS << '`';
|
|
|
|
V.printAsOperand(OS, /*PrintType=*/true, MST);
|
|
|
|
OS << '`';
|
|
|
|
return;
|
|
|
|
}
|
2015-08-04 01:08:19 +02:00
|
|
|
OS << "%ir.";
|
|
|
|
if (V.hasName()) {
|
|
|
|
printLLVMNameWithoutPrefix(OS, V.getName());
|
|
|
|
return;
|
|
|
|
}
|
2015-08-20 01:31:05 +02:00
|
|
|
printIRSlotNumber(OS, MST.getLocalSlot(&V));
|
2015-08-04 01:08:19 +02:00
|
|
|
}
|
|
|
|
|
2015-07-17 01:37:45 +02: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 00:26:15 +02:00
|
|
|
void MIPrinter::printOffset(int64_t Offset) {
|
|
|
|
if (Offset == 0)
|
|
|
|
return;
|
|
|
|
if (Offset < 0) {
|
|
|
|
OS << " - " << -Offset;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OS << " + " << Offset;
|
|
|
|
}
|
|
|
|
|
2015-08-06 02:44:07 +02: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 00:52:15 +02: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 02:44:07 +02:00
|
|
|
OS << ") ";
|
|
|
|
}
|
|
|
|
|
2015-07-29 01:02:45 +02: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-19 20:55:47 +02:00
|
|
|
void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI,
|
2016-09-12 13:20:10 +02:00
|
|
|
unsigned I, bool ShouldPrintRegisterTies, LLT TypeToPrint,
|
|
|
|
bool IsDef) {
|
2015-08-06 02:44:07 +02:00
|
|
|
printTargetFlags(Op);
|
2015-06-23 18:35:26 +02:00
|
|
|
switch (Op.getType()) {
|
|
|
|
case MachineOperand::MO_Register:
|
2015-07-07 01:07:26 +02:00
|
|
|
if (Op.isImplicit())
|
|
|
|
OS << (Op.isDef() ? "implicit-def " : "implicit ");
|
2015-08-19 20:55:47 +02:00
|
|
|
else if (!IsDef && Op.isDef())
|
|
|
|
// Print the 'def' flag only when the operand is defined after '='.
|
|
|
|
OS << "def ";
|
2015-08-14 21:07:07 +02:00
|
|
|
if (Op.isInternalRead())
|
|
|
|
OS << "internal ";
|
2015-07-07 22:34:53 +02:00
|
|
|
if (Op.isDead())
|
|
|
|
OS << "dead ";
|
2015-07-08 23:23:34 +02:00
|
|
|
if (Op.isKill())
|
|
|
|
OS << "killed ";
|
2015-07-09 01:58:31 +02:00
|
|
|
if (Op.isUndef())
|
|
|
|
OS << "undef ";
|
2015-08-05 19:49:03 +02:00
|
|
|
if (Op.isEarlyClobber())
|
|
|
|
OS << "early-clobber ";
|
2015-08-05 19:41:17 +02:00
|
|
|
if (Op.isDebug())
|
|
|
|
OS << "debug-use ";
|
2015-06-23 18:35:26 +02:00
|
|
|
printReg(Op.getReg(), OS, TRI);
|
2015-07-14 01:24:34 +02:00
|
|
|
// Print the sub register.
|
|
|
|
if (Op.getSubReg() != 0)
|
2016-07-26 23:49:34 +02:00
|
|
|
OS << '.' << TRI->getSubRegIndexName(Op.getSubReg());
|
2015-08-19 21:05:34 +02:00
|
|
|
if (ShouldPrintRegisterTies && Op.isTied() && !Op.isDef())
|
|
|
|
OS << "(tied-def " << Op.getParent()->findTiedOperandIdx(I) << ")";
|
2016-09-12 13:20:10 +02:00
|
|
|
if (TypeToPrint.isValid())
|
|
|
|
OS << '(' << TypeToPrint << ')';
|
2015-06-23 18:35:26 +02:00
|
|
|
break;
|
2015-06-24 01:42:28 +02:00
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
OS << Op.getImm();
|
|
|
|
break;
|
2015-08-05 20:52:21 +02:00
|
|
|
case MachineOperand::MO_CImmediate:
|
|
|
|
Op.getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
|
|
|
|
break;
|
2015-07-31 22:49:21 +02:00
|
|
|
case MachineOperand::MO_FPImmediate:
|
|
|
|
Op.getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
|
|
|
|
break;
|
2015-06-26 18:46:11 +02:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2015-06-30 20:00:16 +02:00
|
|
|
printMBBReference(*Op.getMBB());
|
2015-06-26 18:46:11 +02:00
|
|
|
break;
|
2015-07-17 01:37:45 +02:00
|
|
|
case MachineOperand::MO_FrameIndex:
|
|
|
|
printStackObjectReference(Op.getIndex());
|
|
|
|
break;
|
2015-07-20 22:51:18 +02:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
OS << "%const." << Op.getIndex();
|
2015-08-06 00:26:15 +02:00
|
|
|
printOffset(Op.getOffset());
|
2015-07-20 22:51:18 +02:00
|
|
|
break;
|
2017-06-07 00:22:41 +02:00
|
|
|
case MachineOperand::MO_TargetIndex:
|
2015-07-29 01:02:45 +02:00
|
|
|
OS << "target-index(";
|
|
|
|
if (const auto *Name = getTargetIndexName(
|
|
|
|
*Op.getParent()->getParent()->getParent(), Op.getIndex()))
|
|
|
|
OS << Name;
|
|
|
|
else
|
|
|
|
OS << "<unknown>";
|
|
|
|
OS << ')';
|
2015-08-06 00:26:15 +02:00
|
|
|
printOffset(Op.getOffset());
|
2015-07-29 01:02:45 +02:00
|
|
|
break;
|
2015-07-16 01:38:35 +02:00
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
OS << "%jump-table." << Op.getIndex();
|
|
|
|
break;
|
2017-06-06 21:00:58 +02:00
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
|
|
|
StringRef Name = Op.getSymbolName();
|
2015-07-21 18:59:53 +02:00
|
|
|
OS << '$';
|
2017-06-06 21:00:58 +02:00
|
|
|
if (Name.empty()) {
|
|
|
|
OS << "\"\"";
|
|
|
|
} else {
|
|
|
|
printLLVMNameWithoutPrefix(OS, Name);
|
|
|
|
}
|
2015-08-06 00:26:15 +02:00
|
|
|
printOffset(Op.getOffset());
|
2015-07-21 18:59:53 +02:00
|
|
|
break;
|
2017-06-06 21:00:58 +02:00
|
|
|
}
|
2015-06-27 00:56:48 +02:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2015-07-08 01:27:53 +02:00
|
|
|
Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
|
2015-08-06 00:26:15 +02:00
|
|
|
printOffset(Op.getOffset());
|
2015-06-27 00:56:48 +02:00
|
|
|
break;
|
2015-07-28 19:28:03 +02:00
|
|
|
case MachineOperand::MO_BlockAddress:
|
|
|
|
OS << "blockaddress(";
|
|
|
|
Op.getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
|
|
|
|
MST);
|
|
|
|
OS << ", ";
|
|
|
|
printIRBlockReference(*Op.getBlockAddress()->getBasicBlock());
|
|
|
|
OS << ')';
|
2015-08-06 00:26:15 +02:00
|
|
|
printOffset(Op.getOffset());
|
2015-07-28 19:28:03 +02:00
|
|
|
break;
|
2015-06-29 18:57:06 +02:00
|
|
|
case MachineOperand::MO_RegisterMask: {
|
|
|
|
auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
|
|
|
|
if (RegMaskInfo != RegisterMaskIds.end())
|
|
|
|
OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
|
|
|
|
else
|
2017-03-19 09:14:18 +01:00
|
|
|
printCustomRegMask(Op.getRegMask(), OS, TRI);
|
2015-06-29 18:57:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-08-11 01:24:42 +02: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-22 19:58:46 +02:00
|
|
|
case MachineOperand::MO_Metadata:
|
|
|
|
Op.getMetadata()->printAsOperand(OS, MST);
|
|
|
|
break;
|
2015-08-21 23:12:44 +02:00
|
|
|
case MachineOperand::MO_MCSymbol:
|
|
|
|
OS << "<mcsymbol " << *Op.getMCSymbol() << ">";
|
|
|
|
break;
|
2015-07-22 00:28:27 +02:00
|
|
|
case MachineOperand::MO_CFIIndex: {
|
2016-12-01 00:48:42 +01:00
|
|
|
const MachineFunction &MF = *Op.getParent()->getParent()->getParent();
|
|
|
|
print(MF.getFrameInstructions()[Op.getCFIIndex()], TRI);
|
2015-07-22 00:28:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 22:32:59 +02:00
|
|
|
case MachineOperand::MO_IntrinsicID: {
|
|
|
|
Intrinsic::ID ID = Op.getIntrinsicID();
|
|
|
|
if (ID < Intrinsic::num_intrinsics)
|
2016-08-23 00:27:05 +02:00
|
|
|
OS << "intrinsic(@" << Intrinsic::getName(ID, None) << ')';
|
2016-07-29 22:32:59 +02:00
|
|
|
else {
|
|
|
|
const MachineFunction &MF = *Op.getParent()->getParent()->getParent();
|
|
|
|
const TargetIntrinsicInfo *TII = MF.getTarget().getIntrinsicInfo();
|
|
|
|
OS << "intrinsic(@" << TII->getName(ID) << ')';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-08-17 22:25:25 +02:00
|
|
|
case MachineOperand::MO_Predicate: {
|
|
|
|
auto Pred = static_cast<CmpInst::Predicate>(Op.getPredicate());
|
|
|
|
OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred("
|
|
|
|
<< CmpInst::getPredicateName(Pred) << ')';
|
|
|
|
break;
|
|
|
|
}
|
2015-06-23 18:35:26 +02:00
|
|
|
}
|
2015-06-19 19:43:07 +02:00
|
|
|
}
|
|
|
|
|
2015-08-04 01:08:19 +02:00
|
|
|
void MIPrinter::print(const MachineMemOperand &Op) {
|
|
|
|
OS << '(';
|
2015-08-06 18:55:53 +02:00
|
|
|
// TODO: Print operand's target specific flags.
|
2015-08-04 02:24:45 +02:00
|
|
|
if (Op.isVolatile())
|
|
|
|
OS << "volatile ";
|
2015-08-06 18:49:30 +02:00
|
|
|
if (Op.isNonTemporal())
|
|
|
|
OS << "non-temporal ";
|
[CodeGen] Split out the notions of MI invariance and MI dereferenceability.
Summary:
An IR load can be invariant, dereferenceable, neither, or both. But
currently, MI's notion of invariance is IR-invariant &&
IR-dereferenceable.
This patch splits up the notions of invariance and dereferenceability at
the MI level. It's NFC, so adds some probably-unnecessary
"is-dereferenceable" checks, which we can remove later if desired.
Reviewers: chandlerc, tstellarAMD
Subscribers: jholewinski, arsenm, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D23371
llvm-svn: 281151
2016-09-11 03:38:58 +02:00
|
|
|
if (Op.isDereferenceable())
|
|
|
|
OS << "dereferenceable ";
|
2015-08-06 18:55:53 +02:00
|
|
|
if (Op.isInvariant())
|
|
|
|
OS << "invariant ";
|
2015-08-04 01:08:19 +02:00
|
|
|
if (Op.isLoad())
|
|
|
|
OS << "load ";
|
|
|
|
else {
|
|
|
|
assert(Op.isStore() && "Non load machine operand must be a store");
|
|
|
|
OS << "store ";
|
|
|
|
}
|
2017-02-13 23:14:08 +01:00
|
|
|
|
|
|
|
if (Op.getSynchScope() == SynchronizationScope::SingleThread)
|
|
|
|
OS << "singlethread ";
|
|
|
|
|
|
|
|
if (Op.getOrdering() != AtomicOrdering::NotAtomic)
|
|
|
|
OS << toIRString(Op.getOrdering()) << ' ';
|
|
|
|
if (Op.getFailureOrdering() != AtomicOrdering::NotAtomic)
|
|
|
|
OS << toIRString(Op.getFailureOrdering()) << ' ';
|
|
|
|
|
2016-06-04 02:06:31 +02:00
|
|
|
OS << Op.getSize();
|
2015-08-12 22:33:26 +02:00
|
|
|
if (const Value *Val = Op.getValue()) {
|
2016-06-04 02:06:31 +02:00
|
|
|
OS << (Op.isLoad() ? " from " : " into ");
|
2015-08-04 01:08:19 +02:00
|
|
|
printIRValueReference(*Val);
|
2016-06-04 02:06:31 +02:00
|
|
|
} else if (const PseudoSourceValue *PVal = Op.getPseudoValue()) {
|
|
|
|
OS << (Op.isLoad() ? " from " : " into ");
|
2015-08-12 22:33:26 +02:00
|
|
|
assert(PVal && "Expected a pseudo source value");
|
|
|
|
switch (PVal->kind()) {
|
2015-08-12 22:44:16 +02:00
|
|
|
case PseudoSourceValue::Stack:
|
|
|
|
OS << "stack";
|
|
|
|
break;
|
2015-08-12 23:00:22 +02:00
|
|
|
case PseudoSourceValue::GOT:
|
|
|
|
OS << "got";
|
|
|
|
break;
|
2015-08-12 23:11:08 +02:00
|
|
|
case PseudoSourceValue::JumpTable:
|
|
|
|
OS << "jump-table";
|
|
|
|
break;
|
2015-08-12 22:33:26 +02:00
|
|
|
case PseudoSourceValue::ConstantPool:
|
|
|
|
OS << "constant-pool";
|
|
|
|
break;
|
2015-08-12 23:23:17 +02:00
|
|
|
case PseudoSourceValue::FixedStack:
|
|
|
|
printStackObjectReference(
|
|
|
|
cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex());
|
|
|
|
break;
|
2015-08-14 23:08:30 +02:00
|
|
|
case PseudoSourceValue::GlobalValueCallEntry:
|
2015-08-20 02:12:57 +02:00
|
|
|
OS << "call-entry ";
|
2015-08-14 23:08:30 +02:00
|
|
|
cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
|
|
|
|
OS, /*PrintType=*/false, MST);
|
|
|
|
break;
|
2015-08-14 23:14:50 +02:00
|
|
|
case PseudoSourceValue::ExternalSymbolCallEntry:
|
2015-08-20 02:12:57 +02:00
|
|
|
OS << "call-entry $";
|
2015-08-14 23:14:50 +02:00
|
|
|
printLLVMNameWithoutPrefix(
|
|
|
|
OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
|
2015-08-12 22:33:26 +02:00
|
|
|
break;
|
2016-12-17 05:41:53 +01:00
|
|
|
case PseudoSourceValue::TargetCustom:
|
|
|
|
llvm_unreachable("TargetCustom pseudo source values are not supported");
|
|
|
|
break;
|
2015-08-12 22:33:26 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-07 22:26:52 +02:00
|
|
|
printOffset(Op.getOffset());
|
2015-08-07 22:48:30 +02:00
|
|
|
if (Op.getBaseAlignment() != Op.getSize())
|
|
|
|
OS << ", align " << Op.getBaseAlignment();
|
2015-08-18 00:05:15 +02:00
|
|
|
auto AAInfo = Op.getAAInfo();
|
|
|
|
if (AAInfo.TBAA) {
|
|
|
|
OS << ", !tbaa ";
|
|
|
|
AAInfo.TBAA->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-18 00:06:40 +02:00
|
|
|
if (AAInfo.Scope) {
|
|
|
|
OS << ", !alias.scope ";
|
|
|
|
AAInfo.Scope->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-18 00:08:02 +02:00
|
|
|
if (AAInfo.NoAlias) {
|
|
|
|
OS << ", !noalias ";
|
|
|
|
AAInfo.NoAlias->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-18 00:09:52 +02:00
|
|
|
if (Op.getRanges()) {
|
|
|
|
OS << ", !range ";
|
|
|
|
Op.getRanges()->printAsOperand(OS, MST);
|
|
|
|
}
|
2015-08-04 01:08:19 +02:00
|
|
|
OS << ')';
|
|
|
|
}
|
|
|
|
|
2015-07-24 01:09:07 +02: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 00:28:27 +02:00
|
|
|
switch (CFI.getOperation()) {
|
2015-08-14 23:55:58 +02:00
|
|
|
case MCCFIInstruction::OpSameValue:
|
2016-07-26 20:20:00 +02:00
|
|
|
OS << "same_value ";
|
2015-08-14 23:55:58 +02:00
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
break;
|
2015-07-24 01:09:07 +02:00
|
|
|
case MCCFIInstruction::OpOffset:
|
2016-07-26 20:20:00 +02:00
|
|
|
OS << "offset ";
|
2015-07-24 01:09:07 +02:00
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
OS << ", " << CFI.getOffset();
|
|
|
|
break;
|
2015-07-27 22:39:03 +02:00
|
|
|
case MCCFIInstruction::OpDefCfaRegister:
|
2016-07-26 20:20:00 +02:00
|
|
|
OS << "def_cfa_register ";
|
2015-07-27 22:39:03 +02:00
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
break;
|
2015-07-22 00:28:27 +02:00
|
|
|
case MCCFIInstruction::OpDefCfaOffset:
|
2016-07-26 20:20:00 +02:00
|
|
|
OS << "def_cfa_offset ";
|
2015-07-22 00:28:27 +02:00
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
OS << CFI.getOffset();
|
|
|
|
break;
|
2015-07-29 20:57:23 +02:00
|
|
|
case MCCFIInstruction::OpDefCfa:
|
2016-07-26 20:20:00 +02:00
|
|
|
OS << "def_cfa ";
|
2015-07-29 20:57:23 +02:00
|
|
|
if (CFI.getLabel())
|
|
|
|
OS << "<mcsymbol> ";
|
|
|
|
printCFIRegister(CFI.getRegister(), OS, TRI);
|
|
|
|
OS << ", " << CFI.getOffset();
|
|
|
|
break;
|
2015-07-22 00:28:27 +02:00
|
|
|
default:
|
|
|
|
// TODO: Print the other CFI Operations.
|
|
|
|
OS << "<unserializable cfi operation>";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 01:52:35 +02: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);
|
|
|
|
}
|