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