LLVM 22.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"
21#include "llvm/ADT/StringRef.h"
39#include "llvm/IR/DebugLoc.h"
40#include "llvm/IR/Function.h"
43#include "llvm/IR/Module.h"
45#include "llvm/IR/Value.h"
46#include "llvm/MC/LaneBitmask.h"
51#include "llvm/Support/Format.h"
55#include <algorithm>
56#include <cassert>
57#include <cinttypes>
58#include <cstdint>
59#include <iterator>
60#include <string>
61#include <utility>
62#include <vector>
63
64using namespace llvm;
65
67 "simplify-mir", cl::Hidden,
68 cl::desc("Leave out unnecessary information when printing MIR"));
69
70static cl::opt<bool> PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true),
71 cl::desc("Print MIR debug-locations"));
72
73namespace {
74
75/// This structure describes how to print out stack object references.
76struct FrameIndexOperand {
77 std::string Name;
78 unsigned ID;
79 bool IsFixed;
80
81 FrameIndexOperand(StringRef Name, unsigned ID, bool IsFixed)
82 : Name(Name.str()), ID(ID), IsFixed(IsFixed) {}
83
84 /// Return an ordinary stack object reference.
85 static FrameIndexOperand create(StringRef Name, unsigned ID) {
86 return FrameIndexOperand(Name, ID, /*IsFixed=*/false);
87 }
88
89 /// Return a fixed stack object reference.
90 static FrameIndexOperand createFixed(unsigned ID) {
91 return FrameIndexOperand("", ID, /*IsFixed=*/true);
92 }
93};
94
95struct MFPrintState {
96 MachineModuleSlotTracker MST;
97 DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
98 /// Maps from stack object indices to operand indices which will be used when
99 /// printing frame index machine operands.
100 DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;
101 /// Synchronization scope names registered with LLVMContext.
103
104 MFPrintState(const MachineModuleInfo &MMI, const MachineFunction &MF)
105 : MST(MMI, &MF) {}
106};
107
108} // end anonymous namespace
109
110/// This struct serializes the LLVM IR module.
111template <> struct yaml::BlockScalarTraits<Module> {
112 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
113 Mod.print(OS, nullptr);
114 }
115
116 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
117 llvm_unreachable("LLVM Module is supposed to be parsed separately");
118 return "";
119 }
120};
121
123 const TargetRegisterInfo *TRI) {
124 raw_string_ostream OS(Dest.Value);
125 OS << printReg(Reg, TRI);
126}
127
131 const auto *TRI = MF.getSubtarget().getRegisterInfo();
132 unsigned I = 0;
133 for (const uint32_t *Mask : TRI->getRegMasks())
134 RegisterMaskIds.insert(std::make_pair(Mask, I++));
135 return RegisterMaskIds;
136}
137
138static void printMBB(raw_ostream &OS, MFPrintState &State,
139 const MachineBasicBlock &MBB);
140static void convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF,
142 const TargetRegisterInfo *TRI);
143static void convertMCP(yaml::MachineFunction &MF,
145static void convertMJTI(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
146 const MachineJumpTableInfo &JTI);
147static void convertMFI(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
148 const MachineFrameInfo &MFI,
149 const TargetRegisterInfo *TRI);
150static void
152 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
153 const llvm::SaveRestorePoints &SRPoints,
154 const TargetRegisterInfo *TRI);
156 const MachineFunction &MF,
157 ModuleSlotTracker &MST, MFPrintState &State);
159 const MachineFunction &MF,
160 ModuleSlotTracker &MST);
162 const MachineFunction &MF,
163 ModuleSlotTracker &MST);
165 const MachineFunction &MF,
168 const MachineFunction &MF,
170
171static void printMF(raw_ostream &OS, const MachineModuleInfo &MMI,
172 const MachineFunction &MF) {
173 MFPrintState State(MMI, MF);
174 State.RegisterMaskIds = initRegisterMaskIds(MF);
175
177 YamlMF.Name = MF.getName();
178 YamlMF.Alignment = MF.getAlignment();
180 YamlMF.HasWinCFI = MF.hasWinCFI();
181
182 YamlMF.CallsEHReturn = MF.callsEHReturn();
183 YamlMF.CallsUnwindInit = MF.callsUnwindInit();
184 YamlMF.HasEHContTarget = MF.hasEHContTarget();
185 YamlMF.HasEHScopes = MF.hasEHScopes();
186 YamlMF.HasEHFunclets = MF.hasEHFunclets();
187 YamlMF.HasFakeUses = MF.hasFakeUses();
188 YamlMF.IsOutlined = MF.isOutlined();
190
191 const MachineFunctionProperties &Props = MF.getProperties();
192 YamlMF.Legalized = Props.hasLegalized();
193 YamlMF.RegBankSelected = Props.hasRegBankSelected();
194 YamlMF.Selected = Props.hasSelected();
195 YamlMF.FailedISel = Props.hasFailedISel();
196 YamlMF.FailsVerification = Props.hasFailsVerification();
197 YamlMF.TracksDebugUserValues = Props.hasTracksDebugUserValues();
198 YamlMF.NoPHIs = Props.hasNoPHIs();
199 YamlMF.IsSSA = Props.hasIsSSA();
200 YamlMF.NoVRegs = Props.hasNoVRegs();
201
202 convertMRI(YamlMF, MF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
203 MachineModuleSlotTracker &MST = State.MST;
205 convertMFI(MST, YamlMF.FrameInfo, MF.getFrameInfo(),
207 convertStackObjects(YamlMF, MF, MST, State);
208 convertEntryValueObjects(YamlMF, MF, MST);
209 convertCallSiteObjects(YamlMF, MF, MST);
210 for (const auto &Sub : MF.DebugValueSubstitutions) {
211 const auto &SubSrc = Sub.Src;
212 const auto &SubDest = Sub.Dest;
213 YamlMF.DebugValueSubstitutions.push_back({SubSrc.first, SubSrc.second,
214 SubDest.first,
215 SubDest.second,
216 Sub.Subreg});
217 }
218 if (const auto *ConstantPool = MF.getConstantPool())
219 convertMCP(YamlMF, *ConstantPool);
220 if (const auto *JumpTableInfo = MF.getJumpTableInfo())
221 convertMJTI(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
222
223 const TargetMachine &TM = MF.getTarget();
224 YamlMF.MachineFuncInfo =
225 std::unique_ptr<yaml::MachineFunctionInfo>(TM.convertFuncInfoToYAML(MF));
226
227 raw_string_ostream StrOS(YamlMF.Body.Value.Value);
228 bool IsNewlineNeeded = false;
229 for (const auto &MBB : MF) {
230 if (IsNewlineNeeded)
231 StrOS << "\n";
232 printMBB(StrOS, State, MBB);
233 IsNewlineNeeded = true;
234 }
235 // Convert machine metadata collected during the print of the machine
236 // function.
237 convertMachineMetadataNodes(YamlMF, MF, MST);
238
239 convertCalledGlobals(YamlMF, MF, MST);
240
241 yaml::Output Out(OS);
242 if (!SimplifyMIR)
243 Out.setWriteDefaultValues(true);
244 Out << YamlMF;
245}
246
247static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS,
248 const TargetRegisterInfo *TRI) {
249 assert(RegMask && "Can't print an empty register mask");
250 OS << StringRef("CustomRegMask(");
251
252 bool IsRegInRegMaskFound = false;
253 for (int I = 0, E = TRI->getNumRegs(); I < E; I++) {
254 // Check whether the register is asserted in regmask.
255 if (RegMask[I / 32] & (1u << (I % 32))) {
256 if (IsRegInRegMaskFound)
257 OS << ',';
258 OS << printReg(I, TRI);
259 IsRegInRegMaskFound = true;
260 }
261 }
262
263 OS << ')';
264}
265
272
273template <typename T>
274static void
276 T &Object, ModuleSlotTracker &MST) {
277 std::array<std::string *, 3> Outputs{{&Object.DebugVar.Value,
278 &Object.DebugExpr.Value,
279 &Object.DebugLoc.Value}};
280 std::array<const Metadata *, 3> Metas{{DebugVar.Var,
281 DebugVar.Expr,
282 DebugVar.Loc}};
283 for (unsigned i = 0; i < 3; ++i) {
284 raw_string_ostream StrOS(*Outputs[i]);
285 Metas[i]->printAsOperand(StrOS, MST);
286 }
287}
288
290 std::vector<yaml::FlowStringValue> &RegisterFlags,
291 const MachineFunction &MF,
292 const TargetRegisterInfo *TRI) {
293 auto FlagValues = TRI->getVRegFlagsOfReg(Reg, MF);
294 for (auto &Flag : FlagValues)
295 RegisterFlags.push_back(yaml::FlowStringValue(Flag.str()));
296}
297
298static void convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF,
300 const TargetRegisterInfo *TRI) {
301 YamlMF.TracksRegLiveness = RegInfo.tracksLiveness();
302
303 // Print the virtual register definitions.
304 for (unsigned I = 0, E = RegInfo.getNumVirtRegs(); I < E; ++I) {
307 VReg.ID = I;
308 if (RegInfo.getVRegName(Reg) != "")
309 continue;
311 Register PreferredReg = RegInfo.getSimpleHint(Reg);
312 if (PreferredReg)
313 printRegMIR(PreferredReg, VReg.PreferredRegister, TRI);
315 YamlMF.VirtualRegisters.push_back(std::move(VReg));
316 }
317
318 // Print the live ins.
319 for (std::pair<MCRegister, Register> LI : RegInfo.liveins()) {
321 printRegMIR(LI.first, LiveIn.Register, TRI);
322 if (LI.second)
323 printRegMIR(LI.second, LiveIn.VirtualRegister, TRI);
324 YamlMF.LiveIns.push_back(std::move(LiveIn));
325 }
326
327 // Prints the callee saved registers.
328 if (RegInfo.isUpdatedCSRsInitialized()) {
329 const MCPhysReg *CalleeSavedRegs = RegInfo.getCalleeSavedRegs();
330 std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
331 for (const MCPhysReg *I = CalleeSavedRegs; *I; ++I) {
333 printRegMIR(*I, Reg, TRI);
334 CalleeSavedRegisters.push_back(std::move(Reg));
335 }
336 YamlMF.CalleeSavedRegisters = std::move(CalleeSavedRegisters);
337 }
338}
339
341 const MachineFrameInfo &MFI,
342 const TargetRegisterInfo *TRI) {
345 YamlMFI.HasStackMap = MFI.hasStackMap();
346 YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
347 YamlMFI.StackSize = MFI.getStackSize();
349 YamlMFI.MaxAlignment = MFI.getMaxAlign().value();
350 YamlMFI.AdjustsStack = MFI.adjustsStack();
351 YamlMFI.HasCalls = MFI.hasCalls();
353 ? MFI.getMaxCallFrameSize() : ~0u;
357 YamlMFI.HasVAStart = MFI.hasVAStart();
359 YamlMFI.HasTailCall = MFI.hasTailCall();
361 YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
362 if (!MFI.getSavePoints().empty())
363 convertSRPoints(MST, YamlMFI.SavePoints, MFI.getSavePoints(), TRI);
364 if (!MFI.getRestorePoints().empty())
366}
367
369 const MachineFunction &MF,
370 ModuleSlotTracker &MST) {
372 for (const MachineFunction::VariableDbgInfo &DebugVar :
374 yaml::EntryValueObject &Obj = YMF.EntryValueObjects.emplace_back();
375 printStackObjectDbgInfo(DebugVar, Obj, MST);
376 MCRegister EntryValReg = DebugVar.getEntryValueRegister();
377 printRegMIR(EntryValReg, Obj.EntryValueRegister, TRI);
378 }
379}
380
382 const MFPrintState &State,
383 int FrameIndex) {
384 auto ObjectInfo = State.StackObjectOperandMapping.find(FrameIndex);
385 assert(ObjectInfo != State.StackObjectOperandMapping.end() &&
386 "Invalid frame index");
387 const FrameIndexOperand &Operand = ObjectInfo->second;
388 MachineOperand::printStackObjectReference(OS, Operand.ID, Operand.IsFixed,
389 Operand.Name);
390}
391
393 const MachineFunction &MF,
394 ModuleSlotTracker &MST, MFPrintState &State) {
395 const MachineFrameInfo &MFI = MF.getFrameInfo();
397
398 // Process fixed stack objects.
399 assert(YMF.FixedStackObjects.empty());
400 SmallVector<int, 32> FixedStackObjectsIdx;
401 const int BeginIdx = MFI.getObjectIndexBegin();
402 if (BeginIdx < 0)
403 FixedStackObjectsIdx.reserve(-BeginIdx);
404
405 unsigned ID = 0;
406 for (int I = BeginIdx; I < 0; ++I, ++ID) {
407 FixedStackObjectsIdx.push_back(-1); // Fill index for possible dead.
408 if (MFI.isDeadObjectIndex(I))
409 continue;
410
412 YamlObject.ID = ID;
413 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
416 YamlObject.Offset = MFI.getObjectOffset(I);
417 YamlObject.Size = MFI.getObjectSize(I);
418 YamlObject.Alignment = MFI.getObjectAlign(I);
419 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
420 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
421 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
422 // Save the ID' position in FixedStackObjects storage vector.
423 FixedStackObjectsIdx[ID] = YMF.FixedStackObjects.size();
424 YMF.FixedStackObjects.push_back(std::move(YamlObject));
425 State.StackObjectOperandMapping.insert(
426 std::make_pair(I, FrameIndexOperand::createFixed(ID)));
427 }
428
429 // Process ordinary stack objects.
430 assert(YMF.StackObjects.empty());
431 SmallVector<unsigned, 32> StackObjectsIdx;
432 const int EndIdx = MFI.getObjectIndexEnd();
433 if (EndIdx > 0)
434 StackObjectsIdx.reserve(EndIdx);
435 ID = 0;
436 for (int I = 0; I < EndIdx; ++I, ++ID) {
437 StackObjectsIdx.push_back(-1); // Fill index for possible dead.
438 if (MFI.isDeadObjectIndex(I))
439 continue;
440
441 yaml::MachineStackObject YamlObject;
442 YamlObject.ID = ID;
443 if (const auto *Alloca = MFI.getObjectAllocation(I))
444 YamlObject.Name.Value = std::string(
445 Alloca->hasName() ? Alloca->getName() : "");
446 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
451 YamlObject.Offset = MFI.getObjectOffset(I);
452 YamlObject.Size = MFI.getObjectSize(I);
453 YamlObject.Alignment = MFI.getObjectAlign(I);
454 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
455
456 // Save the ID' position in StackObjects storage vector.
457 StackObjectsIdx[ID] = YMF.StackObjects.size();
458 YMF.StackObjects.push_back(YamlObject);
459 State.StackObjectOperandMapping.insert(std::make_pair(
460 I, FrameIndexOperand::create(YamlObject.Name.Value, ID)));
461 }
462
463 for (const auto &CSInfo : MFI.getCalleeSavedInfo()) {
464 const int FrameIdx = CSInfo.getFrameIdx();
465 if (!CSInfo.isSpilledToReg() && MFI.isDeadObjectIndex(FrameIdx))
466 continue;
467
469 printRegMIR(CSInfo.getReg(), Reg, TRI);
470 if (!CSInfo.isSpilledToReg()) {
471 assert(FrameIdx >= MFI.getObjectIndexBegin() &&
472 FrameIdx < MFI.getObjectIndexEnd() &&
473 "Invalid stack object index");
474 if (FrameIdx < 0) { // Negative index means fixed objects.
475 auto &Object =
477 [FixedStackObjectsIdx[FrameIdx + MFI.getNumFixedObjects()]];
478 Object.CalleeSavedRegister = std::move(Reg);
479 Object.CalleeSavedRestored = CSInfo.isRestored();
480 } else {
481 auto &Object = YMF.StackObjects[StackObjectsIdx[FrameIdx]];
482 Object.CalleeSavedRegister = std::move(Reg);
483 Object.CalleeSavedRestored = CSInfo.isRestored();
484 }
485 }
486 }
487 for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) {
488 auto LocalObject = MFI.getLocalFrameObjectMap(I);
489 assert(LocalObject.first >= 0 && "Expected a locally mapped stack object");
490 YMF.StackObjects[StackObjectsIdx[LocalObject.first]].LocalOffset =
491 LocalObject.second;
492 }
493
494 // Print the stack object references in the frame information class after
495 // converting the stack objects.
496 if (MFI.hasStackProtectorIndex()) {
499 }
500
501 if (MFI.hasFunctionContextIndex()) {
504 }
505
506 // Print the debug variable information.
507 for (const MachineFunction::VariableDbgInfo &DebugVar :
509 int Idx = DebugVar.getStackSlot();
510 assert(Idx >= MFI.getObjectIndexBegin() && Idx < MFI.getObjectIndexEnd() &&
511 "Invalid stack object index");
512 if (Idx < 0) { // Negative index means fixed objects.
513 auto &Object =
514 YMF.FixedStackObjects[FixedStackObjectsIdx[Idx +
515 MFI.getNumFixedObjects()]];
516 printStackObjectDbgInfo(DebugVar, Object, MST);
517 } else {
518 auto &Object = YMF.StackObjects[StackObjectsIdx[Idx]];
519 printStackObjectDbgInfo(DebugVar, Object, MST);
520 }
521 }
522}
523
525 const MachineFunction &MF,
526 ModuleSlotTracker &MST) {
527 const auto *TRI = MF.getSubtarget().getRegisterInfo();
528 for (auto [MI, CallSiteInfo] : MF.getCallSitesInfo()) {
529 yaml::CallSiteInfo YmlCS;
530 yaml::MachineInstrLoc CallLocation;
531
532 // Prepare instruction position.
533 MachineBasicBlock::const_instr_iterator CallI = MI->getIterator();
534 CallLocation.BlockNum = CallI->getParent()->getNumber();
535 // Get call instruction offset from the beginning of block.
536 CallLocation.Offset =
537 std::distance(CallI->getParent()->instr_begin(), CallI);
538 YmlCS.CallLocation = CallLocation;
539
540 auto [ArgRegPairs, CalleeTypeIds] = CallSiteInfo;
541 // Construct call arguments and theirs forwarding register info.
542 for (auto ArgReg : ArgRegPairs) {
544 YmlArgReg.ArgNo = ArgReg.ArgNo;
545 printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
546 YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
547 }
548 // Get type ids.
549 for (auto *CalleeTypeId : CalleeTypeIds) {
550 YmlCS.CalleeTypeIds.push_back(CalleeTypeId->getZExtValue());
551 }
552 YMF.CallSitesInfo.push_back(std::move(YmlCS));
553 }
554
555 // Sort call info by position of call instructions.
556 llvm::sort(YMF.CallSitesInfo.begin(), YMF.CallSitesInfo.end(),
558 return std::tie(A.CallLocation.BlockNum, A.CallLocation.Offset) <
559 std::tie(B.CallLocation.BlockNum, B.CallLocation.Offset);
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(std::move(NS));
573 }
574}
575
577 const MachineFunction &MF,
579 for (const auto &[CallInst, CG] : MF.getCalledGlobals()) {
580 yaml::MachineInstrLoc CallSite;
581 CallSite.BlockNum = CallInst->getParent()->getNumber();
582 CallSite.Offset = std::distance(CallInst->getParent()->instr_begin(),
584
585 yaml::CalledGlobal YamlCG{CallSite, CG.Callee->getName().str(),
586 CG.TargetFlags};
587 YMF.CalledGlobals.push_back(std::move(YamlCG));
588 }
589
590 // Sort by position of call instructions.
591 llvm::sort(YMF.CalledGlobals.begin(), YMF.CalledGlobals.end(),
593 return std::tie(A.CallSite.BlockNum, A.CallSite.Offset) <
594 std::tie(B.CallSite.BlockNum, B.CallSite.Offset);
595 });
596}
597
600 unsigned ID = 0;
601 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
602 std::string Str;
603 raw_string_ostream StrOS(Str);
604 if (Constant.isMachineConstantPoolEntry())
605 Constant.Val.MachineCPVal->print(StrOS);
606 else
607 Constant.Val.ConstVal->printAsOperand(StrOS);
608
610 YamlConstant.ID = ID++;
611 YamlConstant.Value = std::move(Str);
612 YamlConstant.Alignment = Constant.getAlign();
613 YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry();
614
615 MF.Constants.push_back(std::move(YamlConstant));
616 }
617}
618
619static void
621 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
622 const llvm::SaveRestorePoints &SRPoints,
623 const TargetRegisterInfo *TRI) {
624 for (const auto &[MBB, CSInfos] : SRPoints) {
625 SmallString<16> Str;
627 raw_svector_ostream StrOS(Str);
628 StrOS << printMBBReference(*MBB);
629 Entry.Point = StrOS.str().str();
630 Str.clear();
631 for (const CalleeSavedInfo &Info : CSInfos) {
632 if (Info.getReg()) {
633 StrOS << printReg(Info.getReg(), TRI);
634 Entry.Registers.push_back(StrOS.str().str());
635 Str.clear();
636 }
637 }
638 // Sort here needed for stable output for lit tests
639 std::sort(Entry.Registers.begin(), Entry.Registers.end(),
640 [](const yaml::StringValue &Lhs, const yaml::StringValue &Rhs) {
641 return Lhs.Value < Rhs.Value;
642 });
643 YamlSRPoints.push_back(std::move(Entry));
644 }
645 // Sort here needed for stable output for lit tests
646 std::sort(YamlSRPoints.begin(), YamlSRPoints.end(),
647 [](const yaml::SaveRestorePointEntry &Lhs,
648 const yaml::SaveRestorePointEntry &Rhs) {
649 return Lhs.Point.Value < Rhs.Point.Value;
650 });
651}
652
654 const MachineJumpTableInfo &JTI) {
655 YamlJTI.Kind = JTI.getEntryKind();
656 unsigned ID = 0;
657 for (const auto &Table : JTI.getJumpTables()) {
658 std::string Str;
660 Entry.ID = ID++;
661 for (const auto *MBB : Table.MBBs) {
662 raw_string_ostream StrOS(Str);
663 StrOS << printMBBReference(*MBB);
664 Entry.Blocks.push_back(Str);
665 Str.clear();
666 }
667 YamlJTI.Entries.push_back(std::move(Entry));
668 }
669}
670
673 bool &IsFallthrough) {
675
676 for (const MachineInstr &MI : MBB) {
677 if (MI.isPHI())
678 continue;
679 for (const MachineOperand &MO : MI.operands()) {
680 if (!MO.isMBB())
681 continue;
682 MachineBasicBlock *Succ = MO.getMBB();
683 auto RP = Seen.insert(Succ);
684 if (RP.second)
685 Result.push_back(Succ);
686 }
687 }
688 MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr();
689 IsFallthrough = I == MBB.end() || !I->isBarrier();
690}
691
694 bool GuessedFallthrough;
695 guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough);
696 if (GuessedFallthrough) {
697 const MachineFunction &MF = *MBB.getParent();
698 MachineFunction::const_iterator NextI = std::next(MBB.getIterator());
699 if (NextI != MF.end()) {
700 MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI);
701 if (!is_contained(GuessedSuccs, Next))
702 GuessedSuccs.push_back(Next);
703 }
704 }
705 if (GuessedSuccs.size() != MBB.succ_size())
706 return false;
707 return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin());
708}
709
710static void printMI(raw_ostream &OS, MFPrintState &State,
711 const MachineInstr &MI);
712
713static void printMIOperand(raw_ostream &OS, MFPrintState &State,
714 const MachineInstr &MI, unsigned OpIdx,
715 const TargetRegisterInfo *TRI,
716 const TargetInstrInfo *TII,
717 bool ShouldPrintRegisterTies,
718 SmallBitVector &PrintedTypes,
719 const MachineRegisterInfo &MRI, bool PrintDef);
720
721void printMBB(raw_ostream &OS, MFPrintState &State,
722 const MachineBasicBlock &MBB) {
723 assert(MBB.getNumber() >= 0 && "Invalid MBB number");
724 MBB.printName(OS,
727 &State.MST);
728 OS << ":\n";
729
730 bool HasLineAttributes = false;
731 // Print the successors
732 bool canPredictProbs = MBB.canPredictBranchProbabilities();
733 // Even if the list of successors is empty, if we cannot guess it,
734 // we need to print it to tell the parser that the list is empty.
735 // This is needed, because MI model unreachable as empty blocks
736 // with an empty successor list. If the parser would see that
737 // without the successor list, it would guess the code would
738 // fallthrough.
739 if ((!MBB.succ_empty() && !SimplifyMIR) || !canPredictProbs ||
741 OS.indent(2) << "successors:";
742 if (!MBB.succ_empty())
743 OS << " ";
744 ListSeparator LS;
745 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
746 OS << LS << printMBBReference(**I);
747 if (!SimplifyMIR || !canPredictProbs)
748 OS << format("(0x%08" PRIx32 ")",
749 MBB.getSuccProbability(I).getNumerator());
750 }
751 OS << "\n";
752 HasLineAttributes = true;
753 }
754
755 // Print the live in registers.
756 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
757 if (!MBB.livein_empty()) {
758 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
759 OS.indent(2) << "liveins: ";
760 ListSeparator LS;
761 for (const auto &LI : MBB.liveins_dbg()) {
762 OS << LS << printReg(LI.PhysReg, &TRI);
763 if (!LI.LaneMask.all())
764 OS << ":0x" << PrintLaneMask(LI.LaneMask);
765 }
766 OS << "\n";
767 HasLineAttributes = true;
768 }
769
770 if (HasLineAttributes && !MBB.empty())
771 OS << "\n";
772 bool IsInBundle = false;
773 for (const MachineInstr &MI : MBB.instrs()) {
774 if (IsInBundle && !MI.isInsideBundle()) {
775 OS.indent(2) << "}\n";
776 IsInBundle = false;
777 }
778 OS.indent(IsInBundle ? 4 : 2);
779 printMI(OS, State, MI);
780 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
781 OS << " {";
782 IsInBundle = true;
783 }
784 OS << "\n";
785 }
786 if (IsInBundle)
787 OS.indent(2) << "}\n";
788}
789
790static void printMI(raw_ostream &OS, MFPrintState &State,
791 const MachineInstr &MI) {
792 const auto *MF = MI.getMF();
793 const auto &MRI = MF->getRegInfo();
794 const auto &SubTarget = MF->getSubtarget();
795 const auto *TRI = SubTarget.getRegisterInfo();
796 assert(TRI && "Expected target register info");
797 const auto *TII = SubTarget.getInstrInfo();
798 assert(TII && "Expected target instruction info");
799 if (MI.isCFIInstruction())
800 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
801
802 SmallBitVector PrintedTypes(8);
803 bool ShouldPrintRegisterTies = MI.hasComplexRegisterTies();
804 ListSeparator LS;
805 unsigned I = 0, E = MI.getNumOperands();
806 for (; I < E; ++I) {
807 const MachineOperand MO = MI.getOperand(I);
808 if (!MO.isReg() || !MO.isDef() || MO.isImplicit())
809 break;
810 OS << LS;
811 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
812 PrintedTypes, MRI, /*PrintDef=*/false);
813 }
814
815 if (I)
816 OS << " = ";
817 if (MI.getFlag(MachineInstr::FrameSetup))
818 OS << "frame-setup ";
819 if (MI.getFlag(MachineInstr::FrameDestroy))
820 OS << "frame-destroy ";
821 if (MI.getFlag(MachineInstr::FmNoNans))
822 OS << "nnan ";
823 if (MI.getFlag(MachineInstr::FmNoInfs))
824 OS << "ninf ";
825 if (MI.getFlag(MachineInstr::FmNsz))
826 OS << "nsz ";
827 if (MI.getFlag(MachineInstr::FmArcp))
828 OS << "arcp ";
829 if (MI.getFlag(MachineInstr::FmContract))
830 OS << "contract ";
831 if (MI.getFlag(MachineInstr::FmAfn))
832 OS << "afn ";
833 if (MI.getFlag(MachineInstr::FmReassoc))
834 OS << "reassoc ";
835 if (MI.getFlag(MachineInstr::NoUWrap))
836 OS << "nuw ";
837 if (MI.getFlag(MachineInstr::NoSWrap))
838 OS << "nsw ";
839 if (MI.getFlag(MachineInstr::IsExact))
840 OS << "exact ";
841 if (MI.getFlag(MachineInstr::NoFPExcept))
842 OS << "nofpexcept ";
843 if (MI.getFlag(MachineInstr::NoMerge))
844 OS << "nomerge ";
845 if (MI.getFlag(MachineInstr::Unpredictable))
846 OS << "unpredictable ";
847 if (MI.getFlag(MachineInstr::NoConvergent))
848 OS << "noconvergent ";
849 if (MI.getFlag(MachineInstr::NonNeg))
850 OS << "nneg ";
851 if (MI.getFlag(MachineInstr::Disjoint))
852 OS << "disjoint ";
853 if (MI.getFlag(MachineInstr::NoUSWrap))
854 OS << "nusw ";
855 if (MI.getFlag(MachineInstr::SameSign))
856 OS << "samesign ";
857 if (MI.getFlag(MachineInstr::InBounds))
858 OS << "inbounds ";
859
860 // NOTE: Please add new MIFlags also to the MI_FLAGS_STR in
861 // llvm/utils/update_mir_test_checks.py.
862
863 OS << TII->getName(MI.getOpcode());
864
865 // Print a space after the opcode if any additional tokens are printed.
866 LS = ListSeparator(", ", " ");
867
868 for (; I < E; ++I) {
869 OS << LS;
870 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
871 PrintedTypes, MRI, /*PrintDef=*/true);
872 }
873
874 // Print any optional symbols attached to this instruction as-if they were
875 // operands.
876 if (MCSymbol *PreInstrSymbol = MI.getPreInstrSymbol()) {
877 OS << LS << "pre-instr-symbol ";
878 MachineOperand::printSymbol(OS, *PreInstrSymbol);
879 }
880 if (MCSymbol *PostInstrSymbol = MI.getPostInstrSymbol()) {
881 OS << LS << "post-instr-symbol ";
882 MachineOperand::printSymbol(OS, *PostInstrSymbol);
883 }
884 if (MDNode *HeapAllocMarker = MI.getHeapAllocMarker()) {
885 OS << LS << "heap-alloc-marker ";
886 HeapAllocMarker->printAsOperand(OS, State.MST);
887 }
888 if (MDNode *PCSections = MI.getPCSections()) {
889 OS << LS << "pcsections ";
890 PCSections->printAsOperand(OS, State.MST);
891 }
892 if (MDNode *MMRA = MI.getMMRAMetadata()) {
893 OS << LS << "mmra ";
894 MMRA->printAsOperand(OS, State.MST);
895 }
896 if (uint32_t CFIType = MI.getCFIType())
897 OS << LS << "cfi-type " << CFIType;
898
899 if (auto Num = MI.peekDebugInstrNum())
900 OS << LS << "debug-instr-number " << Num;
901
902 if (PrintLocations) {
903 if (const DebugLoc &DL = MI.getDebugLoc()) {
904 OS << LS << "debug-location ";
905 DL->printAsOperand(OS, State.MST);
906 }
907 }
908
909 if (!MI.memoperands_empty()) {
910 OS << " :: ";
911 const LLVMContext &Context = MF->getFunction().getContext();
912 const MachineFrameInfo &MFI = MF->getFrameInfo();
913 LS = ListSeparator();
914 for (const auto *Op : MI.memoperands()) {
915 OS << LS;
916 Op->print(OS, State.MST, State.SSNs, Context, &MFI, TII);
917 }
918 }
919}
920
921static std::string formatOperandComment(std::string Comment) {
922 if (Comment.empty())
923 return Comment;
924 return std::string(" /* " + Comment + " */");
925}
926
927static void printMIOperand(raw_ostream &OS, MFPrintState &State,
928 const MachineInstr &MI, unsigned OpIdx,
929 const TargetRegisterInfo *TRI,
930 const TargetInstrInfo *TII,
931 bool ShouldPrintRegisterTies,
932 SmallBitVector &PrintedTypes,
933 const MachineRegisterInfo &MRI, bool PrintDef) {
934 LLT TypeToPrint = MI.getTypeToPrint(OpIdx, PrintedTypes, MRI);
935 const MachineOperand &Op = MI.getOperand(OpIdx);
936 std::string MOComment = TII->createMIROperandComment(MI, Op, OpIdx, TRI);
937
938 switch (Op.getType()) {
940 if (MI.isOperandSubregIdx(OpIdx)) {
943 break;
944 }
945 [[fallthrough]];
964 unsigned TiedOperandIdx = 0;
965 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
966 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
967 Op.print(OS, State.MST, TypeToPrint, OpIdx, PrintDef,
968 /*IsStandalone=*/false, ShouldPrintRegisterTies, TiedOperandIdx,
969 TRI);
970 OS << formatOperandComment(MOComment);
971 break;
972 }
974 printStackObjectReference(OS, State, Op.getIndex());
975 break;
977 const auto &RegisterMaskIds = State.RegisterMaskIds;
978 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
979 if (RegMaskInfo != RegisterMaskIds.end())
980 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
981 else
982 printCustomRegMask(Op.getRegMask(), OS, TRI);
983 break;
984 }
985 }
986}
987
989 ModuleSlotTracker &MST) {
990 if (isa<GlobalValue>(V)) {
991 V.printAsOperand(OS, /*PrintType=*/false, MST);
992 return;
993 }
994 if (isa<Constant>(V)) {
995 // Machine memory operands can load/store to/from constant value pointers.
996 OS << '`';
997 V.printAsOperand(OS, /*PrintType=*/true, MST);
998 OS << '`';
999 return;
1000 }
1001 OS << "%ir.";
1002 if (V.hasName()) {
1003 printLLVMNameWithoutPrefix(OS, V.getName());
1004 return;
1005 }
1006 int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1;
1008}
1009
1010void llvm::printMIR(raw_ostream &OS, const Module &M) {
1011 yaml::Output Out(OS);
1012 Out << const_cast<Module &>(M);
1013}
1014
1016 const MachineFunction &MF) {
1017 printMF(OS, MMI, MF);
1018}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Analysis containing CSE Info
Definition CSEInfo.cpp:27
This file defines the DenseMap class.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
This file contains an interface for creating legacy passes to print out IR in various granularities.
Module.h This file contains the declarations for the Module class.
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 void convertCallSiteObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST)
static void convertMCP(yaml::MachineFunction &MF, const MachineConstantPool &ConstantPool)
static void printMI(raw_ostream &OS, MFPrintState &State, const MachineInstr &MI)
static void convertSRPoints(ModuleSlotTracker &MST, std::vector< yaml::SaveRestorePointEntry > &YamlSRPoints, const llvm::SaveRestorePoints &SRPoints, const TargetRegisterInfo *TRI)
static DenseMap< const uint32_t *, unsigned > initRegisterMaskIds(const MachineFunction &MF)
static void convertCalledGlobals(yaml::MachineFunction &YMF, const MachineFunction &MF, MachineModuleSlotTracker &MST)
static void printMBB(raw_ostream &OS, MFPrintState &State, const MachineBasicBlock &MBB)
static std::string formatOperandComment(std::string Comment)
static cl::opt< bool > PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true), cl::desc("Print MIR debug-locations"))
static bool canPredictSuccessors(const MachineBasicBlock &MBB)
static void convertStackObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST, MFPrintState &State)
static void printMF(raw_ostream &OS, const MachineModuleInfo &MMI, const MachineFunction &MF)
static void printStackObjectReference(raw_ostream &OS, const MFPrintState &State, int FrameIndex)
static void convertEntryValueObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST)
static void convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
static void printStackObjectDbgInfo(const MachineFunction::VariableDbgInfo &DebugVar, T &Object, ModuleSlotTracker &MST)
static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS, const TargetRegisterInfo *TRI)
static void convertMFI(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI, const MachineFrameInfo &MFI, const TargetRegisterInfo *TRI)
static void printRegMIR(Register Reg, yaml::StringValue &Dest, const TargetRegisterInfo *TRI)
static cl::opt< bool > SimplifyMIR("simplify-mir", cl::Hidden, cl::desc("Leave out unnecessary information when printing MIR"))
static void printMIOperand(raw_ostream &OS, MFPrintState &State, const MachineInstr &MI, unsigned OpIdx, const TargetRegisterInfo *TRI, const TargetInstrInfo *TII, bool ShouldPrintRegisterTies, SmallBitVector &PrintedTypes, const MachineRegisterInfo &MRI, bool PrintDef)
static void printRegFlags(Register Reg, std::vector< yaml::FlowStringValue > &RegisterFlags, const MachineFunction &MF, const TargetRegisterInfo *TRI)
static void convertMachineMetadataNodes(yaml::MachineFunction &YMF, const MachineFunction &MF, MachineModuleSlotTracker &MST)
static void convertMJTI(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI, const MachineJumpTableInfo &JTI)
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register Reg
Register const TargetRegisterInfo * TRI
#define T
MachineInstr unsigned OpIdx
This file contains some templates that are useful if you are working with the STL at all.
This file implements the SmallBitVector class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
This class represents a function call, abstracting a target machine's calling convention.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
This is an important base class in LLVM.
Definition Constant.h:43
A debug info location.
Definition DebugLoc.h:124
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:233
Module * getParent()
Get the module that this global value is contained inside of...
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A helper class to return the specified delimiter string after the first invocation of operator String...
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:42
Metadata node.
Definition Metadata.h:1078
static LLVM_ABI 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...
MachineInstrBundleIterator< const MachineInstr > const_iterator
@ PrintNameIr
Add IR name where available.
@ PrintNameAttributes
Print attributes.
Instructions::const_iterator const_instr_iterator
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.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
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.
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.
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
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.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
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.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
uint8_t getStackID(int ObjectIdx) const
const SaveRestorePoints & getRestorePoints() 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.
const SaveRestorePoints & getSavePoints() const
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
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...
Properties which a MachineFunction may have at a given point in time.
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.
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.
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.
auto getCalledGlobals() const
Iterates over the full set of call sites and their associated globals.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
BasicBlockListType::const_iterator const_iterator
Representation of each machine instruction.
const std::vector< MachineJumpTableEntry > & getJumpTables() const
This class contains meta information specific to a module.
void collectMachineMDNodes(MachineMDNodeListType &L) const
MachineOperand class - Representation of each machine instruction operand.
static LLVM_ABI void printStackObjectReference(raw_ostream &OS, unsigned FrameIndex, bool IsFixed, StringRef Name)
Print a stack object reference.
static LLVM_ABI void printSubRegIdx(raw_ostream &OS, uint64_t Index, const TargetRegisterInfo *TRI)
Print a subreg index operand.
static LLVM_ABI void printTargetFlags(raw_ostream &OS, const MachineOperand &Op)
Print operand target flags.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static LLVM_ABI void printIRSlotNumber(raw_ostream &OS, int Slot)
Print an IRSlotNumber.
static LLVM_ABI 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,...
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.
const Function * getCurrentFunction() const
void incorporateFunction(const Function &F)
Incorporate the given function.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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:67
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.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h:225
LLVM_ABI std::string lower() const
TargetInstrInfo - Interface to description of machine instruction set.
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
LLVM_ABI 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.
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
The Output class is used to generate a yaml document from in-memory structs and vectors.
void setWriteDefaultValues(bool Write)
Set whether or not to output optional values which are equal to the default value....
#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)
This is an optimization pass for GlobalISel generic memory operations.
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition LaneBitmask.h:92
LLVM_ABI void printMIR(raw_ostream &OS, const Module &M)
Print LLVM IR using the MIR serialization format to the given output stream.
LLVM_ABI 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...
DenseMap< MachineBasicBlock *, std::vector< CalleeSavedInfo > > SaveRestorePoints
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1622
LLVM_ABI Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:129
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
@ Sub
Subtraction of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
DWARFExpression::Operation Op
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1897
LLVM_ABI void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
LLVM_ABI 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.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77
This class should be specialized by type that requires custom conversion to/from a YAML literal block...
Definition YAMLTraits.h:179
Serializable representation of CallSiteInfo.
std::vector< uint64_t > CalleeTypeIds
Numeric callee type identifiers for the callgraph section.
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.
std::vector< SaveRestorePointEntry > RestorePoints
unsigned MaxCallFrameSize
~0u means: not computed yet.
std::vector< SaveRestorePointEntry > SavePoints
std::vector< MachineStackObject > StackObjects
std::vector< StringValue > MachineMetadataNodes
std::optional< std::vector< FlowStringValue > > CalleeSavedRegisters
std::vector< CalledGlobal > CalledGlobals
std::optional< bool > HasFakeUses
std::vector< EntryValueObject > EntryValueObjects
std::optional< bool > NoPHIs
std::vector< MachineConstantPoolValue > Constants
std::optional< bool > NoVRegs
std::vector< CallSiteInfo > CallSitesInfo
std::vector< MachineFunctionLiveIn > LiveIns
std::vector< VirtualRegisterDefinition > VirtualRegisters
std::vector< FixedMachineStackObject > FixedStackObjects
std::optional< bool > IsSSA
std::vector< DebugValueSubstitution > DebugValueSubstitutions
std::unique_ptr< MachineFunctionInfo > MachineFuncInfo
Constant pool.
Identifies call instruction location in machine function.
std::vector< Entry > Entries
MachineJumpTableInfo::JTEntryKind Kind
Serializable representation of stack object from the MachineFrameInfo class.
A wrapper around std::string which contains a source range that's being set during parsing.
std::vector< FlowStringValue > RegisterFlags
static void output(const Module &Mod, void *Ctxt, raw_ostream &OS)
static StringRef input(StringRef Str, void *Ctxt, Module &Mod)