LLVM 23.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"
43#include "llvm/IR/DebugLoc.h"
44#include "llvm/IR/Function.h"
46#include "llvm/IR/InlineAsm.h"
48#include "llvm/IR/Module.h"
50#include "llvm/IR/Value.h"
51#include "llvm/MC/LaneBitmask.h"
56#include "llvm/Support/Format.h"
60#include <algorithm>
61#include <cassert>
62#include <cinttypes>
63#include <cstdint>
64#include <iterator>
65#include <string>
66#include <utility>
67#include <vector>
68
69using namespace llvm;
70
72 "simplify-mir", cl::Hidden,
73 cl::desc("Leave out unnecessary information when printing MIR"));
74
75static cl::opt<bool> PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true),
76 cl::desc("Print MIR debug-locations"));
77
78namespace {
79
80/// This structure describes how to print out stack object references.
81struct FrameIndexOperand {
82 std::string Name;
83 unsigned ID;
84 bool IsFixed;
85
86 FrameIndexOperand(StringRef Name, unsigned ID, bool IsFixed)
87 : Name(Name.str()), ID(ID), IsFixed(IsFixed) {}
88
89 /// Return an ordinary stack object reference.
90 static FrameIndexOperand create(StringRef Name, unsigned ID) {
91 return FrameIndexOperand(Name, ID, /*IsFixed=*/false);
92 }
93
94 /// Return a fixed stack object reference.
95 static FrameIndexOperand createFixed(unsigned ID) {
96 return FrameIndexOperand("", ID, /*IsFixed=*/true);
97 }
98};
99
100struct MFPrintState {
101 MachineModuleSlotTracker MST;
102 DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
103 /// Maps from stack object indices to operand indices which will be used when
104 /// printing frame index machine operands.
105 DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;
106 /// Synchronization scope names registered with LLVMContext.
108
109 MFPrintState(MFGetterFnT Fn, const MachineFunction &MF)
110 : MST(std::move(Fn), &MF) {}
111};
112
113} // end anonymous namespace
114
115/// This struct serializes the LLVM IR module.
116template <> struct yaml::BlockScalarTraits<Module> {
117 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
118 Mod.print(OS, nullptr);
119 }
120
121 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
122 llvm_unreachable("LLVM Module is supposed to be parsed separately");
123 return "";
124 }
125};
126
128 const TargetRegisterInfo *TRI) {
129 raw_string_ostream OS(Dest.Value);
130 OS << printReg(Reg, TRI);
131}
132
136 const auto *TRI = MF.getSubtarget().getRegisterInfo();
137 unsigned I = 0;
138 for (const uint32_t *Mask : TRI->getRegMasks())
139 RegisterMaskIds.insert(std::make_pair(Mask, I++));
140 return RegisterMaskIds;
141}
142
143static void printMBB(raw_ostream &OS, MFPrintState &State,
144 const MachineBasicBlock &MBB);
145static void convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF,
147 const TargetRegisterInfo *TRI, const VirtRegMap *VRM);
148static void convertMCP(yaml::MachineFunction &MF,
150static void convertMJTI(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
151 const MachineJumpTableInfo &JTI);
152static void convertMFI(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
153 const MachineFrameInfo &MFI,
154 const TargetRegisterInfo *TRI);
155static void
157 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
158 const llvm::SaveRestorePoints &SRPoints,
159 const TargetRegisterInfo *TRI);
161 const MachineFunction &MF,
162 ModuleSlotTracker &MST, MFPrintState &State);
164 const MachineFunction &MF,
165 ModuleSlotTracker &MST);
167 const MachineFunction &MF,
168 ModuleSlotTracker &MST);
170 const MachineFunction &MF,
173 const MachineFunction &MF,
176 const MachineFunction &MF);
177
178static void printMF(raw_ostream &OS, MFGetterFnT Fn, const MachineFunction &MF,
179 const VirtRegMap *VRM) {
180 MFPrintState State(std::move(Fn), MF);
181
182 State.RegisterMaskIds = initRegisterMaskIds(MF);
183
185 YamlMF.Name = MF.getName();
186 YamlMF.Alignment = MF.getAlignment();
188 YamlMF.HasWinCFI = MF.hasWinCFI();
189
190 YamlMF.CallsEHReturn = MF.callsEHReturn();
191 YamlMF.CallsUnwindInit = MF.callsUnwindInit();
192 YamlMF.HasEHContTarget = MF.hasEHContTarget();
193 YamlMF.HasEHScopes = MF.hasEHScopes();
194 YamlMF.HasEHFunclets = MF.hasEHFunclets();
195 YamlMF.HasFakeUses = MF.hasFakeUses();
196 YamlMF.IsOutlined = MF.isOutlined();
198
199 const MachineFunctionProperties &Props = MF.getProperties();
200 YamlMF.Legalized = Props.hasLegalized();
201 YamlMF.RegBankSelected = Props.hasRegBankSelected();
202 YamlMF.Selected = Props.hasSelected();
203 YamlMF.FailedISel = Props.hasFailedISel();
204 YamlMF.FailsVerification = Props.hasFailsVerification();
205 YamlMF.TracksDebugUserValues = Props.hasTracksDebugUserValues();
206 YamlMF.NoPHIs = Props.hasNoPHIs();
207 YamlMF.IsSSA = Props.hasIsSSA();
208 YamlMF.NoVRegs = Props.hasNoVRegs();
209
210 convertMRI(YamlMF, MF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo(),
211 VRM);
212 MachineModuleSlotTracker &MST = State.MST;
214 convertMFI(MST, YamlMF.FrameInfo, MF.getFrameInfo(),
216 convertStackObjects(YamlMF, MF, MST, State);
217 convertEntryValueObjects(YamlMF, MF, MST);
218 convertCallSiteObjects(YamlMF, MF, MST);
219 for (const auto &Sub : MF.DebugValueSubstitutions) {
220 const auto &SubSrc = Sub.Src;
221 const auto &SubDest = Sub.Dest;
222 YamlMF.DebugValueSubstitutions.push_back({SubSrc.first, SubSrc.second,
223 SubDest.first,
224 SubDest.second,
225 Sub.Subreg});
226 }
227 if (const auto *ConstantPool = MF.getConstantPool())
228 convertMCP(YamlMF, *ConstantPool);
229 if (const auto *JumpTableInfo = MF.getJumpTableInfo())
230 convertMJTI(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
231
232 const TargetMachine &TM = MF.getTarget();
233 YamlMF.MachineFuncInfo =
234 std::unique_ptr<yaml::MachineFunctionInfo>(TM.convertFuncInfoToYAML(MF));
235
236 raw_string_ostream StrOS(YamlMF.Body.Value.Value);
237 bool IsNewlineNeeded = false;
238 for (const auto &MBB : MF) {
239 if (IsNewlineNeeded)
240 StrOS << "\n";
241 printMBB(StrOS, State, MBB);
242 IsNewlineNeeded = true;
243 }
244 // Convert machine metadata collected during the print of the machine
245 // function.
246 convertMachineMetadataNodes(YamlMF, MF, MST);
247
248 convertCalledGlobals(YamlMF, MF, MST);
249
250 convertPrefetchTargets(YamlMF, MF);
251
252 yaml::Output Out(OS);
253 if (!SimplifyMIR)
254 Out.setWriteDefaultValues(true);
255 Out << YamlMF;
256}
257
258static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS,
259 const TargetRegisterInfo *TRI) {
260 assert(RegMask && "Can't print an empty register mask");
261 OS << StringRef("CustomRegMask(");
262
263 bool IsRegInRegMaskFound = false;
264 for (int I = 0, E = TRI->getNumRegs(); I < E; I++) {
265 // Check whether the register is asserted in regmask.
266 if (RegMask[I / 32] & (1u << (I % 32))) {
267 if (IsRegInRegMaskFound)
268 OS << ',';
269 OS << printReg(I, TRI);
270 IsRegInRegMaskFound = true;
271 }
272 }
273
274 OS << ')';
275}
276
283
284template <typename T>
285static void
287 T &Object, ModuleSlotTracker &MST) {
288 std::array<std::string *, 3> Outputs{{&Object.DebugVar.Value,
289 &Object.DebugExpr.Value,
290 &Object.DebugLoc.Value}};
291 std::array<const Metadata *, 3> Metas{{DebugVar.Var,
292 DebugVar.Expr,
293 DebugVar.Loc}};
294 for (unsigned i = 0; i < 3; ++i) {
295 raw_string_ostream StrOS(*Outputs[i]);
296 Metas[i]->printAsOperand(StrOS, MST);
297 }
298}
299
301 std::vector<yaml::FlowStringValue> &RegisterFlags,
302 const MachineFunction &MF,
303 const TargetRegisterInfo *TRI) {
304 auto FlagValues = TRI->getVRegFlagsOfReg(Reg, MF);
305 for (auto &Flag : FlagValues)
306 RegisterFlags.push_back(yaml::FlowStringValue(Flag.str()));
307}
308
309static void convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF,
311 const TargetRegisterInfo *TRI, const VirtRegMap *VRM) {
312 YamlMF.TracksRegLiveness = RegInfo.tracksLiveness();
313
314 // Print the virtual register definitions.
315 for (unsigned I = 0, E = RegInfo.getNumVirtRegs(); I < E; ++I) {
318 VReg.ID = I;
319 if (RegInfo.getVRegName(Reg) != "")
320 continue;
322 Register PreferredReg = RegInfo.getSimpleHint(Reg);
323 if (PreferredReg)
324 printRegMIR(PreferredReg, VReg.PreferredRegister, TRI);
326 if (VRM) {
327 Register Orig = VRM->getPreSplitReg(Reg);
328 if (Orig && Orig != Reg) {
330 OS << printReg(Orig, TRI);
331 }
332 if (VRM->hasPhys(Reg)) {
334 OS << printReg(VRM->getPhys(Reg), TRI);
335 }
336 }
337 YamlMF.VirtualRegisters.push_back(std::move(VReg));
338 }
339
340 // Print the live ins.
341 for (std::pair<MCRegister, Register> LI : RegInfo.liveins()) {
343 printRegMIR(LI.first, LiveIn.Register, TRI);
344 if (LI.second)
345 printRegMIR(LI.second, LiveIn.VirtualRegister, TRI);
346 YamlMF.LiveIns.push_back(std::move(LiveIn));
347 }
348
349 // Prints the callee saved registers.
350 if (RegInfo.isUpdatedCSRsInitialized()) {
351 const MCPhysReg *CalleeSavedRegs = RegInfo.getCalleeSavedRegs();
352 std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
353 for (const MCPhysReg *I = CalleeSavedRegs; *I; ++I) {
355 printRegMIR(*I, Reg, TRI);
356 CalleeSavedRegisters.push_back(std::move(Reg));
357 }
358 YamlMF.CalleeSavedRegisters = std::move(CalleeSavedRegisters);
359 }
360}
361
363 const MachineFrameInfo &MFI,
364 const TargetRegisterInfo *TRI) {
367 YamlMFI.HasStackMap = MFI.hasStackMap();
368 YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
369 YamlMFI.StackSize = MFI.getStackSize();
371 YamlMFI.MaxAlignment = MFI.getMaxAlign().value();
372 YamlMFI.AdjustsStack = MFI.adjustsStack();
373 YamlMFI.HasCalls = MFI.hasCalls();
376 ? MFI.getMaxCallFrameSize() : ~0u;
380 YamlMFI.HasVAStart = MFI.hasVAStart();
382 YamlMFI.HasTailCall = MFI.hasTailCall();
384 YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
385 if (!MFI.getSavePoints().empty())
386 convertSRPoints(MST, YamlMFI.SavePoints, MFI.getSavePoints(), TRI);
387 if (!MFI.getRestorePoints().empty())
389}
390
392 const MachineFunction &MF,
393 ModuleSlotTracker &MST) {
395 for (const MachineFunction::VariableDbgInfo &DebugVar :
397 yaml::EntryValueObject &Obj = YMF.EntryValueObjects.emplace_back();
398 printStackObjectDbgInfo(DebugVar, Obj, MST);
399 MCRegister EntryValReg = DebugVar.getEntryValueRegister();
400 printRegMIR(EntryValReg, Obj.EntryValueRegister, TRI);
401 }
402}
403
405 const MFPrintState &State,
406 int FrameIndex) {
407 auto ObjectInfo = State.StackObjectOperandMapping.find(FrameIndex);
408 assert(ObjectInfo != State.StackObjectOperandMapping.end() &&
409 "Invalid frame index");
410 const FrameIndexOperand &Operand = ObjectInfo->second;
411 MachineOperand::printStackObjectReference(OS, Operand.ID, Operand.IsFixed,
412 Operand.Name);
413}
414
416 const MachineFunction &MF,
417 ModuleSlotTracker &MST, MFPrintState &State) {
418 const MachineFrameInfo &MFI = MF.getFrameInfo();
420
421 // Process fixed stack objects.
422 assert(YMF.FixedStackObjects.empty());
423 SmallVector<int, 32> FixedStackObjectsIdx;
424 const int BeginIdx = MFI.getObjectIndexBegin();
425 if (BeginIdx < 0)
426 FixedStackObjectsIdx.reserve(-BeginIdx);
427
428 unsigned ID = 0;
429 for (int I = BeginIdx; I < 0; ++I, ++ID) {
430 FixedStackObjectsIdx.push_back(-1); // Fill index for possible dead.
431 if (MFI.isDeadObjectIndex(I))
432 continue;
433
435 YamlObject.ID = ID;
436 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
439 YamlObject.Offset = MFI.getObjectOffset(I);
440 YamlObject.Size = MFI.getObjectSize(I);
441 YamlObject.Alignment = MFI.getObjectAlign(I);
442 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
443 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
444 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
445 // Save the ID' position in FixedStackObjects storage vector.
446 FixedStackObjectsIdx[ID] = YMF.FixedStackObjects.size();
447 YMF.FixedStackObjects.push_back(std::move(YamlObject));
448 State.StackObjectOperandMapping.insert(
449 std::make_pair(I, FrameIndexOperand::createFixed(ID)));
450 }
451
452 // Process ordinary stack objects.
453 assert(YMF.StackObjects.empty());
454 SmallVector<unsigned, 32> StackObjectsIdx;
455 const int EndIdx = MFI.getObjectIndexEnd();
456 if (EndIdx > 0)
457 StackObjectsIdx.reserve(EndIdx);
458 ID = 0;
459 for (int I = 0; I < EndIdx; ++I, ++ID) {
460 StackObjectsIdx.push_back(-1); // Fill index for possible dead.
461 if (MFI.isDeadObjectIndex(I))
462 continue;
463
464 yaml::MachineStackObject YamlObject;
465 YamlObject.ID = ID;
466 if (const auto *Alloca = MFI.getObjectAllocation(I))
467 YamlObject.Name.Value = std::string(
468 Alloca->hasName() ? Alloca->getName() : "");
469 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
474 YamlObject.Offset = MFI.getObjectOffset(I);
475 YamlObject.Size = MFI.getObjectSize(I);
476 YamlObject.Alignment = MFI.getObjectAlign(I);
477 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
478
479 // Save the ID' position in StackObjects storage vector.
480 StackObjectsIdx[ID] = YMF.StackObjects.size();
481 YMF.StackObjects.push_back(YamlObject);
482 State.StackObjectOperandMapping.insert(std::make_pair(
483 I, FrameIndexOperand::create(YamlObject.Name.Value, ID)));
484 }
485
486 for (const auto &CSInfo : MFI.getCalleeSavedInfo()) {
487 const int FrameIdx = CSInfo.getFrameIdx();
488 if (!CSInfo.isSpilledToReg() && MFI.isDeadObjectIndex(FrameIdx))
489 continue;
490
492 printRegMIR(CSInfo.getReg(), Reg, TRI);
493 if (!CSInfo.isSpilledToReg()) {
494 assert(FrameIdx >= MFI.getObjectIndexBegin() &&
495 FrameIdx < MFI.getObjectIndexEnd() &&
496 "Invalid stack object index");
497 if (FrameIdx < 0) { // Negative index means fixed objects.
498 auto &Object =
500 [FixedStackObjectsIdx[FrameIdx + MFI.getNumFixedObjects()]];
501 Object.CalleeSavedRegister = std::move(Reg);
502 Object.CalleeSavedRestored = CSInfo.isRestored();
503 } else {
504 auto &Object = YMF.StackObjects[StackObjectsIdx[FrameIdx]];
505 Object.CalleeSavedRegister = std::move(Reg);
506 Object.CalleeSavedRestored = CSInfo.isRestored();
507 }
508 }
509 }
510 for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) {
511 auto LocalObject = MFI.getLocalFrameObjectMap(I);
512 assert(LocalObject.first >= 0 && "Expected a locally mapped stack object");
513 YMF.StackObjects[StackObjectsIdx[LocalObject.first]].LocalOffset =
514 LocalObject.second;
515 }
516
517 // Print the stack object references in the frame information class after
518 // converting the stack objects.
519 if (MFI.hasStackProtectorIndex()) {
522 }
523
524 if (MFI.hasFunctionContextIndex()) {
527 }
528
529 // Print the debug variable information.
530 for (const MachineFunction::VariableDbgInfo &DebugVar :
532 int Idx = DebugVar.getStackSlot();
533 assert(Idx >= MFI.getObjectIndexBegin() && Idx < MFI.getObjectIndexEnd() &&
534 "Invalid stack object index");
535 if (Idx < 0) { // Negative index means fixed objects.
536 auto &Object =
537 YMF.FixedStackObjects[FixedStackObjectsIdx[Idx +
538 MFI.getNumFixedObjects()]];
539 printStackObjectDbgInfo(DebugVar, Object, MST);
540 } else {
541 auto &Object = YMF.StackObjects[StackObjectsIdx[Idx]];
542 printStackObjectDbgInfo(DebugVar, Object, MST);
543 }
544 }
545}
546
548 const MachineFunction &MF,
549 ModuleSlotTracker &MST) {
550 const auto *TRI = MF.getSubtarget().getRegisterInfo();
551 for (auto [MI, CallSiteInfo] : MF.getCallSitesInfo()) {
552 yaml::CallSiteInfo YmlCS;
553 yaml::MachineInstrLoc CallLocation;
554
555 // Prepare instruction position.
556 MachineBasicBlock::const_instr_iterator CallI = MI->getIterator();
557 CallLocation.BlockNum = CallI->getParent()->getNumber();
558 // Get call instruction offset from the beginning of block.
559 CallLocation.Offset =
560 std::distance(CallI->getParent()->instr_begin(), CallI);
561 YmlCS.CallLocation = CallLocation;
562
563 auto [ArgRegPairs, CalleeTypeIds, _] = CallSiteInfo;
564 // Construct call arguments and theirs forwarding register info.
565 for (auto ArgReg : ArgRegPairs) {
567 YmlArgReg.ArgNo = ArgReg.ArgNo;
568 printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
569 YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
570 }
571 // Get type ids.
572 for (auto *CalleeTypeId : CalleeTypeIds) {
573 YmlCS.CalleeTypeIds.push_back(CalleeTypeId->getZExtValue());
574 }
575 YMF.CallSitesInfo.push_back(std::move(YmlCS));
576 }
577
578 // Sort call info by position of call instructions.
579 llvm::sort(YMF.CallSitesInfo.begin(), YMF.CallSitesInfo.end(),
581 return std::tie(A.CallLocation.BlockNum, A.CallLocation.Offset) <
582 std::tie(B.CallLocation.BlockNum, B.CallLocation.Offset);
583 });
584}
585
587 const MachineFunction &MF,
590 MST.collectMachineMDNodes(MDList);
591 for (auto &MD : MDList) {
592 std::string NS;
593 raw_string_ostream StrOS(NS);
594 MD.second->print(StrOS, MST, MF.getFunction().getParent());
595 YMF.MachineMetadataNodes.push_back(std::move(NS));
596 }
597}
598
600 const MachineFunction &MF,
602 for (const auto &[CallInst, CG] : MF.getCalledGlobals()) {
603 yaml::MachineInstrLoc CallSite;
604 CallSite.BlockNum = CallInst->getParent()->getNumber();
605 CallSite.Offset = std::distance(CallInst->getParent()->instr_begin(),
607
608 yaml::CalledGlobal YamlCG{CallSite, CG.Callee->getName().str(),
609 CG.TargetFlags};
610 YMF.CalledGlobals.push_back(std::move(YamlCG));
611 }
612
613 // Sort by position of call instructions.
614 llvm::sort(YMF.CalledGlobals.begin(), YMF.CalledGlobals.end(),
616 return std::tie(A.CallSite.BlockNum, A.CallSite.Offset) <
617 std::tie(B.CallSite.BlockNum, B.CallSite.Offset);
618 });
619}
620
622 const MachineFunction &MF) {
623 for (const auto &[BBID, CallsiteIndexes] : MF.getPrefetchTargets()) {
624 for (auto CallsiteIndex : CallsiteIndexes) {
625 std::string Str;
626 raw_string_ostream StrOS(Str);
627 StrOS << "bb_id " << BBID.BaseID << ", " << BBID.CloneID << ", "
628 << CallsiteIndex;
629 YMF.PrefetchTargets.push_back(yaml::FlowStringValue(Str));
630 }
631 }
632}
633
636 unsigned ID = 0;
637 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
638 std::string Str;
639 raw_string_ostream StrOS(Str);
640 if (Constant.isMachineConstantPoolEntry())
641 Constant.Val.MachineCPVal->print(StrOS);
642 else
643 Constant.Val.ConstVal->printAsOperand(StrOS);
644
646 YamlConstant.ID = ID++;
647 YamlConstant.Value = std::move(Str);
648 YamlConstant.Alignment = Constant.getAlign();
649 YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry();
650
651 MF.Constants.push_back(std::move(YamlConstant));
652 }
653}
654
655static void
657 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
658 const llvm::SaveRestorePoints &SRPoints,
659 const TargetRegisterInfo *TRI) {
660 for (const auto &[MBB, CSInfos] : SRPoints) {
661 SmallString<16> Str;
663 raw_svector_ostream StrOS(Str);
664 StrOS << printMBBReference(*MBB);
665 Entry.Point = StrOS.str().str();
666 Str.clear();
667 for (const CalleeSavedInfo &Info : CSInfos) {
668 if (Info.getReg()) {
669 StrOS << printReg(Info.getReg(), TRI);
670 Entry.Registers.push_back(StrOS.str().str());
671 Str.clear();
672 }
673 }
674 // Sort here needed for stable output for lit tests
675 std::sort(Entry.Registers.begin(), Entry.Registers.end(),
676 [](const yaml::StringValue &Lhs, const yaml::StringValue &Rhs) {
677 return Lhs.Value < Rhs.Value;
678 });
679 YamlSRPoints.push_back(std::move(Entry));
680 }
681 // Sort here needed for stable output for lit tests
682 std::sort(YamlSRPoints.begin(), YamlSRPoints.end(),
683 [](const yaml::SaveRestorePointEntry &Lhs,
684 const yaml::SaveRestorePointEntry &Rhs) {
685 return Lhs.Point.Value < Rhs.Point.Value;
686 });
687}
688
690 const MachineJumpTableInfo &JTI) {
691 YamlJTI.Kind = JTI.getEntryKind();
692 unsigned ID = 0;
693 for (const auto &Table : JTI.getJumpTables()) {
694 std::string Str;
696 Entry.ID = ID++;
697 for (const auto *MBB : Table.MBBs) {
698 raw_string_ostream StrOS(Str);
699 StrOS << printMBBReference(*MBB);
700 Entry.Blocks.push_back(Str);
701 Str.clear();
702 }
703 YamlJTI.Entries.push_back(std::move(Entry));
704 }
705}
706
709 bool &IsFallthrough) {
711
712 for (const MachineInstr &MI : MBB) {
713 if (MI.isPHI())
714 continue;
715 for (const MachineOperand &MO : MI.operands()) {
716 if (!MO.isMBB())
717 continue;
718 MachineBasicBlock *Succ = MO.getMBB();
719 auto RP = Seen.insert(Succ);
720 if (RP.second)
721 Result.push_back(Succ);
722 }
723 }
724 MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr();
725 IsFallthrough = I == MBB.end() || !I->isBarrier();
726}
727
730 bool GuessedFallthrough;
731 guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough);
732 if (GuessedFallthrough) {
733 const MachineFunction &MF = *MBB.getParent();
734 MachineFunction::const_iterator NextI = std::next(MBB.getIterator());
735 if (NextI != MF.end()) {
736 MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI);
737 if (!is_contained(GuessedSuccs, Next))
738 GuessedSuccs.push_back(Next);
739 }
740 }
741 if (GuessedSuccs.size() != MBB.succ_size())
742 return false;
743 return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin());
744}
745
746static void printMI(raw_ostream &OS, MFPrintState &State,
747 const MachineInstr &MI);
748
749static void printMIOperand(raw_ostream &OS, MFPrintState &State,
750 const MachineInstr &MI, unsigned OpIdx,
751 const TargetRegisterInfo *TRI,
752 const TargetInstrInfo *TII,
753 bool ShouldPrintRegisterTies,
754 SmallBitVector &PrintedTypes,
755 const MachineRegisterInfo &MRI, bool PrintDef);
756
757void printMBB(raw_ostream &OS, MFPrintState &State,
758 const MachineBasicBlock &MBB) {
759 assert(MBB.getNumber() >= 0 && "Invalid MBB number");
760 MBB.printName(OS,
763 &State.MST);
764 OS << ":\n";
765
766 bool HasLineAttributes = false;
767 // Print the successors
768 bool canPredictProbs = MBB.canPredictBranchProbabilities();
769 // Even if the list of successors is empty, if we cannot guess it,
770 // we need to print it to tell the parser that the list is empty.
771 // This is needed, because MI model unreachable as empty blocks
772 // with an empty successor list. If the parser would see that
773 // without the successor list, it would guess the code would
774 // fallthrough.
775 if ((!MBB.succ_empty() && !SimplifyMIR) || !canPredictProbs ||
777 OS.indent(2) << "successors:";
778 if (!MBB.succ_empty())
779 OS << " ";
780 ListSeparator LS;
781 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
782 OS << LS << printMBBReference(**I);
783 if (!SimplifyMIR || !canPredictProbs)
784 OS << format("(0x%08" PRIx32 ")",
785 MBB.getSuccProbability(I).getNumerator());
786 }
787 OS << "\n";
788 HasLineAttributes = true;
789 }
790
791 // Print the live in registers.
792 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
793 if (!MBB.livein_empty()) {
795 OS.indent(2) << "liveins: ";
796 ListSeparator LS;
797 for (const auto &LI : MBB.liveins_dbg()) {
798 OS << LS << printReg(LI.PhysReg, &TRI);
799 if (!LI.LaneMask.all())
800 OS << ":0x" << PrintLaneMask(LI.LaneMask);
801 }
802 OS << "\n";
803 HasLineAttributes = true;
804 }
805
806 if (HasLineAttributes && !MBB.empty())
807 OS << "\n";
808 bool IsInBundle = false;
809 for (const MachineInstr &MI : MBB.instrs()) {
810 if (IsInBundle && !MI.isInsideBundle()) {
811 OS.indent(2) << "}\n";
812 IsInBundle = false;
813 }
814 OS.indent(IsInBundle ? 4 : 2);
815 printMI(OS, State, MI);
816 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
817 OS << " {";
818 IsInBundle = true;
819 }
820 OS << "\n";
821 }
822 if (IsInBundle)
823 OS.indent(2) << "}\n";
824}
825
826static void printMI(raw_ostream &OS, MFPrintState &State,
827 const MachineInstr &MI) {
828 const auto *MF = MI.getMF();
829 const auto &MRI = MF->getRegInfo();
830 const auto &SubTarget = MF->getSubtarget();
831 const auto *TRI = SubTarget.getRegisterInfo();
832 assert(TRI && "Expected target register info");
833 const auto *TII = SubTarget.getInstrInfo();
834 assert(TII && "Expected target instruction info");
835 if (MI.isCFIInstruction())
836 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
837
838 SmallBitVector PrintedTypes(8);
839 bool ShouldPrintRegisterTies = MI.hasComplexRegisterTies();
840 ListSeparator LS;
841 unsigned I = 0, E = MI.getNumOperands();
842 for (; I < E; ++I) {
843 const MachineOperand MO = MI.getOperand(I);
844 if (!MO.isReg() || !MO.isDef() || MO.isImplicit())
845 break;
846 OS << LS;
847 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
848 PrintedTypes, MRI, /*PrintDef=*/false);
849 }
850
851 if (I)
852 OS << " = ";
853 if (MI.getFlag(MachineInstr::FrameSetup))
854 OS << "frame-setup ";
855 if (MI.getFlag(MachineInstr::FrameDestroy))
856 OS << "frame-destroy ";
857 if (MI.getFlag(MachineInstr::FmNoNans))
858 OS << "nnan ";
859 if (MI.getFlag(MachineInstr::FmNoInfs))
860 OS << "ninf ";
861 if (MI.getFlag(MachineInstr::FmNsz))
862 OS << "nsz ";
863 if (MI.getFlag(MachineInstr::FmArcp))
864 OS << "arcp ";
865 if (MI.getFlag(MachineInstr::FmContract))
866 OS << "contract ";
867 if (MI.getFlag(MachineInstr::FmAfn))
868 OS << "afn ";
869 if (MI.getFlag(MachineInstr::FmReassoc))
870 OS << "reassoc ";
871 if (MI.getFlag(MachineInstr::NoUWrap))
872 OS << "nuw ";
873 if (MI.getFlag(MachineInstr::NoSWrap))
874 OS << "nsw ";
875 if (MI.getFlag(MachineInstr::IsExact))
876 OS << "exact ";
877 if (MI.getFlag(MachineInstr::NoFPExcept))
878 OS << "nofpexcept ";
879 if (MI.getFlag(MachineInstr::NoMerge))
880 OS << "nomerge ";
881 if (MI.getFlag(MachineInstr::Unpredictable))
882 OS << "unpredictable ";
883 if (MI.getFlag(MachineInstr::NoConvergent))
884 OS << "noconvergent ";
885 if (MI.getFlag(MachineInstr::NonNeg))
886 OS << "nneg ";
887 if (MI.getFlag(MachineInstr::Disjoint))
888 OS << "disjoint ";
889 if (MI.getFlag(MachineInstr::NoUSWrap))
890 OS << "nusw ";
891 if (MI.getFlag(MachineInstr::SameSign))
892 OS << "samesign ";
893 if (MI.getFlag(MachineInstr::InBounds))
894 OS << "inbounds ";
895
896 // NOTE: Please add new MIFlags also to the MI_FLAGS_STR in
897 // llvm/utils/update_mir_test_checks.py.
898
899 OS << TII->getName(MI.getOpcode());
900
901 // Print a space after the opcode if any additional tokens are printed.
902 LS = ListSeparator(", ", " ");
903
904 for (; I < E; ++I) {
905 OS << LS;
906 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
907 PrintedTypes, MRI, /*PrintDef=*/true);
908 }
909
910 // Print any optional symbols attached to this instruction as-if they were
911 // operands.
912 if (MCSymbol *PreInstrSymbol = MI.getPreInstrSymbol()) {
913 OS << LS << "pre-instr-symbol ";
914 MachineOperand::printSymbol(OS, *PreInstrSymbol);
915 }
916 if (MCSymbol *PostInstrSymbol = MI.getPostInstrSymbol()) {
917 OS << LS << "post-instr-symbol ";
918 MachineOperand::printSymbol(OS, *PostInstrSymbol);
919 }
920 if (MDNode *HeapAllocMarker = MI.getHeapAllocMarker()) {
921 OS << LS << "heap-alloc-marker ";
922 HeapAllocMarker->printAsOperand(OS, State.MST);
923 }
924 if (MDNode *PCSections = MI.getPCSections()) {
925 OS << LS << "pcsections ";
926 PCSections->printAsOperand(OS, State.MST);
927 }
928 if (MDNode *MMRA = MI.getMMRAMetadata()) {
929 OS << LS << "mmra ";
930 MMRA->printAsOperand(OS, State.MST);
931 }
932 if (uint32_t CFIType = MI.getCFIType())
933 OS << LS << "cfi-type " << CFIType;
934 if (Value *DS = MI.getDeactivationSymbol()) {
935 OS << LS << "deactivation-symbol ";
936 MIRFormatter::printIRValue(OS, *DS, State.MST);
937 }
938
939 if (auto Num = MI.peekDebugInstrNum())
940 OS << LS << "debug-instr-number " << Num;
941
942 if (PrintLocations) {
943 if (const DebugLoc &DL = MI.getDebugLoc()) {
944 OS << LS << "debug-location ";
945 DL->printAsOperand(OS, State.MST);
946 }
947 }
948
949 if (!MI.memoperands_empty()) {
950 OS << " :: ";
951 const LLVMContext &Context = MF->getFunction().getContext();
952 const MachineFrameInfo &MFI = MF->getFrameInfo();
953 LS = ListSeparator();
954 for (const auto *Op : MI.memoperands()) {
955 OS << LS;
956 Op->print(OS, State.MST, State.SSNs, Context, &MFI, TII);
957 }
958 }
959}
960
961static std::string formatOperandComment(std::string Comment) {
962 if (Comment.empty())
963 return Comment;
964 return std::string(" /* " + Comment + " */");
965}
966
967static void printMIOperand(raw_ostream &OS, MFPrintState &State,
968 const MachineInstr &MI, unsigned OpIdx,
969 const TargetRegisterInfo *TRI,
970 const TargetInstrInfo *TII,
971 bool ShouldPrintRegisterTies,
972 SmallBitVector &PrintedTypes,
973 const MachineRegisterInfo &MRI, bool PrintDef) {
974 LLT TypeToPrint = MI.getTypeToPrint(OpIdx, PrintedTypes, MRI);
975 const MachineOperand &Op = MI.getOperand(OpIdx);
976 std::string MOComment = TII->createMIROperandComment(MI, Op, OpIdx, TRI);
977
978 switch (Op.getType()) {
980 if (MI.isOperandSubregIdx(OpIdx)) {
983 break;
984 }
985 if (MI.isInlineAsm()) {
987 unsigned ExtraInfo = Op.getImm();
988 interleave(InlineAsm::getExtraInfoNames(ExtraInfo), OS, " ");
989 break;
990 }
991
992 int FlagIdx = MI.findInlineAsmFlagIdx(OpIdx);
993 if (FlagIdx >= 0 && (unsigned)FlagIdx == OpIdx) {
994 InlineAsm::Flag F(Op.getImm());
995 OS << F.getKindName();
996
997 unsigned RCID;
998 if ((F.isRegDefKind() || F.isRegUseKind() ||
999 F.isRegDefEarlyClobberKind()) &&
1000 F.hasRegClassConstraint(RCID))
1001 OS << ':' << TRI->getRegClassName(TRI->getRegClass(RCID));
1002
1003 if (F.isMemKind()) {
1004 InlineAsm::ConstraintCode MCID = F.getMemoryConstraintID();
1006 }
1007
1008 unsigned TiedTo;
1009 if (F.isUseOperandTiedToDef(TiedTo))
1010 OS << " tiedto:$" << TiedTo;
1011 break;
1012 }
1013 }
1014 [[fallthrough]];
1034 unsigned TiedOperandIdx = 0;
1035 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
1036 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
1037 Op.print(OS, State.MST, TypeToPrint, OpIdx, PrintDef,
1038 /*IsStandalone=*/false, ShouldPrintRegisterTies, TiedOperandIdx,
1039 TRI);
1040 OS << formatOperandComment(MOComment);
1041 break;
1042 }
1044 printStackObjectReference(OS, State, Op.getIndex());
1045 break;
1047 const auto &RegisterMaskIds = State.RegisterMaskIds;
1048 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
1049 if (RegMaskInfo != RegisterMaskIds.end())
1050 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
1051 else
1052 printCustomRegMask(Op.getRegMask(), OS, TRI);
1053 break;
1054 }
1055 }
1056}
1057
1059 ModuleSlotTracker &MST) {
1060 if (isa<GlobalValue>(V)) {
1061 V.printAsOperand(OS, /*PrintType=*/false, MST);
1062 return;
1063 }
1064 if (isa<Constant>(V)) {
1065 // Machine memory operands can load/store to/from constant value pointers.
1066 OS << '`';
1067 V.printAsOperand(OS, /*PrintType=*/true, MST);
1068 OS << '`';
1069 return;
1070 }
1071 OS << "%ir.";
1072 if (V.hasName()) {
1073 printLLVMNameWithoutPrefix(OS, V.getName());
1074 return;
1075 }
1076 int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1;
1078}
1079
1080void llvm::printMIR(raw_ostream &OS, const Module &M) {
1081 yaml::Output Out(OS);
1082 Out << const_cast<Module &>(M);
1083}
1084
1086 const MachineFunction &MF, const VirtRegMap *VRM) {
1087 printMF(
1088 OS, [&](const Function &F) { return MMI.getMachineFunction(F); }, MF,
1089 VRM);
1090}
1091
1093 const MachineFunction &MF, const VirtRegMap *VRM) {
1094 printMF(
1095 OS,
1096 [&](const Function &F) {
1097 return &FAM.getResult<MachineFunctionAnalysis>(
1098 const_cast<Function &>(F))
1099 .getMF();
1100 },
1101 MF, VRM);
1102}
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")
This file defines the DenseMap class.
const HexagonInstrInfo * TII
#define _
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 F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
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 printStackObjectReference(raw_ostream &OS, const MFPrintState &State, int FrameIndex)
static void convertEntryValueObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST)
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 convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI, const VirtRegMap *VRM)
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 printMF(raw_ostream &OS, MFGetterFnT Fn, const MachineFunction &MF, const VirtRegMap *VRM)
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 convertPrefetchTargets(yaml::MachineFunction &YMF, const MachineFunction &MF)
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
FunctionAnalysisManager FAM
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:286
Module * getParent()
Get the module that this global value is contained inside of...
static std::vector< StringRef > getExtraInfoNames(unsigned ExtraInfo)
Definition InlineAsm.h:451
static StringRef getMemConstraintName(ConstraintCode C)
Definition InlineAsm.h:475
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:41
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:1069
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...
FramePointerKind getFramePointerPolicy() const
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...
This analysis create MachineFunction for given Function.
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 DenseMap< UniqueBBID, SmallVector< unsigned > > & getPrefetchTargets() const
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.
LLVM_ABI MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
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_LaneMask
Mask to represent active parts of registers.
@ 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,...
const TargetRegisterInfo * getTargetRegisterInfo() const
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:20
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:72
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
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.
virtual yaml::MachineFunctionInfo * convertFuncInfoToYAML(const MachineFunction &MF) const
Allocate and initialize an instance of the YAML representation of the MachineFunctionInfo.
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.
Register getPreSplitReg(Register virtReg) const
returns the live interval virtReg is split from.
Definition VirtRegMap.h:147
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Definition VirtRegMap.h:91
bool hasPhys(Register virtReg) const
returns true if the specified virtual register is mapped to a physical register
Definition VirtRegMap.h:87
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.
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
An STL-style algorithm similar to std::for_each that applies a second functor between every pair of e...
Definition STLExtras.h:2274
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...
function_ref< MachineFunction *(const Function &)> MFGetterFnT
DenseMap< MachineBasicBlock *, std::vector< CalleeSavedInfo > > SaveRestorePoints
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1635
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
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1916
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1946
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
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:180
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.
FramePointerKind FramePointerPolicy
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< FlowStringValue > PrefetchTargets
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)