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 // Each entry with the number of its block and its offset, for sorting.
565 for (auto [MI, CallSiteInfo] : MF.getCallSitesInfo()) {
566 yaml::CallSiteInfo YmlCS;
567 yaml::MachineInstrLoc CallLocation;
568
569 // Prepare instruction position.
570 MachineBasicBlock::const_instr_iterator CallI = MI->getIterator();
571 const MachineBasicBlock &MBB = *CallI->getParent();
572 raw_string_ostream StrOS(CallLocation.Block.Value);
573 StrOS << printMBBReference(MBB);
574 // Get call instruction offset from the beginning of block.
575 CallLocation.Offset = std::distance(MBB.instr_begin(), CallI);
576 YmlCS.CallLocation = CallLocation;
577
578 auto [ArgRegPairs, CalleeTypeIds, _] = CallSiteInfo;
579 // Construct call arguments and theirs forwarding register info.
580 for (auto ArgReg : ArgRegPairs) {
582 YmlArgReg.ArgNo = ArgReg.ArgNo;
583 printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
584 YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
585 }
586 // Get type ids.
587 for (auto *CalleeTypeId : CalleeTypeIds) {
588 YmlCS.CalleeTypeIds.push_back(CalleeTypeId->getZExtValue());
589 }
590 Entries.push_back(
591 {{MBB.getNumber(), CallLocation.Offset}, std::move(YmlCS)});
592 }
593
594 // Sort call info by position of call instructions.
595 llvm::sort(Entries.begin(), Entries.end(), llvm::less_first());
596 for (auto &Entry : Entries)
597 YMF.CallSitesInfo.push_back(std::move(Entry.second));
598}
599
601 const MachineFunction &MF,
604 MST.collectMachineMDNodes(MDList);
605 for (auto &MD : MDList) {
606 std::string NS;
607 raw_string_ostream StrOS(NS);
608 MD.second->print(StrOS, MST, MF.getFunction().getParent());
609 YMF.MachineMetadataNodes.push_back(std::move(NS));
610 }
611}
612
614 const MachineFunction &MF,
616 // Each entry with the number of its block and its offset, for sorting.
618 for (const auto &[CallInst, CG] : MF.getCalledGlobals()) {
620 yaml::MachineInstrLoc CallSite;
621 raw_string_ostream StrOS(CallSite.Block.Value);
622 StrOS << printMBBReference(MBB);
623 CallSite.Offset = std::distance(MBB.instr_begin(), CallInst->getIterator());
624
625 yaml::CalledGlobal YamlCG{CallSite, CG.Callee->getName().str(),
626 CG.TargetFlags};
627 Entries.push_back({{MBB.getNumber(), CallSite.Offset}, std::move(YamlCG)});
628 }
629
630 // Sort by position of call instructions.
631 llvm::sort(Entries.begin(), Entries.end(), llvm::less_first());
632 for (auto &Entry : Entries)
633 YMF.CalledGlobals.push_back(std::move(Entry.second));
634}
635
637 const MachineFunction &MF) {
638 for (const auto &[BBID, CallsiteIndexes] : MF.getPrefetchTargets()) {
639 for (auto CallsiteIndex : CallsiteIndexes) {
640 std::string Str;
641 raw_string_ostream StrOS(Str);
642 StrOS << "bb_id " << BBID.BaseID << ", " << BBID.CloneID << ", "
643 << CallsiteIndex;
644 YMF.PrefetchTargets.push_back(yaml::FlowStringValue(Str));
645 }
646 }
647}
648
651 unsigned ID = 0;
652 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
653 std::string Str;
654 raw_string_ostream StrOS(Str);
655 if (Constant.isMachineConstantPoolEntry())
656 Constant.Val.MachineCPVal->print(StrOS);
657 else
658 Constant.Val.ConstVal->printAsOperand(StrOS);
659
661 YamlConstant.ID = ID++;
662 YamlConstant.Value = std::move(Str);
663 YamlConstant.Alignment = Constant.getAlign();
664 YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry();
665
666 MF.Constants.push_back(std::move(YamlConstant));
667 }
668}
669
670static void
672 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
673 const llvm::SaveRestorePoints &SRPoints,
674 const TargetRegisterInfo *TRI) {
675 for (const auto &[MBB, CSInfos] : SRPoints) {
676 SmallString<16> Str;
678 raw_svector_ostream StrOS(Str);
679 StrOS << printMBBReference(*MBB);
680 Entry.Point = StrOS.str().str();
681 Str.clear();
682 for (const CalleeSavedInfo &Info : CSInfos) {
683 if (Info.getReg()) {
684 StrOS << printReg(Info.getReg(), TRI);
685 Entry.Registers.push_back(StrOS.str().str());
686 Str.clear();
687 }
688 }
689 // Sort here needed for stable output for lit tests
690 std::sort(Entry.Registers.begin(), Entry.Registers.end(),
691 [](const yaml::StringValue &Lhs, const yaml::StringValue &Rhs) {
692 return Lhs.Value < Rhs.Value;
693 });
694 YamlSRPoints.push_back(std::move(Entry));
695 }
696 // Sort here needed for stable output for lit tests
697 std::sort(YamlSRPoints.begin(), YamlSRPoints.end(),
698 [](const yaml::SaveRestorePointEntry &Lhs,
699 const yaml::SaveRestorePointEntry &Rhs) {
700 return Lhs.Point.Value < Rhs.Point.Value;
701 });
702}
703
705 const MachineJumpTableInfo &JTI) {
706 YamlJTI.Kind = JTI.getEntryKind();
707 unsigned ID = 0;
708 for (const auto &Table : JTI.getJumpTables()) {
709 std::string Str;
711 Entry.ID = ID++;
712 for (const auto *MBB : Table.MBBs) {
713 raw_string_ostream StrOS(Str);
714 StrOS << printMBBReference(*MBB);
715 Entry.Blocks.push_back(Str);
716 Str.clear();
717 }
718 YamlJTI.Entries.push_back(std::move(Entry));
719 }
720}
721
724 bool &IsFallthrough) {
726
727 for (const MachineInstr &MI : MBB) {
728 if (MI.isPHI())
729 continue;
730 for (const MachineOperand &MO : MI.operands()) {
731 if (!MO.isMBB())
732 continue;
733 MachineBasicBlock *Succ = MO.getMBB();
734 auto RP = Seen.insert(Succ);
735 if (RP.second)
736 Result.push_back(Succ);
737 }
738 }
739 MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr();
740 IsFallthrough = I == MBB.end() || !I->isBarrier();
741}
742
745 bool GuessedFallthrough;
746 guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough);
747 if (GuessedFallthrough) {
748 const MachineFunction &MF = *MBB.getParent();
749 MachineFunction::const_iterator NextI = std::next(MBB.getIterator());
750 if (NextI != MF.end()) {
751 MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI);
752 if (!is_contained(GuessedSuccs, Next))
753 GuessedSuccs.push_back(Next);
754 }
755 }
756 if (GuessedSuccs.size() != MBB.succ_size())
757 return false;
758 return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin());
759}
760
761static void printMI(raw_ostream &OS, MFPrintState &State,
762 const MachineInstr &MI);
763
764static void printMIOperand(raw_ostream &OS, MFPrintState &State,
765 const MachineInstr &MI, unsigned OpIdx,
766 const TargetRegisterInfo *TRI,
767 const TargetInstrInfo *TII,
768 bool ShouldPrintRegisterTies,
769 SmallBitVector &PrintedTypes,
770 const MachineRegisterInfo &MRI, bool PrintDef);
771
772void printMBB(raw_ostream &OS, MFPrintState &State,
773 const MachineBasicBlock &MBB) {
774 assert(MBB.getNumber() >= 0 && "Invalid MBB number");
775 MBB.printName(OS,
778 &State.MST);
779 OS << ":\n";
780
781 bool HasLineAttributes = false;
782 // Print the successors
783 bool canPredictProbs = MBB.canPredictBranchProbabilities();
784 // Even if the list of successors is empty, if we cannot guess it,
785 // we need to print it to tell the parser that the list is empty.
786 // This is needed, because MI model unreachable as empty blocks
787 // with an empty successor list. If the parser would see that
788 // without the successor list, it would guess the code would
789 // fallthrough.
790 if ((!MBB.succ_empty() && !SimplifyMIR) || !canPredictProbs ||
792 OS.indent(2) << "successors:";
793 if (!MBB.succ_empty())
794 OS << " ";
795 ListSeparator LS;
796 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
797 OS << LS << printMBBReference(**I);
798 if (!SimplifyMIR || !canPredictProbs)
799 OS << format("(0x%08" PRIx32 ")",
800 MBB.getSuccProbability(I).getNumerator());
801 }
802 OS << "\n";
803 HasLineAttributes = true;
804 }
805
806 // Print the live in registers.
807 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
808 if (!MBB.livein_empty()) {
810 OS.indent(2) << "liveins: ";
811 ListSeparator LS;
812 for (const auto &LI : MBB.liveins_dbg()) {
813 OS << LS << printReg(LI.PhysReg, &TRI);
814 if (!LI.LaneMask.all())
815 OS << ":0x" << PrintLaneMask(LI.LaneMask);
816 }
817 OS << "\n";
818 HasLineAttributes = true;
819 }
820
821 if (HasLineAttributes && !MBB.empty())
822 OS << "\n";
823 bool IsInBundle = false;
824 for (const MachineInstr &MI : MBB.instrs()) {
825 if (IsInBundle && !MI.isInsideBundle()) {
826 OS.indent(2) << "}\n";
827 IsInBundle = false;
828 }
829 OS.indent(IsInBundle ? 4 : 2);
830 printMI(OS, State, MI);
831 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
832 OS << " {";
833 IsInBundle = true;
834 }
835 OS << "\n";
836 }
837 if (IsInBundle)
838 OS.indent(2) << "}\n";
839}
840
841static void printMI(raw_ostream &OS, MFPrintState &State,
842 const MachineInstr &MI) {
843 const auto *MF = MI.getMF();
844 const auto &MRI = MF->getRegInfo();
845 const auto &SubTarget = MF->getSubtarget();
846 const auto *TRI = SubTarget.getRegisterInfo();
847 assert(TRI && "Expected target register info");
848 const auto *TII = SubTarget.getInstrInfo();
849 assert(TII && "Expected target instruction info");
850 if (MI.isCFIInstruction())
851 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
852
853 SmallBitVector PrintedTypes(8);
854 bool ShouldPrintRegisterTies = MI.hasComplexRegisterTies();
855 ListSeparator LS;
856 unsigned I = 0, E = MI.getNumOperands();
857 for (; I < E; ++I) {
858 const MachineOperand MO = MI.getOperand(I);
859 if (!MO.isReg() || !MO.isDef() || MO.isImplicit())
860 break;
861 OS << LS;
862 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
863 PrintedTypes, MRI, /*PrintDef=*/false);
864 }
865
866 if (I)
867 OS << " = ";
868 if (MI.getFlag(MachineInstr::FrameSetup))
869 OS << "frame-setup ";
870 if (MI.getFlag(MachineInstr::FrameDestroy))
871 OS << "frame-destroy ";
872 if (MI.getFlag(MachineInstr::FmNoNans))
873 OS << "nnan ";
874 if (MI.getFlag(MachineInstr::FmNoInfs))
875 OS << "ninf ";
876 if (MI.getFlag(MachineInstr::FmNsz))
877 OS << "nsz ";
878 if (MI.getFlag(MachineInstr::FmArcp))
879 OS << "arcp ";
880 if (MI.getFlag(MachineInstr::FmContract))
881 OS << "contract ";
882 if (MI.getFlag(MachineInstr::FmAfn))
883 OS << "afn ";
884 if (MI.getFlag(MachineInstr::FmReassoc))
885 OS << "reassoc ";
886 if (MI.getFlag(MachineInstr::NoUWrap))
887 OS << "nuw ";
888 if (MI.getFlag(MachineInstr::NoSWrap))
889 OS << "nsw ";
890 if (MI.getFlag(MachineInstr::IsExact))
891 OS << "exact ";
892 if (MI.getFlag(MachineInstr::NoFPExcept))
893 OS << "nofpexcept ";
894 if (MI.getFlag(MachineInstr::NoMerge))
895 OS << "nomerge ";
896 if (MI.getFlag(MachineInstr::Unpredictable))
897 OS << "unpredictable ";
898 if (MI.getFlag(MachineInstr::NoConvergent))
899 OS << "noconvergent ";
900 if (MI.getFlag(MachineInstr::NonNeg))
901 OS << "nneg ";
902 if (MI.getFlag(MachineInstr::Disjoint))
903 OS << "disjoint ";
904 if (MI.getFlag(MachineInstr::NoUSWrap))
905 OS << "nusw ";
906 if (MI.getFlag(MachineInstr::SameSign))
907 OS << "samesign ";
908 if (MI.getFlag(MachineInstr::InBounds))
909 OS << "inbounds ";
910 if (MI.getFlag(MachineInstr::LRSplit))
911 OS << "lr-split ";
912 if (MI.getFlag(MachineInstr::NonNull))
913 OS << "nonnull ";
914
915 // NOTE: Please add new MIFlags also to the MI_FLAGS_STR in
916 // llvm/utils/UpdateTestChecks/mir.py.
917
918 OS << TII->getName(MI.getOpcode());
919
920 // Print a space after the opcode if any additional tokens are printed.
921 LS = ListSeparator(", ", " ");
922
923 for (; I < E; ++I) {
924 OS << LS;
925 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
926 PrintedTypes, MRI, /*PrintDef=*/true);
927 }
928
929 // Print any optional symbols attached to this instruction as-if they were
930 // operands.
931 if (MCSymbol *PreInstrSymbol = MI.getPreInstrSymbol()) {
932 OS << LS << "pre-instr-symbol ";
933 MachineOperand::printSymbol(OS, *PreInstrSymbol);
934 }
935 if (MCSymbol *PostInstrSymbol = MI.getPostInstrSymbol()) {
936 OS << LS << "post-instr-symbol ";
937 MachineOperand::printSymbol(OS, *PostInstrSymbol);
938 }
939 if (MDNode *HeapAllocMarker = MI.getHeapAllocMarker()) {
940 OS << LS << "heap-alloc-marker ";
941 HeapAllocMarker->printAsOperand(OS, State.MST);
942 }
943 if (MDNode *PCSections = MI.getPCSections()) {
944 OS << LS << "pcsections ";
945 PCSections->printAsOperand(OS, State.MST);
946 }
947 if (MDNode *MMRA = MI.getMMRAMetadata()) {
948 OS << LS << "mmra ";
949 MMRA->printAsOperand(OS, State.MST);
950 }
951 if (uint32_t CFIType = MI.getCFIType())
952 OS << LS << "cfi-type " << CFIType;
953 if (Value *DS = MI.getDeactivationSymbol()) {
954 OS << LS << "deactivation-symbol ";
955 MIRFormatter::printIRValue(OS, *DS, State.MST);
956 }
957
958 if (auto Num = MI.peekDebugInstrNum())
959 OS << LS << "debug-instr-number " << Num;
960
961 if (PrintLocations) {
962 if (const DebugLoc &DL = MI.getDebugLoc()) {
963 OS << LS << "debug-location ";
964 DL->printAsOperand(OS, State.MST);
965 }
966 }
967
968 if (!MI.memoperands_empty()) {
969 OS << " :: ";
970 const LLVMContext &Context = MF->getFunction().getContext();
971 const MachineFrameInfo &MFI = MF->getFrameInfo();
972 LS = ListSeparator();
973 for (const auto *Op : MI.memoperands()) {
974 OS << LS;
975 Op->print(OS, State.MST, State.SSNs, Context, &MFI, TII);
976 }
977 }
978}
979
980static std::string formatOperandComment(std::string Comment) {
981 if (Comment.empty())
982 return Comment;
983 return std::string(" /* " + Comment + " */");
984}
985
986static void printMIOperand(raw_ostream &OS, MFPrintState &State,
987 const MachineInstr &MI, unsigned OpIdx,
988 const TargetRegisterInfo *TRI,
989 const TargetInstrInfo *TII,
990 bool ShouldPrintRegisterTies,
991 SmallBitVector &PrintedTypes,
992 const MachineRegisterInfo &MRI, bool PrintDef) {
993 LLT TypeToPrint = MI.getTypeToPrint(OpIdx, PrintedTypes, MRI);
994 const MachineOperand &Op = MI.getOperand(OpIdx);
995 std::string MOComment = TII->createMIROperandComment(MI, Op, OpIdx);
996
997 switch (Op.getType()) {
999 if (MI.isOperandSubregIdx(OpIdx)) {
1001 MachineOperand::printSubRegIdx(OS, Op.getImm(), TRI);
1002 break;
1003 }
1004 if (MI.isInlineAsm()) {
1005 if (OpIdx == InlineAsm::MIOp_ExtraInfo) {
1006 unsigned ExtraInfo = Op.getImm();
1007 interleave(InlineAsm::getExtraInfoNames(ExtraInfo), OS, " ");
1008 break;
1009 }
1010
1011 int FlagIdx = MI.findInlineAsmFlagIdx(OpIdx);
1012 if (FlagIdx >= 0 && (unsigned)FlagIdx == OpIdx) {
1013 InlineAsm::Flag F(Op.getImm());
1014 OS << F.getKindName();
1015
1016 bool IsReg = F.isRegDefKind() || F.isRegUseKind() ||
1017 F.isRegDefEarlyClobberKind();
1018 unsigned RCID;
1019 if (IsReg && F.hasRegClassConstraint(RCID))
1020 OS << ':' << TRI->getRegClassName(TRI->getRegClass(RCID));
1021
1022 if (F.isMemKind()) {
1023 InlineAsm::ConstraintCode MCID = F.getMemoryConstraintID();
1025 }
1026
1027 unsigned TiedTo;
1028 if (F.isUseOperandTiedToDef(TiedTo))
1029 OS << " tiedto:$" << TiedTo;
1030 if (IsReg && F.getRegMayBeFolded())
1031 OS << " foldable";
1032
1033 break;
1034 }
1035 }
1036 [[fallthrough]];
1056 unsigned TiedOperandIdx = 0;
1057 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
1058 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
1059 Op.print(OS, State.MST, TypeToPrint, OpIdx, PrintDef,
1060 /*IsStandalone=*/false, ShouldPrintRegisterTies, TiedOperandIdx,
1061 TRI);
1062 OS << formatOperandComment(MOComment);
1063 break;
1064 }
1066 printStackObjectReference(OS, State, Op.getIndex());
1067 break;
1069 const auto &RegisterMaskIds = State.RegisterMaskIds;
1070 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
1071 if (RegMaskInfo != RegisterMaskIds.end())
1072 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
1073 else
1074 printCustomRegMask(Op.getRegMask(), OS, TRI);
1075 break;
1076 }
1077 }
1078}
1079
1081 ModuleSlotTracker &MST) {
1082 if (isa<GlobalValue>(V)) {
1083 V.printAsOperand(OS, /*PrintType=*/false, MST);
1084 return;
1085 }
1086 if (isa<Constant>(V)) {
1087 // Machine memory operands can load/store to/from constant value pointers.
1088 OS << '`';
1089 V.printAsOperand(OS, /*PrintType=*/true, MST);
1090 OS << '`';
1091 return;
1092 }
1093 OS << "%ir.";
1094 if (V.hasName()) {
1095 printLLVMNameWithoutPrefix(OS, V.getName());
1096 return;
1097 }
1098 int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1;
1100}
1101
1102void llvm::printMIR(raw_ostream &OS, const Module &M) {
1103 yaml::Output Out(OS);
1104 Out << const_cast<Module &>(M);
1105}
1106
1108 const MachineFunction &MF, const VirtRegMap *VRM) {
1109 printMF(
1110 OS, [&](const Function &F) { return MMI.getMachineFunction(F); }, MF,
1111 VRM);
1112}
1113
1115 const MachineFunction &MF, const VirtRegMap *VRM) {
1116 printMF(
1117 OS,
1118 [&](const Function &F) {
1119 return &FAM.getResult<MachineFunctionAnalysis>(
1120 const_cast<Function &>(F))
1121 .getMF();
1122 },
1123 MF, VRM);
1124}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-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:827
Module * getParent()
Get the module that this global value is contained inside of...
static std::vector< StringRef > getExtraInfoNames(unsigned ExtraInfo)
Definition InlineAsm.h:458
static StringRef getMemConstraintName(ConstraintCode C)
Definition InlineAsm.h:482
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
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:82
Function object to check whether the first component of a container supported by std::get (like std::...
Definition STLExtras.h:1455
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)