1 //===- 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 "llvm/CodeGen/MIRPrinter.h" 16 #include "llvm/ADT/DenseMap.h" 17 #include "llvm/ADT/None.h" 18 #include "llvm/ADT/STLExtras.h" 19 #include "llvm/ADT/SmallBitVector.h" 20 #include "llvm/ADT/SmallPtrSet.h" 21 #include "llvm/ADT/SmallVector.h" 22 #include "llvm/ADT/StringExtras.h" 23 #include "llvm/ADT/StringRef.h" 24 #include "llvm/ADT/Twine.h" 25 #include "llvm/CodeGen/GlobalISel/RegisterBank.h" 26 #include "llvm/CodeGen/MIRYamlMapping.h" 27 #include "llvm/CodeGen/MachineBasicBlock.h" 28 #include "llvm/CodeGen/MachineConstantPool.h" 29 #include "llvm/CodeGen/MachineFrameInfo.h" 30 #include "llvm/CodeGen/MachineFunction.h" 31 #include "llvm/CodeGen/MachineInstr.h" 32 #include "llvm/CodeGen/MachineJumpTableInfo.h" 33 #include "llvm/CodeGen/MachineMemOperand.h" 34 #include "llvm/CodeGen/MachineOperand.h" 35 #include "llvm/CodeGen/MachineRegisterInfo.h" 36 #include "llvm/CodeGen/PseudoSourceValue.h" 37 #include "llvm/CodeGen/TargetInstrInfo.h" 38 #include "llvm/CodeGen/TargetRegisterInfo.h" 39 #include "llvm/CodeGen/TargetSubtargetInfo.h" 40 #include "llvm/IR/BasicBlock.h" 41 #include "llvm/IR/Constants.h" 42 #include "llvm/IR/DebugInfo.h" 43 #include "llvm/IR/DebugLoc.h" 44 #include "llvm/IR/Function.h" 45 #include "llvm/IR/GlobalValue.h" 46 #include "llvm/IR/IRPrintingPasses.h" 47 #include "llvm/IR/InstrTypes.h" 48 #include "llvm/IR/Instructions.h" 49 #include "llvm/IR/Intrinsics.h" 50 #include "llvm/IR/Module.h" 51 #include "llvm/IR/ModuleSlotTracker.h" 52 #include "llvm/IR/Value.h" 53 #include "llvm/MC/LaneBitmask.h" 54 #include "llvm/MC/MCDwarf.h" 55 #include "llvm/MC/MCSymbol.h" 56 #include "llvm/Support/AtomicOrdering.h" 57 #include "llvm/Support/BranchProbability.h" 58 #include "llvm/Support/Casting.h" 59 #include "llvm/Support/CommandLine.h" 60 #include "llvm/Support/ErrorHandling.h" 61 #include "llvm/Support/Format.h" 62 #include "llvm/Support/LowLevelTypeImpl.h" 63 #include "llvm/Support/YAMLTraits.h" 64 #include "llvm/Support/raw_ostream.h" 65 #include "llvm/Target/TargetIntrinsicInfo.h" 66 #include "llvm/Target/TargetMachine.h" 67 #include <algorithm> 68 #include <cassert> 69 #include <cinttypes> 70 #include <cstdint> 71 #include <iterator> 72 #include <string> 73 #include <utility> 74 #include <vector> 75 76 using namespace llvm; 77 78 static cl::opt<bool> SimplifyMIR( 79 "simplify-mir", cl::Hidden, 80 cl::desc("Leave out unnecessary information when printing MIR")); 81 82 namespace { 83 84 /// This structure describes how to print out stack object references. 85 struct FrameIndexOperand { 86 std::string Name; 87 unsigned ID; 88 bool IsFixed; 89 90 FrameIndexOperand(StringRef Name, unsigned ID, bool IsFixed) 91 : Name(Name.str()), ID(ID), IsFixed(IsFixed) {} 92 93 /// Return an ordinary stack object reference. 94 static FrameIndexOperand create(StringRef Name, unsigned ID) { 95 return FrameIndexOperand(Name, ID, /*IsFixed=*/false); 96 } 97 98 /// Return a fixed stack object reference. 99 static FrameIndexOperand createFixed(unsigned ID) { 100 return FrameIndexOperand("", ID, /*IsFixed=*/true); 101 } 102 }; 103 104 } // end anonymous namespace 105 106 namespace llvm { 107 108 /// This class prints out the machine functions using the MIR serialization 109 /// format. 110 class MIRPrinter { 111 raw_ostream &OS; 112 DenseMap<const uint32_t *, unsigned> RegisterMaskIds; 113 /// Maps from stack object indices to operand indices which will be used when 114 /// printing frame index machine operands. 115 DenseMap<int, FrameIndexOperand> StackObjectOperandMapping; 116 117 public: 118 MIRPrinter(raw_ostream &OS) : OS(OS) {} 119 120 void print(const MachineFunction &MF); 121 122 void convert(yaml::MachineFunction &MF, const MachineRegisterInfo &RegInfo, 123 const TargetRegisterInfo *TRI); 124 void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI, 125 const MachineFrameInfo &MFI); 126 void convert(yaml::MachineFunction &MF, 127 const MachineConstantPool &ConstantPool); 128 void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI, 129 const MachineJumpTableInfo &JTI); 130 void convertStackObjects(yaml::MachineFunction &YMF, 131 const MachineFunction &MF, ModuleSlotTracker &MST); 132 133 private: 134 void initRegisterMaskIds(const MachineFunction &MF); 135 }; 136 137 /// This class prints out the machine instructions using the MIR serialization 138 /// format. 139 class MIPrinter { 140 raw_ostream &OS; 141 ModuleSlotTracker &MST; 142 const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds; 143 const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping; 144 /// Synchronization scope names registered with LLVMContext. 145 SmallVector<StringRef, 8> SSNs; 146 147 bool canPredictBranchProbabilities(const MachineBasicBlock &MBB) const; 148 bool canPredictSuccessors(const MachineBasicBlock &MBB) const; 149 150 public: 151 MIPrinter(raw_ostream &OS, ModuleSlotTracker &MST, 152 const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds, 153 const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping) 154 : OS(OS), MST(MST), RegisterMaskIds(RegisterMaskIds), 155 StackObjectOperandMapping(StackObjectOperandMapping) {} 156 157 void print(const MachineBasicBlock &MBB); 158 159 void print(const MachineInstr &MI); 160 void printIRBlockReference(const BasicBlock &BB); 161 void printIRValueReference(const Value &V); 162 void printStackObjectReference(int FrameIndex); 163 void printOffset(int64_t Offset); 164 void printTargetFlags(const MachineOperand &Op); 165 void print(const MachineInstr &MI, unsigned OpIdx, 166 const TargetRegisterInfo *TRI, bool ShouldPrintRegisterTies, 167 LLT TypeToPrint, bool PrintDef = true); 168 void print(const LLVMContext &Context, const TargetInstrInfo &TII, 169 const MachineMemOperand &Op); 170 void printSyncScope(const LLVMContext &Context, SyncScope::ID SSID); 171 172 void print(const MCCFIInstruction &CFI, const TargetRegisterInfo *TRI); 173 }; 174 175 } // end namespace llvm 176 177 namespace llvm { 178 namespace yaml { 179 180 /// This struct serializes the LLVM IR module. 181 template <> struct BlockScalarTraits<Module> { 182 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) { 183 Mod.print(OS, nullptr); 184 } 185 186 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) { 187 llvm_unreachable("LLVM Module is supposed to be parsed separately"); 188 return ""; 189 } 190 }; 191 192 } // end namespace yaml 193 } // end namespace llvm 194 195 static void printRegMIR(unsigned Reg, yaml::StringValue &Dest, 196 const TargetRegisterInfo *TRI) { 197 raw_string_ostream OS(Dest.Value); 198 OS << printReg(Reg, TRI); 199 } 200 201 void MIRPrinter::print(const MachineFunction &MF) { 202 initRegisterMaskIds(MF); 203 204 yaml::MachineFunction YamlMF; 205 YamlMF.Name = MF.getName(); 206 YamlMF.Alignment = MF.getAlignment(); 207 YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice(); 208 209 YamlMF.Legalized = MF.getProperties().hasProperty( 210 MachineFunctionProperties::Property::Legalized); 211 YamlMF.RegBankSelected = MF.getProperties().hasProperty( 212 MachineFunctionProperties::Property::RegBankSelected); 213 YamlMF.Selected = MF.getProperties().hasProperty( 214 MachineFunctionProperties::Property::Selected); 215 216 convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo()); 217 ModuleSlotTracker MST(MF.getFunction()->getParent()); 218 MST.incorporateFunction(*MF.getFunction()); 219 convert(MST, YamlMF.FrameInfo, MF.getFrameInfo()); 220 convertStackObjects(YamlMF, MF, MST); 221 if (const auto *ConstantPool = MF.getConstantPool()) 222 convert(YamlMF, *ConstantPool); 223 if (const auto *JumpTableInfo = MF.getJumpTableInfo()) 224 convert(MST, YamlMF.JumpTableInfo, *JumpTableInfo); 225 raw_string_ostream StrOS(YamlMF.Body.Value.Value); 226 bool IsNewlineNeeded = false; 227 for (const auto &MBB : MF) { 228 if (IsNewlineNeeded) 229 StrOS << "\n"; 230 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping) 231 .print(MBB); 232 IsNewlineNeeded = true; 233 } 234 StrOS.flush(); 235 yaml::Output Out(OS); 236 if (!SimplifyMIR) 237 Out.setWriteDefaultValues(true); 238 Out << YamlMF; 239 } 240 241 static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS, 242 const TargetRegisterInfo *TRI) { 243 assert(RegMask && "Can't print an empty register mask"); 244 OS << StringRef("CustomRegMask("); 245 246 bool IsRegInRegMaskFound = false; 247 for (int I = 0, E = TRI->getNumRegs(); I < E; I++) { 248 // Check whether the register is asserted in regmask. 249 if (RegMask[I / 32] & (1u << (I % 32))) { 250 if (IsRegInRegMaskFound) 251 OS << ','; 252 OS << printReg(I, TRI); 253 IsRegInRegMaskFound = true; 254 } 255 } 256 257 OS << ')'; 258 } 259 260 static void printRegClassOrBank(unsigned Reg, yaml::StringValue &Dest, 261 const MachineRegisterInfo &RegInfo, 262 const TargetRegisterInfo *TRI) { 263 raw_string_ostream OS(Dest.Value); 264 OS << printRegClassOrBank(Reg, RegInfo, TRI); 265 } 266 267 268 void MIRPrinter::convert(yaml::MachineFunction &MF, 269 const MachineRegisterInfo &RegInfo, 270 const TargetRegisterInfo *TRI) { 271 MF.TracksRegLiveness = RegInfo.tracksLiveness(); 272 273 // Print the virtual register definitions. 274 for (unsigned I = 0, E = RegInfo.getNumVirtRegs(); I < E; ++I) { 275 unsigned Reg = TargetRegisterInfo::index2VirtReg(I); 276 yaml::VirtualRegisterDefinition VReg; 277 VReg.ID = I; 278 ::printRegClassOrBank(Reg, VReg.Class, RegInfo, TRI); 279 unsigned PreferredReg = RegInfo.getSimpleHint(Reg); 280 if (PreferredReg) 281 printRegMIR(PreferredReg, VReg.PreferredRegister, TRI); 282 MF.VirtualRegisters.push_back(VReg); 283 } 284 285 // Print the live ins. 286 for (std::pair<unsigned, unsigned> LI : RegInfo.liveins()) { 287 yaml::MachineFunctionLiveIn LiveIn; 288 printRegMIR(LI.first, LiveIn.Register, TRI); 289 if (LI.second) 290 printRegMIR(LI.second, LiveIn.VirtualRegister, TRI); 291 MF.LiveIns.push_back(LiveIn); 292 } 293 294 // Prints the callee saved registers. 295 if (RegInfo.isUpdatedCSRsInitialized()) { 296 const MCPhysReg *CalleeSavedRegs = RegInfo.getCalleeSavedRegs(); 297 std::vector<yaml::FlowStringValue> CalleeSavedRegisters; 298 for (const MCPhysReg *I = CalleeSavedRegs; *I; ++I) { 299 yaml::FlowStringValue Reg; 300 printRegMIR(*I, Reg, TRI); 301 CalleeSavedRegisters.push_back(Reg); 302 } 303 MF.CalleeSavedRegisters = CalleeSavedRegisters; 304 } 305 } 306 307 void MIRPrinter::convert(ModuleSlotTracker &MST, 308 yaml::MachineFrameInfo &YamlMFI, 309 const MachineFrameInfo &MFI) { 310 YamlMFI.IsFrameAddressTaken = MFI.isFrameAddressTaken(); 311 YamlMFI.IsReturnAddressTaken = MFI.isReturnAddressTaken(); 312 YamlMFI.HasStackMap = MFI.hasStackMap(); 313 YamlMFI.HasPatchPoint = MFI.hasPatchPoint(); 314 YamlMFI.StackSize = MFI.getStackSize(); 315 YamlMFI.OffsetAdjustment = MFI.getOffsetAdjustment(); 316 YamlMFI.MaxAlignment = MFI.getMaxAlignment(); 317 YamlMFI.AdjustsStack = MFI.adjustsStack(); 318 YamlMFI.HasCalls = MFI.hasCalls(); 319 YamlMFI.MaxCallFrameSize = MFI.isMaxCallFrameSizeComputed() 320 ? MFI.getMaxCallFrameSize() : ~0u; 321 YamlMFI.HasOpaqueSPAdjustment = MFI.hasOpaqueSPAdjustment(); 322 YamlMFI.HasVAStart = MFI.hasVAStart(); 323 YamlMFI.HasMustTailInVarArgFunc = MFI.hasMustTailInVarArgFunc(); 324 if (MFI.getSavePoint()) { 325 raw_string_ostream StrOS(YamlMFI.SavePoint.Value); 326 StrOS << printMBBReference(*MFI.getSavePoint()); 327 } 328 if (MFI.getRestorePoint()) { 329 raw_string_ostream StrOS(YamlMFI.RestorePoint.Value); 330 StrOS << printMBBReference(*MFI.getRestorePoint()); 331 } 332 } 333 334 void MIRPrinter::convertStackObjects(yaml::MachineFunction &YMF, 335 const MachineFunction &MF, 336 ModuleSlotTracker &MST) { 337 const MachineFrameInfo &MFI = MF.getFrameInfo(); 338 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); 339 // Process fixed stack objects. 340 unsigned ID = 0; 341 for (int I = MFI.getObjectIndexBegin(); I < 0; ++I) { 342 if (MFI.isDeadObjectIndex(I)) 343 continue; 344 345 yaml::FixedMachineStackObject YamlObject; 346 YamlObject.ID = ID; 347 YamlObject.Type = MFI.isSpillSlotObjectIndex(I) 348 ? yaml::FixedMachineStackObject::SpillSlot 349 : yaml::FixedMachineStackObject::DefaultType; 350 YamlObject.Offset = MFI.getObjectOffset(I); 351 YamlObject.Size = MFI.getObjectSize(I); 352 YamlObject.Alignment = MFI.getObjectAlignment(I); 353 YamlObject.StackID = MFI.getStackID(I); 354 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I); 355 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I); 356 YMF.FixedStackObjects.push_back(YamlObject); 357 StackObjectOperandMapping.insert( 358 std::make_pair(I, FrameIndexOperand::createFixed(ID++))); 359 } 360 361 // Process ordinary stack objects. 362 ID = 0; 363 for (int I = 0, E = MFI.getObjectIndexEnd(); I < E; ++I) { 364 if (MFI.isDeadObjectIndex(I)) 365 continue; 366 367 yaml::MachineStackObject YamlObject; 368 YamlObject.ID = ID; 369 if (const auto *Alloca = MFI.getObjectAllocation(I)) 370 YamlObject.Name.Value = 371 Alloca->hasName() ? Alloca->getName() : "<unnamed alloca>"; 372 YamlObject.Type = MFI.isSpillSlotObjectIndex(I) 373 ? yaml::MachineStackObject::SpillSlot 374 : MFI.isVariableSizedObjectIndex(I) 375 ? yaml::MachineStackObject::VariableSized 376 : yaml::MachineStackObject::DefaultType; 377 YamlObject.Offset = MFI.getObjectOffset(I); 378 YamlObject.Size = MFI.getObjectSize(I); 379 YamlObject.Alignment = MFI.getObjectAlignment(I); 380 YamlObject.StackID = MFI.getStackID(I); 381 382 YMF.StackObjects.push_back(YamlObject); 383 StackObjectOperandMapping.insert(std::make_pair( 384 I, FrameIndexOperand::create(YamlObject.Name.Value, ID++))); 385 } 386 387 for (const auto &CSInfo : MFI.getCalleeSavedInfo()) { 388 yaml::StringValue Reg; 389 printRegMIR(CSInfo.getReg(), Reg, TRI); 390 auto StackObjectInfo = StackObjectOperandMapping.find(CSInfo.getFrameIdx()); 391 assert(StackObjectInfo != StackObjectOperandMapping.end() && 392 "Invalid stack object index"); 393 const FrameIndexOperand &StackObject = StackObjectInfo->second; 394 if (StackObject.IsFixed) { 395 YMF.FixedStackObjects[StackObject.ID].CalleeSavedRegister = Reg; 396 YMF.FixedStackObjects[StackObject.ID].CalleeSavedRestored = 397 CSInfo.isRestored(); 398 } else { 399 YMF.StackObjects[StackObject.ID].CalleeSavedRegister = Reg; 400 YMF.StackObjects[StackObject.ID].CalleeSavedRestored = 401 CSInfo.isRestored(); 402 } 403 } 404 for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) { 405 auto LocalObject = MFI.getLocalFrameObjectMap(I); 406 auto StackObjectInfo = StackObjectOperandMapping.find(LocalObject.first); 407 assert(StackObjectInfo != StackObjectOperandMapping.end() && 408 "Invalid stack object index"); 409 const FrameIndexOperand &StackObject = StackObjectInfo->second; 410 assert(!StackObject.IsFixed && "Expected a locally mapped stack object"); 411 YMF.StackObjects[StackObject.ID].LocalOffset = LocalObject.second; 412 } 413 414 // Print the stack object references in the frame information class after 415 // converting the stack objects. 416 if (MFI.hasStackProtectorIndex()) { 417 raw_string_ostream StrOS(YMF.FrameInfo.StackProtector.Value); 418 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping) 419 .printStackObjectReference(MFI.getStackProtectorIndex()); 420 } 421 422 // Print the debug variable information. 423 for (const MachineFunction::VariableDbgInfo &DebugVar : 424 MF.getVariableDbgInfo()) { 425 auto StackObjectInfo = StackObjectOperandMapping.find(DebugVar.Slot); 426 assert(StackObjectInfo != StackObjectOperandMapping.end() && 427 "Invalid stack object index"); 428 const FrameIndexOperand &StackObject = StackObjectInfo->second; 429 assert(!StackObject.IsFixed && "Expected a non-fixed stack object"); 430 auto &Object = YMF.StackObjects[StackObject.ID]; 431 { 432 raw_string_ostream StrOS(Object.DebugVar.Value); 433 DebugVar.Var->printAsOperand(StrOS, MST); 434 } 435 { 436 raw_string_ostream StrOS(Object.DebugExpr.Value); 437 DebugVar.Expr->printAsOperand(StrOS, MST); 438 } 439 { 440 raw_string_ostream StrOS(Object.DebugLoc.Value); 441 DebugVar.Loc->printAsOperand(StrOS, MST); 442 } 443 } 444 } 445 446 void MIRPrinter::convert(yaml::MachineFunction &MF, 447 const MachineConstantPool &ConstantPool) { 448 unsigned ID = 0; 449 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) { 450 std::string Str; 451 raw_string_ostream StrOS(Str); 452 if (Constant.isMachineConstantPoolEntry()) { 453 Constant.Val.MachineCPVal->print(StrOS); 454 } else { 455 Constant.Val.ConstVal->printAsOperand(StrOS); 456 } 457 458 yaml::MachineConstantPoolValue YamlConstant; 459 YamlConstant.ID = ID++; 460 YamlConstant.Value = StrOS.str(); 461 YamlConstant.Alignment = Constant.getAlignment(); 462 YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry(); 463 464 MF.Constants.push_back(YamlConstant); 465 } 466 } 467 468 void MIRPrinter::convert(ModuleSlotTracker &MST, 469 yaml::MachineJumpTable &YamlJTI, 470 const MachineJumpTableInfo &JTI) { 471 YamlJTI.Kind = JTI.getEntryKind(); 472 unsigned ID = 0; 473 for (const auto &Table : JTI.getJumpTables()) { 474 std::string Str; 475 yaml::MachineJumpTable::Entry Entry; 476 Entry.ID = ID++; 477 for (const auto *MBB : Table.MBBs) { 478 raw_string_ostream StrOS(Str); 479 StrOS << printMBBReference(*MBB); 480 Entry.Blocks.push_back(StrOS.str()); 481 Str.clear(); 482 } 483 YamlJTI.Entries.push_back(Entry); 484 } 485 } 486 487 void MIRPrinter::initRegisterMaskIds(const MachineFunction &MF) { 488 const auto *TRI = MF.getSubtarget().getRegisterInfo(); 489 unsigned I = 0; 490 for (const uint32_t *Mask : TRI->getRegMasks()) 491 RegisterMaskIds.insert(std::make_pair(Mask, I++)); 492 } 493 494 void llvm::guessSuccessors(const MachineBasicBlock &MBB, 495 SmallVectorImpl<MachineBasicBlock*> &Result, 496 bool &IsFallthrough) { 497 SmallPtrSet<MachineBasicBlock*,8> Seen; 498 499 for (const MachineInstr &MI : MBB) { 500 if (MI.isPHI()) 501 continue; 502 for (const MachineOperand &MO : MI.operands()) { 503 if (!MO.isMBB()) 504 continue; 505 MachineBasicBlock *Succ = MO.getMBB(); 506 auto RP = Seen.insert(Succ); 507 if (RP.second) 508 Result.push_back(Succ); 509 } 510 } 511 MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr(); 512 IsFallthrough = I == MBB.end() || !I->isBarrier(); 513 } 514 515 bool 516 MIPrinter::canPredictBranchProbabilities(const MachineBasicBlock &MBB) const { 517 if (MBB.succ_size() <= 1) 518 return true; 519 if (!MBB.hasSuccessorProbabilities()) 520 return true; 521 522 SmallVector<BranchProbability,8> Normalized(MBB.Probs.begin(), 523 MBB.Probs.end()); 524 BranchProbability::normalizeProbabilities(Normalized.begin(), 525 Normalized.end()); 526 SmallVector<BranchProbability,8> Equal(Normalized.size()); 527 BranchProbability::normalizeProbabilities(Equal.begin(), Equal.end()); 528 529 return std::equal(Normalized.begin(), Normalized.end(), Equal.begin()); 530 } 531 532 bool MIPrinter::canPredictSuccessors(const MachineBasicBlock &MBB) const { 533 SmallVector<MachineBasicBlock*,8> GuessedSuccs; 534 bool GuessedFallthrough; 535 guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough); 536 if (GuessedFallthrough) { 537 const MachineFunction &MF = *MBB.getParent(); 538 MachineFunction::const_iterator NextI = std::next(MBB.getIterator()); 539 if (NextI != MF.end()) { 540 MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI); 541 if (!is_contained(GuessedSuccs, Next)) 542 GuessedSuccs.push_back(Next); 543 } 544 } 545 if (GuessedSuccs.size() != MBB.succ_size()) 546 return false; 547 return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin()); 548 } 549 550 void MIPrinter::print(const MachineBasicBlock &MBB) { 551 assert(MBB.getNumber() >= 0 && "Invalid MBB number"); 552 OS << "bb." << MBB.getNumber(); 553 bool HasAttributes = false; 554 if (const auto *BB = MBB.getBasicBlock()) { 555 if (BB->hasName()) { 556 OS << "." << BB->getName(); 557 } else { 558 HasAttributes = true; 559 OS << " ("; 560 int Slot = MST.getLocalSlot(BB); 561 if (Slot == -1) 562 OS << "<ir-block badref>"; 563 else 564 OS << (Twine("%ir-block.") + Twine(Slot)).str(); 565 } 566 } 567 if (MBB.hasAddressTaken()) { 568 OS << (HasAttributes ? ", " : " ("); 569 OS << "address-taken"; 570 HasAttributes = true; 571 } 572 if (MBB.isEHPad()) { 573 OS << (HasAttributes ? ", " : " ("); 574 OS << "landing-pad"; 575 HasAttributes = true; 576 } 577 if (MBB.getAlignment()) { 578 OS << (HasAttributes ? ", " : " ("); 579 OS << "align " << MBB.getAlignment(); 580 HasAttributes = true; 581 } 582 if (HasAttributes) 583 OS << ")"; 584 OS << ":\n"; 585 586 bool HasLineAttributes = false; 587 // Print the successors 588 bool canPredictProbs = canPredictBranchProbabilities(MBB); 589 // Even if the list of successors is empty, if we cannot guess it, 590 // we need to print it to tell the parser that the list is empty. 591 // This is needed, because MI model unreachable as empty blocks 592 // with an empty successor list. If the parser would see that 593 // without the successor list, it would guess the code would 594 // fallthrough. 595 if ((!MBB.succ_empty() && !SimplifyMIR) || !canPredictProbs || 596 !canPredictSuccessors(MBB)) { 597 OS.indent(2) << "successors: "; 598 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) { 599 if (I != MBB.succ_begin()) 600 OS << ", "; 601 OS << printMBBReference(**I); 602 if (!SimplifyMIR || !canPredictProbs) 603 OS << '(' 604 << format("0x%08" PRIx32, MBB.getSuccProbability(I).getNumerator()) 605 << ')'; 606 } 607 OS << "\n"; 608 HasLineAttributes = true; 609 } 610 611 // Print the live in registers. 612 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); 613 if (MRI.tracksLiveness() && !MBB.livein_empty()) { 614 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo(); 615 OS.indent(2) << "liveins: "; 616 bool First = true; 617 for (const auto &LI : MBB.liveins()) { 618 if (!First) 619 OS << ", "; 620 First = false; 621 OS << printReg(LI.PhysReg, &TRI); 622 if (!LI.LaneMask.all()) 623 OS << ":0x" << PrintLaneMask(LI.LaneMask); 624 } 625 OS << "\n"; 626 HasLineAttributes = true; 627 } 628 629 if (HasLineAttributes) 630 OS << "\n"; 631 bool IsInBundle = false; 632 for (auto I = MBB.instr_begin(), E = MBB.instr_end(); I != E; ++I) { 633 const MachineInstr &MI = *I; 634 if (IsInBundle && !MI.isInsideBundle()) { 635 OS.indent(2) << "}\n"; 636 IsInBundle = false; 637 } 638 OS.indent(IsInBundle ? 4 : 2); 639 print(MI); 640 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) { 641 OS << " {"; 642 IsInBundle = true; 643 } 644 OS << "\n"; 645 } 646 if (IsInBundle) 647 OS.indent(2) << "}\n"; 648 } 649 650 void MIPrinter::print(const MachineInstr &MI) { 651 const auto *MF = MI.getMF(); 652 const auto &MRI = MF->getRegInfo(); 653 const auto &SubTarget = MF->getSubtarget(); 654 const auto *TRI = SubTarget.getRegisterInfo(); 655 assert(TRI && "Expected target register info"); 656 const auto *TII = SubTarget.getInstrInfo(); 657 assert(TII && "Expected target instruction info"); 658 if (MI.isCFIInstruction()) 659 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction"); 660 661 SmallBitVector PrintedTypes(8); 662 bool ShouldPrintRegisterTies = MI.hasComplexRegisterTies(); 663 unsigned I = 0, E = MI.getNumOperands(); 664 for (; I < E && MI.getOperand(I).isReg() && MI.getOperand(I).isDef() && 665 !MI.getOperand(I).isImplicit(); 666 ++I) { 667 if (I) 668 OS << ", "; 669 print(MI, I, TRI, ShouldPrintRegisterTies, 670 MI.getTypeToPrint(I, PrintedTypes, MRI), 671 /*PrintDef=*/false); 672 } 673 674 if (I) 675 OS << " = "; 676 if (MI.getFlag(MachineInstr::FrameSetup)) 677 OS << "frame-setup "; 678 OS << TII->getName(MI.getOpcode()); 679 if (I < E) 680 OS << ' '; 681 682 bool NeedComma = false; 683 for (; I < E; ++I) { 684 if (NeedComma) 685 OS << ", "; 686 print(MI, I, TRI, ShouldPrintRegisterTies, 687 MI.getTypeToPrint(I, PrintedTypes, MRI)); 688 NeedComma = true; 689 } 690 691 if (MI.getDebugLoc()) { 692 if (NeedComma) 693 OS << ','; 694 OS << " debug-location "; 695 MI.getDebugLoc()->printAsOperand(OS, MST); 696 } 697 698 if (!MI.memoperands_empty()) { 699 OS << " :: "; 700 const LLVMContext &Context = MF->getFunction()->getContext(); 701 bool NeedComma = false; 702 for (const auto *Op : MI.memoperands()) { 703 if (NeedComma) 704 OS << ", "; 705 print(Context, *TII, *Op); 706 NeedComma = true; 707 } 708 } 709 } 710 711 static void printIRSlotNumber(raw_ostream &OS, int Slot) { 712 if (Slot == -1) 713 OS << "<badref>"; 714 else 715 OS << Slot; 716 } 717 718 void MIPrinter::printIRBlockReference(const BasicBlock &BB) { 719 OS << "%ir-block."; 720 if (BB.hasName()) { 721 printLLVMNameWithoutPrefix(OS, BB.getName()); 722 return; 723 } 724 const Function *F = BB.getParent(); 725 int Slot; 726 if (F == MST.getCurrentFunction()) { 727 Slot = MST.getLocalSlot(&BB); 728 } else { 729 ModuleSlotTracker CustomMST(F->getParent(), 730 /*ShouldInitializeAllMetadata=*/false); 731 CustomMST.incorporateFunction(*F); 732 Slot = CustomMST.getLocalSlot(&BB); 733 } 734 printIRSlotNumber(OS, Slot); 735 } 736 737 void MIPrinter::printIRValueReference(const Value &V) { 738 if (isa<GlobalValue>(V)) { 739 V.printAsOperand(OS, /*PrintType=*/false, MST); 740 return; 741 } 742 if (isa<Constant>(V)) { 743 // Machine memory operands can load/store to/from constant value pointers. 744 OS << '`'; 745 V.printAsOperand(OS, /*PrintType=*/true, MST); 746 OS << '`'; 747 return; 748 } 749 OS << "%ir."; 750 if (V.hasName()) { 751 printLLVMNameWithoutPrefix(OS, V.getName()); 752 return; 753 } 754 printIRSlotNumber(OS, MST.getLocalSlot(&V)); 755 } 756 757 void MIPrinter::printStackObjectReference(int FrameIndex) { 758 auto ObjectInfo = StackObjectOperandMapping.find(FrameIndex); 759 assert(ObjectInfo != StackObjectOperandMapping.end() && 760 "Invalid frame index"); 761 const FrameIndexOperand &Operand = ObjectInfo->second; 762 if (Operand.IsFixed) { 763 OS << "%fixed-stack." << Operand.ID; 764 return; 765 } 766 OS << "%stack." << Operand.ID; 767 if (!Operand.Name.empty()) 768 OS << '.' << Operand.Name; 769 } 770 771 void MIPrinter::printOffset(int64_t Offset) { 772 if (Offset == 0) 773 return; 774 if (Offset < 0) { 775 OS << " - " << -Offset; 776 return; 777 } 778 OS << " + " << Offset; 779 } 780 781 static const char *getTargetFlagName(const TargetInstrInfo *TII, unsigned TF) { 782 auto Flags = TII->getSerializableDirectMachineOperandTargetFlags(); 783 for (const auto &I : Flags) { 784 if (I.first == TF) { 785 return I.second; 786 } 787 } 788 return nullptr; 789 } 790 791 void MIPrinter::printTargetFlags(const MachineOperand &Op) { 792 if (!Op.getTargetFlags()) 793 return; 794 const auto *TII = Op.getParent()->getMF()->getSubtarget().getInstrInfo(); 795 assert(TII && "expected instruction info"); 796 auto Flags = TII->decomposeMachineOperandsTargetFlags(Op.getTargetFlags()); 797 OS << "target-flags("; 798 const bool HasDirectFlags = Flags.first; 799 const bool HasBitmaskFlags = Flags.second; 800 if (!HasDirectFlags && !HasBitmaskFlags) { 801 OS << "<unknown>) "; 802 return; 803 } 804 if (HasDirectFlags) { 805 if (const auto *Name = getTargetFlagName(TII, Flags.first)) 806 OS << Name; 807 else 808 OS << "<unknown target flag>"; 809 } 810 if (!HasBitmaskFlags) { 811 OS << ") "; 812 return; 813 } 814 bool IsCommaNeeded = HasDirectFlags; 815 unsigned BitMask = Flags.second; 816 auto BitMasks = TII->getSerializableBitmaskMachineOperandTargetFlags(); 817 for (const auto &Mask : BitMasks) { 818 // Check if the flag's bitmask has the bits of the current mask set. 819 if ((BitMask & Mask.first) == Mask.first) { 820 if (IsCommaNeeded) 821 OS << ", "; 822 IsCommaNeeded = true; 823 OS << Mask.second; 824 // Clear the bits which were serialized from the flag's bitmask. 825 BitMask &= ~(Mask.first); 826 } 827 } 828 if (BitMask) { 829 // When the resulting flag's bitmask isn't zero, we know that we didn't 830 // serialize all of the bit flags. 831 if (IsCommaNeeded) 832 OS << ", "; 833 OS << "<unknown bitmask target flag>"; 834 } 835 OS << ") "; 836 } 837 838 static const char *getTargetIndexName(const MachineFunction &MF, int Index) { 839 const auto *TII = MF.getSubtarget().getInstrInfo(); 840 assert(TII && "expected instruction info"); 841 auto Indices = TII->getSerializableTargetIndices(); 842 for (const auto &I : Indices) { 843 if (I.first == Index) { 844 return I.second; 845 } 846 } 847 return nullptr; 848 } 849 850 void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx, 851 const TargetRegisterInfo *TRI, 852 bool ShouldPrintRegisterTies, LLT TypeToPrint, 853 bool PrintDef) { 854 const MachineOperand &Op = MI.getOperand(OpIdx); 855 printTargetFlags(Op); 856 switch (Op.getType()) { 857 case MachineOperand::MO_Immediate: 858 if (MI.isOperandSubregIdx(OpIdx)) { 859 MachineOperand::printSubregIdx(OS, Op.getImm(), TRI); 860 break; 861 } 862 LLVM_FALLTHROUGH; 863 case MachineOperand::MO_Register: 864 case MachineOperand::MO_CImmediate: 865 case MachineOperand::MO_MachineBasicBlock: { 866 unsigned TiedOperandIdx = 0; 867 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef()) 868 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx); 869 const TargetIntrinsicInfo *TII = MI.getMF()->getTarget().getIntrinsicInfo(); 870 Op.print(OS, MST, TypeToPrint, PrintDef, ShouldPrintRegisterTies, 871 TiedOperandIdx, TRI, TII); 872 break; 873 } 874 case MachineOperand::MO_FPImmediate: 875 Op.getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST); 876 break; 877 case MachineOperand::MO_FrameIndex: 878 printStackObjectReference(Op.getIndex()); 879 break; 880 case MachineOperand::MO_ConstantPoolIndex: 881 OS << "%const." << Op.getIndex(); 882 printOffset(Op.getOffset()); 883 break; 884 case MachineOperand::MO_TargetIndex: 885 OS << "target-index("; 886 if (const auto *Name = 887 getTargetIndexName(*Op.getParent()->getMF(), Op.getIndex())) 888 OS << Name; 889 else 890 OS << "<unknown>"; 891 OS << ')'; 892 printOffset(Op.getOffset()); 893 break; 894 case MachineOperand::MO_JumpTableIndex: 895 OS << "%jump-table." << Op.getIndex(); 896 break; 897 case MachineOperand::MO_ExternalSymbol: { 898 StringRef Name = Op.getSymbolName(); 899 OS << '$'; 900 if (Name.empty()) { 901 OS << "\"\""; 902 } else { 903 printLLVMNameWithoutPrefix(OS, Name); 904 } 905 printOffset(Op.getOffset()); 906 break; 907 } 908 case MachineOperand::MO_GlobalAddress: 909 Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST); 910 printOffset(Op.getOffset()); 911 break; 912 case MachineOperand::MO_BlockAddress: 913 OS << "blockaddress("; 914 Op.getBlockAddress()->getFunction()->printAsOperand(OS, /*PrintType=*/false, 915 MST); 916 OS << ", "; 917 printIRBlockReference(*Op.getBlockAddress()->getBasicBlock()); 918 OS << ')'; 919 printOffset(Op.getOffset()); 920 break; 921 case MachineOperand::MO_RegisterMask: { 922 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask()); 923 if (RegMaskInfo != RegisterMaskIds.end()) 924 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower(); 925 else 926 printCustomRegMask(Op.getRegMask(), OS, TRI); 927 break; 928 } 929 case MachineOperand::MO_RegisterLiveOut: { 930 const uint32_t *RegMask = Op.getRegLiveOut(); 931 OS << "liveout("; 932 bool IsCommaNeeded = false; 933 for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) { 934 if (RegMask[Reg / 32] & (1U << (Reg % 32))) { 935 if (IsCommaNeeded) 936 OS << ", "; 937 OS << printReg(Reg, TRI); 938 IsCommaNeeded = true; 939 } 940 } 941 OS << ")"; 942 break; 943 } 944 case MachineOperand::MO_Metadata: 945 Op.getMetadata()->printAsOperand(OS, MST); 946 break; 947 case MachineOperand::MO_MCSymbol: 948 OS << "<mcsymbol " << *Op.getMCSymbol() << ">"; 949 break; 950 case MachineOperand::MO_CFIIndex: { 951 const MachineFunction &MF = *Op.getParent()->getMF(); 952 print(MF.getFrameInstructions()[Op.getCFIIndex()], TRI); 953 break; 954 } 955 case MachineOperand::MO_IntrinsicID: { 956 Intrinsic::ID ID = Op.getIntrinsicID(); 957 if (ID < Intrinsic::num_intrinsics) 958 OS << "intrinsic(@" << Intrinsic::getName(ID, None) << ')'; 959 else { 960 const MachineFunction &MF = *Op.getParent()->getMF(); 961 const TargetIntrinsicInfo *TII = MF.getTarget().getIntrinsicInfo(); 962 OS << "intrinsic(@" << TII->getName(ID) << ')'; 963 } 964 break; 965 } 966 case MachineOperand::MO_Predicate: { 967 auto Pred = static_cast<CmpInst::Predicate>(Op.getPredicate()); 968 OS << (CmpInst::isIntPredicate(Pred) ? "int" : "float") << "pred(" 969 << CmpInst::getPredicateName(Pred) << ')'; 970 break; 971 } 972 } 973 } 974 975 static const char *getTargetMMOFlagName(const TargetInstrInfo &TII, 976 unsigned TMMOFlag) { 977 auto Flags = TII.getSerializableMachineMemOperandTargetFlags(); 978 for (const auto &I : Flags) { 979 if (I.first == TMMOFlag) { 980 return I.second; 981 } 982 } 983 return nullptr; 984 } 985 986 void MIPrinter::print(const LLVMContext &Context, const TargetInstrInfo &TII, 987 const MachineMemOperand &Op) { 988 OS << '('; 989 if (Op.isVolatile()) 990 OS << "volatile "; 991 if (Op.isNonTemporal()) 992 OS << "non-temporal "; 993 if (Op.isDereferenceable()) 994 OS << "dereferenceable "; 995 if (Op.isInvariant()) 996 OS << "invariant "; 997 if (Op.getFlags() & MachineMemOperand::MOTargetFlag1) 998 OS << '"' << getTargetMMOFlagName(TII, MachineMemOperand::MOTargetFlag1) 999 << "\" "; 1000 if (Op.getFlags() & MachineMemOperand::MOTargetFlag2) 1001 OS << '"' << getTargetMMOFlagName(TII, MachineMemOperand::MOTargetFlag2) 1002 << "\" "; 1003 if (Op.getFlags() & MachineMemOperand::MOTargetFlag3) 1004 OS << '"' << getTargetMMOFlagName(TII, MachineMemOperand::MOTargetFlag3) 1005 << "\" "; 1006 1007 assert((Op.isLoad() || Op.isStore()) && "machine memory operand must be a load or store (or both)"); 1008 if (Op.isLoad()) 1009 OS << "load "; 1010 if (Op.isStore()) 1011 OS << "store "; 1012 1013 printSyncScope(Context, Op.getSyncScopeID()); 1014 1015 if (Op.getOrdering() != AtomicOrdering::NotAtomic) 1016 OS << toIRString(Op.getOrdering()) << ' '; 1017 if (Op.getFailureOrdering() != AtomicOrdering::NotAtomic) 1018 OS << toIRString(Op.getFailureOrdering()) << ' '; 1019 1020 OS << Op.getSize(); 1021 if (const Value *Val = Op.getValue()) { 1022 OS << ((Op.isLoad() && Op.isStore()) ? " on " 1023 : Op.isLoad() ? " from " : " into "); 1024 printIRValueReference(*Val); 1025 } else if (const PseudoSourceValue *PVal = Op.getPseudoValue()) { 1026 OS << ((Op.isLoad() && Op.isStore()) ? " on " 1027 : Op.isLoad() ? " from " : " into "); 1028 assert(PVal && "Expected a pseudo source value"); 1029 switch (PVal->kind()) { 1030 case PseudoSourceValue::Stack: 1031 OS << "stack"; 1032 break; 1033 case PseudoSourceValue::GOT: 1034 OS << "got"; 1035 break; 1036 case PseudoSourceValue::JumpTable: 1037 OS << "jump-table"; 1038 break; 1039 case PseudoSourceValue::ConstantPool: 1040 OS << "constant-pool"; 1041 break; 1042 case PseudoSourceValue::FixedStack: 1043 printStackObjectReference( 1044 cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex()); 1045 break; 1046 case PseudoSourceValue::GlobalValueCallEntry: 1047 OS << "call-entry "; 1048 cast<GlobalValuePseudoSourceValue>(PVal)->getValue()->printAsOperand( 1049 OS, /*PrintType=*/false, MST); 1050 break; 1051 case PseudoSourceValue::ExternalSymbolCallEntry: 1052 OS << "call-entry $"; 1053 printLLVMNameWithoutPrefix( 1054 OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol()); 1055 break; 1056 case PseudoSourceValue::TargetCustom: 1057 llvm_unreachable("TargetCustom pseudo source values are not supported"); 1058 break; 1059 } 1060 } 1061 printOffset(Op.getOffset()); 1062 if (Op.getBaseAlignment() != Op.getSize()) 1063 OS << ", align " << Op.getBaseAlignment(); 1064 auto AAInfo = Op.getAAInfo(); 1065 if (AAInfo.TBAA) { 1066 OS << ", !tbaa "; 1067 AAInfo.TBAA->printAsOperand(OS, MST); 1068 } 1069 if (AAInfo.Scope) { 1070 OS << ", !alias.scope "; 1071 AAInfo.Scope->printAsOperand(OS, MST); 1072 } 1073 if (AAInfo.NoAlias) { 1074 OS << ", !noalias "; 1075 AAInfo.NoAlias->printAsOperand(OS, MST); 1076 } 1077 if (Op.getRanges()) { 1078 OS << ", !range "; 1079 Op.getRanges()->printAsOperand(OS, MST); 1080 } 1081 OS << ')'; 1082 } 1083 1084 void MIPrinter::printSyncScope(const LLVMContext &Context, SyncScope::ID SSID) { 1085 switch (SSID) { 1086 case SyncScope::System: { 1087 break; 1088 } 1089 default: { 1090 if (SSNs.empty()) 1091 Context.getSyncScopeNames(SSNs); 1092 1093 OS << "syncscope(\""; 1094 PrintEscapedString(SSNs[SSID], OS); 1095 OS << "\") "; 1096 break; 1097 } 1098 } 1099 } 1100 1101 static void printCFIRegister(unsigned DwarfReg, raw_ostream &OS, 1102 const TargetRegisterInfo *TRI) { 1103 int Reg = TRI->getLLVMRegNum(DwarfReg, true); 1104 if (Reg == -1) { 1105 OS << "<badreg>"; 1106 return; 1107 } 1108 OS << printReg(Reg, TRI); 1109 } 1110 1111 void MIPrinter::print(const MCCFIInstruction &CFI, 1112 const TargetRegisterInfo *TRI) { 1113 switch (CFI.getOperation()) { 1114 case MCCFIInstruction::OpSameValue: 1115 OS << "same_value "; 1116 if (CFI.getLabel()) 1117 OS << "<mcsymbol> "; 1118 printCFIRegister(CFI.getRegister(), OS, TRI); 1119 break; 1120 case MCCFIInstruction::OpOffset: 1121 OS << "offset "; 1122 if (CFI.getLabel()) 1123 OS << "<mcsymbol> "; 1124 printCFIRegister(CFI.getRegister(), OS, TRI); 1125 OS << ", " << CFI.getOffset(); 1126 break; 1127 case MCCFIInstruction::OpDefCfaRegister: 1128 OS << "def_cfa_register "; 1129 if (CFI.getLabel()) 1130 OS << "<mcsymbol> "; 1131 printCFIRegister(CFI.getRegister(), OS, TRI); 1132 break; 1133 case MCCFIInstruction::OpDefCfaOffset: 1134 OS << "def_cfa_offset "; 1135 if (CFI.getLabel()) 1136 OS << "<mcsymbol> "; 1137 OS << CFI.getOffset(); 1138 break; 1139 case MCCFIInstruction::OpDefCfa: 1140 OS << "def_cfa "; 1141 if (CFI.getLabel()) 1142 OS << "<mcsymbol> "; 1143 printCFIRegister(CFI.getRegister(), OS, TRI); 1144 OS << ", " << CFI.getOffset(); 1145 break; 1146 case MCCFIInstruction::OpRestore: 1147 OS << "restore "; 1148 if (CFI.getLabel()) 1149 OS << "<mcsymbol> "; 1150 printCFIRegister(CFI.getRegister(), OS, TRI); 1151 break; 1152 default: 1153 // TODO: Print the other CFI Operations. 1154 OS << "<unserializable cfi operation>"; 1155 break; 1156 } 1157 } 1158 1159 void llvm::printMIR(raw_ostream &OS, const Module &M) { 1160 yaml::Output Out(OS); 1161 Out << const_cast<Module &>(M); 1162 } 1163 1164 void llvm::printMIR(raw_ostream &OS, const MachineFunction &MF) { 1165 MIRPrinter Printer(OS); 1166 Printer.print(MF); 1167 } 1168