Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.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"
39#include "llvm/IR/DebugLoc.h"
40#include "llvm/IR/Function.h"
43#include "llvm/IR/Module.h"
45#include "llvm/IR/Value.h"
46#include "llvm/MC/LaneBitmask.h"
51#include "llvm/Support/Format.h"
55#include <algorithm>
56#include <cassert>
57#include <cinttypes>
58#include <cstdint>
59#include <iterator>
60#include <string>
61#include <utility>
62#include <vector>
63
64using namespace llvm;
65
67 "simplify-mir", cl::Hidden,
68 cl::desc("Leave out unnecessary information when printing MIR"));
69
70static cl::opt<bool> PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true),
71 cl::desc("Print MIR debug-locations"));
72
73namespace {
74
75/// This structure describes how to print out stack object references.
76struct FrameIndexOperand {
77 std::string Name;
78 unsigned ID;
79 bool IsFixed;
80
81 FrameIndexOperand(StringRef Name, unsigned ID, bool IsFixed)
82 : Name(Name.str()), ID(ID), IsFixed(IsFixed) {}
83
84 /// Return an ordinary stack object reference.
85 static FrameIndexOperand create(StringRef Name, unsigned ID) {
86 return FrameIndexOperand(Name, ID, /*IsFixed=*/false);
87 }
88
89 /// Return a fixed stack object reference.
90 static FrameIndexOperand createFixed(unsigned ID) {
91 return FrameIndexOperand("", ID, /*IsFixed=*/true);
92 }
93};
94
95struct MFPrintState {
96 MachineModuleSlotTracker MST;
97 DenseMap<const uint32_t *, unsigned> RegisterMaskIds;
98 /// Maps from stack object indices to operand indices which will be used when
99 /// printing frame index machine operands.
100 DenseMap<int, FrameIndexOperand> StackObjectOperandMapping;
101 /// Synchronization scope names registered with LLVMContext.
103
104 MFPrintState(const MachineModuleInfo &MMI, const MachineFunction &MF)
105 : MST(MMI, &MF) {}
106};
107
108} // end anonymous namespace
109
110namespace llvm::yaml {
111
112/// This struct serializes the LLVM IR module.
113template <> struct BlockScalarTraits<Module> {
114 static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {
115 Mod.print(OS, nullptr);
116 }
117
118 static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {
119 llvm_unreachable("LLVM Module is supposed to be parsed separately");
120 return "";
121 }
122};
123
124} // end namespace llvm::yaml
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,
174
175static void printMF(raw_ostream &OS, const MachineModuleInfo &MMI,
176 const MachineFunction &MF) {
177 MFPrintState State(MMI, MF);
178 State.RegisterMaskIds = initRegisterMaskIds(MF);
179
181 YamlMF.Name = MF.getName();
182 YamlMF.Alignment = MF.getAlignment();
184 YamlMF.HasWinCFI = MF.hasWinCFI();
185
186 YamlMF.CallsEHReturn = MF.callsEHReturn();
187 YamlMF.CallsUnwindInit = MF.callsUnwindInit();
188 YamlMF.HasEHContTarget = MF.hasEHContTarget();
189 YamlMF.HasEHScopes = MF.hasEHScopes();
190 YamlMF.HasEHFunclets = MF.hasEHFunclets();
191 YamlMF.HasFakeUses = MF.hasFakeUses();
192 YamlMF.IsOutlined = MF.isOutlined();
194
195 const MachineFunctionProperties &Props = MF.getProperties();
196 YamlMF.Legalized = Props.hasLegalized();
197 YamlMF.RegBankSelected = Props.hasRegBankSelected();
198 YamlMF.Selected = Props.hasSelected();
199 YamlMF.FailedISel = Props.hasFailedISel();
200 YamlMF.FailsVerification = Props.hasFailsVerification();
201 YamlMF.TracksDebugUserValues = Props.hasTracksDebugUserValues();
202 YamlMF.NoPHIs = Props.hasNoPHIs();
203 YamlMF.IsSSA = Props.hasIsSSA();
204 YamlMF.NoVRegs = Props.hasNoVRegs();
205
206 convertMRI(YamlMF, MF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
207 MachineModuleSlotTracker &MST = State.MST;
209 convertMFI(MST, YamlMF.FrameInfo, MF.getFrameInfo(),
211 convertStackObjects(YamlMF, MF, MST, State);
212 convertEntryValueObjects(YamlMF, MF, MST);
213 convertCallSiteObjects(YamlMF, MF, MST);
214 for (const auto &Sub : MF.DebugValueSubstitutions) {
215 const auto &SubSrc = Sub.Src;
216 const auto &SubDest = Sub.Dest;
217 YamlMF.DebugValueSubstitutions.push_back({SubSrc.first, SubSrc.second,
218 SubDest.first,
219 SubDest.second,
220 Sub.Subreg});
221 }
222 if (const auto *ConstantPool = MF.getConstantPool())
223 convertMCP(YamlMF, *ConstantPool);
224 if (const auto *JumpTableInfo = MF.getJumpTableInfo())
225 convertMJTI(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
226
227 const TargetMachine &TM = MF.getTarget();
228 YamlMF.MachineFuncInfo =
229 std::unique_ptr<yaml::MachineFunctionInfo>(TM.convertFuncInfoToYAML(MF));
230
231 raw_string_ostream StrOS(YamlMF.Body.Value.Value);
232 bool IsNewlineNeeded = false;
233 for (const auto &MBB : MF) {
234 if (IsNewlineNeeded)
235 StrOS << "\n";
236 printMBB(StrOS, State, MBB);
237 IsNewlineNeeded = true;
238 }
239 // Convert machine metadata collected during the print of the machine
240 // function.
241 convertMachineMetadataNodes(YamlMF, MF, MST);
242
243 convertCalledGlobals(YamlMF, MF, MST);
244
245 yaml::Output Out(OS);
246 if (!SimplifyMIR)
247 Out.setWriteDefaultValues(true);
248 Out << YamlMF;
249}
250
251static void printCustomRegMask(const uint32_t *RegMask, raw_ostream &OS,
252 const TargetRegisterInfo *TRI) {
253 assert(RegMask && "Can't print an empty register mask");
254 OS << StringRef("CustomRegMask(");
255
256 bool IsRegInRegMaskFound = false;
257 for (int I = 0, E = TRI->getNumRegs(); I < E; I++) {
258 // Check whether the register is asserted in regmask.
259 if (RegMask[I / 32] & (1u << (I % 32))) {
260 if (IsRegInRegMaskFound)
261 OS << ',';
262 OS << printReg(I, TRI);
263 IsRegInRegMaskFound = true;
264 }
265 }
266
267 OS << ')';
268}
269
276
277template <typename T>
278static void
280 T &Object, ModuleSlotTracker &MST) {
281 std::array<std::string *, 3> Outputs{{&Object.DebugVar.Value,
282 &Object.DebugExpr.Value,
283 &Object.DebugLoc.Value}};
284 std::array<const Metadata *, 3> Metas{{DebugVar.Var,
285 DebugVar.Expr,
286 DebugVar.Loc}};
287 for (unsigned i = 0; i < 3; ++i) {
288 raw_string_ostream StrOS(*Outputs[i]);
289 Metas[i]->printAsOperand(StrOS, MST);
290 }
291}
292
294 std::vector<yaml::FlowStringValue> &RegisterFlags,
295 const MachineFunction &MF,
296 const TargetRegisterInfo *TRI) {
297 auto FlagValues = TRI->getVRegFlagsOfReg(Reg, MF);
298 for (auto &Flag : FlagValues)
299 RegisterFlags.push_back(yaml::FlowStringValue(Flag.str()));
300}
301
302static void convertMRI(yaml::MachineFunction &YamlMF, const MachineFunction &MF,
304 const TargetRegisterInfo *TRI) {
305 YamlMF.TracksRegLiveness = RegInfo.tracksLiveness();
306
307 // Print the virtual register definitions.
308 for (unsigned I = 0, E = RegInfo.getNumVirtRegs(); I < E; ++I) {
311 VReg.ID = I;
312 if (RegInfo.getVRegName(Reg) != "")
313 continue;
315 Register PreferredReg = RegInfo.getSimpleHint(Reg);
316 if (PreferredReg)
317 printRegMIR(PreferredReg, VReg.PreferredRegister, TRI);
319 YamlMF.VirtualRegisters.push_back(std::move(VReg));
320 }
321
322 // Print the live ins.
323 for (std::pair<MCRegister, Register> LI : RegInfo.liveins()) {
325 printRegMIR(LI.first, LiveIn.Register, TRI);
326 if (LI.second)
327 printRegMIR(LI.second, LiveIn.VirtualRegister, TRI);
328 YamlMF.LiveIns.push_back(std::move(LiveIn));
329 }
330
331 // Prints the callee saved registers.
332 if (RegInfo.isUpdatedCSRsInitialized()) {
333 const MCPhysReg *CalleeSavedRegs = RegInfo.getCalleeSavedRegs();
334 std::vector<yaml::FlowStringValue> CalleeSavedRegisters;
335 for (const MCPhysReg *I = CalleeSavedRegs; *I; ++I) {
337 printRegMIR(*I, Reg, TRI);
338 CalleeSavedRegisters.push_back(std::move(Reg));
339 }
340 YamlMF.CalleeSavedRegisters = std::move(CalleeSavedRegisters);
341 }
342}
343
345 const MachineFrameInfo &MFI,
346 const TargetRegisterInfo *TRI) {
349 YamlMFI.HasStackMap = MFI.hasStackMap();
350 YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
351 YamlMFI.StackSize = MFI.getStackSize();
353 YamlMFI.MaxAlignment = MFI.getMaxAlign().value();
354 YamlMFI.AdjustsStack = MFI.adjustsStack();
355 YamlMFI.HasCalls = MFI.hasCalls();
357 ? MFI.getMaxCallFrameSize() : ~0u;
361 YamlMFI.HasVAStart = MFI.hasVAStart();
363 YamlMFI.HasTailCall = MFI.hasTailCall();
365 YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
366 if (!MFI.getSavePoints().empty())
367 convertSRPoints(MST, YamlMFI.SavePoints, MFI.getSavePoints(), TRI);
368 if (!MFI.getRestorePoints().empty())
370}
371
373 const MachineFunction &MF,
374 ModuleSlotTracker &MST) {
376 for (const MachineFunction::VariableDbgInfo &DebugVar :
378 yaml::EntryValueObject &Obj = YMF.EntryValueObjects.emplace_back();
379 printStackObjectDbgInfo(DebugVar, Obj, MST);
380 MCRegister EntryValReg = DebugVar.getEntryValueRegister();
381 printRegMIR(EntryValReg, Obj.EntryValueRegister, TRI);
382 }
383}
384
386 const MFPrintState &State,
387 int FrameIndex) {
388 auto ObjectInfo = State.StackObjectOperandMapping.find(FrameIndex);
389 assert(ObjectInfo != State.StackObjectOperandMapping.end() &&
390 "Invalid frame index");
391 const FrameIndexOperand &Operand = ObjectInfo->second;
392 MachineOperand::printStackObjectReference(OS, Operand.ID, Operand.IsFixed,
393 Operand.Name);
394}
395
397 const MachineFunction &MF,
398 ModuleSlotTracker &MST, MFPrintState &State) {
399 const MachineFrameInfo &MFI = MF.getFrameInfo();
401
402 // Process fixed stack objects.
403 assert(YMF.FixedStackObjects.empty());
404 SmallVector<int, 32> FixedStackObjectsIdx;
405 const int BeginIdx = MFI.getObjectIndexBegin();
406 if (BeginIdx < 0)
407 FixedStackObjectsIdx.reserve(-BeginIdx);
408
409 unsigned ID = 0;
410 for (int I = BeginIdx; I < 0; ++I, ++ID) {
411 FixedStackObjectsIdx.push_back(-1); // Fill index for possible dead.
412 if (MFI.isDeadObjectIndex(I))
413 continue;
414
416 YamlObject.ID = ID;
417 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
420 YamlObject.Offset = MFI.getObjectOffset(I);
421 YamlObject.Size = MFI.getObjectSize(I);
422 YamlObject.Alignment = MFI.getObjectAlign(I);
423 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
424 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
425 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
426 // Save the ID' position in FixedStackObjects storage vector.
427 FixedStackObjectsIdx[ID] = YMF.FixedStackObjects.size();
428 YMF.FixedStackObjects.push_back(std::move(YamlObject));
429 State.StackObjectOperandMapping.insert(
430 std::make_pair(I, FrameIndexOperand::createFixed(ID)));
431 }
432
433 // Process ordinary stack objects.
434 assert(YMF.StackObjects.empty());
435 SmallVector<unsigned, 32> StackObjectsIdx;
436 const int EndIdx = MFI.getObjectIndexEnd();
437 if (EndIdx > 0)
438 StackObjectsIdx.reserve(EndIdx);
439 ID = 0;
440 for (int I = 0; I < EndIdx; ++I, ++ID) {
441 StackObjectsIdx.push_back(-1); // Fill index for possible dead.
442 if (MFI.isDeadObjectIndex(I))
443 continue;
444
445 yaml::MachineStackObject YamlObject;
446 YamlObject.ID = ID;
447 if (const auto *Alloca = MFI.getObjectAllocation(I))
448 YamlObject.Name.Value = std::string(
449 Alloca->hasName() ? Alloca->getName() : "");
450 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
455 YamlObject.Offset = MFI.getObjectOffset(I);
456 YamlObject.Size = MFI.getObjectSize(I);
457 YamlObject.Alignment = MFI.getObjectAlign(I);
458 YamlObject.StackID = (TargetStackID::Value)MFI.getStackID(I);
459
460 // Save the ID' position in StackObjects storage vector.
461 StackObjectsIdx[ID] = YMF.StackObjects.size();
462 YMF.StackObjects.push_back(YamlObject);
463 State.StackObjectOperandMapping.insert(std::make_pair(
464 I, FrameIndexOperand::create(YamlObject.Name.Value, ID)));
465 }
466
467 for (const auto &CSInfo : MFI.getCalleeSavedInfo()) {
468 const int FrameIdx = CSInfo.getFrameIdx();
469 if (!CSInfo.isSpilledToReg() && MFI.isDeadObjectIndex(FrameIdx))
470 continue;
471
473 printRegMIR(CSInfo.getReg(), Reg, TRI);
474 if (!CSInfo.isSpilledToReg()) {
475 assert(FrameIdx >= MFI.getObjectIndexBegin() &&
476 FrameIdx < MFI.getObjectIndexEnd() &&
477 "Invalid stack object index");
478 if (FrameIdx < 0) { // Negative index means fixed objects.
479 auto &Object =
481 [FixedStackObjectsIdx[FrameIdx + MFI.getNumFixedObjects()]];
482 Object.CalleeSavedRegister = std::move(Reg);
483 Object.CalleeSavedRestored = CSInfo.isRestored();
484 } else {
485 auto &Object = YMF.StackObjects[StackObjectsIdx[FrameIdx]];
486 Object.CalleeSavedRegister = std::move(Reg);
487 Object.CalleeSavedRestored = CSInfo.isRestored();
488 }
489 }
490 }
491 for (unsigned I = 0, E = MFI.getLocalFrameObjectCount(); I < E; ++I) {
492 auto LocalObject = MFI.getLocalFrameObjectMap(I);
493 assert(LocalObject.first >= 0 && "Expected a locally mapped stack object");
494 YMF.StackObjects[StackObjectsIdx[LocalObject.first]].LocalOffset =
495 LocalObject.second;
496 }
497
498 // Print the stack object references in the frame information class after
499 // converting the stack objects.
500 if (MFI.hasStackProtectorIndex()) {
503 }
504
505 if (MFI.hasFunctionContextIndex()) {
508 }
509
510 // Print the debug variable information.
511 for (const MachineFunction::VariableDbgInfo &DebugVar :
513 int Idx = DebugVar.getStackSlot();
514 assert(Idx >= MFI.getObjectIndexBegin() && Idx < MFI.getObjectIndexEnd() &&
515 "Invalid stack object index");
516 if (Idx < 0) { // Negative index means fixed objects.
517 auto &Object =
518 YMF.FixedStackObjects[FixedStackObjectsIdx[Idx +
519 MFI.getNumFixedObjects()]];
520 printStackObjectDbgInfo(DebugVar, Object, MST);
521 } else {
522 auto &Object = YMF.StackObjects[StackObjectsIdx[Idx]];
523 printStackObjectDbgInfo(DebugVar, Object, MST);
524 }
525 }
526}
527
529 const MachineFunction &MF,
530 ModuleSlotTracker &MST) {
531 const auto *TRI = MF.getSubtarget().getRegisterInfo();
532 for (auto [MI, CallSiteInfo] : MF.getCallSitesInfo()) {
533 yaml::CallSiteInfo YmlCS;
534 yaml::MachineInstrLoc CallLocation;
535
536 // Prepare instruction position.
537 MachineBasicBlock::const_instr_iterator CallI = MI->getIterator();
538 CallLocation.BlockNum = CallI->getParent()->getNumber();
539 // Get call instruction offset from the beginning of block.
540 CallLocation.Offset =
541 std::distance(CallI->getParent()->instr_begin(), CallI);
542 YmlCS.CallLocation = CallLocation;
543
544 auto [ArgRegPairs, CalleeTypeIds] = CallSiteInfo;
545 // Construct call arguments and theirs forwarding register info.
546 for (auto ArgReg : ArgRegPairs) {
548 YmlArgReg.ArgNo = ArgReg.ArgNo;
549 printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI);
550 YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg);
551 }
552 // Get type ids.
553 for (auto *CalleeTypeId : CalleeTypeIds) {
554 YmlCS.CalleeTypeIds.push_back(CalleeTypeId->getZExtValue());
555 }
556 YMF.CallSitesInfo.push_back(std::move(YmlCS));
557 }
558
559 // Sort call info by position of call instructions.
560 llvm::sort(YMF.CallSitesInfo.begin(), YMF.CallSitesInfo.end(),
562 return std::tie(A.CallLocation.BlockNum, A.CallLocation.Offset) <
563 std::tie(B.CallLocation.BlockNum, B.CallLocation.Offset);
564 });
565}
566
568 const MachineFunction &MF,
571 MST.collectMachineMDNodes(MDList);
572 for (auto &MD : MDList) {
573 std::string NS;
574 raw_string_ostream StrOS(NS);
575 MD.second->print(StrOS, MST, MF.getFunction().getParent());
576 YMF.MachineMetadataNodes.push_back(std::move(NS));
577 }
578}
579
581 const MachineFunction &MF,
583 for (const auto &[CallInst, CG] : MF.getCalledGlobals()) {
584 yaml::MachineInstrLoc CallSite;
585 CallSite.BlockNum = CallInst->getParent()->getNumber();
586 CallSite.Offset = std::distance(CallInst->getParent()->instr_begin(),
588
589 yaml::CalledGlobal YamlCG{CallSite, CG.Callee->getName().str(),
590 CG.TargetFlags};
591 YMF.CalledGlobals.push_back(std::move(YamlCG));
592 }
593
594 // Sort by position of call instructions.
595 llvm::sort(YMF.CalledGlobals.begin(), YMF.CalledGlobals.end(),
597 return std::tie(A.CallSite.BlockNum, A.CallSite.Offset) <
598 std::tie(B.CallSite.BlockNum, B.CallSite.Offset);
599 });
600}
601
604 unsigned ID = 0;
605 for (const MachineConstantPoolEntry &Constant : ConstantPool.getConstants()) {
606 std::string Str;
607 raw_string_ostream StrOS(Str);
608 if (Constant.isMachineConstantPoolEntry())
609 Constant.Val.MachineCPVal->print(StrOS);
610 else
611 Constant.Val.ConstVal->printAsOperand(StrOS);
612
614 YamlConstant.ID = ID++;
615 YamlConstant.Value = std::move(Str);
616 YamlConstant.Alignment = Constant.getAlign();
617 YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry();
618
619 MF.Constants.push_back(std::move(YamlConstant));
620 }
621}
622
623static void
625 std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
626 const llvm::SaveRestorePoints &SRPoints,
627 const TargetRegisterInfo *TRI) {
628 for (const auto &[MBB, CSInfos] : SRPoints) {
629 SmallString<16> Str;
631 raw_svector_ostream StrOS(Str);
632 StrOS << printMBBReference(*MBB);
633 Entry.Point = StrOS.str().str();
634 Str.clear();
635 for (const CalleeSavedInfo &Info : CSInfos) {
636 if (Info.getReg()) {
637 StrOS << printReg(Info.getReg(), TRI);
638 Entry.Registers.push_back(StrOS.str().str());
639 Str.clear();
640 }
641 }
642 // Sort here needed for stable output for lit tests
643 std::sort(Entry.Registers.begin(), Entry.Registers.end(),
644 [](const yaml::StringValue &Lhs, const yaml::StringValue &Rhs) {
645 return Lhs.Value < Rhs.Value;
646 });
647 YamlSRPoints.push_back(std::move(Entry));
648 }
649 // Sort here needed for stable output for lit tests
650 std::sort(YamlSRPoints.begin(), YamlSRPoints.end(),
651 [](const yaml::SaveRestorePointEntry &Lhs,
652 const yaml::SaveRestorePointEntry &Rhs) {
653 return Lhs.Point.Value < Rhs.Point.Value;
654 });
655}
656
658 const MachineJumpTableInfo &JTI) {
659 YamlJTI.Kind = JTI.getEntryKind();
660 unsigned ID = 0;
661 for (const auto &Table : JTI.getJumpTables()) {
662 std::string Str;
664 Entry.ID = ID++;
665 for (const auto *MBB : Table.MBBs) {
666 raw_string_ostream StrOS(Str);
667 StrOS << printMBBReference(*MBB);
668 Entry.Blocks.push_back(Str);
669 Str.clear();
670 }
671 YamlJTI.Entries.push_back(std::move(Entry));
672 }
673}
674
677 bool &IsFallthrough) {
679
680 for (const MachineInstr &MI : MBB) {
681 if (MI.isPHI())
682 continue;
683 for (const MachineOperand &MO : MI.operands()) {
684 if (!MO.isMBB())
685 continue;
686 MachineBasicBlock *Succ = MO.getMBB();
687 auto RP = Seen.insert(Succ);
688 if (RP.second)
689 Result.push_back(Succ);
690 }
691 }
692 MachineBasicBlock::const_iterator I = MBB.getLastNonDebugInstr();
693 IsFallthrough = I == MBB.end() || !I->isBarrier();
694}
695
698 bool GuessedFallthrough;
699 guessSuccessors(MBB, GuessedSuccs, GuessedFallthrough);
700 if (GuessedFallthrough) {
701 const MachineFunction &MF = *MBB.getParent();
702 MachineFunction::const_iterator NextI = std::next(MBB.getIterator());
703 if (NextI != MF.end()) {
704 MachineBasicBlock *Next = const_cast<MachineBasicBlock*>(&*NextI);
705 if (!is_contained(GuessedSuccs, Next))
706 GuessedSuccs.push_back(Next);
707 }
708 }
709 if (GuessedSuccs.size() != MBB.succ_size())
710 return false;
711 return std::equal(MBB.succ_begin(), MBB.succ_end(), GuessedSuccs.begin());
712}
713
714static void printMI(raw_ostream &OS, MFPrintState &State,
715 const MachineInstr &MI);
716
717static void printMIOperand(raw_ostream &OS, MFPrintState &State,
718 const MachineInstr &MI, unsigned OpIdx,
719 const TargetRegisterInfo *TRI,
720 const TargetInstrInfo *TII,
721 bool ShouldPrintRegisterTies,
722 SmallBitVector &PrintedTypes,
723 const MachineRegisterInfo &MRI, bool PrintDef);
724
725void printMBB(raw_ostream &OS, MFPrintState &State,
726 const MachineBasicBlock &MBB) {
727 assert(MBB.getNumber() >= 0 && "Invalid MBB number");
728 MBB.printName(OS,
731 &State.MST);
732 OS << ":\n";
733
734 bool HasLineAttributes = false;
735 // Print the successors
736 bool canPredictProbs = MBB.canPredictBranchProbabilities();
737 // Even if the list of successors is empty, if we cannot guess it,
738 // we need to print it to tell the parser that the list is empty.
739 // This is needed, because MI model unreachable as empty blocks
740 // with an empty successor list. If the parser would see that
741 // without the successor list, it would guess the code would
742 // fallthrough.
743 if ((!MBB.succ_empty() && !SimplifyMIR) || !canPredictProbs ||
745 OS.indent(2) << "successors:";
746 if (!MBB.succ_empty())
747 OS << " ";
748 ListSeparator LS;
749 for (auto I = MBB.succ_begin(), E = MBB.succ_end(); I != E; ++I) {
750 OS << LS << printMBBReference(**I);
751 if (!SimplifyMIR || !canPredictProbs)
752 OS << format("(0x%08" PRIx32 ")",
753 MBB.getSuccProbability(I).getNumerator());
754 }
755 OS << "\n";
756 HasLineAttributes = true;
757 }
758
759 // Print the live in registers.
760 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
761 if (!MBB.livein_empty()) {
762 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
763 OS.indent(2) << "liveins: ";
764 ListSeparator LS;
765 for (const auto &LI : MBB.liveins_dbg()) {
766 OS << LS << printReg(LI.PhysReg, &TRI);
767 if (!LI.LaneMask.all())
768 OS << ":0x" << PrintLaneMask(LI.LaneMask);
769 }
770 OS << "\n";
771 HasLineAttributes = true;
772 }
773
774 if (HasLineAttributes && !MBB.empty())
775 OS << "\n";
776 bool IsInBundle = false;
777 for (const MachineInstr &MI : MBB.instrs()) {
778 if (IsInBundle && !MI.isInsideBundle()) {
779 OS.indent(2) << "}\n";
780 IsInBundle = false;
781 }
782 OS.indent(IsInBundle ? 4 : 2);
783 printMI(OS, State, MI);
784 if (!IsInBundle && MI.getFlag(MachineInstr::BundledSucc)) {
785 OS << " {";
786 IsInBundle = true;
787 }
788 OS << "\n";
789 }
790 if (IsInBundle)
791 OS.indent(2) << "}\n";
792}
793
794static void printMI(raw_ostream &OS, MFPrintState &State,
795 const MachineInstr &MI) {
796 const auto *MF = MI.getMF();
797 const auto &MRI = MF->getRegInfo();
798 const auto &SubTarget = MF->getSubtarget();
799 const auto *TRI = SubTarget.getRegisterInfo();
800 assert(TRI && "Expected target register info");
801 const auto *TII = SubTarget.getInstrInfo();
802 assert(TII && "Expected target instruction info");
803 if (MI.isCFIInstruction())
804 assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction");
805
806 SmallBitVector PrintedTypes(8);
807 bool ShouldPrintRegisterTies = MI.hasComplexRegisterTies();
808 ListSeparator LS;
809 unsigned I = 0, E = MI.getNumOperands();
810 for (; I < E; ++I) {
811 const MachineOperand MO = MI.getOperand(I);
812 if (!MO.isReg() || !MO.isDef() || MO.isImplicit())
813 break;
814 OS << LS;
815 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
816 PrintedTypes, MRI, /*PrintDef=*/false);
817 }
818
819 if (I)
820 OS << " = ";
821 if (MI.getFlag(MachineInstr::FrameSetup))
822 OS << "frame-setup ";
823 if (MI.getFlag(MachineInstr::FrameDestroy))
824 OS << "frame-destroy ";
825 if (MI.getFlag(MachineInstr::FmNoNans))
826 OS << "nnan ";
827 if (MI.getFlag(MachineInstr::FmNoInfs))
828 OS << "ninf ";
829 if (MI.getFlag(MachineInstr::FmNsz))
830 OS << "nsz ";
831 if (MI.getFlag(MachineInstr::FmArcp))
832 OS << "arcp ";
833 if (MI.getFlag(MachineInstr::FmContract))
834 OS << "contract ";
835 if (MI.getFlag(MachineInstr::FmAfn))
836 OS << "afn ";
837 if (MI.getFlag(MachineInstr::FmReassoc))
838 OS << "reassoc ";
839 if (MI.getFlag(MachineInstr::NoUWrap))
840 OS << "nuw ";
841 if (MI.getFlag(MachineInstr::NoSWrap))
842 OS << "nsw ";
843 if (MI.getFlag(MachineInstr::IsExact))
844 OS << "exact ";
845 if (MI.getFlag(MachineInstr::NoFPExcept))
846 OS << "nofpexcept ";
847 if (MI.getFlag(MachineInstr::NoMerge))
848 OS << "nomerge ";
849 if (MI.getFlag(MachineInstr::Unpredictable))
850 OS << "unpredictable ";
851 if (MI.getFlag(MachineInstr::NoConvergent))
852 OS << "noconvergent ";
853 if (MI.getFlag(MachineInstr::NonNeg))
854 OS << "nneg ";
855 if (MI.getFlag(MachineInstr::Disjoint))
856 OS << "disjoint ";
857 if (MI.getFlag(MachineInstr::NoUSWrap))
858 OS << "nusw ";
859 if (MI.getFlag(MachineInstr::SameSign))
860 OS << "samesign ";
861 if (MI.getFlag(MachineInstr::InBounds))
862 OS << "inbounds ";
863
864 // NOTE: Please add new MIFlags also to the MI_FLAGS_STR in
865 // llvm/utils/update_mir_test_checks.py.
866
867 OS << TII->getName(MI.getOpcode());
868
869 LS = ListSeparator();
870
871 if (I < E) {
872 OS << ' ';
873 for (; I < E; ++I) {
874 OS << LS;
875 printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
876 PrintedTypes, MRI, /*PrintDef=*/true);
877 }
878 }
879
880 // Print any optional symbols attached to this instruction as-if they were
881 // operands.
882 if (MCSymbol *PreInstrSymbol = MI.getPreInstrSymbol()) {
883 OS << LS << " pre-instr-symbol ";
884 MachineOperand::printSymbol(OS, *PreInstrSymbol);
885 }
886 if (MCSymbol *PostInstrSymbol = MI.getPostInstrSymbol()) {
887 OS << LS << " post-instr-symbol ";
888 MachineOperand::printSymbol(OS, *PostInstrSymbol);
889 }
890 if (MDNode *HeapAllocMarker = MI.getHeapAllocMarker()) {
891 OS << LS << " heap-alloc-marker ";
892 HeapAllocMarker->printAsOperand(OS, State.MST);
893 }
894 if (MDNode *PCSections = MI.getPCSections()) {
895 OS << LS << " pcsections ";
896 PCSections->printAsOperand(OS, State.MST);
897 }
898 if (MDNode *MMRA = MI.getMMRAMetadata()) {
899 OS << LS << " mmra ";
900 MMRA->printAsOperand(OS, State.MST);
901 }
902 if (uint32_t CFIType = MI.getCFIType())
903 OS << LS << " cfi-type " << CFIType;
904
905 if (auto Num = MI.peekDebugInstrNum())
906 OS << LS << " debug-instr-number " << Num;
907
908 if (PrintLocations) {
909 if (const DebugLoc &DL = MI.getDebugLoc()) {
910 OS << LS << " debug-location ";
911 DL->printAsOperand(OS, State.MST);
912 }
913 }
914
915 if (!MI.memoperands_empty()) {
916 OS << " :: ";
917 const LLVMContext &Context = MF->getFunction().getContext();
918 const MachineFrameInfo &MFI = MF->getFrameInfo();
919 LS = ListSeparator();
920 for (const auto *Op : MI.memoperands()) {
921 OS << LS;
922 Op->print(OS, State.MST, State.SSNs, Context, &MFI, TII);
923 }
924 }
925}
926
927static std::string formatOperandComment(std::string Comment) {
928 if (Comment.empty())
929 return Comment;
930 return std::string(" /* " + Comment + " */");
931}
932
933static void printMIOperand(raw_ostream &OS, MFPrintState &State,
934 const MachineInstr &MI, unsigned OpIdx,
935 const TargetRegisterInfo *TRI,
936 const TargetInstrInfo *TII,
937 bool ShouldPrintRegisterTies,
938 SmallBitVector &PrintedTypes,
939 const MachineRegisterInfo &MRI, bool PrintDef) {
940 LLT TypeToPrint = MI.getTypeToPrint(OpIdx, PrintedTypes, MRI);
941 const MachineOperand &Op = MI.getOperand(OpIdx);
942 std::string MOComment = TII->createMIROperandComment(MI, Op, OpIdx, TRI);
943
944 switch (Op.getType()) {
946 if (MI.isOperandSubregIdx(OpIdx)) {
949 break;
950 }
951 [[fallthrough]];
970 unsigned TiedOperandIdx = 0;
971 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
972 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
973 Op.print(OS, State.MST, TypeToPrint, OpIdx, PrintDef,
974 /*IsStandalone=*/false, ShouldPrintRegisterTies, TiedOperandIdx,
975 TRI);
976 OS << formatOperandComment(MOComment);
977 break;
978 }
980 printStackObjectReference(OS, State, Op.getIndex());
981 break;
983 const auto &RegisterMaskIds = State.RegisterMaskIds;
984 auto RegMaskInfo = RegisterMaskIds.find(Op.getRegMask());
985 if (RegMaskInfo != RegisterMaskIds.end())
986 OS << StringRef(TRI->getRegMaskNames()[RegMaskInfo->second]).lower();
987 else
988 printCustomRegMask(Op.getRegMask(), OS, TRI);
989 break;
990 }
991 }
992}
993
995 ModuleSlotTracker &MST) {
996 if (isa<GlobalValue>(V)) {
997 V.printAsOperand(OS, /*PrintType=*/false, MST);
998 return;
999 }
1000 if (isa<Constant>(V)) {
1001 // Machine memory operands can load/store to/from constant value pointers.
1002 OS << '`';
1003 V.printAsOperand(OS, /*PrintType=*/true, MST);
1004 OS << '`';
1005 return;
1006 }
1007 OS << "%ir.";
1008 if (V.hasName()) {
1009 printLLVMNameWithoutPrefix(OS, V.getName());
1010 return;
1011 }
1012 int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1;
1014}
1015
1016void llvm::printMIR(raw_ostream &OS, const Module &M) {
1017 yaml::Output Out(OS);
1018 Out << const_cast<Module &>(M);
1019}
1020
1022 const MachineFunction &MF) {
1023 printMF(OS, MMI, MF);
1024}
unsigned const MachineRegisterInfo * MRI
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")
Analysis containing CSE Info
Definition CSEInfo.cpp:27
This file defines the DenseMap class.
const HexagonInstrInfo * TII
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 I(x, y, z)
Definition MD5.cpp:58
static void convertCallSiteObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST)
static void convertMCP(yaml::MachineFunction &MF, const MachineConstantPool &ConstantPool)
static void printMI(raw_ostream &OS, MFPrintState &State, const MachineInstr &MI)
static void convertSRPoints(ModuleSlotTracker &MST, std::vector< yaml::SaveRestorePointEntry > &YamlSRPoints, const llvm::SaveRestorePoints &SRPoints, const TargetRegisterInfo *TRI)
static DenseMap< const uint32_t *, unsigned > initRegisterMaskIds(const MachineFunction &MF)
static void convertCalledGlobals(yaml::MachineFunction &YMF, const MachineFunction &MF, MachineModuleSlotTracker &MST)
static void printMBB(raw_ostream &OS, MFPrintState &State, const MachineBasicBlock &MBB)
static std::string formatOperandComment(std::string Comment)
static cl::opt< bool > PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true), cl::desc("Print MIR debug-locations"))
static bool canPredictSuccessors(const MachineBasicBlock &MBB)
static void convertStackObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST, MFPrintState &State)
static void printMF(raw_ostream &OS, const MachineModuleInfo &MMI, const MachineFunction &MF)
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 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
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:124
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:214
Module * getParent()
Get the module that this global value is contained inside of...
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A helper class to return the specified delimiter string after the first invocation of operator String...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
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:1077
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...
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 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.
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_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,...
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:19
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:67
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:225
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.
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:130
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.
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...
DenseMap< MachineBasicBlock *, std::vector< CalleeSavedInfo > > SaveRestorePoints
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1624
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:548
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:126
@ 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
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1877
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.
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:85
static void output(const Module &Mod, void *Ctxt, raw_ostream &OS)
static StringRef input(StringRef Str, void *Ctxt, Module &Mod)
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< 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