LLVM 24.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
327 // Print the anti-hints.
328 const auto &AntiHints = RegInfo.getRegAllocationAntiHints(Reg);
329 if (!AntiHints.empty()) {
330 std::vector<yaml::FlowStringValue> AntiHintStrings;
331 for (Register AntiHint : AntiHints) {
332 yaml::FlowStringValue AntiHintStr;
333 printRegMIR(AntiHint, AntiHintStr, TRI);
334 AntiHintStrings.push_back(std::move(AntiHintStr));
335 }
336 VReg.AntiHints = std::move(AntiHintStrings);
337 }
338 if (VRM) {
339 Register Orig = VRM->getPreSplitReg(Reg);
340 if (Orig && Orig != Reg) {
342 OS << printReg(Orig, TRI);
343 }
344 if (VRM->hasPhys(Reg)) {
346 OS << printReg(VRM->getPhys(Reg), TRI);
347 }
348 }
349 YamlMF.VirtualRegisters.push_back(std::move(VReg));
350 }
351
352 // Print the live ins.
353 for (std::pair<MCRegister, Register> LI : RegInfo.liveins()) {
355 printRegMIR(LI.first, LiveIn.Register, TRI);
356 if (LI.second)
357 printRegMIR(LI.second, LiveIn.VirtualRegister, TRI);
358 YamlMF.LiveIns.push_back(std::move(LiveIn));
359 }
360
361 // Prints the callee saved registers.
362 if (RegInfo.isUpdatedCSRsInitialized()) {
363 const MCPhysReg *CalleeSavedRegs = RegInfo.getCalleeSavedRegs();
364 std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
365 for (const MCPhysReg *I = CalleeSavedRegs; *I; ++I) {
367 printRegMIR(*I, Reg, TRI);
368 CalleeSavedRegisters.push_back(std::move(Reg));
369 }
370 YamlMF.CalleeSavedRegisters = std::move(CalleeSavedRegisters);
371 }
372}
373
375 const MachineFrameInfo &MFI,
376 const TargetRegisterInfo *TRI) {
379 YamlMFI.HasStackMap = MFI.hasStackMap();
380 YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
381 YamlMFI.StackSize = MFI.getStackSize();
383 YamlMFI.MaxAlignment = MFI.getMaxAlign().value();
384 YamlMFI.AdjustsStack = MFI.adjustsStack();
385 YamlMFI.HasCalls = MFI.hasCalls();
388 ? MFI.getMaxCallFrameSize() : ~0u;
392 YamlMFI.HasVAStart = MFI.hasVAStart();
394 YamlMFI.HasTailCall = MFI.hasTailCall();
396 YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
397 if (!MFI.getSavePoints().empty())
398 convertSRPoints(MST, YamlMFI.SavePoints, MFI.getSavePoints(), TRI);
399 if (!MFI.getRestorePoints().empty())
401}
402
404 const MachineFunction &MF,
405 ModuleSlotTracker &MST) {
407 for (const MachineFunction::VariableDbgInfo &DebugVar :
409 yaml::EntryValueObject &Obj = YMF.EntryValueObjects.emplace_back();
410 printStackObjectDbgInfo(DebugVar, Obj, MST);
411 MCRegister EntryValReg = DebugVar.getEntryValueRegister();
412 printRegMIR(EntryValReg, Obj.EntryValueRegister, TRI);
413 }
414}
415
417 const MFPrintState &State,
418 int FrameIndex) {
419 auto ObjectInfo = State.StackObjectOperandMapping.find(FrameIndex);
420 assert(ObjectInfo != State.StackObjectOperandMapping.end() &&
421 "Invalid frame index");
422 const FrameIndexOperand &Operand = ObjectInfo->second;
423 MachineOperand::printStackObjectReference(OS, Operand.ID, Operand.IsFixed,
424 Operand.Name);
425}
426
428 const MachineFunction &MF,
429 ModuleSlotTracker &MST, MFPrintState &State) {
430 const MachineFrameInfo &MFI = MF.getFrameInfo();
432
433 // Process fixed stack objects.
434 assert(YMF.FixedStackObjects.empty());
435 SmallVector<int, 32> FixedStackObjectsIdx;
436 const int BeginIdx = MFI.getObjectIndexBegin();
437 if (BeginIdx < 0)
438 FixedStackObjectsIdx.reserve(-BeginIdx);
439
440 unsigned ID = 0;
441 for (int I = BeginIdx; I < 0; ++I, ++ID) {
442 FixedStackObjectsIdx.push_back(-1); // Fill index for possible dead.
443 if (MFI.isDeadObjectIndex(I))
444 continue;
445
447 YamlObject.ID = ID;
448 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 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
456 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
457 // Save the ID' position in FixedStackObjects storage vector.
458 FixedStackObjectsIdx[ID] = YMF.FixedStackObjects.size();
459 YMF.FixedStackObjects.push_back(std::move(YamlObject));
460 State.StackObjectOperandMapping.insert(
461 std::make_pair(I, FrameIndexOperand::createFixed(ID)));
462 }
463
464 // Process ordinary stack objects.
465 assert(YMF.StackObjects.empty());
466 SmallVector<unsigned, 32> StackObjectsIdx;
467 const int EndIdx = MFI.getObjectIndexEnd();
468 if (EndIdx > 0)
469 StackObjectsIdx.reserve(EndIdx);
470 ID = 0;
471 for (int I = 0; I < EndIdx; ++I, ++ID) {
472 StackObjectsIdx.push_back(-1); // Fill index for possible dead.
473 if (MFI.isDeadObjectIndex(I))
474 continue;
475
476 yaml::MachineStackObject YamlObject;
477 YamlObject.ID = ID;
478 if (const auto *Alloca = MFI.getObjectAllocation(I))
479 YamlObject.Name.Value = std::string(
480 Alloca->hasName() ? Alloca->getName() : "");
481 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
486 YamlObject.Offset = MFI.getObjectOffset(I);
487 YamlObject.Size = MFI.getObjectSize(I);
488 YamlObject.Alignment = MFI.getObjectAlign(I);
489 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
490
491 // Save the ID' position in StackObjects storage vector.
492 StackObjectsIdx[ID] = YMF.StackObjects.size();
493 YMF.StackObjects.push_back(YamlObject);
494 State.StackObjectOperandMapping.insert(std::make_pair(
495 I, FrameIndexOperand::create(YamlObject.Name.Value, ID)));
496 }
497
498 for (const auto &CSInfo : MFI.getCalleeSavedInfo()) {
499 const int FrameIdx = CSInfo.getFrameIdx();
500 if (!CSInfo.isSpilledToReg() && MFI.isDeadObjectIndex(FrameIdx))
501 continue;
502
504 printRegMIR(CSInfo.getReg(), Reg, TRI);
505 if (!CSInfo.isSpilledToReg()) {
506 assert(FrameIdx >= MFI.getObjectIndexBegin() &&
507 FrameIdx < MFI.getObjectIndexEnd() &&
508 "Invalid stack object index");
509 if (FrameIdx < 0) { // Negative index means fixed objects.
510 auto &Object =
512 [FixedStackObjectsIdx[FrameIdx + MFI.getNumFixedObjects()]];
513 Object.CalleeSavedRegister = std::move(Reg);
514 Object.CalleeSavedRestored = CSInfo.isRestored();
515 } else {
516 auto &Object = YMF.StackObjects[StackObjectsIdx[FrameIdx]];
517 Object.CalleeSavedRegister = std::move(Reg);
518 Object.CalleeSavedRestored = CSInfo.isRestored();
519 }
520 }
521 }
522 for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) {
523 auto LocalObject = MFI.getLocalFrameObjectMap(I);
524 assert(LocalObject.first >= 0 && "Expected a locally mapped stack object");
525 YMF.StackObjects[StackObjectsIdx[LocalObject.first]].LocalOffset =
526 LocalObject.second;
527 }
528
529 // Print the stack object references in the frame information class after
530 // converting the stack objects.
531 if (MFI.hasStackProtectorIndex()) {
534 }
535
536 if (MFI.hasFunctionContextIndex()) {
539 }
540
541 // Print the debug variable information.
542 for (const MachineFunction::VariableDbgInfo &DebugVar :
544 int Idx = DebugVar.getStackSlot();
545 assert(Idx >= MFI.getObjectIndexBegin() && Idx < MFI.getObjectIndexEnd() &&
546 "Invalid stack object index");
547 if (Idx < 0) { // Negative index means fixed objects.
548 auto &Object =
549 YMF.FixedStackObjects[FixedStackObjectsIdx[Idx +
550 MFI.getNumFixedObjects()]];
551 printStackObjectDbgInfo(DebugVar, Object, MST);
552 } else {
553 auto &Object = YMF.StackObjects[StackObjectsIdx[Idx]];
554 printStackObjectDbgInfo(DebugVar, Object, MST);
555 }
556 }
557}
558
560 const MachineFunction &MF,
561 ModuleSlotTracker &MST) {
562 const auto *TRI = MF.getSubtarget().getRegisterInfo();
563 for (auto [MI, CallSiteInfo] : MF.getCallSitesInfo()) {
564 yaml::CallSiteInfo YmlCS;
565 yaml::MachineInstrLoc CallLocation;
566
567 // Prepare instruction position.
568 MachineBasicBlock::const_instr_iterator CallI = MI->getIterator();
569 CallLocation.BlockNum = CallI->getParent()->getNumber();
570 // Get call instruction offset from the beginning of block.
571 CallLocation.Offset =
572 std::distance(CallI->getParent()->instr_begin(), CallI);
573 YmlCS.CallLocation = CallLocation;
574
575 auto [ArgRegPairs, CalleeTypeIds, _] = CallSiteInfo;
576 // Construct call arguments and theirs forwarding register info.
577 for (auto ArgReg : ArgRegPairs) {
579 YmlArgReg.ArgNo = ArgReg.ArgNo;
580 printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
581 YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
582 }
583 // Get type ids.
584 for (auto *CalleeTypeId : CalleeTypeIds) {
585 YmlCS.CalleeTypeIds.push_back(CalleeTypeId->getZExtValue());
586 }
587 YMF.CallSitesInfo.push_back(std::move(YmlCS));
588 }
589
590 // Sort call info by position of call instructions.
591 llvm::sort(YMF.CallSitesInfo.begin(), YMF.CallSitesInfo.end(),
593 return std::tie(A.CallLocation.BlockNum, A.CallLocation.Offset) <
594 std::tie(B.CallLocation.BlockNum, B.CallLocation.Offset);
595 });
596}
597
599 const MachineFunction &MF,
602 MST.collectMachineMDNodes(MDList);
603 for (auto &MD : MDList) {
604 std::string NS;
605 raw_string_ostream StrOS(NS);
606 MD.second->print(StrOS, MST, MF.getFunction().getParent());
607 YMF.MachineMetadataNodes.push_back(std::move(NS));
608 }
609}
610
612 const MachineFunction &MF,
614 for (const auto &[CallInst, CG] : MF.getCalledGlobals()) {
615 yaml::MachineInstrLoc CallSite;
616 CallSite.BlockNum = CallInst->getParent()->getNumber();
617 CallSite.Offset = std::distance(CallInst->getParent()->instr_begin(),
619
620 yaml::CalledGlobal YamlCG{CallSite, CG.Callee->getName().str(),
621 CG.TargetFlags};
622 YMF.CalledGlobals.push_back(std::move(YamlCG));
623 }
624
625 // Sort by position of call instructions.
626 llvm::sort(YMF.CalledGlobals.begin(), YMF.CalledGlobals.end(),
628 return std::tie(A.CallSite.BlockNum, A.CallSite.Offset) <
629 std::tie(B.CallSite.BlockNum, B.CallSite.Offset);
630 });
631}
632
634 const MachineFunction &MF) {
635 for (const auto &[BBID, CallsiteIndexes] : MF.getPrefetchTargets()) {
636 for (auto CallsiteIndex : CallsiteIndexes) {
637 std::string Str;
638 raw_string_ostream StrOS(Str);
639 StrOS << "bb_id " << BBID.BaseID << ", " << BBID.CloneID << ", "
640 << CallsiteIndex;
641 YMF.PrefetchTargets.push_back(yaml::FlowStringValue(Str));
642 }
643 }
644}
645
648 unsigned ID = 0;
649 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
650 std::string Str;
651 raw_string_ostream StrOS(Str);
652 if (Constant.isMachineConstantPoolEntry())
653 Constant.Val.MachineCPVal->print(StrOS);
654 else
655 Constant.Val.ConstVal->printAsOperand(StrOS);
656
658 YamlConstant.ID = ID++;
659 YamlConstant.Value = std::move(Str);
660 YamlConstant.Alignment = Constant.getAlign();
661 YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry();
662
663 MF.Constants.push_back(std::move(YamlConstant));
664 }
665}
666
667static void
669 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
670 const llvm::SaveRestorePoints &SRPoints,
671 const TargetRegisterInfo *TRI) {
672 for (const auto &[MBB, CSInfos] : SRPoints) {
673 SmallString<16> Str;
675 raw_svector_ostream StrOS(Str);
676 StrOS << printMBBReference(*MBB);
677 Entry.Point = StrOS.str().str();
678 Str.clear();
679 for (const CalleeSavedInfo &Info : CSInfos) {
680 if (Info.getReg()) {
681 StrOS << printReg(Info.getReg(), TRI);
682 Entry.Registers.push_back(StrOS.str().str());
683 Str.clear();
684 }
685 }
686 // Sort here needed for stable output for lit tests
687 std::sort(Entry.Registers.begin(), Entry.Registers.end(),
688 [](const yaml::StringValue &Lhs, const yaml::StringValue &Rhs) {
689 return Lhs.Value < Rhs.Value;
690 });
691 YamlSRPoints.push_back(std::move(Entry));
692 }
693 // Sort here needed for stable output for lit tests
694 std::sort(YamlSRPoints.begin(), YamlSRPoints.end(),
695 [](const yaml::SaveRestorePointEntry &Lhs,
696 const yaml::SaveRestorePointEntry &Rhs) {
697 return Lhs.Point.Value < Rhs.Point.Value;
698 });
699}
700
702 const MachineJumpTableInfo &JTI) {
703 YamlJTI.Kind = JTI.getEntryKind();
704 unsigned ID = 0;
705 for (const auto &Table : JTI.getJumpTables()) {
706 std::string Str;
708 Entry.ID = ID++;
709 for (const auto *MBB : Table.MBBs) {
710 raw_string_ostream StrOS(Str);
711 StrOS << printMBBReference(*MBB);
712 Entry.Blocks.push_back(Str);
713 Str.clear();
714 }
715 YamlJTI.Entries.push_back(std::move(Entry));
716 }
717}
718
721 bool &IsFallthrough) {
723
724 for (const MachineInstr &MI : MBB) {
725 if (MI.isPHI())
726 continue;
727 for (const MachineOperand &MO : MI.operands()) {
728 if (!MO.isMBB())
729 continue;
730 MachineBasicBlock *Succ = MO.getMBB();
731 auto RP = Seen.insert(Succ);
732 if (RP.second)
733 Result.push_back(Succ);
734 }
735 }
736 MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr();
737 IsFallthrough = I == MBB.end() || !I->isBarrier();
738}
739
742 bool GuessedFallthrough;
743 guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough);
744 if (GuessedFallthrough) {
745 const MachineFunction &MF = *MBB.getParent();
746 MachineFunction::const_iterator NextI = std::next(MBB.getIterator());
747 if (NextI != MF.end()) {
748 MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI);
749 if (!is_contained(GuessedSuccs, Next))
750 GuessedSuccs.push_back(Next);
751 }
752 }
753 if (GuessedSuccs.size() != MBB.succ_size())
754 return false;
755 return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin());
756}
757
758static void printMI(raw_ostream &OS, MFPrintState &State,
759 const MachineInstr &MI);
760
761static void printMIOperand(raw_ostream &OS, MFPrintState &State,
762 const MachineInstr &MI, unsigned OpIdx,
763 const TargetRegisterInfo *TRI,
764 const TargetInstrInfo *TII,
765 bool ShouldPrintRegisterTies,
766 SmallBitVector &PrintedTypes,
767 const MachineRegisterInfo &MRI, bool PrintDef);
768
769void printMBB(raw_ostream &OS, MFPrintState &State,
770 const MachineBasicBlock &MBB) {
771 assert(MBB.getNumber() >= 0 && "Invalid MBB number");
772 MBB.printName(OS,
775 &State.MST);
776 OS << ":\n";
777
778 bool HasLineAttributes = false;
779 // Print the successors
780 bool canPredictProbs = MBB.canPredictBranchProbabilities();
781 // Even if the list of successors is empty, if we cannot guess it,
782 // we need to print it to tell the parser that the list is empty.
783 // This is needed, because MI model unreachable as empty blocks
784 // with an empty successor list. If the parser would see that
785 // without the successor list, it would guess the code would
786 // fallthrough.
787 if ((!MBB.succ_empty() && !SimplifyMIR) || !canPredictProbs ||
789 OS.indent(2) << "successors:";
790 if (!MBB.succ_empty())
791 OS << " ";
792 ListSeparator LS;
793 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
794 OS << LS << printMBBReference(**I);
795 if (!SimplifyMIR || !canPredictProbs)
796 OS << format("(0x%08" PRIx32 ")",
797 MBB.getSuccProbability(I).getNumerator());
798 }
799 OS << "\n";
800 HasLineAttributes = true;
801 }
802
803 // Print the live in registers.
804 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
805 if (!MBB.livein_empty()) {
807 OS.indent(2) << "liveins: ";
808 ListSeparator LS;
809 for (const auto &LI : MBB.liveins_dbg()) {
810 OS << LS << printReg(LI.PhysReg, &TRI);
811 if (!LI.LaneMask.all())
812 OS << ":0x" << PrintLaneMask(LI.LaneMask);
813 }
814 OS << "\n";
815 HasLineAttributes = true;
816 }
817
818 if (HasLineAttributes && !MBB.empty())
819 OS << "\n";
820 bool IsInBundle = false;
821 for (const MachineInstr &MI : MBB.instrs()) {
822 if (IsInBundle && !MI.isInsideBundle()) {
823 OS.indent(2) << "}\n";
824 IsInBundle = false;
825 }
826 OS.indent(IsInBundle ? 4 : 2);
827 printMI(OS, State, MI);
828 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
829 OS << " {";
830 IsInBundle = true;
831 }
832 OS << "\n";
833 }
834 if (IsInBundle)
835 OS.indent(2) << "}\n";
836}
837
838static void printMI(raw_ostream &OS, MFPrintState &State,
839 const MachineInstr &MI) {
840 const auto *MF = MI.getMF();
841 const auto &MRI = MF->getRegInfo();
842 const auto &SubTarget = MF->getSubtarget();
843 const auto *TRI = SubTarget.getRegisterInfo();
844 assert(TRI && "Expected target register info");
845 const auto *TII = SubTarget.getInstrInfo();
846 assert(TII && "Expected target instruction info");
847 if (MI.isCFIInstruction())
848 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
849
850 SmallBitVector PrintedTypes(8);
851 bool ShouldPrintRegisterTies = MI.hasComplexRegisterTies();
852 ListSeparator LS;
853 unsigned I = 0, E = MI.getNumOperands();
854 for (; I < E; ++I) {
855 const MachineOperand MO = MI.getOperand(I);
856 if (!MO.isReg() || !MO.isDef() || MO.isImplicit())
857 break;
858 OS << LS;
859 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
860 PrintedTypes, MRI, /*PrintDef=*/false);
861 }
862
863 if (I)
864 OS << " = ";
865 if (MI.getFlag(MachineInstr::FrameSetup))
866 OS << "frame-setup ";
867 if (MI.getFlag(MachineInstr::FrameDestroy))
868 OS << "frame-destroy ";
869 if (MI.getFlag(MachineInstr::FmNoNans))
870 OS << "nnan ";
871 if (MI.getFlag(MachineInstr::FmNoInfs))
872 OS << "ninf ";
873 if (MI.getFlag(MachineInstr::FmNsz))
874 OS << "nsz ";
875 if (MI.getFlag(MachineInstr::FmArcp))
876 OS << "arcp ";
877 if (MI.getFlag(MachineInstr::FmContract))
878 OS << "contract ";
879 if (MI.getFlag(MachineInstr::FmAfn))
880 OS << "afn ";
881 if (MI.getFlag(MachineInstr::FmReassoc))
882 OS << "reassoc ";
883 if (MI.getFlag(MachineInstr::NoUWrap))
884 OS << "nuw ";
885 if (MI.getFlag(MachineInstr::NoSWrap))
886 OS << "nsw ";
887 if (MI.getFlag(MachineInstr::IsExact))
888 OS << "exact ";
889 if (MI.getFlag(MachineInstr::NoFPExcept))
890 OS << "nofpexcept ";
891 if (MI.getFlag(MachineInstr::NoMerge))
892 OS << "nomerge ";
893 if (MI.getFlag(MachineInstr::Unpredictable))
894 OS << "unpredictable ";
895 if (MI.getFlag(MachineInstr::NoConvergent))
896 OS << "noconvergent ";
897 if (MI.getFlag(MachineInstr::NonNeg))
898 OS << "nneg ";
899 if (MI.getFlag(MachineInstr::Disjoint))
900 OS << "disjoint ";
901 if (MI.getFlag(MachineInstr::NoUSWrap))
902 OS << "nusw ";
903 if (MI.getFlag(MachineInstr::SameSign))
904 OS << "samesign ";
905 if (MI.getFlag(MachineInstr::InBounds))
906 OS << "inbounds ";
907 if (MI.getFlag(MachineInstr::LRSplit))
908 OS << "lr-split ";
909 if (MI.getFlag(MachineInstr::NonNull))
910 OS << "nonnull ";
911
912 // NOTE: Please add new MIFlags also to the MI_FLAGS_STR in
913 // llvm/utils/UpdateTestChecks/mir.py.
914
915 OS << TII->getName(MI.getOpcode());
916
917 // Print a space after the opcode if any additional tokens are printed.
918 LS = ListSeparator(", ", " ");
919
920 for (; I < E; ++I) {
921 OS << LS;
922 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
923 PrintedTypes, MRI, /*PrintDef=*/true);
924 }
925
926 // Print any optional symbols attached to this instruction as-if they were
927 // operands.
928 if (MCSymbol *PreInstrSymbol = MI.getPreInstrSymbol()) {
929 OS << LS << "pre-instr-symbol ";
930 MachineOperand::printSymbol(OS, *PreInstrSymbol);
931 }
932 if (MCSymbol *PostInstrSymbol = MI.getPostInstrSymbol()) {
933 OS << LS << "post-instr-symbol ";
934 MachineOperand::printSymbol(OS, *PostInstrSymbol);
935 }
936 if (MDNode *HeapAllocMarker = MI.getHeapAllocMarker()) {
937 OS << LS << "heap-alloc-marker ";
938 HeapAllocMarker->printAsOperand(OS, State.MST);
939 }
940 if (MDNode *PCSections = MI.getPCSections()) {
941 OS << LS << "pcsections ";
942 PCSections->printAsOperand(OS, State.MST);
943 }
944 if (MDNode *MMRA = MI.getMMRAMetadata()) {
945 OS << LS << "mmra ";
946 MMRA->printAsOperand(OS, State.MST);
947 }
948 if (uint32_t CFIType = MI.getCFIType())
949 OS << LS << "cfi-type " << CFIType;
950 if (Value *DS = MI.getDeactivationSymbol()) {
951 OS << LS << "deactivation-symbol ";
952 MIRFormatter::printIRValue(OS, *DS, State.MST);
953 }
954
955 if (auto Num = MI.peekDebugInstrNum())
956 OS << LS << "debug-instr-number " << Num;
957
958 if (PrintLocations) {
959 if (const DebugLoc &DL = MI.getDebugLoc()) {
960 OS << LS << "debug-location ";
961 DL->printAsOperand(OS, State.MST);
962 }
963 }
964
965 if (!MI.memoperands_empty()) {
966 OS << " :: ";
967 const LLVMContext &Context = MF->getFunction().getContext();
968 const MachineFrameInfo &MFI = MF->getFrameInfo();
969 LS = ListSeparator();
970 for (const auto *Op : MI.memoperands()) {
971 OS << LS;
972 Op->print(OS, State.MST, State.SSNs, Context, &MFI, TII);
973 }
974 }
975}
976
977static std::string formatOperandComment(std::string Comment) {
978 if (Comment.empty())
979 return Comment;
980 return std::string(" /* " + Comment + " */");
981}
982
983static void printMIOperand(raw_ostream &OS, MFPrintState &State,
984 const MachineInstr &MI, unsigned OpIdx,
985 const TargetRegisterInfo *TRI,
986 const TargetInstrInfo *TII,
987 bool ShouldPrintRegisterTies,
988 SmallBitVector &PrintedTypes,
989 const MachineRegisterInfo &MRI, bool PrintDef) {
990 LLT TypeToPrint = MI.getTypeToPrint(OpIdx, PrintedTypes, MRI);
991 const MachineOperand &Op = MI.getOperand(OpIdx);
992 std::string MOComment = TII->createMIROperandComment(MI, Op, OpIdx, TRI);
993
994 switch (Op.getType()) {
996 if (MI.isOperandSubregIdx(OpIdx)) {
999 break;
1000 }
1001 if (MI.isInlineAsm()) {
1002 if (OpIdx == InlineAsm::MIOp_ExtraInfo) {
1003 unsigned ExtraInfo = Op.getImm();
1004 interleave(InlineAsm::getExtraInfoNames(ExtraInfo), OS, " ");
1005 break;
1006 }
1007
1008 int FlagIdx = MI.findInlineAsmFlagIdx(OpIdx);
1009 if (FlagIdx >= 0 && (unsigned)FlagIdx == OpIdx) {
1010 InlineAsm::Flag F(Op.getImm());
1011 OS << F.getKindName();
1012
1013 unsigned RCID;
1014 if ((F.isRegDefKind() || F.isRegUseKind() ||
1015 F.isRegDefEarlyClobberKind()) &&
1016 F.hasRegClassConstraint(RCID))
1017 OS << ':' << TRI->getRegClassName(TRI->getRegClass(RCID));
1018
1019 if (F.isMemKind()) {
1020 InlineAsm::ConstraintCode MCID = F.getMemoryConstraintID();
1022 }
1023
1024 unsigned TiedTo;
1025 if (F.isUseOperandTiedToDef(TiedTo))
1026 OS << " tiedto:$" << TiedTo;
1027 break;
1028 }
1029 }
1030 [[fallthrough]];
1050 unsigned TiedOperandIdx = 0;
1051 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
1052 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
1053 Op.print(OS, State.MST, TypeToPrint, OpIdx, PrintDef,
1054 /*IsStandalone=*/false, ShouldPrintRegisterTies, TiedOperandIdx,
1055 TRI);
1056 OS << formatOperandComment(MOComment);
1057 break;
1058 }
1060 printStackObjectReference(OS, State, Op.getIndex());
1061 break;
1063 const auto &RegisterMaskIds = State.RegisterMaskIds;
1064 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
1065 if (RegMaskInfo != RegisterMaskIds.end())
1066 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
1067 else
1068 printCustomRegMask(Op.getRegMask(), OS, TRI);
1069 break;
1070 }
1071 }
1072}
1073
1075 ModuleSlotTracker &MST) {
1076 if (isa<GlobalValue>(V)) {
1077 V.printAsOperand(OS, /*PrintType=*/false, MST);
1078 return;
1079 }
1080 if (isa<Constant>(V)) {
1081 // Machine memory operands can load/store to/from constant value pointers.
1082 OS << '`';
1083 V.printAsOperand(OS, /*PrintType=*/true, MST);
1084 OS << '`';
1085 return;
1086 }
1087 OS << "%ir.";
1088 if (V.hasName()) {
1089 printLLVMNameWithoutPrefix(OS, V.getName());
1090 return;
1091 }
1092 int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1;
1094}
1095
1096void llvm::printMIR(raw_ostream &OS, const Module &M) {
1097 yaml::Output Out(OS);
1098 Out << const_cast<Module &>(M);
1099}
1100
1102 const MachineFunction &MF, const VirtRegMap *VRM) {
1103 printMF(
1104 OS, [&](const Function &F) { return MMI.getMachineFunction(F); }, MF,
1105 VRM);
1106}
1107
1109 const MachineFunction &MF, const VirtRegMap *VRM) {
1110 printMF(
1111 OS,
1112 [&](const Function &F) {
1113 return &FAM.getResult<MachineFunctionAnalysis>(
1114 const_cast<Function &>(F))
1115 .getMF();
1116 },
1117 MF, VRM);
1118}
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
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:126
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:319
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:1081
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 alignment of this function's frame.
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.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
const Function * getCurrentFunction() const
SmallVector< std::pair< unsigned, const MDNode * >, 0 > MachineMDNodeListType
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:68
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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:2291
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:1652
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:102
@ 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
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:1933
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
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 > AntiHints
std::vector< FlowStringValue > RegisterFlags
static void output(const Module &Mod, void *Ctxt, raw_ostream &OS)
static StringRef input(StringRef Str, void *Ctxt, Module &Mod)