blob: 57e9d87514832f818206cf1f9e9ac546c1c63027 [file] [log] [blame]
Alex Lorenz345c1442015-06-15 23:52:35 +00001//===- MIRPrinter.cpp - MIR serialization format printer ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the class that prints out the LLVM IR and machine
11// functions using the MIR serialization format.
12//
13//===----------------------------------------------------------------------===//
14
15#include "MIRPrinter.h"
16#include "llvm/ADT/STLExtras.h"
Alex Lorenzab980492015-07-20 20:51:18 +000017#include "llvm/CodeGen/MachineConstantPool.h"
Alex Lorenz345c1442015-06-15 23:52:35 +000018#include "llvm/CodeGen/MachineFunction.h"
Alex Lorenz60541c12015-07-09 19:55:27 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
Alex Lorenz4af7e612015-08-03 23:08:19 +000020#include "llvm/CodeGen/MachineMemOperand.h"
Alex Lorenzf4baeb52015-07-21 22:28:27 +000021#include "llvm/CodeGen/MachineModuleInfo.h"
Alex Lorenz54565cf2015-06-24 19:56:10 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Alex Lorenz345c1442015-06-15 23:52:35 +000023#include "llvm/CodeGen/MIRYamlMapping.h"
Alex Lorenz4f093bf2015-06-19 17:43:07 +000024#include "llvm/IR/BasicBlock.h"
Alex Lorenzdeb53492015-07-28 17:28:03 +000025#include "llvm/IR/Constants.h"
Alex Lorenz37643a02015-07-15 22:14:49 +000026#include "llvm/IR/Instructions.h"
Alex Lorenz6ede3742015-07-21 16:59:53 +000027#include "llvm/IR/IRPrintingPasses.h"
Alex Lorenz345c1442015-06-15 23:52:35 +000028#include "llvm/IR/Module.h"
Alex Lorenz900b5cb2015-07-07 23:27:53 +000029#include "llvm/IR/ModuleSlotTracker.h"
Alex Lorenz345c1442015-06-15 23:52:35 +000030#include "llvm/Support/MemoryBuffer.h"
31#include "llvm/Support/raw_ostream.h"
32#include "llvm/Support/YAMLTraits.h"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000033#include "llvm/Target/TargetInstrInfo.h"
34#include "llvm/Target/TargetSubtargetInfo.h"
Alex Lorenz345c1442015-06-15 23:52:35 +000035
36using namespace llvm;
37
38namespace {
39
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000040/// This structure describes how to print out stack object references.
41struct FrameIndexOperand {
42 std::string Name;
43 unsigned ID;
44 bool IsFixed;
45
46 FrameIndexOperand(StringRef Name, unsigned ID, bool IsFixed)
47 : Name(Name.str()), ID(ID), IsFixed(IsFixed) {}
48
49 /// Return an ordinary stack object reference.
50 static FrameIndexOperand create(StringRef Name, unsigned ID) {
51 return FrameIndexOperand(Name, ID, /*IsFixed=*/false);
52 }
53
54 /// Return a fixed stack object reference.
55 static FrameIndexOperand createFixed(unsigned ID) {
56 return FrameIndexOperand("", ID, /*IsFixed=*/true);
57 }
58};
59
Alex Lorenz618b2832015-07-30 16:54:38 +000060} // end anonymous namespace
61
62namespace llvm {
63
Alex Lorenz345c1442015-06-15 23:52:35 +000064/// This class prints out the machine functions using the MIR serialization
65/// format.
66class MIRPrinter {
67 raw_ostream &OS;
Alex Lorenz8f6f4282015-06-29 16:57:06 +000068 DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000069 /// Maps from stack object indices to operand indices which will be used when
70 /// printing frame index machine operands.
71 DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;
Alex Lorenz345c1442015-06-15 23:52:35 +000072
73public:
74 MIRPrinter(raw_ostream &OS) : OS(OS) {}
75
76 void print(const MachineFunction &MF);
Alex Lorenz4f093bf2015-06-19 17:43:07 +000077
Alex Lorenz28148ba2015-07-09 22:23:13 +000078 void convert(yaml::MachineFunction &MF, const MachineRegisterInfo &RegInfo,
79 const TargetRegisterInfo *TRI);
Alex Lorenza6f9a372015-07-29 21:09:09 +000080 void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
81 const MachineFrameInfo &MFI);
Alex Lorenzab980492015-07-20 20:51:18 +000082 void convert(yaml::MachineFunction &MF,
83 const MachineConstantPool &ConstantPool);
Alex Lorenz6799e9b2015-07-15 23:31:07 +000084 void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
85 const MachineJumpTableInfo &JTI);
Alex Lorenzf6bc8662015-07-10 18:13:57 +000086 void convertStackObjects(yaml::MachineFunction &MF,
Alex Lorenz1bb48de2015-07-24 22:22:50 +000087 const MachineFrameInfo &MFI,
88 const TargetRegisterInfo *TRI);
Alex Lorenz8f6f4282015-06-29 16:57:06 +000089
90private:
91 void initRegisterMaskIds(const MachineFunction &MF);
Alex Lorenz345c1442015-06-15 23:52:35 +000092};
93
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000094/// This class prints out the machine instructions using the MIR serialization
95/// format.
96class MIPrinter {
97 raw_ostream &OS;
Alex Lorenz900b5cb2015-07-07 23:27:53 +000098 ModuleSlotTracker &MST;
Alex Lorenz8f6f4282015-06-29 16:57:06 +000099 const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000100 const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000101
102public:
Alex Lorenz900b5cb2015-07-07 23:27:53 +0000103 MIPrinter(raw_ostream &OS, ModuleSlotTracker &MST,
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000104 const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds,
105 const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping)
106 : OS(OS), MST(MST), RegisterMaskIds(RegisterMaskIds),
107 StackObjectOperandMapping(StackObjectOperandMapping) {}
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000108
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000109 void print(const MachineBasicBlock &MBB);
110
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000111 void print(const MachineInstr &MI);
Alex Lorenz5d26fa82015-06-30 18:00:16 +0000112 void printMBBReference(const MachineBasicBlock &MBB);
Alex Lorenzdeb53492015-07-28 17:28:03 +0000113 void printIRBlockReference(const BasicBlock &BB);
Alex Lorenz4af7e612015-08-03 23:08:19 +0000114 void printIRValueReference(const Value &V);
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000115 void printStackObjectReference(int FrameIndex);
Alex Lorenz5672a892015-08-05 22:26:15 +0000116 void printOffset(int64_t Offset);
Alex Lorenz49873a82015-08-06 00:44:07 +0000117 void printTargetFlags(const MachineOperand &Op);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000118 void print(const MachineOperand &Op, const TargetRegisterInfo *TRI);
Alex Lorenz4af7e612015-08-03 23:08:19 +0000119 void print(const MachineMemOperand &Op);
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000120
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000121 void print(const MCCFIInstruction &CFI, const TargetRegisterInfo *TRI);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000122};
123
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000124} // end namespace llvm
Alex Lorenz345c1442015-06-15 23:52:35 +0000125
126namespace llvm {
127namespace yaml {
128
129/// This struct serializes the LLVM IR module.
130template <> struct BlockScalarTraits<Module> {
131 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
132 Mod.print(OS, nullptr);
133 }
134 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
135 llvm_unreachable("LLVM Module is supposed to be parsed separately");
136 return "";
137 }
138};
139
140} // end namespace yaml
141} // end namespace llvm
142
Alex Lorenz15a00a82015-07-14 21:18:25 +0000143static void printReg(unsigned Reg, raw_ostream &OS,
144 const TargetRegisterInfo *TRI) {
145 // TODO: Print Stack Slots.
146 if (!Reg)
147 OS << '_';
148 else if (TargetRegisterInfo::isVirtualRegister(Reg))
149 OS << '%' << TargetRegisterInfo::virtReg2Index(Reg);
150 else if (Reg < TRI->getNumRegs())
151 OS << '%' << StringRef(TRI->getName(Reg)).lower();
152 else
153 llvm_unreachable("Can't print this kind of register yet");
154}
155
Alex Lorenzab4cbcf2015-07-24 20:35:40 +0000156static void printReg(unsigned Reg, yaml::StringValue &Dest,
157 const TargetRegisterInfo *TRI) {
158 raw_string_ostream OS(Dest.Value);
159 printReg(Reg, OS, TRI);
160}
161
Alex Lorenz345c1442015-06-15 23:52:35 +0000162void MIRPrinter::print(const MachineFunction &MF) {
Alex Lorenz8f6f4282015-06-29 16:57:06 +0000163 initRegisterMaskIds(MF);
164
Alex Lorenz345c1442015-06-15 23:52:35 +0000165 yaml::MachineFunction YamlMF;
166 YamlMF.Name = MF.getName();
Alex Lorenz5b5f9752015-06-16 00:10:47 +0000167 YamlMF.Alignment = MF.getAlignment();
168 YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice();
169 YamlMF.HasInlineAsm = MF.hasInlineAsm();
Alex Lorenz28148ba2015-07-09 22:23:13 +0000170 convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
Alex Lorenza6f9a372015-07-29 21:09:09 +0000171 ModuleSlotTracker MST(MF.getFunction()->getParent());
172 MST.incorporateFunction(*MF.getFunction());
173 convert(MST, YamlMF.FrameInfo, *MF.getFrameInfo());
Alex Lorenz1bb48de2015-07-24 22:22:50 +0000174 convertStackObjects(YamlMF, *MF.getFrameInfo(),
175 MF.getSubtarget().getRegisterInfo());
Alex Lorenzab980492015-07-20 20:51:18 +0000176 if (const auto *ConstantPool = MF.getConstantPool())
177 convert(YamlMF, *ConstantPool);
Alex Lorenz6799e9b2015-07-15 23:31:07 +0000178 if (const auto *JumpTableInfo = MF.getJumpTableInfo())
179 convert(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000180 raw_string_ostream StrOS(YamlMF.Body.Value.Value);
181 bool IsNewlineNeeded = false;
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000182 for (const auto &MBB : MF) {
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000183 if (IsNewlineNeeded)
184 StrOS << "\n";
185 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
186 .print(MBB);
187 IsNewlineNeeded = true;
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000188 }
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000189 StrOS.flush();
Alex Lorenz345c1442015-06-15 23:52:35 +0000190 yaml::Output Out(OS);
191 Out << YamlMF;
192}
193
Alex Lorenz54565cf2015-06-24 19:56:10 +0000194void MIRPrinter::convert(yaml::MachineFunction &MF,
Alex Lorenz28148ba2015-07-09 22:23:13 +0000195 const MachineRegisterInfo &RegInfo,
196 const TargetRegisterInfo *TRI) {
Alex Lorenz54565cf2015-06-24 19:56:10 +0000197 MF.IsSSA = RegInfo.isSSA();
198 MF.TracksRegLiveness = RegInfo.tracksLiveness();
199 MF.TracksSubRegLiveness = RegInfo.subRegLivenessEnabled();
Alex Lorenz28148ba2015-07-09 22:23:13 +0000200
201 // Print the virtual register definitions.
202 for (unsigned I = 0, E = RegInfo.getNumVirtRegs(); I < E; ++I) {
203 unsigned Reg = TargetRegisterInfo::index2VirtReg(I);
204 yaml::VirtualRegisterDefinition VReg;
205 VReg.ID = I;
206 VReg.Class =
207 StringRef(TRI->getRegClassName(RegInfo.getRegClass(Reg))).lower();
Alex Lorenzab4cbcf2015-07-24 20:35:40 +0000208 unsigned PreferredReg = RegInfo.getSimpleHint(Reg);
209 if (PreferredReg)
210 printReg(PreferredReg, VReg.PreferredRegister, TRI);
Alex Lorenz28148ba2015-07-09 22:23:13 +0000211 MF.VirtualRegisters.push_back(VReg);
212 }
Alex Lorenz12045a42015-07-27 17:42:45 +0000213
214 // Print the live ins.
215 for (auto I = RegInfo.livein_begin(), E = RegInfo.livein_end(); I != E; ++I) {
216 yaml::MachineFunctionLiveIn LiveIn;
217 printReg(I->first, LiveIn.Register, TRI);
218 if (I->second)
219 printReg(I->second, LiveIn.VirtualRegister, TRI);
220 MF.LiveIns.push_back(LiveIn);
221 }
Alex Lorenzc4838082015-08-11 00:32:49 +0000222 // The used physical register mask is printed as an inverted callee saved
223 // register mask.
224 const BitVector &UsedPhysRegMask = RegInfo.getUsedPhysRegsMask();
225 if (UsedPhysRegMask.none())
226 return;
227 std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
228 for (unsigned I = 0, E = UsedPhysRegMask.size(); I != E; ++I) {
229 if (!UsedPhysRegMask[I]) {
230 yaml::FlowStringValue Reg;
231 printReg(I, Reg, TRI);
232 CalleeSavedRegisters.push_back(Reg);
233 }
234 }
235 MF.CalleeSavedRegisters = CalleeSavedRegisters;
Alex Lorenz54565cf2015-06-24 19:56:10 +0000236}
237
Alex Lorenza6f9a372015-07-29 21:09:09 +0000238void MIRPrinter::convert(ModuleSlotTracker &MST,
239 yaml::MachineFrameInfo &YamlMFI,
Alex Lorenz60541c12015-07-09 19:55:27 +0000240 const MachineFrameInfo &MFI) {
241 YamlMFI.IsFrameAddressTaken = MFI.isFrameAddressTaken();
242 YamlMFI.IsReturnAddressTaken = MFI.isReturnAddressTaken();
243 YamlMFI.HasStackMap = MFI.hasStackMap();
244 YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
245 YamlMFI.StackSize = MFI.getStackSize();
246 YamlMFI.OffsetAdjustment = MFI.getOffsetAdjustment();
247 YamlMFI.MaxAlignment = MFI.getMaxAlignment();
248 YamlMFI.AdjustsStack = MFI.adjustsStack();
249 YamlMFI.HasCalls = MFI.hasCalls();
250 YamlMFI.MaxCallFrameSize = MFI.getMaxCallFrameSize();
251 YamlMFI.HasOpaqueSPAdjustment = MFI.hasOpaqueSPAdjustment();
252 YamlMFI.HasVAStart = MFI.hasVAStart();
253 YamlMFI.HasMustTailInVarArgFunc = MFI.hasMustTailInVarArgFunc();
Alex Lorenza6f9a372015-07-29 21:09:09 +0000254 if (MFI.getSavePoint()) {
255 raw_string_ostream StrOS(YamlMFI.SavePoint.Value);
256 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
257 .printMBBReference(*MFI.getSavePoint());
258 }
259 if (MFI.getRestorePoint()) {
260 raw_string_ostream StrOS(YamlMFI.RestorePoint.Value);
261 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
262 .printMBBReference(*MFI.getRestorePoint());
263 }
Alex Lorenz60541c12015-07-09 19:55:27 +0000264}
265
Alex Lorenzf6bc8662015-07-10 18:13:57 +0000266void MIRPrinter::convertStackObjects(yaml::MachineFunction &MF,
Alex Lorenz1bb48de2015-07-24 22:22:50 +0000267 const MachineFrameInfo &MFI,
268 const TargetRegisterInfo *TRI) {
Alex Lorenzde491f02015-07-13 18:07:26 +0000269 // Process fixed stack objects.
Alex Lorenzf6bc8662015-07-10 18:13:57 +0000270 unsigned ID = 0;
Alex Lorenzde491f02015-07-13 18:07:26 +0000271 for (int I = MFI.getObjectIndexBegin(); I < 0; ++I) {
272 if (MFI.isDeadObjectIndex(I))
273 continue;
274
275 yaml::FixedMachineStackObject YamlObject;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000276 YamlObject.ID = ID;
Alex Lorenzde491f02015-07-13 18:07:26 +0000277 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
278 ? yaml::FixedMachineStackObject::SpillSlot
279 : yaml::FixedMachineStackObject::DefaultType;
280 YamlObject.Offset = MFI.getObjectOffset(I);
281 YamlObject.Size = MFI.getObjectSize(I);
282 YamlObject.Alignment = MFI.getObjectAlignment(I);
283 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
284 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
285 MF.FixedStackObjects.push_back(YamlObject);
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000286 StackObjectOperandMapping.insert(
287 std::make_pair(I, FrameIndexOperand::createFixed(ID++)));
Alex Lorenzde491f02015-07-13 18:07:26 +0000288 }
289
290 // Process ordinary stack objects.
291 ID = 0;
Alex Lorenzf6bc8662015-07-10 18:13:57 +0000292 for (int I = 0, E = MFI.getObjectIndexEnd(); I < E; ++I) {
293 if (MFI.isDeadObjectIndex(I))
294 continue;
295
296 yaml::MachineStackObject YamlObject;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000297 YamlObject.ID = ID;
Alex Lorenz37643a02015-07-15 22:14:49 +0000298 if (const auto *Alloca = MFI.getObjectAllocation(I))
299 YamlObject.Name.Value =
300 Alloca->hasName() ? Alloca->getName() : "<unnamed alloca>";
Alex Lorenzf6bc8662015-07-10 18:13:57 +0000301 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
302 ? yaml::MachineStackObject::SpillSlot
Alex Lorenz418f3ec2015-07-14 00:26:26 +0000303 : MFI.isVariableSizedObjectIndex(I)
304 ? yaml::MachineStackObject::VariableSized
305 : yaml::MachineStackObject::DefaultType;
Alex Lorenzf6bc8662015-07-10 18:13:57 +0000306 YamlObject.Offset = MFI.getObjectOffset(I);
307 YamlObject.Size = MFI.getObjectSize(I);
308 YamlObject.Alignment = MFI.getObjectAlignment(I);
309
310 MF.StackObjects.push_back(YamlObject);
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000311 StackObjectOperandMapping.insert(std::make_pair(
312 I, FrameIndexOperand::create(YamlObject.Name.Value, ID++)));
Alex Lorenzf6bc8662015-07-10 18:13:57 +0000313 }
Alex Lorenz1bb48de2015-07-24 22:22:50 +0000314
315 for (const auto &CSInfo : MFI.getCalleeSavedInfo()) {
316 yaml::StringValue Reg;
317 printReg(CSInfo.getReg(), Reg, TRI);
318 auto StackObjectInfo = StackObjectOperandMapping.find(CSInfo.getFrameIdx());
319 assert(StackObjectInfo != StackObjectOperandMapping.end() &&
320 "Invalid stack object index");
321 const FrameIndexOperand &StackObject = StackObjectInfo->second;
322 if (StackObject.IsFixed)
323 MF.FixedStackObjects[StackObject.ID].CalleeSavedRegister = Reg;
324 else
325 MF.StackObjects[StackObject.ID].CalleeSavedRegister = Reg;
326 }
Alex Lorenza56ba6a2015-08-17 22:17:42 +0000327 for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) {
328 auto LocalObject = MFI.getLocalFrameObjectMap(I);
329 auto StackObjectInfo = StackObjectOperandMapping.find(LocalObject.first);
330 assert(StackObjectInfo != StackObjectOperandMapping.end() &&
331 "Invalid stack object index");
332 const FrameIndexOperand &StackObject = StackObjectInfo->second;
333 assert(!StackObject.IsFixed && "Expected a locally mapped stack object");
334 MF.StackObjects[StackObject.ID].LocalOffset = LocalObject.second;
335 }
Alex Lorenzf6bc8662015-07-10 18:13:57 +0000336}
337
Alex Lorenzab980492015-07-20 20:51:18 +0000338void MIRPrinter::convert(yaml::MachineFunction &MF,
339 const MachineConstantPool &ConstantPool) {
340 unsigned ID = 0;
341 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
342 // TODO: Serialize target specific constant pool entries.
343 if (Constant.isMachineConstantPoolEntry())
344 llvm_unreachable("Can't print target specific constant pool entries yet");
345
346 yaml::MachineConstantPoolValue YamlConstant;
347 std::string Str;
348 raw_string_ostream StrOS(Str);
349 Constant.Val.ConstVal->printAsOperand(StrOS);
350 YamlConstant.ID = ID++;
351 YamlConstant.Value = StrOS.str();
352 YamlConstant.Alignment = Constant.getAlignment();
353 MF.Constants.push_back(YamlConstant);
354 }
355}
356
Alex Lorenz900b5cb2015-07-07 23:27:53 +0000357void MIRPrinter::convert(ModuleSlotTracker &MST,
Alex Lorenz6799e9b2015-07-15 23:31:07 +0000358 yaml::MachineJumpTable &YamlJTI,
359 const MachineJumpTableInfo &JTI) {
360 YamlJTI.Kind = JTI.getEntryKind();
361 unsigned ID = 0;
362 for (const auto &Table : JTI.getJumpTables()) {
363 std::string Str;
364 yaml::MachineJumpTable::Entry Entry;
365 Entry.ID = ID++;
366 for (const auto *MBB : Table.MBBs) {
367 raw_string_ostream StrOS(Str);
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000368 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
369 .printMBBReference(*MBB);
Alex Lorenz6799e9b2015-07-15 23:31:07 +0000370 Entry.Blocks.push_back(StrOS.str());
371 Str.clear();
372 }
373 YamlJTI.Entries.push_back(Entry);
374 }
375}
376
Alex Lorenz8f6f4282015-06-29 16:57:06 +0000377void MIRPrinter::initRegisterMaskIds(const MachineFunction &MF) {
378 const auto *TRI = MF.getSubtarget().getRegisterInfo();
379 unsigned I = 0;
380 for (const uint32_t *Mask : TRI->getRegMasks())
381 RegisterMaskIds.insert(std::make_pair(Mask, I++));
382}
383
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000384void MIPrinter::print(const MachineBasicBlock &MBB) {
385 assert(MBB.getNumber() >= 0 && "Invalid MBB number");
386 OS << "bb." << MBB.getNumber();
387 bool HasAttributes = false;
388 if (const auto *BB = MBB.getBasicBlock()) {
389 if (BB->hasName()) {
390 OS << "." << BB->getName();
391 } else {
392 HasAttributes = true;
393 OS << " (";
394 int Slot = MST.getLocalSlot(BB);
395 if (Slot == -1)
396 OS << "<ir-block badref>";
397 else
398 OS << (Twine("%ir-block.") + Twine(Slot)).str();
399 }
400 }
401 if (MBB.hasAddressTaken()) {
402 OS << (HasAttributes ? ", " : " (");
403 OS << "address-taken";
404 HasAttributes = true;
405 }
406 if (MBB.isLandingPad()) {
407 OS << (HasAttributes ? ", " : " (");
408 OS << "landing-pad";
409 HasAttributes = true;
410 }
411 if (MBB.getAlignment()) {
412 OS << (HasAttributes ? ", " : " (");
413 OS << "align " << MBB.getAlignment();
414 HasAttributes = true;
415 }
416 if (HasAttributes)
417 OS << ")";
418 OS << ":\n";
419
420 bool HasLineAttributes = false;
421 // Print the successors
422 if (!MBB.succ_empty()) {
423 OS.indent(2) << "successors: ";
424 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
425 if (I != MBB.succ_begin())
426 OS << ", ";
427 printMBBReference(**I);
428 if (MBB.hasSuccessorWeights())
429 OS << '(' << MBB.getSuccWeight(I) << ')';
430 }
431 OS << "\n";
432 HasLineAttributes = true;
433 }
434
435 // Print the live in registers.
436 const auto *TRI = MBB.getParent()->getSubtarget().getRegisterInfo();
437 assert(TRI && "Expected target register info");
438 if (!MBB.livein_empty()) {
439 OS.indent(2) << "liveins: ";
440 for (auto I = MBB.livein_begin(), E = MBB.livein_end(); I != E; ++I) {
441 if (I != MBB.livein_begin())
442 OS << ", ";
443 printReg(*I, OS, TRI);
444 }
445 OS << "\n";
446 HasLineAttributes = true;
447 }
448
449 if (HasLineAttributes)
450 OS << "\n";
Alex Lorenzf9a2b122015-08-14 18:57:24 +0000451 bool IsInBundle = false;
452 for (auto I = MBB.instr_begin(), E = MBB.instr_end(); I != E; ++I) {
453 const MachineInstr &MI = *I;
454 if (IsInBundle && !MI.isInsideBundle()) {
455 OS.indent(2) << "}\n";
456 IsInBundle = false;
457 }
458 OS.indent(IsInBundle ? 4 : 2);
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000459 print(MI);
Alex Lorenzf9a2b122015-08-14 18:57:24 +0000460 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
461 OS << " {";
462 IsInBundle = true;
463 }
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000464 OS << "\n";
465 }
Alex Lorenzf9a2b122015-08-14 18:57:24 +0000466 if (IsInBundle)
467 OS.indent(2) << "}\n";
Alex Lorenz5022f6b2015-08-13 23:10:16 +0000468}
469
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000470void MIPrinter::print(const MachineInstr &MI) {
471 const auto &SubTarget = MI.getParent()->getParent()->getSubtarget();
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000472 const auto *TRI = SubTarget.getRegisterInfo();
473 assert(TRI && "Expected target register info");
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000474 const auto *TII = SubTarget.getInstrInfo();
475 assert(TII && "Expected target instruction info");
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000476 if (MI.isCFIInstruction())
477 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000478
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000479 unsigned I = 0, E = MI.getNumOperands();
480 for (; I < E && MI.getOperand(I).isReg() && MI.getOperand(I).isDef() &&
481 !MI.getOperand(I).isImplicit();
482 ++I) {
483 if (I)
484 OS << ", ";
485 print(MI.getOperand(I), TRI);
486 }
487
488 if (I)
489 OS << " = ";
Alex Lorenze5a44662015-07-17 00:24:15 +0000490 if (MI.getFlag(MachineInstr::FrameSetup))
491 OS << "frame-setup ";
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000492 OS << TII->getName(MI.getOpcode());
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000493 if (I < E)
494 OS << ' ';
495
496 bool NeedComma = false;
497 for (; I < E; ++I) {
498 if (NeedComma)
499 OS << ", ";
500 print(MI.getOperand(I), TRI);
501 NeedComma = true;
502 }
Alex Lorenz46d760d2015-07-22 21:15:11 +0000503
504 if (MI.getDebugLoc()) {
505 if (NeedComma)
506 OS << ',';
507 OS << " debug-location ";
508 MI.getDebugLoc()->printAsOperand(OS, MST);
509 }
Alex Lorenz4af7e612015-08-03 23:08:19 +0000510
511 if (!MI.memoperands_empty()) {
512 OS << " :: ";
513 bool NeedComma = false;
514 for (const auto *Op : MI.memoperands()) {
515 if (NeedComma)
516 OS << ", ";
517 print(*Op);
518 NeedComma = true;
519 }
520 }
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000521}
522
Alex Lorenz5d26fa82015-06-30 18:00:16 +0000523void MIPrinter::printMBBReference(const MachineBasicBlock &MBB) {
524 OS << "%bb." << MBB.getNumber();
525 if (const auto *BB = MBB.getBasicBlock()) {
526 if (BB->hasName())
527 OS << '.' << BB->getName();
528 }
529}
530
Alex Lorenzdeb53492015-07-28 17:28:03 +0000531void MIPrinter::printIRBlockReference(const BasicBlock &BB) {
532 OS << "%ir-block.";
533 if (BB.hasName()) {
534 printLLVMNameWithoutPrefix(OS, BB.getName());
535 return;
536 }
Alex Lorenzcba8c5f2015-08-06 23:57:04 +0000537 const Function *F = BB.getParent();
538 int Slot;
539 if (F == MST.getCurrentFunction()) {
540 Slot = MST.getLocalSlot(&BB);
541 } else {
542 ModuleSlotTracker CustomMST(F->getParent(),
543 /*ShouldInitializeAllMetadata=*/false);
544 CustomMST.incorporateFunction(*F);
545 Slot = CustomMST.getLocalSlot(&BB);
546 }
Alex Lorenzdeb53492015-07-28 17:28:03 +0000547 if (Slot == -1)
548 OS << "<badref>";
549 else
550 OS << Slot;
551}
552
Alex Lorenz4af7e612015-08-03 23:08:19 +0000553void MIPrinter::printIRValueReference(const Value &V) {
554 OS << "%ir.";
555 if (V.hasName()) {
556 printLLVMNameWithoutPrefix(OS, V.getName());
557 return;
558 }
559 // TODO: Serialize the unnamed IR value references.
560 OS << "<unserializable ir value>";
561}
562
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000563void MIPrinter::printStackObjectReference(int FrameIndex) {
564 auto ObjectInfo = StackObjectOperandMapping.find(FrameIndex);
565 assert(ObjectInfo != StackObjectOperandMapping.end() &&
566 "Invalid frame index");
567 const FrameIndexOperand &Operand = ObjectInfo->second;
568 if (Operand.IsFixed) {
569 OS << "%fixed-stack." << Operand.ID;
570 return;
571 }
572 OS << "%stack." << Operand.ID;
573 if (!Operand.Name.empty())
574 OS << '.' << Operand.Name;
575}
576
Alex Lorenz5672a892015-08-05 22:26:15 +0000577void MIPrinter::printOffset(int64_t Offset) {
578 if (Offset == 0)
579 return;
580 if (Offset < 0) {
581 OS << " - " << -Offset;
582 return;
583 }
584 OS << " + " << Offset;
585}
586
Alex Lorenz49873a82015-08-06 00:44:07 +0000587static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) {
588 auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
589 for (const auto &I : Flags) {
590 if (I.first == TF) {
591 return I.second;
592 }
593 }
594 return nullptr;
595}
596
597void MIPrinter::printTargetFlags(const MachineOperand &Op) {
598 if (!Op.getTargetFlags())
599 return;
600 const auto *TII =
601 Op.getParent()->getParent()->getParent()->getSubtarget().getInstrInfo();
602 assert(TII && "expected instruction info");
603 auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags());
604 OS << "target-flags(";
605 if (const auto *Name = getTargetFlagName(TII, Flags.first))
606 OS << Name;
607 else
608 OS << "<unknown target flag>";
609 // TODO: Print the target's bit flags.
610 OS << ") ";
611}
612
Alex Lorenzef5c1962015-07-28 23:02:45 +0000613static const char *getTargetIndexName(const MachineFunction &MF, int Index) {
614 const auto *TII = MF.getSubtarget().getInstrInfo();
615 assert(TII && "expected instruction info");
616 auto Indices = TII->getSerializableTargetIndices();
617 for (const auto &I : Indices) {
618 if (I.first == Index) {
619 return I.second;
620 }
621 }
622 return nullptr;
623}
624
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000625void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI) {
Alex Lorenz49873a82015-08-06 00:44:07 +0000626 printTargetFlags(Op);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000627 switch (Op.getType()) {
628 case MachineOperand::MO_Register:
Alex Lorenz1039fd12015-08-14 19:07:07 +0000629 // FIXME: Serialize the tied register.
Alex Lorenzcb268d42015-07-06 23:07:26 +0000630 if (Op.isImplicit())
631 OS << (Op.isDef() ? "implicit-def " : "implicit ");
Alex Lorenz1039fd12015-08-14 19:07:07 +0000632 if (Op.isInternalRead())
633 OS << "internal ";
Alex Lorenzcbbfd0b2015-07-07 20:34:53 +0000634 if (Op.isDead())
635 OS << "dead ";
Alex Lorenz495ad872015-07-08 21:23:34 +0000636 if (Op.isKill())
637 OS << "killed ";
Alex Lorenz4d026b892015-07-08 23:58:31 +0000638 if (Op.isUndef())
639 OS << "undef ";
Alex Lorenz01c1a5e2015-08-05 17:49:03 +0000640 if (Op.isEarlyClobber())
641 OS << "early-clobber ";
Alex Lorenz90752582015-08-05 17:41:17 +0000642 if (Op.isDebug())
643 OS << "debug-use ";
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000644 printReg(Op.getReg(), OS, TRI);
Alex Lorenz2eacca82015-07-13 23:24:34 +0000645 // Print the sub register.
646 if (Op.getSubReg() != 0)
647 OS << ':' << TRI->getSubRegIndexName(Op.getSubReg());
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000648 break;
Alex Lorenz240fc1e2015-06-23 23:42:28 +0000649 case MachineOperand::MO_Immediate:
650 OS << Op.getImm();
651 break;
Alex Lorenz05e38822015-08-05 18:52:21 +0000652 case MachineOperand::MO_CImmediate:
653 Op.getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
654 break;
Alex Lorenzad156fb2015-07-31 20:49:21 +0000655 case MachineOperand::MO_FPImmediate:
656 Op.getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
657 break;
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000658 case MachineOperand::MO_MachineBasicBlock:
Alex Lorenz5d26fa82015-06-30 18:00:16 +0000659 printMBBReference(*Op.getMBB());
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000660 break;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000661 case MachineOperand::MO_FrameIndex:
662 printStackObjectReference(Op.getIndex());
663 break;
Alex Lorenzab980492015-07-20 20:51:18 +0000664 case MachineOperand::MO_ConstantPoolIndex:
665 OS << "%const." << Op.getIndex();
Alex Lorenz5672a892015-08-05 22:26:15 +0000666 printOffset(Op.getOffset());
Alex Lorenzab980492015-07-20 20:51:18 +0000667 break;
Alex Lorenzef5c1962015-07-28 23:02:45 +0000668 case MachineOperand::MO_TargetIndex: {
669 OS << "target-index(";
670 if (const auto *Name = getTargetIndexName(
671 *Op.getParent()->getParent()->getParent(), Op.getIndex()))
672 OS << Name;
673 else
674 OS << "<unknown>";
675 OS << ')';
Alex Lorenz5672a892015-08-05 22:26:15 +0000676 printOffset(Op.getOffset());
Alex Lorenzef5c1962015-07-28 23:02:45 +0000677 break;
678 }
Alex Lorenz31d70682015-07-15 23:38:35 +0000679 case MachineOperand::MO_JumpTableIndex:
680 OS << "%jump-table." << Op.getIndex();
Alex Lorenz31d70682015-07-15 23:38:35 +0000681 break;
Alex Lorenz6ede3742015-07-21 16:59:53 +0000682 case MachineOperand::MO_ExternalSymbol:
683 OS << '$';
684 printLLVMNameWithoutPrefix(OS, Op.getSymbolName());
Alex Lorenz5672a892015-08-05 22:26:15 +0000685 printOffset(Op.getOffset());
Alex Lorenz6ede3742015-07-21 16:59:53 +0000686 break;
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000687 case MachineOperand::MO_GlobalAddress:
Alex Lorenz900b5cb2015-07-07 23:27:53 +0000688 Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
Alex Lorenz5672a892015-08-05 22:26:15 +0000689 printOffset(Op.getOffset());
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000690 break;
Alex Lorenzdeb53492015-07-28 17:28:03 +0000691 case MachineOperand::MO_BlockAddress:
692 OS << "blockaddress(";
693 Op.getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false,
694 MST);
695 OS << ", ";
696 printIRBlockReference(*Op.getBlockAddress()->getBasicBlock());
697 OS << ')';
Alex Lorenz5672a892015-08-05 22:26:15 +0000698 printOffset(Op.getOffset());
Alex Lorenzdeb53492015-07-28 17:28:03 +0000699 break;
Alex Lorenz8f6f4282015-06-29 16:57:06 +0000700 case MachineOperand::MO_RegisterMask: {
701 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
702 if (RegMaskInfo != RegisterMaskIds.end())
703 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
704 else
705 llvm_unreachable("Can't print this machine register mask yet.");
706 break;
707 }
Alex Lorenzb97c9ef2015-08-10 23:24:42 +0000708 case MachineOperand::MO_RegisterLiveOut: {
709 const uint32_t *RegMask = Op.getRegLiveOut();
710 OS << "liveout(";
711 bool IsCommaNeeded = false;
712 for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
713 if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
714 if (IsCommaNeeded)
715 OS << ", ";
716 printReg(Reg, OS, TRI);
717 IsCommaNeeded = true;
718 }
719 }
720 OS << ")";
721 break;
722 }
Alex Lorenz35e44462015-07-22 17:58:46 +0000723 case MachineOperand::MO_Metadata:
724 Op.getMetadata()->printAsOperand(OS, MST);
725 break;
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000726 case MachineOperand::MO_CFIIndex: {
727 const auto &MMI = Op.getParent()->getParent()->getParent()->getMMI();
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000728 print(MMI.getFrameInstructions()[Op.getCFIIndex()], TRI);
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000729 break;
730 }
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000731 default:
732 // TODO: Print the other machine operands.
733 llvm_unreachable("Can't print this machine operand at the moment");
734 }
Alex Lorenz4f093bf2015-06-19 17:43:07 +0000735}
736
Alex Lorenz4af7e612015-08-03 23:08:19 +0000737void MIPrinter::print(const MachineMemOperand &Op) {
738 OS << '(';
Alex Lorenzdc8de2a2015-08-06 16:55:53 +0000739 // TODO: Print operand's target specific flags.
Alex Lorenza518b792015-08-04 00:24:45 +0000740 if (Op.isVolatile())
741 OS << "volatile ";
Alex Lorenz10fd0382015-08-06 16:49:30 +0000742 if (Op.isNonTemporal())
743 OS << "non-temporal ";
Alex Lorenzdc8de2a2015-08-06 16:55:53 +0000744 if (Op.isInvariant())
745 OS << "invariant ";
Alex Lorenz4af7e612015-08-03 23:08:19 +0000746 if (Op.isLoad())
747 OS << "load ";
748 else {
749 assert(Op.isStore() && "Non load machine operand must be a store");
750 OS << "store ";
751 }
752 OS << Op.getSize() << (Op.isLoad() ? " from " : " into ");
Alex Lorenz91097a32015-08-12 20:33:26 +0000753 if (const Value *Val = Op.getValue()) {
Alex Lorenz4af7e612015-08-03 23:08:19 +0000754 printIRValueReference(*Val);
Alex Lorenz91097a32015-08-12 20:33:26 +0000755 } else {
756 const PseudoSourceValue *PVal = Op.getPseudoValue();
757 assert(PVal && "Expected a pseudo source value");
758 switch (PVal->kind()) {
Alex Lorenz46e95582015-08-12 20:44:16 +0000759 case PseudoSourceValue::Stack:
760 OS << "stack";
761 break;
Alex Lorenzd858f872015-08-12 21:00:22 +0000762 case PseudoSourceValue::GOT:
763 OS << "got";
764 break;
Alex Lorenz4be56e92015-08-12 21:11:08 +0000765 case PseudoSourceValue::JumpTable:
766 OS << "jump-table";
767 break;
Alex Lorenz91097a32015-08-12 20:33:26 +0000768 case PseudoSourceValue::ConstantPool:
769 OS << "constant-pool";
770 break;
Alex Lorenz0cc671b2015-08-12 21:23:17 +0000771 case PseudoSourceValue::FixedStack:
772 printStackObjectReference(
773 cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex());
774 break;
Alex Lorenz50b826f2015-08-14 21:08:30 +0000775 case PseudoSourceValue::GlobalValueCallEntry:
776 cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand(
777 OS, /*PrintType=*/false, MST);
778 break;
Alex Lorenzc3ba7502015-08-14 21:14:50 +0000779 case PseudoSourceValue::ExternalSymbolCallEntry:
780 OS << '$';
781 printLLVMNameWithoutPrefix(
782 OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
Alex Lorenz91097a32015-08-12 20:33:26 +0000783 break;
784 }
785 }
Alex Lorenz83127732015-08-07 20:26:52 +0000786 printOffset(Op.getOffset());
Alex Lorenz61420f72015-08-07 20:48:30 +0000787 if (Op.getBaseAlignment() != Op.getSize())
788 OS << ", align " << Op.getBaseAlignment();
Alex Lorenza617c912015-08-17 22:05:15 +0000789 auto AAInfo = Op.getAAInfo();
790 if (AAInfo.TBAA) {
791 OS << ", !tbaa ";
792 AAInfo.TBAA->printAsOperand(OS, MST);
793 }
Alex Lorenza16f6242015-08-17 22:06:40 +0000794 if (AAInfo.Scope) {
795 OS << ", !alias.scope ";
796 AAInfo.Scope->printAsOperand(OS, MST);
797 }
Alex Lorenz03e940d2015-08-17 22:08:02 +0000798 if (AAInfo.NoAlias) {
799 OS << ", !noalias ";
800 AAInfo.NoAlias->printAsOperand(OS, MST);
801 }
Alex Lorenzeb625682015-08-17 22:09:52 +0000802 if (Op.getRanges()) {
803 OS << ", !range ";
804 Op.getRanges()->printAsOperand(OS, MST);
805 }
Alex Lorenz4af7e612015-08-03 23:08:19 +0000806 OS << ')';
807}
808
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000809static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS,
810 const TargetRegisterInfo *TRI) {
811 int Reg = TRI->getLLVMRegNum(DwarfReg, true);
812 if (Reg == -1) {
813 OS << "<badreg>";
814 return;
815 }
816 printReg(Reg, OS, TRI);
817}
818
819void MIPrinter::print(const MCCFIInstruction &CFI,
820 const TargetRegisterInfo *TRI) {
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000821 switch (CFI.getOperation()) {
Alex Lorenz577d2712015-08-14 21:55:58 +0000822 case MCCFIInstruction::OpSameValue:
823 OS << ".cfi_same_value ";
824 if (CFI.getLabel())
825 OS << "<mcsymbol> ";
826 printCFIRegister(CFI.getRegister(), OS, TRI);
827 break;
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000828 case MCCFIInstruction::OpOffset:
829 OS << ".cfi_offset ";
830 if (CFI.getLabel())
831 OS << "<mcsymbol> ";
832 printCFIRegister(CFI.getRegister(), OS, TRI);
833 OS << ", " << CFI.getOffset();
834 break;
Alex Lorenz5b0d5f62015-07-27 20:39:03 +0000835 case MCCFIInstruction::OpDefCfaRegister:
836 OS << ".cfi_def_cfa_register ";
837 if (CFI.getLabel())
838 OS << "<mcsymbol> ";
839 printCFIRegister(CFI.getRegister(), OS, TRI);
840 break;
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000841 case MCCFIInstruction::OpDefCfaOffset:
842 OS << ".cfi_def_cfa_offset ";
843 if (CFI.getLabel())
844 OS << "<mcsymbol> ";
845 OS << CFI.getOffset();
846 break;
Alex Lorenzb1393232015-07-29 18:57:23 +0000847 case MCCFIInstruction::OpDefCfa:
848 OS << ".cfi_def_cfa ";
849 if (CFI.getLabel())
850 OS << "<mcsymbol> ";
851 printCFIRegister(CFI.getRegister(), OS, TRI);
852 OS << ", " << CFI.getOffset();
853 break;
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000854 default:
855 // TODO: Print the other CFI Operations.
856 OS << "<unserializable cfi operation>";
857 break;
858 }
859}
860
Alex Lorenz345c1442015-06-15 23:52:35 +0000861void llvm::printMIR(raw_ostream &OS, const Module &M) {
862 yaml::Output Out(OS);
863 Out << const_cast<Module &>(M);
864}
865
866void llvm::printMIR(raw_ostream &OS, const MachineFunction &MF) {
867 MIRPrinter Printer(OS);
868 Printer.print(MF);
869}