LLVM: lib/CodeGen/MIRParser/MIRParser.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
41#include
42
43using namespace llvm;
44
45namespace llvm {
48
49
50
54 yaml::Input In;
57 std::unique_ptr Target;
58
59
60
61 bool NoLLVMIR = false;
62
63
64 bool NoMIRDocuments = false;
65
66 std::function<void(Function &)> ProcessIRFunction;
67
68public:
71 std::function<void(Function &)> ProcessIRFunction);
72
74
75
76
77
79
80
81
82
84
85
86
87
88
90
91
92
93
94
95 std::unique_ptr
97
98
100
103
104
105
106
107
110
111
112
113
114
117
120
123
126
129
131 std::vector &CSIInfo,
133 bool IsRestored, int FrameIdx);
134
139 };
140
145 template
147 const T &Object,
148 int FrameIdx);
149
153
156
160
163
164private:
167
171
174
175
178
179
180
183
186
189
192};
193
194}
195
197 reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
198}
199
202 std::function<void(Function &)> Callback)
203 : Context(Context),
204 In(SM.getMemoryBuffer(SM.AddNewSourceBuffer(std::move(Contents), SMLoc()))
205 ->getBuffer(),
207 Filename(Filename), ProcessIRFunction(Callback) {
208 In.setContext(&In);
209}
210
214 return true;
215}
216
220 return true;
221}
222
226 return true;
227}
228
231 switch (Diag.getKind()) {
234 break;
237 break;
240 break;
243 break;
244 }
246}
247
248std::unique_ptr
250 if (!In.setCurrentDocument()) {
251 if (In.error())
252 return nullptr;
253
254 NoMIRDocuments = true;
255 auto M = std::make_unique(Filename, Context);
256 if (auto LayoutOverride =
257 DataLayoutCallback(M->getTargetTriple(), M->getDataLayoutStr()))
258 M->setDataLayout(*LayoutOverride);
259 return M;
260 }
261
262 std::unique_ptr M;
263
264
265 if (const auto *BSN =
266 dyn_cast_or_nullyaml::BlockScalarNode(In.getCurrentNode())) {
269 Context, &IRSlots, DataLayoutCallback);
270 if (!M) {
272 return nullptr;
273 }
274 In.nextDocument();
275 if (!In.setCurrentDocument())
276 NoMIRDocuments = true;
277 } else {
278
279 M = std::make_unique(Filename, Context);
280 if (auto LayoutOverride =
281 DataLayoutCallback(M->getTargetTriple(), M->getDataLayoutStr()))
282 M->setDataLayout(*LayoutOverride);
283 NoLLVMIR = true;
284 }
285 return M;
286}
287
290 if (NoMIRDocuments)
291 return false;
292
293
294 do {
296 return true;
297 In.nextDocument();
298 } while (In.setCurrentDocument());
299
300 return false;
301}
302
304 auto &Context = M.getContext();
310
311 if (ProcessIRFunction)
312 ProcessIRFunction(*F);
313
314 return F;
315}
316
319
321 yaml::EmptyContext Ctx;
322
324 YamlMF.MachineFuncInfo = std::unique_ptryaml::MachineFunctionInfo(
325 TM.createDefaultFuncInfoYAML());
326
327 yaml::yamlize(In, YamlMF, false, Ctx);
328 if (In.error())
329 return true;
330
331
333 Function *F = M.getFunction(FunctionName);
334 if () {
335 if (NoLLVMIR) {
337 } else {
338 return error(Twine("function '") + FunctionName +
339 "' isn't defined in the provided LLVM IR");
340 }
341 }
342
343 if () {
345 return error(Twine("redefinition of machine function '") + FunctionName +
346 "'");
347
348
351 return true;
352 } else {
353 auto &FAM =
356 return error(Twine("redefinition of machine function '") + FunctionName +
357 "'");
358
359
362 return true;
363 }
364
365 return false;
366}
367
370 for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
372 if (.hasOneDef(Reg) &&
.def_empty(Reg))
373 return false;
374
375
377 if (RegDef && RegDef->getSubReg() != 0)
378 return false;
379 }
380 return true;
381}
382
383bool MIRParserImpl::computeFunctionProperties(
386
387 bool HasPHI = false;
388 bool HasInlineAsm = false;
389 bool HasFakeUses = false;
390 bool AllTiedOpsRewritten = true, HasTiedOps = false;
393 if (MI.isPHI())
394 HasPHI = true;
395 if (MI.isInlineAsm())
396 HasInlineAsm = true;
397 if (MI.isFakeUse())
398 HasFakeUses = true;
399 for (unsigned I = 0; I < MI.getNumOperands(); ++I) {
402 continue;
403 unsigned DefIdx;
404 if (MO.isUse() && MI.isRegTiedToDefOperand(I, &DefIdx)) {
405 HasTiedOps = true;
406 if (MO.getReg() != MI.getOperand(DefIdx).getReg())
407 AllTiedOpsRewritten = false;
408 }
409 }
410 }
411 }
412
413
414
415 auto ComputedPropertyHelper =
416 [&Properties](std::optional ExplicitProp, bool ComputedProp,
418
419 if (ExplicitProp.value_or(ComputedProp))
421 else
423
424
425 return ExplicitProp && *ExplicitProp && !ComputedProp;
426 };
427
428 if (ComputedPropertyHelper(YamlMF.NoPHIs, !HasPHI,
430 return error(MF.getName() +
431 " has explicit property NoPhi, but contains at least one PHI");
432 }
433
434 MF.setHasInlineAsm(HasInlineAsm);
435
436 if (HasTiedOps && AllTiedOpsRewritten)
438
439 if (ComputedPropertyHelper(YamlMF.IsSSA, isSSA(MF),
441 return error(MF.getName() +
442 " has explicit property IsSSA, but is not valid SSA");
443 }
444
446 if (ComputedPropertyHelper(YamlMF.NoVRegs, MRI.getNumVirtRegs() == 0,
449 MF.getName() +
450 " has explicit property NoVRegs, but contains virtual registers");
451 }
452
453
454
455
456
459 MF.getName() +
460 " has explicit property hasFakeUses=false, but contains fake uses");
461 MF.setHasFakeUses(YamlMF.HasFakeUses.value_or(HasFakeUses));
462
463 return false;
464}
465
471 Twine(" instruction block out of range.") +
472 " Unable to reference bb:" + Twine(MILoc.BlockNum));
473 }
475 if (MILoc.Offset >= BB->size())
477 Twine(MF.getName()) + Twine(" instruction offset out of range.") +
478 " Unable to reference instruction at bb: " + Twine(MILoc.BlockNum) +
480 MI = &*std::next(BB->instr_begin(), MILoc.Offset);
481 return false;
482}
483
492 if (parseMachineInst(MF, MILoc, CallI))
493 return true;
496 Twine(" call site info should reference call "
497 "instruction. Instruction at bb:") +
499 " is not a call instruction");
501 for (auto ArgRegPair : YamlCSInfo.ArgForwardingRegs) {
504 return error(Error, ArgRegPair.Reg.SourceRange);
505 CSInfo.ArgRegPairs.emplace_back(Reg, ArgRegPair.ArgNo);
506 }
507
508 if (TM.Options.EmitCallSiteInfo)
510 }
511
512 if (YamlMF.CallSitesInfo.size() && !TM.Options.EmitCallSiteInfo)
513 return error(Twine("Call site info provided but not used"));
514 return false;
515}
516
517void MIRParserImpl::setupDebugValueTracking(
520
521 unsigned MaxInstrNum = 0;
522 for (auto &MBB : MF)
524 MaxInstrNum = std::max((unsigned)MI.peekDebugInstrNum(), MaxInstrNum);
525 MF.setDebugInstrNumberingCount(MaxInstrNum);
526
527
529 MF.makeDebugValueSubstitution({Sub.SrcInst, Sub.SrcOp},
530 {Sub.DstInst, Sub.DstOp}, Sub.Subreg);
531 }
532
533
535}
536
537bool
540
542
544 } else {
546 }
547
551
558
574
577 return true;
582 return true;
583 }
586 return true;
587
594 PFS.SM = &BlockSM;
598 return true;
599 }
600
603 }
604 PFS.SM = &SM;
605
606
607
609 return true;
610
611
614 return true;
615
616
622 PFS.SM = &InsnSM;
626 return true;
627 }
628 PFS.SM = &SM;
629
631 return true;
632
635
636
637
638
641 SrcRange)) {
643 }
644 }
645
646
647
648
649
650
652 MRI.freezeReservedRegs();
653
654 if (computeFunctionProperties(MF, YamlMF))
655 return true;
656
658 return true;
659
661 return true;
662
663 setupDebugValueTracking(MF, PFS, YamlMF);
664
666
667 MF.verify(nullptr, nullptr, &errs());
668 return false;
669}
670
678
680
683 if (Info.Explicit)
684 return error(VReg.ID.SourceRange.Start,
685 Twine("redefinition of virtual register '%") +
686 Twine(VReg.ID.Value) + "'");
687 Info.Explicit = true;
688
689 if (VReg.Class.Value == "_") {
691 Info.D.RegBank = nullptr;
692 } else {
693 const auto *RC = Target->getRegClass(VReg.Class.Value);
694 if (RC) {
696 Info.D.RC = RC;
697 } else {
699 if (!RegBank)
701 VReg.Class.SourceRange.Start,
702 Twine("use of undefined register class or register bank '") +
703 VReg.Class.Value + "'");
705 Info.D.RegBank = RegBank;
706 }
707 }
708
709 if (!VReg.PreferredRegister.Value.empty()) {
711 return error(VReg.Class.SourceRange.Start,
712 Twine("preferred register can only be set for normal vregs"));
713
715 VReg.PreferredRegister.Value, Error))
716 return error(Error, VReg.PreferredRegister.SourceRange);
717 }
718
719 for (const auto &FlagStringValue : VReg.RegisterFlags) {
721 if (Target->getVRegFlagValue(FlagStringValue.Value, FlagValue))
722 return error(FlagStringValue.SourceRange.Start,
723 Twine("use of undefined register flag '") +
724 FlagStringValue.Value + "'");
725 Info.Flags |= FlagValue;
726 }
728 }
729
730
731 for (const auto &LiveIn : YamlMF.LiveIns) {
734 return error(Error, LiveIn.Register.SourceRange);
736 if (!LiveIn.VirtualRegister.Value.empty()) {
740 return error(Error, LiveIn.VirtualRegister.SourceRange);
741 VReg = Info->VReg;
742 }
744 }
745
746
747
753 return error(Error, RegSource.SourceRange);
754 CalleeSavedRegisters.push_back(Reg);
755 }
757 }
758
759 return false;
760}
761
767
768 bool Error = false;
769
772 switch (Info.Kind) {
774 error(Twine("Cannot determine class/bank of virtual register ") +
775 Name + " in function '" + MF.getName() + "'");
777 break;
779 if (.D.RC->isAllocatable()) {
780 error(Twine("Cannot use non-allocatable class '") +
781 TRI->getRegClassName(Info.D.RC) + "' for virtual register " +
782 Name + " in function '" + MF.getName() + "'");
784 break;
785 }
786
787 MRI.setRegClass(Reg, Info.D.RC);
788 if (Info.PreferredReg != 0)
789 MRI.setSimpleHint(Reg, Info.PreferredReg);
790 break;
792 break;
794 MRI.setRegBank(Reg, *Info.D.RegBank);
795 break;
796 }
797 };
798
801 populateVRegInfo(Info, Twine(P.first()));
802 }
803
806 populateVRegInfo(Info, Twine(P.first));
807 }
808
809
811
813 if (auto *RegMask = TRI->getCustomEHPadPreservedMask(MF))
814 MRI.addPhysRegsUsedFromRegMask(RegMask);
815
819 continue;
821 }
822 }
823 }
824
826}
827
856 if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
857 return true;
859 }
863 return true;
865 }
866
867 std::vector CSIInfo;
868
870 int ObjectIdx;
873 Object.IsImmutable, Object.IsAliased);
874 else
876
878 return error(Object.ID.SourceRange.Start,
879 Twine("StackID is not supported by target"));
880 MFI.setStackID(ObjectIdx, Object.StackID);
883 ObjectIdx))
884 .second)
885 return error(Object.ID.SourceRange.Start,
886 Twine("redefinition of fixed stack object '%fixed-stack.") +
887 Twine(Object.ID.Value) + "'");
889 Object.CalleeSavedRestored, ObjectIdx))
890 return true;
892 return true;
893 }
894
900 return error(Error, Object.EntryValueRegister.SourceRange);
901 if (!Reg.isPhysical())
902 return error(Object.EntryValueRegister.SourceRange.Start,
903 "Expected physical register for entry value field");
905 PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
906 if (!MaybeInfo)
907 return true;
908 if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
910 Reg.asMCReg(), MaybeInfo->DILoc);
911 }
912
913
914 for (const auto &Object : YamlMF.StackObjects) {
915 int ObjectIdx;
918 if (.Value.empty()) {
919 Alloca = dyn_cast_or_null(
920 F.getValueSymbolTable()->lookup(Name.Value));
921 if (!Alloca)
922 return error(Name.SourceRange.Start,
923 "alloca instruction named '" + Name.Value +
924 "' isn't defined in the function '" + F.getName() +
925 "'");
926 }
928 return error(Object.ID.SourceRange.Start,
929 Twine("StackID is not supported by target"));
931 ObjectIdx =
933 else
935 Object.Size, Object.Alignment.valueOrOne(),
937 Object.StackID);
939
941 .second)
942 return error(Object.ID.SourceRange.Start,
943 Twine("redefinition of stack object '%stack.") +
944 Twine(Object.ID.Value) + "'");
946 Object.CalleeSavedRestored, ObjectIdx))
947 return true;
948 if (Object.LocalOffset)
951 return true;
952 }
954 if (!CSIInfo.empty())
956
957
958
961 int FI;
965 }
966
969 int FI;
973 }
974
975 return false;
976}
977
979 std::vector &CSIInfo,
980 const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx) {
981 if (RegisterSource.Value.empty())
982 return false;
989 CSIInfo.push_back(CSI);
990 return false;
991}
992
993
994template
999 return false;
1000 Result = dyn_cast(Node);
1001 if (!Result)
1002 return Parser.error(Source.SourceRange.Start,
1003 "expected a reference to a '" + TypeString +
1004 "' metadata node");
1005 return false;
1006}
1007
1011 MDNode *Var = nullptr;
1012 MDNode *Expr = nullptr;
1013 MDNode *Loc = nullptr;
1014 if (parseMDNode(PFS, Var, VarStr) || parseMDNode(PFS, Expr, ExprStr) ||
1015 parseMDNode(PFS, Loc, LocStr))
1016 return std::nullopt;
1020 if (typecheckMDNode(DIVar, Var, VarStr, "DILocalVariable", *this) ||
1021 typecheckMDNode(DIExpr, Expr, ExprStr, "DIExpression", *this) ||
1022 typecheckMDNode(DILoc, Loc, LocStr, "DILocation", *this))
1023 return std::nullopt;
1024 return VarExprLoc{DIVar, DIExpr, DILoc};
1025}
1026
1027template
1029 const T &Object, int FrameIdx) {
1030 std::optional MaybeInfo =
1031 parseVarExprLoc(PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
1032 if (!MaybeInfo)
1033 return true;
1034
1035
1036 if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
1038 MaybeInfo->DILoc);
1039 return false;
1040}
1041
1044 if (Source.Value.empty())
1045 return false;
1048 return error(Error, Source.SourceRange);
1049 return false;
1050}
1051
1058 for (const auto &YamlConstant : YamlMF.Constants) {
1059 if (YamlConstant.IsTargetSpecific)
1060
1061 return error(YamlConstant.Value.SourceRange.Start,
1062 "Can't parse target-specific constant pool entries yet");
1063 const Constant *Value = dyn_cast_or_null(
1066 return error(Error, YamlConstant.Value.SourceRange);
1067 const Align PrefTypeAlign =
1068 M.getDataLayout().getPrefTypeAlign(Value->getType());
1069 const Align Alignment = YamlConstant.Alignment.value_or(PrefTypeAlign);
1070 unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
1071 if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
1072 .second)
1073 return error(YamlConstant.ID.SourceRange.Start,
1074 Twine("redefinition of constant pool item '%const.") +
1075 Twine(YamlConstant.ID.Value) + "'");
1076 }
1077 return false;
1078}
1079
1083 for (const auto &Entry : YamlJTI.Entries) {
1084 std::vector<MachineBasicBlock *> Blocks;
1085 for (const auto &MBBSource : Entry.Blocks) {
1087 if (parseMBBReference(PFS, MBB, MBBSource.Value))
1088 return true;
1090 }
1093 .second)
1094 return error(Entry.ID.SourceRange.Start,
1095 Twine("redefinition of jump table entry '%jump-table.") +
1096 Twine(Entry.ID.Value) + "'");
1097 }
1098 return false;
1099}
1100
1106 return error(Error, Source.SourceRange);
1107 return false;
1108}
1109
1114 return error(Error, Source.SourceRange);
1115 return false;
1116}
1117
1122 if (parseMachineMetadata(PFS, MDS))
1123 return true;
1124 }
1125
1128 "use of undefined metadata '!" +
1130 return false;
1131}
1132
1140 if (parseMachineInst(MF, MILoc, CallI))
1141 return true;
1144 Twine(" called global should reference call "
1145 "instruction. Instruction at bb:") +
1147 " is not a call instruction");
1148
1149 auto Callee =
1150 F.getParent()->getValueSymbolTable().lookup(YamlCG.Callee.Value);
1151 if (!Callee)
1152 return error(YamlCG.Callee.SourceRange.Start,
1153 "use of undefined global '" + YamlCG.Callee.Value + "'");
1154 if (!isa(Callee))
1155 return error(YamlCG.Callee.SourceRange.Start,
1156 "use of non-global value '" + YamlCG.Callee.Value + "'");
1157
1158 MF.addCalledGlobal(CallI, {cast(Callee), YamlCG.Flags});
1159 }
1160
1161 return false;
1162}
1163
1166 assert(SourceRange.isValid() && "Invalid source range");
1170
1171
1173 (HasQuote ? 1 : 0));
1174
1175
1177 Error.getFixIts());
1178}
1179
1183
1184
1185
1187 unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
1188 unsigned Column = Error.getColumnNo();
1191
1192
1193
1195 L != E; ++L) {
1196 if (L.line_number() == Line) {
1197 LineStr = *L;
1199 auto Indent = LineStr.find(Error.getLineContents());
1201 Column += Indent;
1202 break;
1203 }
1204 }
1205
1206 return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
1207 Error.getMessage(), LineStr, Error.getRanges(),
1208 Error.getFixIts());
1209}
1210
1212 : Impl(std::move(Impl)) {}
1213
1215
1216std::unique_ptr
1218 return Impl->parseIRModule(DataLayoutCallback);
1219}
1220
1222 return Impl->parseMachineFunctions(M, MMI);
1223}
1224
1227 return Impl->parseMachineFunctions(M, MMI, &MAM);
1228}
1229
1232 std::function<void(Function &)> ProcessIRFunction) {
1234 if (std::error_code EC = FileOrErr.getError()) {
1236 "Could not open input file: " + EC.message());
1237 return nullptr;
1238 }
1239 return createMIRParser(std::move(FileOrErr.get()), Context,
1240 ProcessIRFunction);
1241}
1242
1243std::unique_ptr
1246 std::function<void(Function &)> ProcessIRFunction) {
1247 auto Filename = Contents->getBufferIdentifier();
1253 "Can't read MIR with a Context that discards named Values")));
1254 return nullptr;
1255 }
1256 return std::make_unique(std::make_unique(
1257 std::move(Contents), Filename, Context, ProcessIRFunction));
1258}
unsigned const MachineRegisterInfo * MRI
Analysis containing CSE Info
This file defines the DenseMap class.
DenseMap< Block *, BlockRelaxAux > Blocks
Module.h This file contains the declarations for the Module class.
static bool isSSA(const MachineFunction &MF)
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
static bool typecheckMDNode(T *&Result, MDNode *Node, const yaml::StringValue &Source, StringRef TypeString, MIRParserImpl &Parser)
Verify that given node is of a certain type. Return true on error.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
unsigned const TargetRegisterInfo * TRI
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
an instruction to allocate memory on the stack
A container for analyses that lazily runs them and caches their results.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
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.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Diagnostic information for machine IR parser.
Lightweight error class with error context and mandatory checking.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Module * getParent()
Get the module that this global value is contained inside of...
@ ExternalLinkage
Externally visible function.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
This is an important class for using LLVM in a threaded context.
bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
This class implements the parsing of LLVM IR that's embedded inside a MIR file.
bool error(const Twine &Message)
Report an error with the given message at unknown location.
void reportDiagnostic(const SMDiagnostic &Diag)
bool setupRegisterInfo(const PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
bool initializeFrameInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Function * createDummyFunction(StringRef Name, Module &M)
Create an empty function with the given name.
bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const T &Object, int FrameIdx)
bool initializeMachineFunction(const yaml::MachineFunction &YamlMF, MachineFunction &MF)
Initialize the machine function to the state that's described in the MIR file.
std::unique_ptr< Module > parseIRModule(DataLayoutCallbackTy DataLayoutCallback)
Try to parse the optional LLVM module and the machine functions in the MIR file.
bool initializeJumpTableInfo(PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI)
bool initializeConstantPool(PerFunctionMIParsingState &PFS, MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF)
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction)
std::optional< VarExprLoc > parseVarExprLoc(PerFunctionMIParsingState &PFS, const yaml::StringValue &VarStr, const yaml::StringValue &ExprStr, const yaml::StringValue &LocStr)
bool parseCalledGlobals(PerFunctionMIParsingState &PFS, MachineFunction &MF, const yaml::MachineFunction &YMF)
bool parseCalleeSavedRegister(PerFunctionMIParsingState &PFS, std::vector< CalleeSavedInfo > &CSIInfo, const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx)
bool parseMachineMetadataNodes(PerFunctionMIParsingState &PFS, MachineFunction &MF, const yaml::MachineFunction &YMF)
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
bool parseMachineFunction(Module &M, MachineModuleInfo &MMI, ModuleAnalysisManager *FAM)
Parse the machine function in the current YAML document.
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI, ModuleAnalysisManager *FAM=nullptr)
MIRParser(std::unique_ptr< MIRParserImpl > Impl)
std::unique_ptr< Module > parseIRModule(DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Parses the optional LLVM IR module in the MIR file.
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Parses MachineFunctions in the MIR file and add them to the given MachineModuleInfo MMI.
bool isEHPad() const
Returns true if the block is a landing pad.
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.
void setMaxCallFrameSize(uint64_t S)
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
void setAdjustsStack(bool V)
void setRestorePoint(MachineBasicBlock *NewRestore)
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
void ensureMaxAlignment(Align Alignment)
Make sure the function is at least Align bytes aligned.
void setHasPatchPoint(bool s=true)
void setLocalFrameSize(int64_t sz)
Set the size of the local object blob.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
void setFrameAddressIsTaken(bool T)
void setHasStackMap(bool s=true)
void setCVBytesOfCalleeSavedRegisters(unsigned S)
void setStackID(int ObjectIdx, uint8_t ID)
void setHasTailCall(bool V=true)
void setStackProtectorIndex(int I)
void setCalleeSavedInfoValid(bool v)
void setReturnAddressIsTaken(bool s)
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
void setHasOpaqueSPAdjustment(bool B)
void setCalleeSavedInfo(std::vector< CalleeSavedInfo > CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
void setSavePoint(MachineBasicBlock *NewSave)
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
void setStackSize(uint64_t Size)
Set the size of the stack.
void setHasVAStart(bool B)
void setHasMustTailInVarArgFunc(bool B)
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
void setOffsetAdjustment(int64_t Adj)
Set the correction for frame offsets.
void setFunctionContextIndex(int I)
This analysis create MachineFunction for given Function.
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
MachineFunctionProperties & reset(Property P)
void setCallsUnwindInit(bool b)
void setHasEHFunclets(bool V)
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there's a call to a "returns twice" function.
void setHasWinCFI(bool v)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineJumpTableInfo * getOrCreateJumpTableInfo(unsigned JTEntryKind)
getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it does already exist,...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
void setHasEHCatchret(bool V)
void setCallsEHReturn(bool b)
void setAlignment(Align A)
setAlignment - Set the alignment of the function.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool hasBBSections() const
Returns true if this function has basic block sections enabled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, raw_ostream *OS=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use.
Function & getFunction()
Return the LLVM function that this machine code represents.
void setIsOutlined(bool V)
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
void addCallSiteInfo(const MachineInstr *CallI, CallSiteInfo &&CallInfo)
Start tracking the arguments passed to the call CallI.
const MachineFunctionProperties & getProperties() const
Get the function properties.
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, int Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable in a stack slot.
void setHasEHScopes(bool V)
void addCalledGlobal(const MachineInstr *MI, CalledGlobalInfo Details)
Notes the global and target flags for a call site.
void assignBeginEndSections()
Assign IsBeginSection IsEndSection fields for basic blocks in this function.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
bool isCall(QueryType Type=AnyInBundle) const
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock * > &DestBBs)
createJumpTableIndex - Create a new jump table.
An analysis that produces MachineModuleInfo for a module.
This class contains meta information specific to a module.
MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
const TargetMachine & getTarget() const
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
Register getReg() const
getReg - Returns the register number.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
void noteNewVirtualRegister(Register Reg)
void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
A Module instance is used to store all the information related to an LLVM module.
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
SourceMgr::DiagKind getKind() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
Represents a range in source code.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
unsigned getMainFileID() const
std::pair< unsigned, unsigned > getLineAndColumn(SMLoc Loc, unsigned BufferID=0) const
Find the line and column number for the specified location in the specified file.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
StringRef - Represent a constant reference to a string, i.e.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static constexpr size_t npos
Information about stack frame layout on the target.
virtual bool isSupportedStackID(TargetStackID::Value ID) const
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
getRegisterInfo - If register information is available, return it.
virtual void mirFileLoaded(MachineFunction &MF) const
This is called after a .mir file was loaded.
virtual const TargetFrameLowering * getFrameLowering() const
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::string str() const
Return the twine contents as a std::string.
static Type * getVoidTy(LLVMContext &C)
This function has undefined behavior.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
An efficient, type-erasing, non-owning reference to a callable.
A forward iterator which reads text lines from a buffer.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
std::unique_ptr< MIRParser > createMIRParserFromFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction=nullptr)
This function is the main interface to the MIR serialization format parser.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
std::unique_ptr< MIRParser > createMIRParser(std::unique_ptr< MemoryBuffer > Contents, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction=nullptr)
This function is another interface to the MIR serialization format parser.
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
parseAssemblyFile and parseAssemblyString are wrappers around this function.
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
Constant * parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type and a constant value in the given string.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
bool parseMachineMetadata(PerFunctionMIParsingState &PFS, StringRef Src, SMRange SourceRange, SMDiagnostic &Error)
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
SmallVector< ArgRegPair, 1 > ArgRegPairs
Vector of call argument and its forwarding register.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
DenseMap< unsigned, unsigned > JumpTableSlots
VRegInfo & getVRegInfo(Register Num)
DenseMap< unsigned, int > FixedStackObjectSlots
DenseMap< unsigned, unsigned > ConstantPoolSlots
StringMap< VRegInfo * > VRegInfosNamed
DenseMap< unsigned, int > StackObjectSlots
std::map< unsigned, std::pair< TempMDTuple, SMLoc > > MachineForwardRefMDNodes
DenseMap< Register, VRegInfo * > VRegInfos
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Serializable representation of MachineFrameInfo.
bool IsCalleeSavedInfoValid
unsigned MaxCallFrameSize
~0u means: not computed yet.
StringValue StackProtector
bool HasMustTailInVarArgFunc
unsigned CVBytesOfCalleeSavedRegisters
bool HasOpaqueSPAdjustment
bool IsReturnAddressTaken
StringValue FunctionContext
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
bool TracksDebugUserValues
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.
MachineJumpTable JumpTableInfo
MachineFrameInfo FrameInfo
Identifies call instruction location in machine function.
std::vector< Entry > Entries
MachineJumpTableInfo::JTEntryKind Kind
A wrapper around std::string which contains a source range that's being set during parsing.