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