LLVM 23.0.0git
MIRPrinter.cpp
Go to the documentation of this file.
1//===- MIRPrinter.cpp - MIR serialization format printer ------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the class that prints out the LLVM IR and machine
10// functions using the MIR serialization format.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/StringRef.h"
42#include "llvm/IR/DebugLoc.h"
43#include "llvm/IR/Function.h"
46#include "llvm/IR/Module.h"
48#include "llvm/IR/Value.h"
49#include "llvm/MC/LaneBitmask.h"
54#include "llvm/Support/Format.h"
58#include <algorithm>
59#include <cassert>
60#include <cinttypes>
61#include <cstdint>
62#include <iterator>
63#include <string>
64#include <utility>
65#include <vector>
66
67using namespace llvm;
68
70 "simplify-mir", cl::Hidden,
71 cl::desc("Leave out unnecessary information when printing MIR"));
72
73static cl::opt<bool> PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true),
74 cl::desc("Print MIR debug-locations"));
75
76namespace {
77
78/// This structure describes how to print out stack object references.
79struct FrameIndexOperand {
80 std::string Name;
81 unsigned ID;
82 bool IsFixed;
83
84 FrameIndexOperand(StringRef Name, unsigned ID, bool IsFixed)
85 : Name(Name.str()), ID(ID), IsFixed(IsFixed) {}
86
87 /// Return an ordinary stack object reference.
88 static FrameIndexOperand create(StringRef Name, unsigned ID) {
89 return FrameIndexOperand(Name, ID, /*IsFixed=*/false);
90 }
91
92 /// Return a fixed stack object reference.
93 static FrameIndexOperand createFixed(unsigned ID) {
94 return FrameIndexOperand("", ID, /*IsFixed=*/true);
95 }
96};
97
98struct MFPrintState {
99 MachineModuleSlotTracker MST;
100 DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
101 /// Maps from stack object indices to operand indices which will be used when
102 /// printing frame index machine operands.
103 DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;
104 /// Synchronization scope names registered with LLVMContext.
106
107 MFPrintState(MFGetterFnT Fn, const MachineFunction &MF)
108 : MST(std::move(Fn), &MF) {}
109};
110
111} // end anonymous namespace
112
113/// This struct serializes the LLVM IR module.
114template <> struct yaml::BlockScalarTraits<Module> {
115 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
116 Mod.print(OS, nullptr);
117 }
118
119 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
120 llvm_unreachable("LLVM Module is supposed to be parsed separately");
121 return "";
122 }
123};
124
126 const TargetRegisterInfo *TRI) {
127 raw_string_ostream OS(Dest.Value);
128 OS << printReg(Reg, TRI);
129}
130
134 const auto *TRI = MF.getSubtarget().getRegisterInfo();
135 unsigned I = 0;
136 for (const uint32_t *Mask : TRI->getRegMasks())
137 RegisterMaskIds.insert(std::make_pair(Mask, I++));
138 return RegisterMaskIds;
139}
140
141static void printMBB(raw_ostream &OS, MFPrintState &State,
142 const MachineBasicBlock &MBB);
143static void convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF,
145 const TargetRegisterInfo *TRI);
146static void convertMCP(yaml::MachineFunction &MF,
148static void convertMJTI(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
149 const MachineJumpTableInfo &JTI);
150static void convertMFI(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
151 const MachineFrameInfo &MFI,
152 const TargetRegisterInfo *TRI);
153static void
155 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
156 const llvm::SaveRestorePoints &SRPoints,
157 const TargetRegisterInfo *TRI);
159 const MachineFunction &MF,
160 ModuleSlotTracker &MST, MFPrintState &State);
162 const MachineFunction &MF,
163 ModuleSlotTracker &MST);
165 const MachineFunction &MF,
166 ModuleSlotTracker &MST);
168 const MachineFunction &MF,
171 const MachineFunction &MF,
174 const MachineFunction &MF);
175
176static void printMF(raw_ostream &OS, MFGetterFnT Fn,
177 const MachineFunction &MF) {
178 MFPrintState State(std::move(Fn), MF);
179
180 State.RegisterMaskIds = initRegisterMaskIds(MF);
181
183 YamlMF.Name = MF.getName();
184 YamlMF.Alignment = MF.getAlignment();
186 YamlMF.HasWinCFI = MF.hasWinCFI();
187
188 YamlMF.CallsEHReturn = MF.callsEHReturn();
189 YamlMF.CallsUnwindInit = MF.callsUnwindInit();
190 YamlMF.HasEHContTarget = MF.hasEHContTarget();
191 YamlMF.HasEHScopes = MF.hasEHScopes();
192 YamlMF.HasEHFunclets = MF.hasEHFunclets();
193 YamlMF.HasFakeUses = MF.hasFakeUses();
194 YamlMF.IsOutlined = MF.isOutlined();
196
197 const MachineFunctionProperties &Props = MF.getProperties();
198 YamlMF.Legalized = Props.hasLegalized();
199 YamlMF.RegBankSelected = Props.hasRegBankSelected();
200 YamlMF.Selected = Props.hasSelected();
201 YamlMF.FailedISel = Props.hasFailedISel();
202 YamlMF.FailsVerification = Props.hasFailsVerification();
203 YamlMF.TracksDebugUserValues = Props.hasTracksDebugUserValues();
204 YamlMF.NoPHIs = Props.hasNoPHIs();
205 YamlMF.IsSSA = Props.hasIsSSA();
206 YamlMF.NoVRegs = Props.hasNoVRegs();
207
208 convertMRI(YamlMF, MF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
209 MachineModuleSlotTracker &MST = State.MST;
211 convertMFI(MST, YamlMF.FrameInfo, MF.getFrameInfo(),
213 convertStackObjects(YamlMF, MF, MST, State);
214 convertEntryValueObjects(YamlMF, MF, MST);
215 convertCallSiteObjects(YamlMF, MF, MST);
216 for (const auto &Sub : MF.DebugValueSubstitutions) {
217 const auto &SubSrc = Sub.Src;
218 const auto &SubDest = Sub.Dest;
219 YamlMF.DebugValueSubstitutions.push_back({SubSrc.first, SubSrc.second,
220 SubDest.first,
221 SubDest.second,
222 Sub.Subreg});
223 }
224 if (const auto *ConstantPool = MF.getConstantPool())
225 convertMCP(YamlMF, *ConstantPool);
226 if (const auto *JumpTableInfo = MF.getJumpTableInfo())
227 convertMJTI(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
228
229 const TargetMachine &TM = MF.getTarget();
230 YamlMF.MachineFuncInfo =
231 std::unique_ptr<yaml::MachineFunctionInfo>(TM.convertFuncInfoToYAML(MF));
232
233 raw_string_ostream StrOS(YamlMF.Body.Value.Value);
234 bool IsNewlineNeeded = false;
235 for (const auto &MBB : MF) {
236 if (IsNewlineNeeded)
237 StrOS << "\n";
238 printMBB(StrOS, State, MBB);
239 IsNewlineNeeded = true;
240 }
241 // Convert machine metadata collected during the print of the machine
242 // function.
243 convertMachineMetadataNodes(YamlMF, MF, MST);
244
245 convertCalledGlobals(YamlMF, MF, MST);
246
247 convertPrefetchTargets(YamlMF, MF);
248
249 yaml::Output Out(OS);
250 if (!SimplifyMIR)
251 Out.setWriteDefaultValues(true);
252 Out << YamlMF;
253}
254
255static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS,
256 const TargetRegisterInfo *TRI) {
257 assert(RegMask && "Can't print an empty register mask");
258 OS << StringRef("CustomRegMask(");
259
260 bool IsRegInRegMaskFound = false;
261 for (int I = 0, E = TRI->getNumRegs(); I < E; I++) {
262 // Check whether the register is asserted in regmask.
263 if (RegMask[I / 32] & (1u << (I % 32))) {
264 if (IsRegInRegMaskFound)
265 OS << ',';
266 OS << printReg(I, TRI);
267 IsRegInRegMaskFound = true;
268 }
269 }
270
271 OS << ')';
272}
273
280
281template <typename T>
282static void
284 T &Object, ModuleSlotTracker &MST) {
285 std::array<std::string *, 3> Outputs{{&Object.DebugVar.Value,
286 &Object.DebugExpr.Value,
287 &Object.DebugLoc.Value}};
288 std::array<const Metadata *, 3> Metas{{DebugVar.Var,
289 DebugVar.Expr,
290 DebugVar.Loc}};
291 for (unsigned i = 0; i < 3; ++i) {
292 raw_string_ostream StrOS(*Outputs[i]);
293 Metas[i]->printAsOperand(StrOS, MST);
294 }
295}
296
298 std::vector<yaml::FlowStringValue> &RegisterFlags,
299 const MachineFunction &MF,
300 const TargetRegisterInfo *TRI) {
301 auto FlagValues = TRI->getVRegFlagsOfReg(Reg, MF);
302 for (auto &Flag : FlagValues)
303 RegisterFlags.push_back(yaml::FlowStringValue(Flag.str()));
304}
305
306static void convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF,
308 const TargetRegisterInfo *TRI) {
309 YamlMF.TracksRegLiveness = RegInfo.tracksLiveness();
310
311 // Print the virtual register definitions.
312 for (unsigned I = 0, E = RegInfo.getNumVirtRegs(); I < E; ++I) {
315 VReg.ID = I;
316 if (RegInfo.getVRegName(Reg) != "")
317 continue;
319 Register PreferredReg = RegInfo.getSimpleHint(Reg);
320 if (PreferredReg)
321 printRegMIR(PreferredReg, VReg.PreferredRegister, TRI);
323 YamlMF.VirtualRegisters.push_back(std::move(VReg));
324 }
325
326 // Print the live ins.
327 for (std::pair<MCRegister, Register> LI : RegInfo.liveins()) {
329 printRegMIR(LI.first, LiveIn.Register, TRI);
330 if (LI.second)
331 printRegMIR(LI.second, LiveIn.VirtualRegister, TRI);
332 YamlMF.LiveIns.push_back(std::move(LiveIn));
333 }
334
335 // Prints the callee saved registers.
336 if (RegInfo.isUpdatedCSRsInitialized()) {
337 const MCPhysReg *CalleeSavedRegs = RegInfo.getCalleeSavedRegs();
338 std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
339 for (const MCPhysReg *I = CalleeSavedRegs; *I; ++I) {
341 printRegMIR(*I, Reg, TRI);
342 CalleeSavedRegisters.push_back(std::move(Reg));
343 }
344 YamlMF.CalleeSavedRegisters = std::move(CalleeSavedRegisters);
345 }
346}
347
349 const MachineFrameInfo &MFI,
350 const TargetRegisterInfo *TRI) {
353 YamlMFI.HasStackMap = MFI.hasStackMap();
354 YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
355 YamlMFI.StackSize = MFI.getStackSize();
357 YamlMFI.MaxAlignment = MFI.getMaxAlign().value();
358 YamlMFI.AdjustsStack = MFI.adjustsStack();
359 YamlMFI.HasCalls = MFI.hasCalls();
361 ? MFI.getMaxCallFrameSize() : ~0u;
365 YamlMFI.HasVAStart = MFI.hasVAStart();
367 YamlMFI.HasTailCall = MFI.hasTailCall();
369 YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
370 if (!MFI.getSavePoints().empty())
371 convertSRPoints(MST, YamlMFI.SavePoints, MFI.getSavePoints(), TRI);
372 if (!MFI.getRestorePoints().empty())
374}
375
377 const MachineFunction &MF,
378 ModuleSlotTracker &MST) {
380 for (const MachineFunction::VariableDbgInfo &DebugVar :
382 yaml::EntryValueObject &Obj = YMF.EntryValueObjects.emplace_back();
383 printStackObjectDbgInfo(DebugVar, Obj, MST);
384 MCRegister EntryValReg = DebugVar.getEntryValueRegister();
385 printRegMIR(EntryValReg, Obj.EntryValueRegister, TRI);
386 }
387}
388
390 const MFPrintState &State,
391 int FrameIndex) {
392 auto ObjectInfo = State.StackObjectOperandMapping.find(FrameIndex);
393 assert(ObjectInfo != State.StackObjectOperandMapping.end() &&
394 "Invalid frame index");
395 const FrameIndexOperand &Operand = ObjectInfo->second;
396 MachineOperand::printStackObjectReference(OS, Operand.ID, Operand.IsFixed,
397 Operand.Name);
398}
399
401 const MachineFunction &MF,
402 ModuleSlotTracker &MST, MFPrintState &State) {
403 const MachineFrameInfo &MFI = MF.getFrameInfo();
405
406 // Process fixed stack objects.
407 assert(YMF.FixedStackObjects.empty());
408 SmallVector<int, 32> FixedStackObjectsIdx;
409 const int BeginIdx = MFI.getObjectIndexBegin();
410 if (BeginIdx < 0)
411 FixedStackObjectsIdx.reserve(-BeginIdx);
412
413 unsigned ID = 0;
414 for (int I = BeginIdx; I < 0; ++I, ++ID) {
415 FixedStackObjectsIdx.push_back(-1); // Fill index for possible dead.
416 if (MFI.isDeadObjectIndex(I))
417 continue;
418
420 YamlObject.ID = ID;
421 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
424 YamlObject.Offset = MFI.getObjectOffset(I);
425 YamlObject.Size = MFI.getObjectSize(I);
426 YamlObject.Alignment = MFI.getObjectAlign(I);
427 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
428 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
429 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
430 // Save the ID' position in FixedStackObjects storage vector.
431 FixedStackObjectsIdx[ID] = YMF.FixedStackObjects.size();
432 YMF.FixedStackObjects.push_back(std::move(YamlObject));
433 State.StackObjectOperandMapping.insert(
434 std::make_pair(I, FrameIndexOperand::createFixed(ID)));
435 }
436
437 // Process ordinary stack objects.
438 assert(YMF.StackObjects.empty());
439 SmallVector<unsigned, 32> StackObjectsIdx;
440 const int EndIdx = MFI.getObjectIndexEnd();
441 if (EndIdx > 0)
442 StackObjectsIdx.reserve(EndIdx);
443 ID = 0;
444 for (int I = 0; I < EndIdx; ++I, ++ID) {
445 StackObjectsIdx.push_back(-1); // Fill index for possible dead.
446 if (MFI.isDeadObjectIndex(I))
447 continue;
448
449 yaml::MachineStackObject YamlObject;
450 YamlObject.ID = ID;
451 if (const auto *Alloca = MFI.getObjectAllocation(I))
452 YamlObject.Name.Value = std::string(
453 Alloca->hasName() ? Alloca->getName() : "");
454 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
459 YamlObject.Offset = MFI.getObjectOffset(I);
460 YamlObject.Size = MFI.getObjectSize(I);
461 YamlObject.Alignment = MFI.getObjectAlign(I);
462 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
463
464 // Save the ID' position in StackObjects storage vector.
465 StackObjectsIdx[ID] = YMF.StackObjects.size();
466 YMF.StackObjects.push_back(YamlObject);
467 State.StackObjectOperandMapping.insert(std::make_pair(
468 I, FrameIndexOperand::create(YamlObject.Name.Value, ID)));
469 }
470
471 for (const auto &CSInfo : MFI.getCalleeSavedInfo()) {
472 const int FrameIdx = CSInfo.getFrameIdx();
473 if (!CSInfo.isSpilledToReg() && MFI.isDeadObjectIndex(FrameIdx))
474 continue;
475
477 printRegMIR(CSInfo.getReg(), Reg, TRI);
478 if (!CSInfo.isSpilledToReg()) {
479 assert(FrameIdx >= MFI.getObjectIndexBegin() &&
480 FrameIdx < MFI.getObjectIndexEnd() &&
481 "Invalid stack object index");
482 if (FrameIdx < 0) { // Negative index means fixed objects.
483 auto &Object =
485 [FixedStackObjectsIdx[FrameIdx + MFI.getNumFixedObjects()]];
486 Object.CalleeSavedRegister = std::move(Reg);
487 Object.CalleeSavedRestored = CSInfo.isRestored();
488 } else {
489 auto &Object = YMF.StackObjects[StackObjectsIdx[FrameIdx]];
490 Object.CalleeSavedRegister = std::move(Reg);
491 Object.CalleeSavedRestored = CSInfo.isRestored();
492 }
493 }
494 }
495 for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) {
496 auto LocalObject = MFI.getLocalFrameObjectMap(I);
497 assert(LocalObject.first >= 0 && "Expected a locally mapped stack object");
498 YMF.StackObjects[StackObjectsIdx[LocalObject.first]].LocalOffset =
499 LocalObject.second;
500 }
501
502 // Print the stack object references in the frame information class after
503 // converting the stack objects.
504 if (MFI.hasStackProtectorIndex()) {
507 }
508
509 if (MFI.hasFunctionContextIndex()) {
512 }
513
514 // Print the debug variable information.
515 for (const MachineFunction::VariableDbgInfo &DebugVar :
517 int Idx = DebugVar.getStackSlot();
518 assert(Idx >= MFI.getObjectIndexBegin() && Idx < MFI.getObjectIndexEnd() &&
519 "Invalid stack object index");
520 if (Idx < 0) { // Negative index means fixed objects.
521 auto &Object =
522 YMF.FixedStackObjects[FixedStackObjectsIdx[Idx +
523 MFI.getNumFixedObjects()]];
524 printStackObjectDbgInfo(DebugVar, Object, MST);
525 } else {
526 auto &Object = YMF.StackObjects[StackObjectsIdx[Idx]];
527 printStackObjectDbgInfo(DebugVar, Object, MST);
528 }
529 }
530}
531
533 const MachineFunction &MF,
534 ModuleSlotTracker &MST) {
535 const auto *TRI = MF.getSubtarget().getRegisterInfo();
536 for (auto [MI, CallSiteInfo] : MF.getCallSitesInfo()) {
537 yaml::CallSiteInfo YmlCS;
538 yaml::MachineInstrLoc CallLocation;
539
540 // Prepare instruction position.
541 MachineBasicBlock::const_instr_iterator CallI = MI->getIterator();
542 CallLocation.BlockNum = CallI->getParent()->getNumber();
543 // Get call instruction offset from the beginning of block.
544 CallLocation.Offset =
545 std::distance(CallI->getParent()->instr_begin(), CallI);
546 YmlCS.CallLocation = CallLocation;
547
548 auto [ArgRegPairs, CalleeTypeIds, _] = CallSiteInfo;
549 // Construct call arguments and theirs forwarding register info.
550 for (auto ArgReg : ArgRegPairs) {
552 YmlArgReg.ArgNo = ArgReg.ArgNo;
553 printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
554 YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
555 }
556 // Get type ids.
557 for (auto *CalleeTypeId : CalleeTypeIds) {
558 YmlCS.CalleeTypeIds.push_back(CalleeTypeId->getZExtValue());
559 }
560 YMF.CallSitesInfo.push_back(std::move(YmlCS));
561 }
562
563 // Sort call info by position of call instructions.
564 llvm::sort(YMF.CallSitesInfo.begin(), YMF.CallSitesInfo.end(),
566 return std::tie(A.CallLocation.BlockNum, A.CallLocation.Offset) <
567 std::tie(B.CallLocation.BlockNum, B.CallLocation.Offset);
568 });
569}
570
572 const MachineFunction &MF,
575 MST.collectMachineMDNodes(MDList);
576 for (auto &MD : MDList) {
577 std::string NS;
578 raw_string_ostream StrOS(NS);
579 MD.second->print(StrOS, MST, MF.getFunction().getParent());
580 YMF.MachineMetadataNodes.push_back(std::move(NS));
581 }
582}
583
585 const MachineFunction &MF,
587 for (const auto &[CallInst, CG] : MF.getCalledGlobals()) {
588 yaml::MachineInstrLoc CallSite;
589 CallSite.BlockNum = CallInst->getParent()->getNumber();
590 CallSite.Offset = std::distance(CallInst->getParent()->instr_begin(),
592
593 yaml::CalledGlobal YamlCG{CallSite, CG.Callee->getName().str(),
594 CG.TargetFlags};
595 YMF.CalledGlobals.push_back(std::move(YamlCG));
596 }
597
598 // Sort by position of call instructions.
599 llvm::sort(YMF.CalledGlobals.begin(), YMF.CalledGlobals.end(),
601 return std::tie(A.CallSite.BlockNum, A.CallSite.Offset) <
602 std::tie(B.CallSite.BlockNum, B.CallSite.Offset);
603 });
604}
605
607 const MachineFunction &MF) {
608 for (const auto &[BBID, CallsiteIndexes] : MF.getPrefetchTargets()) {
609 for (auto CallsiteIndex : CallsiteIndexes) {
610 std::string Str;
611 raw_string_ostream StrOS(Str);
612 StrOS << "bb_id " << BBID.BaseID << ", " << BBID.CloneID << ", "
613 << CallsiteIndex;
614 YMF.PrefetchTargets.push_back(yaml::FlowStringValue(Str));
615 }
616 }
617}
618
621 unsigned ID = 0;
622 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
623 std::string Str;
624 raw_string_ostream StrOS(Str);
625 if (Constant.isMachineConstantPoolEntry())
626 Constant.Val.MachineCPVal->print(StrOS);
627 else
628 Constant.Val.ConstVal->printAsOperand(StrOS);
629
631 YamlConstant.ID = ID++;
632 YamlConstant.Value = std::move(Str);
633 YamlConstant.Alignment = Constant.getAlign();
634 YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry();
635
636 MF.Constants.push_back(std::move(YamlConstant));
637 }
638}
639
640static void
642 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
643 const llvm::SaveRestorePoints &SRPoints,
644 const TargetRegisterInfo *TRI) {
645 for (const auto &[MBB, CSInfos] : SRPoints) {
646 SmallString<16> Str;
648 raw_svector_ostream StrOS(Str);
649 StrOS << printMBBReference(*MBB);
650 Entry.Point = StrOS.str().str();
651 Str.clear();
652 for (const CalleeSavedInfo &Info : CSInfos) {
653 if (Info.getReg()) {
654 StrOS << printReg(Info.getReg(), TRI);
655 Entry.Registers.push_back(StrOS.str().str());
656 Str.clear();
657 }
658 }
659 // Sort here needed for stable output for lit tests
660 std::sort(Entry.Registers.begin(), Entry.Registers.end(),
661 [](const yaml::StringValue &Lhs, const yaml::StringValue &Rhs) {
662 return Lhs.Value < Rhs.Value;
663 });
664 YamlSRPoints.push_back(std::move(Entry));
665 }
666 // Sort here needed for stable output for lit tests
667 std::sort(YamlSRPoints.begin(), YamlSRPoints.end(),
668 [](const yaml::SaveRestorePointEntry &Lhs,
669 const yaml::SaveRestorePointEntry &Rhs) {
670 return Lhs.Point.Value < Rhs.Point.Value;
671 });
672}
673
675 const MachineJumpTableInfo &JTI) {
676 YamlJTI.Kind = JTI.getEntryKind();
677 unsigned ID = 0;
678 for (const auto &Table : JTI.getJumpTables()) {
679 std::string Str;
681 Entry.ID = ID++;
682 for (const auto *MBB : Table.MBBs) {
683 raw_string_ostream StrOS(Str);
684 StrOS << printMBBReference(*MBB);
685 Entry.Blocks.push_back(Str);
686 Str.clear();
687 }
688 YamlJTI.Entries.push_back(std::move(Entry));
689 }
690}
691
694 bool &IsFallthrough) {
696
697 for (const MachineInstr &MI : MBB) {
698 if (MI.isPHI())
699 continue;
700 for (const MachineOperand &MO : MI.operands()) {
701 if (!MO.isMBB())
702 continue;
703 MachineBasicBlock *Succ = MO.getMBB();
704 auto RP = Seen.insert(Succ);
705 if (RP.second)
706 Result.push_back(Succ);
707 }
708 }
709 MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr();
710 IsFallthrough = I == MBB.end() || !I->isBarrier();
711}
712
715 bool GuessedFallthrough;
716 guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough);
717 if (GuessedFallthrough) {
718 const MachineFunction &MF = *MBB.getParent();
719 MachineFunction::const_iterator NextI = std::next(MBB.getIterator());
720 if (NextI != MF.end()) {
721 MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI);
722 if (!is_contained(GuessedSuccs, Next))
723 GuessedSuccs.push_back(Next);
724 }
725 }
726 if (GuessedSuccs.size() != MBB.succ_size())
727 return false;
728 return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin());
729}
730
731static void printMI(raw_ostream &OS, MFPrintState &State,
732 const MachineInstr &MI);
733
734static void printMIOperand(raw_ostream &OS, MFPrintState &State,
735 const MachineInstr &MI, unsigned OpIdx,
736 const TargetRegisterInfo *TRI,
737 const TargetInstrInfo *TII,
738 bool ShouldPrintRegisterTies,
739 SmallBitVector &PrintedTypes,
740 const MachineRegisterInfo &MRI, bool PrintDef);
741
742void printMBB(raw_ostream &OS, MFPrintState &State,
743 const MachineBasicBlock &MBB) {
744 assert(MBB.getNumber() >= 0 && "Invalid MBB number");
745 MBB.printName(OS,
748 &State.MST);
749 OS << ":\n";
750
751 bool HasLineAttributes = false;
752 // Print the successors
753 bool canPredictProbs = MBB.canPredictBranchProbabilities();
754 // Even if the list of successors is empty, if we cannot guess it,
755 // we need to print it to tell the parser that the list is empty.
756 // This is needed, because MI model unreachable as empty blocks
757 // with an empty successor list. If the parser would see that
758 // without the successor list, it would guess the code would
759 // fallthrough.
760 if ((!MBB.succ_empty() && !SimplifyMIR) || !canPredictProbs ||
762 OS.indent(2) << "successors:";
763 if (!MBB.succ_empty())
764 OS << " ";
765 ListSeparator LS;
766 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
767 OS << LS << printMBBReference(**I);
768 if (!SimplifyMIR || !canPredictProbs)
769 OS << format("(0x%08" PRIx32 ")",
770 MBB.getSuccProbability(I).getNumerator());
771 }
772 OS << "\n";
773 HasLineAttributes = true;
774 }
775
776 // Print the live in registers.
777 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
778 if (!MBB.livein_empty()) {
780 OS.indent(2) << "liveins: ";
781 ListSeparator LS;
782 for (const auto &LI : MBB.liveins_dbg()) {
783 OS << LS << printReg(LI.PhysReg, &TRI);
784 if (!LI.LaneMask.all())
785 OS << ":0x" << PrintLaneMask(LI.LaneMask);
786 }
787 OS << "\n";
788 HasLineAttributes = true;
789 }
790
791 if (HasLineAttributes && !MBB.empty())
792 OS << "\n";
793 bool IsInBundle = false;
794 for (const MachineInstr &MI : MBB.instrs()) {
795 if (IsInBundle && !MI.isInsideBundle()) {
796 OS.indent(2) << "}\n";
797 IsInBundle = false;
798 }
799 OS.indent(IsInBundle ? 4 : 2);
800 printMI(OS, State, MI);
801 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
802 OS << " {";
803 IsInBundle = true;
804 }
805 OS << "\n";
806 }
807 if (IsInBundle)
808 OS.indent(2) << "}\n";
809}
810
811static void printMI(raw_ostream &OS, MFPrintState &State,
812 const MachineInstr &MI) {
813 const auto *MF = MI.getMF();
814 const auto &MRI = MF->getRegInfo();
815 const auto &SubTarget = MF->getSubtarget();
816 const auto *TRI = SubTarget.getRegisterInfo();
817 assert(TRI && "Expected target register info");
818 const auto *TII = SubTarget.getInstrInfo();
819 assert(TII && "Expected target instruction info");
820 if (MI.isCFIInstruction())
821 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
822
823 SmallBitVector PrintedTypes(8);
824 bool ShouldPrintRegisterTies = MI.hasComplexRegisterTies();
825 ListSeparator LS;
826 unsigned I = 0, E = MI.getNumOperands();
827 for (; I < E; ++I) {
828 const MachineOperand MO = MI.getOperand(I);
829 if (!MO.isReg() || !MO.isDef() || MO.isImplicit())
830 break;
831 OS << LS;
832 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
833 PrintedTypes, MRI, /*PrintDef=*/false);
834 }
835
836 if (I)
837 OS << " = ";
838 if (MI.getFlag(MachineInstr::FrameSetup))
839 OS << "frame-setup ";
840 if (MI.getFlag(MachineInstr::FrameDestroy))
841 OS << "frame-destroy ";
842 if (MI.getFlag(MachineInstr::FmNoNans))
843 OS << "nnan ";
844 if (MI.getFlag(MachineInstr::FmNoInfs))
845 OS << "ninf ";
846 if (MI.getFlag(MachineInstr::FmNsz))
847 OS << "nsz ";
848 if (MI.getFlag(MachineInstr::FmArcp))
849 OS << "arcp ";
850 if (MI.getFlag(MachineInstr::FmContract))
851 OS << "contract ";
852 if (MI.getFlag(MachineInstr::FmAfn))
853 OS << "afn ";
854 if (MI.getFlag(MachineInstr::FmReassoc))
855 OS << "reassoc ";
856 if (MI.getFlag(MachineInstr::NoUWrap))
857 OS << "nuw ";
858 if (MI.getFlag(MachineInstr::NoSWrap))
859 OS << "nsw ";
860 if (MI.getFlag(MachineInstr::IsExact))
861 OS << "exact ";
862 if (MI.getFlag(MachineInstr::NoFPExcept))
863 OS << "nofpexcept ";
864 if (MI.getFlag(MachineInstr::NoMerge))
865 OS << "nomerge ";
866 if (MI.getFlag(MachineInstr::Unpredictable))
867 OS << "unpredictable ";
868 if (MI.getFlag(MachineInstr::NoConvergent))
869 OS << "noconvergent ";
870 if (MI.getFlag(MachineInstr::NonNeg))
871 OS << "nneg ";
872 if (MI.getFlag(MachineInstr::Disjoint))
873 OS << "disjoint ";
874 if (MI.getFlag(MachineInstr::NoUSWrap))
875 OS << "nusw ";
876 if (MI.getFlag(MachineInstr::SameSign))
877 OS << "samesign ";
878 if (MI.getFlag(MachineInstr::InBounds))
879 OS << "inbounds ";
880
881 // NOTE: Please add new MIFlags also to the MI_FLAGS_STR in
882 // llvm/utils/update_mir_test_checks.py.
883
884 OS << TII->getName(MI.getOpcode());
885
886 // Print a space after the opcode if any additional tokens are printed.
887 LS = ListSeparator(", ", " ");
888
889 for (; I < E; ++I) {
890 OS << LS;
891 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
892 PrintedTypes, MRI, /*PrintDef=*/true);
893 }
894
895 // Print any optional symbols attached to this instruction as-if they were
896 // operands.
897 if (MCSymbol *PreInstrSymbol = MI.getPreInstrSymbol()) {
898 OS << LS << "pre-instr-symbol ";
899 MachineOperand::printSymbol(OS, *PreInstrSymbol);
900 }
901 if (MCSymbol *PostInstrSymbol = MI.getPostInstrSymbol()) {
902 OS << LS << "post-instr-symbol ";
903 MachineOperand::printSymbol(OS, *PostInstrSymbol);
904 }
905 if (MDNode *HeapAllocMarker = MI.getHeapAllocMarker()) {
906 OS << LS << "heap-alloc-marker ";
907 HeapAllocMarker->printAsOperand(OS, State.MST);
908 }
909 if (MDNode *PCSections = MI.getPCSections()) {
910 OS << LS << "pcsections ";
911 PCSections->printAsOperand(OS, State.MST);
912 }
913 if (MDNode *MMRA = MI.getMMRAMetadata()) {
914 OS << LS << "mmra ";
915 MMRA->printAsOperand(OS, State.MST);
916 }
917 if (uint32_t CFIType = MI.getCFIType())
918 OS << LS << "cfi-type " << CFIType;
919 if (Value *DS = MI.getDeactivationSymbol()) {
920 OS << LS << "deactivation-symbol ";
921 MIRFormatter::printIRValue(OS, *DS, State.MST);
922 }
923
924 if (auto Num = MI.peekDebugInstrNum())
925 OS << LS << "debug-instr-number " << Num;
926
927 if (PrintLocations) {
928 if (const DebugLoc &DL = MI.getDebugLoc()) {
929 OS << LS << "debug-location ";
930 DL->printAsOperand(OS, State.MST);
931 }
932 }
933
934 if (!MI.memoperands_empty()) {
935 OS << " :: ";
936 const LLVMContext &Context = MF->getFunction().getContext();
937 const MachineFrameInfo &MFI = MF->getFrameInfo();
938 LS = ListSeparator();
939 for (const auto *Op : MI.memoperands()) {
940 OS << LS;
941 Op->print(OS, State.MST, State.SSNs, Context, &MFI, TII);
942 }
943 }
944}
945
946static std::string formatOperandComment(std::string Comment) {
947 if (Comment.empty())
948 return Comment;
949 return std::string(" /* " + Comment + " */");
950}
951
952static void printMIOperand(raw_ostream &OS, MFPrintState &State,
953 const MachineInstr &MI, unsigned OpIdx,
954 const TargetRegisterInfo *TRI,
955 const TargetInstrInfo *TII,
956 bool ShouldPrintRegisterTies,
957 SmallBitVector &PrintedTypes,
958 const MachineRegisterInfo &MRI, bool PrintDef) {
959 LLT TypeToPrint = MI.getTypeToPrint(OpIdx, PrintedTypes, MRI);
960 const MachineOperand &Op = MI.getOperand(OpIdx);
961 std::string MOComment = TII->createMIROperandComment(MI, Op, OpIdx, TRI);
962
963 switch (Op.getType()) {
965 if (MI.isOperandSubregIdx(OpIdx)) {
968 break;
969 }
970 [[fallthrough]];
990 unsigned TiedOperandIdx = 0;
991 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
992 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
993 Op.print(OS, State.MST, TypeToPrint, OpIdx, PrintDef,
994 /*IsStandalone=*/false, ShouldPrintRegisterTies, TiedOperandIdx,
995 TRI);
996 OS << formatOperandComment(MOComment);
997 break;
998 }
1000 printStackObjectReference(OS, State, Op.getIndex());
1001 break;
1003 const auto &RegisterMaskIds = State.RegisterMaskIds;
1004 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
1005 if (RegMaskInfo != RegisterMaskIds.end())
1006 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
1007 else
1008 printCustomRegMask(Op.getRegMask(), OS, TRI);
1009 break;
1010 }
1011 }
1012}
1013
1015 ModuleSlotTracker &MST) {
1016 if (isa<GlobalValue>(V)) {
1017 V.printAsOperand(OS, /*PrintType=*/false, MST);
1018 return;
1019 }
1020 if (isa<Constant>(V)) {
1021 // Machine memory operands can load/store to/from constant value pointers.
1022 OS << '`';
1023 V.printAsOperand(OS, /*PrintType=*/true, MST);
1024 OS << '`';
1025 return;
1026 }
1027 OS << "%ir.";
1028 if (V.hasName()) {
1029 printLLVMNameWithoutPrefix(OS, V.getName());
1030 return;
1031 }
1032 int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1;
1034}
1035
1036void llvm::printMIR(raw_ostream &OS, const Module &M) {
1037 yaml::Output Out(OS);
1038 Out << const_cast<Module &>(M);
1039}
1040
1042 const MachineFunction &MF) {
1043 printMF(OS, [&](const Function &F) { return MMI.getMachineFunction(F); }, MF);
1044}
1045
1047 const MachineFunction &MF) {
1048 printMF(
1049 OS,
1050 [&](const Function &F) {
1051 return &FAM.getResult<MachineFunctionAnalysis>(
1052 const_cast<Function &>(F))
1053 .getMF();
1054 },
1055 MF);
1056}
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 printMF(raw_ostream &OS, MFGetterFnT Fn, const MachineFunction &MF)
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 convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
static void printStackObjectDbgInfo(const MachineFunction::VariableDbgInfo &DebugVar, T &Object, ModuleSlotTracker &MST)
static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS, const TargetRegisterInfo *TRI)
static void convertMFI(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI, const MachineFrameInfo &MFI, const TargetRegisterInfo *TRI)
static void printRegMIR(Register Reg, yaml::StringValue &Dest, const TargetRegisterInfo *TRI)
static cl::opt< bool > SimplifyMIR("simplify-mir", cl::Hidden, cl::desc("Leave out unnecessary information when printing MIR"))
static void printMIOperand(raw_ostream &OS, MFPrintState &State, const MachineInstr &MI, unsigned OpIdx, const TargetRegisterInfo *TRI, const TargetInstrInfo *TII, bool ShouldPrintRegisterTies, SmallBitVector &PrintedTypes, const MachineRegisterInfo &MRI, bool PrintDef)
static void printRegFlags(Register Reg, std::vector< yaml::FlowStringValue > &RegisterFlags, const MachineFunction &MF, const TargetRegisterInfo *TRI)
static void convertPrefetchTargets(yaml::MachineFunction &YMF, const MachineFunction &MF)
static void convertMachineMetadataNodes(yaml::MachineFunction &YMF, const MachineFunction &MF, MachineModuleSlotTracker &MST)
static void convertMJTI(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI, const MachineJumpTableInfo &JTI)
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register Reg
Register const TargetRegisterInfo * TRI
#define T
MachineInstr unsigned OpIdx
FunctionAnalysisManager FAM
This file contains some templates that are useful if you are working with the STL at all.
This file implements the SmallBitVector class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
This class represents a function call, abstracting a target machine's calling convention.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
This is an important base class in LLVM.
Definition Constant.h:43
A debug info location.
Definition DebugLoc.h:123
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:241
Module * getParent()
Get the module that this global value is contained inside of...
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A helper class to return the specified delimiter string after the first invocation of operator String...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h: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:1080
static LLVM_ABI void printIRValue(raw_ostream &OS, const Value &V, ModuleSlotTracker &MST)
Helper functions to print IR value as MIR serialization format which will be useful for target specif...
MachineInstrBundleIterator< const MachineInstr > const_iterator
@ PrintNameIr
Add IR name where available.
@ PrintNameAttributes
Print attributes.
Instructions::const_iterator const_instr_iterator
This class is a data container for one entry in a MachineConstantPool.
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
bool isReturnAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
bool hasCalls() const
Return true if the current function has any function calls.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
bool isImmutableObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an immutable object.
int getStackProtectorIndex() const
Return the index for the stack protector object.
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
bool hasTailCall() const
Returns true if the function contains a tail call.
bool hasMustTailInVarArgFunc() const
Returns true if the function is variadic and contains a musttail call.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool isMaxCallFrameSizeComputed() const
int64_t getLocalFrameSize() const
Get the size of the local object blob.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
bool hasVAStart() const
Returns true if the function calls the llvm.va_start intrinsic.
unsigned getCVBytesOfCalleeSavedRegisters() const
Returns how many bytes of callee-saved registers the target pushed in the prologue.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
uint8_t getStackID(int ObjectIdx) const
const SaveRestorePoints & getRestorePoints() const
unsigned getNumFixedObjects() const
Return the number of fixed objects.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool hasFunctionContextIndex() const
int getObjectIndexBegin() const
Return the minimum frame object index.
const SaveRestorePoints & getSavePoints() const
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
int getFunctionContextIndex() const
Return the index for the function context object.
bool isAliasedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an object that might be pointed to by an LLVM IR v...
This analysis create MachineFunction for given Function.
Properties which a MachineFunction may have at a given point in time.
Description of the location of a variable whose Address is valid and unchanging during function execu...
auto getEntryValueVariableDbgInfo() const
Returns the collection of variables for which we have debug info and that have been assigned an entry...
bool useDebugInstrRef() const
Returns true if the function's variable locations are tracked with instruction referencing.
SmallVector< DebugSubstitution, 8 > DebugValueSubstitutions
Debug value substitutions: a collection of DebugSubstitution objects, recording changes in where a va...
const DenseMap< UniqueBBID, SmallVector< unsigned > > & getPrefetchTargets() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const CallSiteInfoMap & getCallSitesInfo() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
auto getInStackSlotVariableDbgInfo()
Returns the collection of variables for which we have debug info and that have been assigned a stack ...
Align getAlignment() const
getAlignment - Return the alignment of the function.
Function & getFunction()
Return the LLVM function that this machine code represents.
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
auto getCalledGlobals() const
Iterates over the full set of call sites and their associated globals.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
BasicBlockListType::const_iterator const_iterator
Representation of each machine instruction.
const std::vector< MachineJumpTableEntry > & getJumpTables() const
This class contains meta information specific to a module.
LLVM_ABI MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
void collectMachineMDNodes(MachineMDNodeListType &L) const
MachineOperand class - Representation of each machine instruction operand.
static LLVM_ABI void printStackObjectReference(raw_ostream &OS, unsigned FrameIndex, bool IsFixed, StringRef Name)
Print a stack object reference.
static LLVM_ABI void printSubRegIdx(raw_ostream &OS, uint64_t Index, const TargetRegisterInfo *TRI)
Print a subreg index operand.
static LLVM_ABI void printTargetFlags(raw_ostream &OS, const MachineOperand &Op)
Print operand target flags.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static LLVM_ABI void printIRSlotNumber(raw_ostream &OS, int Slot)
Print an IRSlotNumber.
static LLVM_ABI void printSymbol(raw_ostream &OS, MCSymbol &Sym)
Print a MCSymbol as an operand.
@ MO_CFIIndex
MCCFIInstruction index.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_Predicate
Generic predicate for ISel.
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_ShuffleMask
Other IR Constant for ISel (shuffle masks)
@ MO_CImmediate
Immediate >64bit operand.
@ MO_BlockAddress
Address of a basic block.
@ MO_DbgInstrRef
Integer indices referring to an instruction+operand.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_LaneMask
Mask to represent active parts of registers.
@ MO_FrameIndex
Abstract Stack Frame Index.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_IntrinsicID
Intrinsic ID for ISel.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
@ MO_TargetIndex
Target-dependent index+offset operand.
@ MO_Metadata
Metadata reference (for debug info)
@ MO_FPImmediate
Floating-point immediate operand.
@ MO_RegisterLiveOut
Mask of live-out registers.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterInfo * getTargetRegisterInfo() const
Manage lifetime of a slot tracker for printing IR.
std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
const Function * getCurrentFunction() const
void incorporateFunction(const Function &F)
Incorporate the given function.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:72
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h: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.
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
The Output class is used to generate a yaml document from in-memory structs and vectors.
void setWriteDefaultValues(bool Write)
Set whether or not to output optional values which are equal to the default value....
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
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:1636
LLVM_ABI Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:129
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
@ Sub
Subtraction of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
DWARFExpression::Operation Op
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
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:179
Serializable representation of CallSiteInfo.
std::vector< uint64_t > CalleeTypeIds
Numeric callee type identifiers for the callgraph section.
std::vector< ArgRegPair > ArgForwardingRegs
MachineInstrLoc CallLocation
Serializable representation of the MCRegister variant of MachineFunction::VariableDbgInfo.
Serializable representation of the fixed stack object from the MachineFrameInfo class.
Serializable representation of MachineFrameInfo.
std::vector< SaveRestorePointEntry > RestorePoints
unsigned MaxCallFrameSize
~0u means: not computed yet.
std::vector< SaveRestorePointEntry > SavePoints
std::vector< MachineStackObject > StackObjects
std::vector< StringValue > MachineMetadataNodes
std::optional< std::vector< FlowStringValue > > CalleeSavedRegisters
std::vector< CalledGlobal > CalledGlobals
std::optional< bool > HasFakeUses
std::vector< EntryValueObject > EntryValueObjects
std::optional< bool > NoPHIs
std::vector< FlowStringValue > PrefetchTargets
std::vector< MachineConstantPoolValue > Constants
std::optional< bool > NoVRegs
std::vector< CallSiteInfo > CallSitesInfo
std::vector< MachineFunctionLiveIn > LiveIns
std::vector< VirtualRegisterDefinition > VirtualRegisters
std::vector< FixedMachineStackObject > FixedStackObjects
std::optional< bool > IsSSA
std::vector< DebugValueSubstitution > DebugValueSubstitutions
std::unique_ptr< MachineFunctionInfo > MachineFuncInfo
Constant pool.
Identifies call instruction location in machine function.
std::vector< Entry > Entries
MachineJumpTableInfo::JTEntryKind Kind
Serializable representation of stack object from the MachineFrameInfo class.
A wrapper around std::string which contains a source range that's being set during parsing.
std::vector< FlowStringValue > RegisterFlags
static void output(const Module &Mod, void *Ctxt, raw_ostream &OS)
static StringRef input(StringRef Str, void *Ctxt, Module &Mod)