LLVM 19.0.0git
MIRPrinter.cpp
Go to the documentation of this file.
1//===- MIRPrinter.cpp - MIR serialization format printer ------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the class that prints out the LLVM IR and machine
10// functions using the MIR serialization format.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/StringRef.h"
38#include "llvm/IR/DebugLoc.h"
39#include "llvm/IR/Function.h"
42#include "llvm/IR/Module.h"
44#include "llvm/IR/Value.h"
45#include "llvm/MC/LaneBitmask.h"
50#include "llvm/Support/Format.h"
54#include <algorithm>
55#include <cassert>
56#include <cinttypes>
57#include <cstdint>
58#include <iterator>
59#include <string>
60#include <utility>
61#include <vector>
62
63using namespace llvm;
64
66 "simplify-mir", cl::Hidden,
67 cl::desc("Leave out unnecessary information when printing MIR"));
68
69static cl::opt<bool> PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true),
70 cl::desc("Print MIR debug-locations"));
71
73
74namespace {
75
76/// This structure describes how to print out stack object references.
77struct FrameIndexOperand {
78 std::string Name;
79 unsigned ID;
80 bool IsFixed;
81
82 FrameIndexOperand(StringRef Name, unsigned ID, bool IsFixed)
83 : Name(Name.str()), ID(ID), IsFixed(IsFixed) {}
84
85 /// Return an ordinary stack object reference.
86 static FrameIndexOperand create(StringRef Name, unsigned ID) {
87 return FrameIndexOperand(Name, ID, /*IsFixed=*/false);
88 }
89
90 /// Return a fixed stack object reference.
91 static FrameIndexOperand createFixed(unsigned ID) {
92 return FrameIndexOperand("", ID, /*IsFixed=*/true);
93 }
94};
95
96} // end anonymous namespace
97
98namespace llvm {
99
100/// This class prints out the machine functions using the MIR serialization
101/// format.
103 raw_ostream &OS;
105 /// Maps from stack object indices to operand indices which will be used when
106 /// printing frame index machine operands.
107 DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;
108
109public:
111
112 void print(const MachineFunction &MF);
113
114 void convert(yaml::MachineFunction &MF, const MachineRegisterInfo &RegInfo,
115 const TargetRegisterInfo *TRI);
117 const MachineFrameInfo &MFI);
121 const MachineJumpTableInfo &JTI);
123 const MachineFunction &MF, ModuleSlotTracker &MST);
125 const MachineFunction &MF,
126 ModuleSlotTracker &MST);
128 const MachineFunction &MF,
129 ModuleSlotTracker &MST);
131 const MachineFunction &MF,
133
134private:
135 void initRegisterMaskIds(const MachineFunction &MF);
136};
137
138/// This class prints out the machine instructions using the MIR serialization
139/// format.
141 raw_ostream &OS;
143 const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds;
144 const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping;
145 /// Synchronization scope names registered with LLVMContext.
147
148 bool canPredictBranchProbabilities(const MachineBasicBlock &MBB) const;
149 bool canPredictSuccessors(const MachineBasicBlock &MBB) const;
150
151public:
153 const DenseMap<const uint32_t *, unsigned> &RegisterMaskIds,
154 const DenseMap<int, FrameIndexOperand> &StackObjectOperandMapping)
155 : OS(OS), MST(MST), RegisterMaskIds(RegisterMaskIds),
156 StackObjectOperandMapping(StackObjectOperandMapping) {}
157
158 void print(const MachineBasicBlock &MBB);
159
160 void print(const MachineInstr &MI);
161 void printStackObjectReference(int FrameIndex);
162 void print(const MachineInstr &MI, unsigned OpIdx,
164 bool ShouldPrintRegisterTies, LLT TypeToPrint,
165 bool PrintDef = true);
166};
167
168} // end namespace llvm
169
170namespace llvm {
171namespace yaml {
172
173/// This struct serializes the LLVM IR module.
174template <> struct BlockScalarTraits<Module> {
175 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
176 Mod.print(OS, nullptr);
177 }
178
179 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
180 llvm_unreachable("LLVM Module is supposed to be parsed separately");
181 return "";
182 }
183};
184
185} // end namespace yaml
186} // end namespace llvm
187
188static void printRegMIR(unsigned Reg, yaml::StringValue &Dest,
189 const TargetRegisterInfo *TRI) {
191 OS << printReg(Reg, TRI);
192}
193
195 initRegisterMaskIds(MF);
196
198 YamlMF.Name = MF.getName();
199 YamlMF.Alignment = MF.getAlignment();
201 YamlMF.HasWinCFI = MF.hasWinCFI();
202
203 YamlMF.CallsEHReturn = MF.callsEHReturn();
204 YamlMF.CallsUnwindInit = MF.callsUnwindInit();
205 YamlMF.HasEHCatchret = MF.hasEHCatchret();
206 YamlMF.HasEHScopes = MF.hasEHScopes();
207 YamlMF.HasEHFunclets = MF.hasEHFunclets();
208 YamlMF.IsOutlined = MF.isOutlined();
210
211 YamlMF.Legalized = MF.getProperties().hasProperty(
215 YamlMF.Selected = MF.getProperties().hasProperty(
223
224 convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
227 convert(MST, YamlMF.FrameInfo, MF.getFrameInfo());
228 convertStackObjects(YamlMF, MF, MST);
229 convertEntryValueObjects(YamlMF, MF, MST);
230 convertCallSiteObjects(YamlMF, MF, MST);
231 for (const auto &Sub : MF.DebugValueSubstitutions) {
232 const auto &SubSrc = Sub.Src;
233 const auto &SubDest = Sub.Dest;
234 YamlMF.DebugValueSubstitutions.push_back({SubSrc.first, SubSrc.second,
235 SubDest.first,
236 SubDest.second,
237 Sub.Subreg});
238 }
239 if (const auto *ConstantPool = MF.getConstantPool())
240 convert(YamlMF, *ConstantPool);
241 if (const auto *JumpTableInfo = MF.getJumpTableInfo())
242 convert(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
243
244 const TargetMachine &TM = MF.getTarget();
245 YamlMF.MachineFuncInfo =
246 std::unique_ptr<yaml::MachineFunctionInfo>(TM.convertFuncInfoToYAML(MF));
247
248 raw_string_ostream StrOS(YamlMF.Body.Value.Value);
249 bool IsNewlineNeeded = false;
250 for (const auto &MBB : MF) {
251 if (IsNewlineNeeded)
252 StrOS << "\n";
253 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
254 .print(MBB);
255 IsNewlineNeeded = true;
256 }
257 StrOS.flush();
258 // Convert machine metadata collected during the print of the machine
259 // function.
260 convertMachineMetadataNodes(YamlMF, MF, MST);
261
262 yaml::Output Out(OS);
263 if (!SimplifyMIR)
264 Out.setWriteDefaultValues(true);
265 Out << YamlMF;
266}
267
268static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS,
269 const TargetRegisterInfo *TRI) {
270 assert(RegMask && "Can't print an empty register mask");
271 OS << StringRef("CustomRegMask(");
272
273 bool IsRegInRegMaskFound = false;
274 for (int I = 0, E = TRI->getNumRegs(); I < E; I++) {
275 // Check whether the register is asserted in regmask.
276 if (RegMask[I / 32] & (1u << (I % 32))) {
277 if (IsRegInRegMaskFound)
278 OS << ',';
279 OS << printReg(I, TRI);
280 IsRegInRegMaskFound = true;
281 }
282 }
283
284 OS << ')';
285}
286
287static void printRegClassOrBank(unsigned Reg, yaml::StringValue &Dest,
289 const TargetRegisterInfo *TRI) {
292}
293
294template <typename T>
295static void
297 T &Object, ModuleSlotTracker &MST) {
298 std::array<std::string *, 3> Outputs{{&Object.DebugVar.Value,
299 &Object.DebugExpr.Value,
300 &Object.DebugLoc.Value}};
301 std::array<const Metadata *, 3> Metas{{DebugVar.Var,
302 DebugVar.Expr,
303 DebugVar.Loc}};
304 for (unsigned i = 0; i < 3; ++i) {
305 raw_string_ostream StrOS(*Outputs[i]);
306 Metas[i]->printAsOperand(StrOS, MST);
307 }
308}
309
311 const MachineRegisterInfo &RegInfo,
312 const TargetRegisterInfo *TRI) {
313 MF.TracksRegLiveness = RegInfo.tracksLiveness();
314
315 // Print the virtual register definitions.
316 for (unsigned I = 0, E = RegInfo.getNumVirtRegs(); I < E; ++I) {
319 VReg.ID = I;
320 if (RegInfo.getVRegName(Reg) != "")
321 continue;
322 ::printRegClassOrBank(Reg, VReg.Class, RegInfo, TRI);
323 Register PreferredReg = RegInfo.getSimpleHint(Reg);
324 if (PreferredReg)
325 printRegMIR(PreferredReg, VReg.PreferredRegister, TRI);
326 MF.VirtualRegisters.push_back(VReg);
327 }
328
329 // Print the live ins.
330 for (std::pair<unsigned, unsigned> LI : RegInfo.liveins()) {
332 printRegMIR(LI.first, LiveIn.Register, TRI);
333 if (LI.second)
334 printRegMIR(LI.second, LiveIn.VirtualRegister, TRI);
335 MF.LiveIns.push_back(LiveIn);
336 }
337
338 // Prints the callee saved registers.
339 if (RegInfo.isUpdatedCSRsInitialized()) {
340 const MCPhysReg *CalleeSavedRegs = RegInfo.getCalleeSavedRegs();
341 std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
342 for (const MCPhysReg *I = CalleeSavedRegs; *I; ++I) {
344 printRegMIR(*I, Reg, TRI);
345 CalleeSavedRegisters.push_back(Reg);
346 }
347 MF.CalleeSavedRegisters = CalleeSavedRegisters;
348 }
349}
350
352 yaml::MachineFrameInfo &YamlMFI,
353 const MachineFrameInfo &MFI) {
356 YamlMFI.HasStackMap = MFI.hasStackMap();
357 YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
358 YamlMFI.StackSize = MFI.getStackSize();
360 YamlMFI.MaxAlignment = MFI.getMaxAlign().value();
361 YamlMFI.AdjustsStack = MFI.adjustsStack();
362 YamlMFI.HasCalls = MFI.hasCalls();
364 ? MFI.getMaxCallFrameSize() : ~0u;
368 YamlMFI.HasVAStart = MFI.hasVAStart();
370 YamlMFI.HasTailCall = MFI.hasTailCall();
371 YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
372 if (MFI.getSavePoint()) {
373 raw_string_ostream StrOS(YamlMFI.SavePoint.Value);
374 StrOS << printMBBReference(*MFI.getSavePoint());
375 }
376 if (MFI.getRestorePoint()) {
378 StrOS << printMBBReference(*MFI.getRestorePoint());
379 }
380}
381
383 const MachineFunction &MF,
384 ModuleSlotTracker &MST) {
386 for (const MachineFunction::VariableDbgInfo &DebugVar :
388 yaml::EntryValueObject &Obj = YMF.EntryValueObjects.emplace_back();
389 printStackObjectDbgInfo(DebugVar, Obj, MST);
390 MCRegister EntryValReg = DebugVar.getEntryValueRegister();
391 printRegMIR(EntryValReg, Obj.EntryValueRegister, TRI);
392 }
393}
394
396 const MachineFunction &MF,
397 ModuleSlotTracker &MST) {
398 const MachineFrameInfo &MFI = MF.getFrameInfo();
400
401 // Process fixed stack objects.
402 assert(YMF.FixedStackObjects.empty());
403 SmallVector<int, 32> FixedStackObjectsIdx;
404 const int BeginIdx = MFI.getObjectIndexBegin();
405 if (BeginIdx < 0)
406 FixedStackObjectsIdx.reserve(-BeginIdx);
407
408 unsigned ID = 0;
409 for (int I = BeginIdx; I < 0; ++I, ++ID) {
410 FixedStackObjectsIdx.push_back(-1); // Fill index for possible dead.
411 if (MFI.isDeadObjectIndex(I))
412 continue;
413
415 YamlObject.ID = ID;
416 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
419 YamlObject.Offset = MFI.getObjectOffset(I);
420 YamlObject.Size = MFI.getObjectSize(I);
421 YamlObject.Alignment = MFI.getObjectAlign(I);
422 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
423 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
424 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
425 // Save the ID' position in FixedStackObjects storage vector.
426 FixedStackObjectsIdx[ID] = YMF.FixedStackObjects.size();
427 YMF.FixedStackObjects.push_back(YamlObject);
428 StackObjectOperandMapping.insert(
429 std::make_pair(I, FrameIndexOperand::createFixed(ID)));
430 }
431
432 // Process ordinary stack objects.
433 assert(YMF.StackObjects.empty());
434 SmallVector<unsigned, 32> StackObjectsIdx;
435 const int EndIdx = MFI.getObjectIndexEnd();
436 if (EndIdx > 0)
437 StackObjectsIdx.reserve(EndIdx);
438 ID = 0;
439 for (int I = 0; I < EndIdx; ++I, ++ID) {
440 StackObjectsIdx.push_back(-1); // Fill index for possible dead.
441 if (MFI.isDeadObjectIndex(I))
442 continue;
443
444 yaml::MachineStackObject YamlObject;
445 YamlObject.ID = ID;
446 if (const auto *Alloca = MFI.getObjectAllocation(I))
447 YamlObject.Name.Value = std::string(
448 Alloca->hasName() ? Alloca->getName() : "");
449 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
454 YamlObject.Offset = MFI.getObjectOffset(I);
455 YamlObject.Size = MFI.getObjectSize(I);
456 YamlObject.Alignment = MFI.getObjectAlign(I);
457 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
458
459 // Save the ID' position in StackObjects storage vector.
460 StackObjectsIdx[ID] = YMF.StackObjects.size();
461 YMF.StackObjects.push_back(YamlObject);
462 StackObjectOperandMapping.insert(std::make_pair(
463 I, FrameIndexOperand::create(YamlObject.Name.Value, ID)));
464 }
465
466 for (const auto &CSInfo : MFI.getCalleeSavedInfo()) {
467 const int FrameIdx = CSInfo.getFrameIdx();
468 if (!CSInfo.isSpilledToReg() && MFI.isDeadObjectIndex(FrameIdx))
469 continue;
470
472 printRegMIR(CSInfo.getReg(), Reg, TRI);
473 if (!CSInfo.isSpilledToReg()) {
474 assert(FrameIdx >= MFI.getObjectIndexBegin() &&
475 FrameIdx < MFI.getObjectIndexEnd() &&
476 "Invalid stack object index");
477 if (FrameIdx < 0) { // Negative index means fixed objects.
478 auto &Object =
480 [FixedStackObjectsIdx[FrameIdx + MFI.getNumFixedObjects()]];
481 Object.CalleeSavedRegister = Reg;
482 Object.CalleeSavedRestored = CSInfo.isRestored();
483 } else {
484 auto &Object = YMF.StackObjects[StackObjectsIdx[FrameIdx]];
485 Object.CalleeSavedRegister = Reg;
486 Object.CalleeSavedRestored = CSInfo.isRestored();
487 }
488 }
489 }
490 for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) {
491 auto LocalObject = MFI.getLocalFrameObjectMap(I);
492 assert(LocalObject.first >= 0 && "Expected a locally mapped stack object");
493 YMF.StackObjects[StackObjectsIdx[LocalObject.first]].LocalOffset =
494 LocalObject.second;
495 }
496
497 // Print the stack object references in the frame information class after
498 // converting the stack objects.
499 if (MFI.hasStackProtectorIndex()) {
501 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
503 }
504
505 if (MFI.hasFunctionContextIndex()) {
507 MIPrinter(StrOS, MST, RegisterMaskIds, StackObjectOperandMapping)
509 }
510
511 // Print the debug variable information.
512 for (const MachineFunction::VariableDbgInfo &DebugVar :
514 int Idx = DebugVar.getStackSlot();
515 assert(Idx >= MFI.getObjectIndexBegin() && Idx < MFI.getObjectIndexEnd() &&
516 "Invalid stack object index");
517 if (Idx < 0) { // Negative index means fixed objects.
518 auto &Object =
519 YMF.FixedStackObjects[FixedStackObjectsIdx[Idx +
520 MFI.getNumFixedObjects()]];
521 printStackObjectDbgInfo(DebugVar, Object, MST);
522 } else {
523 auto &Object = YMF.StackObjects[StackObjectsIdx[Idx]];
524 printStackObjectDbgInfo(DebugVar, Object, MST);
525 }
526 }
527}
528
530 const MachineFunction &MF,
531 ModuleSlotTracker &MST) {
532 const auto *TRI = MF.getSubtarget().getRegisterInfo();
533 for (auto CSInfo : MF.getCallSitesInfo()) {
534 yaml::CallSiteInfo YmlCS;
536
537 // Prepare instruction position.
538 MachineBasicBlock::const_instr_iterator CallI = CSInfo.first->getIterator();
539 CallLocation.BlockNum = CallI->getParent()->getNumber();
540 // Get call instruction offset from the beginning of block.
541 CallLocation.Offset =
542 std::distance(CallI->getParent()->instr_begin(), CallI);
543 YmlCS.CallLocation = CallLocation;
544 // Construct call arguments and theirs forwarding register info.
545 for (auto ArgReg : CSInfo.second.ArgRegPairs) {
547 YmlArgReg.ArgNo = ArgReg.ArgNo;
548 printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
549 YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
550 }
551 YMF.CallSitesInfo.push_back(YmlCS);
552 }
553
554 // Sort call info by position of call instructions.
555 llvm::sort(YMF.CallSitesInfo.begin(), YMF.CallSitesInfo.end(),
557 if (A.CallLocation.BlockNum == B.CallLocation.BlockNum)
558 return A.CallLocation.Offset < B.CallLocation.Offset;
559 return A.CallLocation.BlockNum < B.CallLocation.BlockNum;
560 });
561}
562
564 const MachineFunction &MF,
567 MST.collectMachineMDNodes(MDList);
568 for (auto &MD : MDList) {
569 std::string NS;
570 raw_string_ostream StrOS(NS);
571 MD.second->print(StrOS, MST, MF.getFunction().getParent());
572 YMF.MachineMetadataNodes.push_back(StrOS.str());
573 }
574}
575
578 unsigned ID = 0;
579 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
580 std::string Str;
581 raw_string_ostream StrOS(Str);
582 if (Constant.isMachineConstantPoolEntry()) {
583 Constant.Val.MachineCPVal->print(StrOS);
584 } else {
585 Constant.Val.ConstVal->printAsOperand(StrOS);
586 }
587
589 YamlConstant.ID = ID++;
590 YamlConstant.Value = StrOS.str();
591 YamlConstant.Alignment = Constant.getAlign();
592 YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry();
593
594 MF.Constants.push_back(YamlConstant);
595 }
596}
597
599 yaml::MachineJumpTable &YamlJTI,
600 const MachineJumpTableInfo &JTI) {
601 YamlJTI.Kind = JTI.getEntryKind();
602 unsigned ID = 0;
603 for (const auto &Table : JTI.getJumpTables()) {
604 std::string Str;
606 Entry.ID = ID++;
607 for (const auto *MBB : Table.MBBs) {
608 raw_string_ostream StrOS(Str);
609 StrOS << printMBBReference(*MBB);
610 Entry.Blocks.push_back(StrOS.str());
611 Str.clear();
612 }
613 YamlJTI.Entries.push_back(Entry);
614 }
615}
616
617void MIRPrinter::initRegisterMaskIds(const MachineFunction &MF) {
618 const auto *TRI = MF.getSubtarget().getRegisterInfo();
619 unsigned I = 0;
620 for (const uint32_t *Mask : TRI->getRegMasks())
621 RegisterMaskIds.insert(std::make_pair(Mask, I++));
622}
623
626 bool &IsFallthrough) {
628
629 for (const MachineInstr &MI : MBB) {
630 if (MI.isPHI())
631 continue;
632 for (const MachineOperand &MO : MI.operands()) {
633 if (!MO.isMBB())
634 continue;
635 MachineBasicBlock *Succ = MO.getMBB();
636 auto RP = Seen.insert(Succ);
637 if (RP.second)
638 Result.push_back(Succ);
639 }
640 }
642 IsFallthrough = I == MBB.end() || !I->isBarrier();
643}
644
645bool
646MIPrinter::canPredictBranchProbabilities(const MachineBasicBlock &MBB) const {
647 if (MBB.succ_size() <= 1)
648 return true;
650 return true;
651
652 SmallVector<BranchProbability,8> Normalized(MBB.Probs.begin(),
653 MBB.Probs.end());
655 Normalized.end());
656 SmallVector<BranchProbability,8> Equal(Normalized.size());
657 BranchProbability::normalizeProbabilities(Equal.begin(), Equal.end());
658
659 return std::equal(Normalized.begin(), Normalized.end(), Equal.begin());
660}
661
662bool MIPrinter::canPredictSuccessors(const MachineBasicBlock &MBB) const {
664 bool GuessedFallthrough;
665 guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough);
666 if (GuessedFallthrough) {
667 const MachineFunction &MF = *MBB.getParent();
669 if (NextI != MF.end()) {
670 MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI);
671 if (!is_contained(GuessedSuccs, Next))
672 GuessedSuccs.push_back(Next);
673 }
674 }
675 if (GuessedSuccs.size() != MBB.succ_size())
676 return false;
677 return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin());
678}
679
681 assert(MBB.getNumber() >= 0 && "Invalid MBB number");
682 MBB.printName(OS,
685 &MST);
686 OS << ":\n";
687
688 bool HasLineAttributes = false;
689 // Print the successors
690 bool canPredictProbs = canPredictBranchProbabilities(MBB);
691 // Even if the list of successors is empty, if we cannot guess it,
692 // we need to print it to tell the parser that the list is empty.
693 // This is needed, because MI model unreachable as empty blocks
694 // with an empty successor list. If the parser would see that
695 // without the successor list, it would guess the code would
696 // fallthrough.
697 if ((!MBB.succ_empty() && !SimplifyMIR) || !canPredictProbs ||
698 !canPredictSuccessors(MBB)) {
699 OS.indent(2) << "successors:";
700 if (!MBB.succ_empty())
701 OS << " ";
702 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
703 if (I != MBB.succ_begin())
704 OS << ", ";
705 OS << printMBBReference(**I);
706 if (!SimplifyMIR || !canPredictProbs)
707 OS << '('
708 << format("0x%08" PRIx32, MBB.getSuccProbability(I).getNumerator())
709 << ')';
710 }
711 OS << "\n";
712 HasLineAttributes = true;
713 }
714
715 // Print the live in registers.
717 if (!MBB.livein_empty()) {
718 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
719 OS.indent(2) << "liveins: ";
720 bool First = true;
721 for (const auto &LI : MBB.liveins_dbg()) {
722 if (!First)
723 OS << ", ";
724 First = false;
725 OS << printReg(LI.PhysReg, &TRI);
726 if (!LI.LaneMask.all())
727 OS << ":0x" << PrintLaneMask(LI.LaneMask);
728 }
729 OS << "\n";
730 HasLineAttributes = true;
731 }
732
733 if (HasLineAttributes && !MBB.empty())
734 OS << "\n";
735 bool IsInBundle = false;
736 for (const MachineInstr &MI : MBB.instrs()) {
737 if (IsInBundle && !MI.isInsideBundle()) {
738 OS.indent(2) << "}\n";
739 IsInBundle = false;
740 }
741 OS.indent(IsInBundle ? 4 : 2);
742 print(MI);
743 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
744 OS << " {";
745 IsInBundle = true;
746 }
747 OS << "\n";
748 }
749 if (IsInBundle)
750 OS.indent(2) << "}\n";
751}
752
754 const auto *MF = MI.getMF();
755 const auto &MRI = MF->getRegInfo();
756 const auto &SubTarget = MF->getSubtarget();
757 const auto *TRI = SubTarget.getRegisterInfo();
758 assert(TRI && "Expected target register info");
759 const auto *TII = SubTarget.getInstrInfo();
760 assert(TII && "Expected target instruction info");
761 if (MI.isCFIInstruction())
762 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
763
764 SmallBitVector PrintedTypes(8);
765 bool ShouldPrintRegisterTies = MI.hasComplexRegisterTies();
766 unsigned I = 0, E = MI.getNumOperands();
767 for (; I < E && MI.getOperand(I).isReg() && MI.getOperand(I).isDef() &&
768 !MI.getOperand(I).isImplicit();
769 ++I) {
770 if (I)
771 OS << ", ";
772 print(MI, I, TRI, TII, ShouldPrintRegisterTies,
773 MI.getTypeToPrint(I, PrintedTypes, MRI),
774 /*PrintDef=*/false);
775 }
776
777 if (I)
778 OS << " = ";
779 if (MI.getFlag(MachineInstr::FrameSetup))
780 OS << "frame-setup ";
781 if (MI.getFlag(MachineInstr::FrameDestroy))
782 OS << "frame-destroy ";
783 if (MI.getFlag(MachineInstr::FmNoNans))
784 OS << "nnan ";
785 if (MI.getFlag(MachineInstr::FmNoInfs))
786 OS << "ninf ";
787 if (MI.getFlag(MachineInstr::FmNsz))
788 OS << "nsz ";
789 if (MI.getFlag(MachineInstr::FmArcp))
790 OS << "arcp ";
791 if (MI.getFlag(MachineInstr::FmContract))
792 OS << "contract ";
793 if (MI.getFlag(MachineInstr::FmAfn))
794 OS << "afn ";
795 if (MI.getFlag(MachineInstr::FmReassoc))
796 OS << "reassoc ";
797 if (MI.getFlag(MachineInstr::NoUWrap))
798 OS << "nuw ";
799 if (MI.getFlag(MachineInstr::NoSWrap))
800 OS << "nsw ";
801 if (MI.getFlag(MachineInstr::IsExact))
802 OS << "exact ";
803 if (MI.getFlag(MachineInstr::NoFPExcept))
804 OS << "nofpexcept ";
805 if (MI.getFlag(MachineInstr::NoMerge))
806 OS << "nomerge ";
807 if (MI.getFlag(MachineInstr::Unpredictable))
808 OS << "unpredictable ";
809 if (MI.getFlag(MachineInstr::NoConvergent))
810 OS << "noconvergent ";
811 if (MI.getFlag(MachineInstr::NonNeg))
812 OS << "nneg ";
813 if (MI.getFlag(MachineInstr::Disjoint))
814 OS << "disjoint ";
815
816 OS << TII->getName(MI.getOpcode());
817 if (I < E)
818 OS << ' ';
819
820 bool NeedComma = false;
821 for (; I < E; ++I) {
822 if (NeedComma)
823 OS << ", ";
824 print(MI, I, TRI, TII, ShouldPrintRegisterTies,
825 MI.getTypeToPrint(I, PrintedTypes, MRI));
826 NeedComma = true;
827 }
828
829 // Print any optional symbols attached to this instruction as-if they were
830 // operands.
831 if (MCSymbol *PreInstrSymbol = MI.getPreInstrSymbol()) {
832 if (NeedComma)
833 OS << ',';
834 OS << " pre-instr-symbol ";
835 MachineOperand::printSymbol(OS, *PreInstrSymbol);
836 NeedComma = true;
837 }
838 if (MCSymbol *PostInstrSymbol = MI.getPostInstrSymbol()) {
839 if (NeedComma)
840 OS << ',';
841 OS << " post-instr-symbol ";
842 MachineOperand::printSymbol(OS, *PostInstrSymbol);
843 NeedComma = true;
844 }
845 if (MDNode *HeapAllocMarker = MI.getHeapAllocMarker()) {
846 if (NeedComma)
847 OS << ',';
848 OS << " heap-alloc-marker ";
849 HeapAllocMarker->printAsOperand(OS, MST);
850 NeedComma = true;
851 }
852 if (MDNode *PCSections = MI.getPCSections()) {
853 if (NeedComma)
854 OS << ',';
855 OS << " pcsections ";
856 PCSections->printAsOperand(OS, MST);
857 NeedComma = true;
858 }
859 if (MDNode *MMRA = MI.getMMRAMetadata()) {
860 if (NeedComma)
861 OS << ',';
862 OS << " mmra ";
863 MMRA->printAsOperand(OS, MST);
864 NeedComma = true;
865 }
866 if (uint32_t CFIType = MI.getCFIType()) {
867 if (NeedComma)
868 OS << ',';
869 OS << " cfi-type " << CFIType;
870 NeedComma = true;
871 }
872
873 if (auto Num = MI.peekDebugInstrNum()) {
874 if (NeedComma)
875 OS << ',';
876 OS << " debug-instr-number " << Num;
877 NeedComma = true;
878 }
879
880 if (PrintLocations) {
881 if (const DebugLoc &DL = MI.getDebugLoc()) {
882 if (NeedComma)
883 OS << ',';
884 OS << " debug-location ";
885 DL->printAsOperand(OS, MST);
886 }
887 }
888
889 if (!MI.memoperands_empty()) {
890 OS << " :: ";
891 const LLVMContext &Context = MF->getFunction().getContext();
892 const MachineFrameInfo &MFI = MF->getFrameInfo();
893 bool NeedComma = false;
894 for (const auto *Op : MI.memoperands()) {
895 if (NeedComma)
896 OS << ", ";
897 Op->print(OS, MST, SSNs, Context, &MFI, TII);
898 NeedComma = true;
899 }
900 }
901}
902
904 auto ObjectInfo = StackObjectOperandMapping.find(FrameIndex);
905 assert(ObjectInfo != StackObjectOperandMapping.end() &&
906 "Invalid frame index");
907 const FrameIndexOperand &Operand = ObjectInfo->second;
908 MachineOperand::printStackObjectReference(OS, Operand.ID, Operand.IsFixed,
909 Operand.Name);
910}
911
912static std::string formatOperandComment(std::string Comment) {
913 if (Comment.empty())
914 return Comment;
915 return std::string(" /* " + Comment + " */");
916}
917
918void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
919 const TargetRegisterInfo *TRI,
920 const TargetInstrInfo *TII,
921 bool ShouldPrintRegisterTies, LLT TypeToPrint,
922 bool PrintDef) {
923 const MachineOperand &Op = MI.getOperand(OpIdx);
924 std::string MOComment = TII->createMIROperandComment(MI, Op, OpIdx, TRI);
925
926 switch (Op.getType()) {
928 if (MI.isOperandSubregIdx(OpIdx)) {
931 break;
932 }
933 [[fallthrough]];
952 unsigned TiedOperandIdx = 0;
953 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
954 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
955 const TargetIntrinsicInfo *TII = MI.getMF()->getTarget().getIntrinsicInfo();
956 Op.print(OS, MST, TypeToPrint, OpIdx, PrintDef, /*IsStandalone=*/false,
957 ShouldPrintRegisterTies, TiedOperandIdx, TRI, TII);
958 OS << formatOperandComment(MOComment);
959 break;
960 }
962 printStackObjectReference(Op.getIndex());
963 break;
965 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
966 if (RegMaskInfo != RegisterMaskIds.end())
967 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
968 else
969 printCustomRegMask(Op.getRegMask(), OS, TRI);
970 break;
971 }
972 }
973}
974
976 ModuleSlotTracker &MST) {
977 if (isa<GlobalValue>(V)) {
978 V.printAsOperand(OS, /*PrintType=*/false, MST);
979 return;
980 }
981 if (isa<Constant>(V)) {
982 // Machine memory operands can load/store to/from constant value pointers.
983 OS << '`';
984 V.printAsOperand(OS, /*PrintType=*/true, MST);
985 OS << '`';
986 return;
987 }
988 OS << "%ir.";
989 if (V.hasName()) {
990 printLLVMNameWithoutPrefix(OS, V.getName());
991 return;
992 }
993 int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1;
995}
996
998 ScopedDbgInfoFormatSetter FormatSetter(const_cast<Module &>(M),
1000
1001 yaml::Output Out(OS);
1002 Out << const_cast<Module &>(M);
1003}
1004
1006 // RemoveDIs: as there's no textual form for DbgRecords yet, print debug-info
1007 // in dbg.value format.
1008 ScopedDbgInfoFormatSetter FormatSetter(
1009 const_cast<Function &>(MF.getFunction()), WriteNewDbgInfoFormat);
1010
1012 Printer.print(MF);
1013}
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
dxil pretty DXIL Metadata Pretty Printer
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
expand large fp convert
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
This file contains an interface for creating legacy passes to print out IR in various granularities.
cl::opt< bool > WriteNewDbgInfoFormat
A common definition of LaneBitmask for use in TableGen and CodeGen.
Implement a low-level type suitable for MachineInstr level instruction selection.
#define I(x, y, z)
Definition: MD5.cpp:58
static std::string formatOperandComment(std::string Comment)
Definition: MIRPrinter.cpp:912
static void printRegMIR(unsigned Reg, yaml::StringValue &Dest, const TargetRegisterInfo *TRI)
Definition: MIRPrinter.cpp:188
static cl::opt< bool > PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true), cl::desc("Print MIR debug-locations"))
cl::opt< bool > WriteNewDbgInfoFormat
static void printStackObjectDbgInfo(const MachineFunction::VariableDbgInfo &DebugVar, T &Object, ModuleSlotTracker &MST)
Definition: MIRPrinter.cpp:296
static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS, const TargetRegisterInfo *TRI)
Definition: MIRPrinter.cpp:268
static cl::opt< bool > SimplifyMIR("simplify-mir", cl::Hidden, cl::desc("Leave out unnecessary information when printing MIR"))
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
unsigned const TargetRegisterInfo * TRI
static bool isReg(const MCInst &MI, unsigned OpNo)
Module.h This file contains the declarations for the Module class.
LLVMContext & Context
Module * Mod
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
This file implements the SmallBitVector class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
uint32_t getNumerator() const
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
This is an important base class in LLVM.
Definition: Constant.h:41
This class represents an Operation in the Expression.
bool print(raw_ostream &OS, DIDumpOptions DumpOpts, const DWARFExpression *Expr, DWARFUnit *U) const
A debug info location.
Definition: DebugLoc.h:33
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:356
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:656
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
Metadata node.
Definition: Metadata.h:1067
This class prints out the machine instructions using the MIR serialization format.
Definition: MIRPrinter.cpp:140
void print(const MachineBasicBlock &MBB)
Definition: MIRPrinter.cpp:680
MIPrinter(raw_ostream &OS, ModuleSlotTracker &MST, const DenseMap< const uint32_t *, unsigned > &RegisterMaskIds, const DenseMap< int, FrameIndexOperand > &StackObjectOperandMapping)
Definition: MIRPrinter.cpp:152
void printStackObjectReference(int FrameIndex)
Definition: MIRPrinter.cpp:903
static void printIRValue(raw_ostream &OS, const Value &V, ModuleSlotTracker &MST)
Helper functions to print IR value as MIR serialization format which will be useful for target specif...
Definition: MIRPrinter.cpp:975
This class prints out the machine functions using the MIR serialization format.
Definition: MIRPrinter.cpp:102
void convert(yaml::MachineFunction &MF, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Definition: MIRPrinter.cpp:310
void convertEntryValueObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST)
Definition: MIRPrinter.cpp:382
void convertCallSiteObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST)
Definition: MIRPrinter.cpp:529
void print(const MachineFunction &MF)
Definition: MIRPrinter.cpp:194
void convertMachineMetadataNodes(yaml::MachineFunction &YMF, const MachineFunction &MF, MachineModuleSlotTracker &MST)
Definition: MIRPrinter.cpp:563
MIRPrinter(raw_ostream &OS)
Definition: MIRPrinter.cpp:110
void convertStackObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST)
Definition: MIRPrinter.cpp:395
BranchProbability getSuccProbability(const_succ_iterator Succ) const
Return probability of the edge from this block to MBB.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
@ PrintNameIr
Add IR name where available.
@ PrintNameAttributes
Print attributes.
void printAsOperand(raw_ostream &OS, bool PrintType=true) const
unsigned succ_size() const
iterator_range< livein_iterator > liveins_dbg() const
bool hasSuccessorProbabilities() const
Return true if any of the successors have probabilities attached to them.
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
Instructions::const_iterator const_instr_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void printName(raw_ostream &os, unsigned printNameFlags=PrintNameIr, ModuleSlotTracker *moduleSlotTracker=nullptr) const
Print the basic block's name as:
This class is a data container for one entry in a MachineConstantPool.
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
bool isReturnAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
bool hasCalls() const
Return true if the current function has any function calls.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
MachineBasicBlock * getRestorePoint() const
bool isImmutableObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an immutable object.
int getStackProtectorIndex() const
Return the index for the stack protector object.
bool hasTailCall() const
Returns true if the function contains a tail call.
bool hasMustTailInVarArgFunc() const
Returns true if the function is variadic and contains a musttail call.
int getOffsetAdjustment() const
Return the correction for frame offsets.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool isMaxCallFrameSizeComputed() const
int64_t getLocalFrameSize() const
Get the size of the local object blob.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
bool hasVAStart() const
Returns true if the function calls the llvm.va_start intrinsic.
unsigned getCVBytesOfCalleeSavedRegisters() const
Returns how many bytes of callee-saved registers the target pushed in the prologue.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
uint8_t getStackID(int ObjectIdx) const
unsigned getNumFixedObjects() const
Return the number of fixed objects.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool hasFunctionContextIndex() const
int getObjectIndexBegin() const
Return the minimum frame object index.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
MachineBasicBlock * getSavePoint() const
int getFunctionContextIndex() const
Return the index for the function context object.
bool isAliasedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an object that might be pointed to by an LLVM IR v...
bool hasProperty(Property P) const
Description of the location of a variable whose Address is valid and unchanging during function execu...
auto getEntryValueVariableDbgInfo() const
Returns the collection of variables for which we have debug info and that have been assigned an entry...
bool useDebugInstrRef() const
Returns true if the function's variable locations are tracked with instruction referencing.
SmallVector< DebugSubstitution, 8 > DebugValueSubstitutions
Debug value substitutions: a collection of DebugSubstitution objects, recording changes in where a va...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool callsUnwindInit() const
const CallSiteInfoMap & getCallSitesInfo() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
auto getInStackSlotVariableDbgInfo()
Returns the collection of variables for which we have debug info and that have been assigned a stack ...
Align getAlignment() const
getAlignment - Return the alignment of the function.
Function & getFunction()
Return the LLVM function that this machine code represents.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
BasicBlockListType::const_iterator const_iterator
Representation of each machine instruction.
Definition: MachineInstr.h:69
JTEntryKind getEntryKind() const
const std::vector< MachineJumpTableEntry > & getJumpTables() const
void collectMachineMDNodes(MachineMDNodeListType &L) const
MachineOperand class - Representation of each machine instruction operand.
static void printStackObjectReference(raw_ostream &OS, unsigned FrameIndex, bool IsFixed, StringRef Name)
Print a stack object reference.
static void printSubRegIdx(raw_ostream &OS, uint64_t Index, const TargetRegisterInfo *TRI)
Print a subreg index operand.
static void printTargetFlags(raw_ostream &OS, const MachineOperand &Op)
Print operand target flags.
static void printIRSlotNumber(raw_ostream &OS, int Slot)
Print an IRSlotNumber.
static void printSymbol(raw_ostream &OS, MCSymbol &Sym)
Print a MCSymbol as an operand.
@ MO_CFIIndex
MCCFIInstruction index.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_Predicate
Generic predicate for ISel.
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_ShuffleMask
Other IR Constant for ISel (shuffle masks)
@ MO_CImmediate
Immediate >64bit operand.
@ MO_BlockAddress
Address of a basic block.
@ MO_DbgInstrRef
Integer indices referring to an instruction+operand.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_IntrinsicID
Intrinsic ID for ISel.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
@ MO_TargetIndex
Target-dependent index+offset operand.
@ MO_Metadata
Metadata reference (for debug info)
@ MO_FPImmediate
Floating-point immediate operand.
@ MO_RegisterLiveOut
Mask of live-out registers.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Register getSimpleHint(Register VReg) const
getSimpleHint - same as getRegAllocationHint except it will only return a target independent hint.
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
bool isUpdatedCSRsInitialized() const
Returns true if the updated CSR list was initialized and false otherwise.
ArrayRef< std::pair< MCRegister, Register > > liveins() const
const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
StringRef getVRegName(Register Reg) const
void print(raw_ostream &OS, const Module *M=nullptr, bool IsForDebug=false) const
Print.
Definition: AsmWriter.cpp:5195
Manage lifetime of a slot tracker for printing IR.
std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
Definition: AsmWriter.cpp:913
const Function * getCurrentFunction() const
void incorporateFunction(const Function &F)
Incorporate the given function.
Definition: AsmWriter.cpp:899
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
Definition: AsmWriter.cpp:4847
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition: Register.h:84
Used to temporarily set the debug info format of a function, module, or basic block for the duration ...
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:342
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:427
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void reserve(size_type N)
Definition: SmallVector.h:676
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string lower() const
Definition: StringRef.cpp:111
TargetInstrInfo - Interface to description of machine instruction set.
TargetIntrinsicInfo - Interface to description of machine instruction set.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
LLVM Value Representation.
Definition: Value.h:74
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Definition: AsmWriter.cpp:4996
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Definition: AsmWriter.cpp:5079
self_iterator getIterator()
Definition: ilist_node.h:109
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:660
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:678
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:450
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition: LaneBitmask.h:92
void printMIR(raw_ostream &OS, const Module &M)
Print LLVM IR using the MIR serialization format to the given output stream.
Definition: MIRPrinter.cpp:997
void guessSuccessors(const MachineBasicBlock &MBB, SmallVectorImpl< MachineBasicBlock * > &Result, bool &IsFallthrough)
Determine a possible list of successors of a basic block based on the basic block machine operand bei...
Definition: MIRPrinter.cpp:624
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1647
Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1879
void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
Definition: AsmWriter.cpp:380
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
static void output(const Module &Mod, void *Ctxt, raw_ostream &OS)
Definition: MIRPrinter.cpp:175
static StringRef input(StringRef Str, void *Ctxt, Module &Mod)
Definition: MIRPrinter.cpp:179
Identifies call instruction location in machine function.
Serializable representation of CallSiteInfo.
std::vector< ArgRegPair > ArgForwardingRegs
MachineInstrLoc CallLocation
Serializable representation of the MCRegister variant of MachineFunction::VariableDbgInfo.
Serializable representation of the fixed stack object from the MachineFrameInfo class.
Serializable representation of MachineFrameInfo.
unsigned MaxCallFrameSize
~0u means: not computed yet.
std::vector< MachineStackObject > StackObjects
std::vector< StringValue > MachineMetadataNodes
std::optional< std::vector< FlowStringValue > > CalleeSavedRegisters
std::vector< EntryValueObject > EntryValueObjects
std::vector< MachineConstantPoolValue > Constants
std::vector< CallSiteInfo > CallSitesInfo
std::vector< MachineFunctionLiveIn > LiveIns
std::vector< VirtualRegisterDefinition > VirtualRegisters
std::vector< FixedMachineStackObject > FixedStackObjects
std::vector< DebugValueSubstitution > DebugValueSubstitutions
std::unique_ptr< MachineFunctionInfo > MachineFuncInfo
Constant pool.
MachineJumpTable JumpTableInfo
std::vector< Entry > Entries
MachineJumpTableInfo::JTEntryKind Kind
Serializable representation of stack object from the MachineFrameInfo class.
TargetStackID::Value StackID
A wrapper around std::string which contains a source range that's being set during parsing.