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
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 const std::vectoryaml::SaveRestorePointEntry &YamlSRPoints,
131
134
136 std::vector &CSIInfo,
138 bool IsRestored, int FrameIdx);
139
145
150 template
152 const T &Object,
153 int FrameIdx);
154
158
161
165
168
169private:
172
176
179
180
183
184
185
188
191
194
197};
198
199}
200
202 reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
203}
204
207 std::function<void(Function &)> Callback)
208 : Context(Context),
209 In(SM.getMemoryBuffer(SM.AddNewSourceBuffer(std::move(Contents), SMLoc()))
210 ->getBuffer(),
212 Filename(Filename), ProcessIRFunction(Callback) {
213 In.setContext(&In);
214}
215
221
227
233
236 switch (Diag.getKind()) {
239 break;
242 break;
245 break;
248 break;
249 }
251}
252
253std::unique_ptr
255 if (!In.setCurrentDocument()) {
256 if (In.error())
257 return nullptr;
258
259 NoMIRDocuments = true;
260 auto M = std::make_unique(Filename, Context);
261 if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
262 M->getDataLayoutStr()))
263 M->setDataLayout(*LayoutOverride);
264 return M;
265 }
266
267 std::unique_ptr M;
268
269
270 if (const auto *BSN =
274 Context, &IRSlots, DataLayoutCallback);
275 if (!M) {
277 return nullptr;
278 }
279 In.nextDocument();
280 if (!In.setCurrentDocument())
281 NoMIRDocuments = true;
282 } else {
283
284 M = std::make_unique(Filename, Context);
285 if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
286 M->getDataLayoutStr()))
287 M->setDataLayout(*LayoutOverride);
288 NoLLVMIR = true;
289 }
290 return M;
291}
292
295 if (NoMIRDocuments)
296 return false;
297
298
299 do {
301 return true;
302 In.nextDocument();
303 } while (In.setCurrentDocument());
304
305 return false;
306}
307
315
316 if (ProcessIRFunction)
317 ProcessIRFunction(*F);
318
319 return F;
320}
321
324
327
329 YamlMF.MachineFuncInfo = std::unique_ptryaml::MachineFunctionInfo(
331
333 if (In.error())
334 return true;
335
336
338 Function *F = M.getFunction(FunctionName);
339 if () {
340 if (NoLLVMIR) {
342 } else {
343 return error(Twine("function '") + FunctionName +
344 "' isn't defined in the provided LLVM IR");
345 }
346 }
347
348 if () {
350 return error(Twine("redefinition of machine function '") + FunctionName +
351 "'");
352
353
356 return true;
357 } else {
358 auto &FAM =
361 return error(Twine("redefinition of machine function '") + FunctionName +
362 "'");
363
364
367 return true;
368 }
369
370 return false;
371}
372
375 for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
377 if (.hasOneDef(Reg) &&
.def_empty(Reg))
378 return false;
379
380
382 if (RegDef && RegDef->getSubReg() != 0)
383 return false;
384 }
385 return true;
386}
387
388bool MIRParserImpl::computeFunctionProperties(
390 MachineFunctionProperties &Properties = MF.getProperties();
391
392 bool HasPHI = false;
393 bool HasInlineAsm = false;
394 bool HasFakeUses = false;
395 bool AllTiedOpsRewritten = true, HasTiedOps = false;
396 for (const MachineBasicBlock &MBB : MF) {
397 for (const MachineInstr &MI : MBB) {
398 if (MI.isPHI())
399 HasPHI = true;
400 if (MI.isInlineAsm())
401 HasInlineAsm = true;
402 if (MI.isFakeUse())
403 HasFakeUses = true;
404 for (unsigned I = 0; I < MI.getNumOperands(); ++I) {
405 const MachineOperand &MO = MI.getOperand(I);
407 continue;
408 unsigned DefIdx;
409 if (MO.isUse() && MI.isRegTiedToDefOperand(I, &DefIdx)) {
410 HasTiedOps = true;
411 if (MO.getReg() != MI.getOperand(DefIdx).getReg())
412 AllTiedOpsRewritten = false;
413 }
414 }
415 }
416 }
417
418
419
420 auto ComputedPropertyHelper =
421 [&Properties](std::optional ExplicitProp, bool ComputedProp,
423
424 if (ExplicitProp.value_or(ComputedProp))
426 else
428
429
430 return ExplicitProp && *ExplicitProp && !ComputedProp;
431 };
432
433 if (ComputedPropertyHelper(YamlMF.NoPHIs, !HasPHI,
435 return error(MF.getName() +
436 " has explicit property NoPhi, but contains at least one PHI");
437 }
438
439 MF.setHasInlineAsm(HasInlineAsm);
440
441 if (HasTiedOps && AllTiedOpsRewritten)
442 Properties.setTiedOpsRewritten();
443
444 if (ComputedPropertyHelper(YamlMF.IsSSA, isSSA(MF),
446 return error(MF.getName() +
447 " has explicit property IsSSA, but is not valid SSA");
448 }
449
450 const MachineRegisterInfo &MRI = MF.getRegInfo();
451 if (ComputedPropertyHelper(YamlMF.NoVRegs, MRI.getNumVirtRegs() == 0,
454 MF.getName() +
455 " has explicit property NoVRegs, but contains virtual registers");
456 }
457
458
459
460
461
464 MF.getName() +
465 " has explicit property hasFakeUses=false, but contains fake uses");
466 MF.setHasFakeUses(YamlMF.HasFakeUses.value_or(HasFakeUses));
467
468 return false;
469}
470
476 Twine(" instruction block out of range.") +
477 " Unable to reference bb:" + Twine(MILoc.BlockNum));
478 }
480 if (MILoc.Offset >= BB->size())
482 Twine(MF.getName()) + Twine(" instruction offset out of range.") +
483 " Unable to reference instruction at bb: " + Twine(MILoc.BlockNum) +
484 " at offset:" + Twine(MILoc.Offset));
485 MI = &*std::next(BB->instr_begin(), MILoc.Offset);
486 return false;
487}
488
497 if (parseMachineInst(MF, MILoc, CallI))
498 return true;
501 Twine(" call site info should reference call "
502 "instruction. Instruction at bb:") +
504 " is not a call instruction");
506 for (auto ArgRegPair : YamlCSInfo.ArgForwardingRegs) {
509 return error(Error, ArgRegPair.Reg.SourceRange);
510 CSInfo.ArgRegPairs.emplace_back(Reg, ArgRegPair.ArgNo);
511 }
512 if (!YamlCSInfo.CalleeTypeIds.empty()) {
513 for (auto CalleeTypeId : YamlCSInfo.CalleeTypeIds) {
515 CSInfo.CalleeTypeIds.push_back(ConstantInt::get(Int64Ty, CalleeTypeId,
516 false));
517 }
518 }
519
522 }
523
526 return error("call site info provided but not used");
527 return false;
528}
529
530void MIRParserImpl::setupDebugValueTracking(
533
534 unsigned MaxInstrNum = 0;
535 for (auto &MBB : MF)
537 MaxInstrNum = std::max(MI.peekDebugInstrNum(), MaxInstrNum);
538 MF.setDebugInstrNumberingCount(MaxInstrNum);
539
540
542 MF.makeDebugValueSubstitution({Sub.SrcInst, Sub.SrcOp},
543 {Sub.DstInst, Sub.DstOp}, Sub.Subreg);
544 }
545
546
548}
549
550bool
553
554 if (Target) {
555
557 } else {
559 }
560
564
571
574 Props.setLegalized();
576 Props.setRegBankSelected();
578 Props.setSelected();
580 Props.setFailedISel();
582 Props.setFailsVerification();
584 Props.setTracksDebugUserValues();
585
588 return true;
593 return true;
594 }
597 return true;
598
605 PFS.SM = &BlockSM;
609 return true;
610 }
611
614 }
615 PFS.SM = &SM;
616
617
618
620 return true;
621
622
625 return true;
626
627
633 PFS.SM = &InsnSM;
637 return true;
638 }
639 PFS.SM = &SM;
640
642 return true;
643
646
647
648
649
652 SrcRange)) {
654 }
655 }
656
657
658
659
660
661
663 MRI.freezeReservedRegs();
664
665 if (computeFunctionProperties(MF, YamlMF))
666 return true;
667
669 return true;
670
672 return true;
673
674 setupDebugValueTracking(MF, PFS, YamlMF);
675
677
678 MF.verify(nullptr, nullptr, &errs());
679 return false;
680}
681
686 assert(RegInfo.tracksLiveness());
688 RegInfo.invalidateLiveness();
689
691
694 if (Info.Explicit)
695 return error(VReg.ID.SourceRange.Start,
696 Twine("redefinition of virtual register '%") +
697 Twine(VReg.ID.Value) + "'");
698 Info.Explicit = true;
699
700 if (VReg.Class.Value == "_") {
702 Info.D.RegBank = nullptr;
703 } else {
704 const auto *RC = Target->getRegClass(VReg.Class.Value);
705 if (RC) {
707 Info.D.RC = RC;
708 } else {
709 const RegisterBank *RegBank = Target->getRegBank(VReg.Class.Value);
710 if (!RegBank)
712 VReg.Class.SourceRange.Start,
713 Twine("use of undefined register class or register bank '") +
714 VReg.Class.Value + "'");
716 Info.D.RegBank = RegBank;
717 }
718 }
719
720 if (!VReg.PreferredRegister.Value.empty()) {
722 return error(VReg.Class.SourceRange.Start,
723 Twine("preferred register can only be set for normal vregs"));
724
726 VReg.PreferredRegister.Value, Error))
727 return error(Error, VReg.PreferredRegister.SourceRange);
728 }
729
730 for (const auto &FlagStringValue : VReg.RegisterFlags) {
732 if (Target->getVRegFlagValue(FlagStringValue.Value, FlagValue))
733 return error(FlagStringValue.SourceRange.Start,
734 Twine("use of undefined register flag '") +
735 FlagStringValue.Value + "'");
736 Info.Flags |= FlagValue;
737 }
738 RegInfo.noteNewVirtualRegister(Info.VReg);
739 }
740
741
742 for (const auto &LiveIn : YamlMF.LiveIns) {
745 return error(Error, LiveIn.Register.SourceRange);
747 if (!LiveIn.VirtualRegister.Value.empty()) {
751 return error(Error, LiveIn.VirtualRegister.SourceRange);
752 VReg = Info->VReg;
753 }
754 RegInfo.addLiveIn(Reg, VReg);
755 }
756
757
758
764 return error(Error, RegSource.SourceRange);
765 CalleeSavedRegisters.push_back(Reg.id());
766 }
767 RegInfo.setCalleeSavedRegs(CalleeSavedRegisters);
768 }
769
770 return false;
771}
772
778
780
781
782 auto populateVRegInfo = [&](const VRegInfo &Info, const Twine &Name) {
784 switch (Info.Kind) {
787 (Twine("Cannot determine class/bank of virtual register ") + Name +
788 " in function '" + MF.getName() + "'")
789 .str());
790 break;
792 if (!Info.D.RC->isAllocatable()) {
793 Errors.push_back((Twine("Cannot use non-allocatable class '") +
794 TRI->getRegClassName(Info.D.RC) +
795 "' for virtual register " + Name + " in function '" +
797 .str());
798 break;
799 }
800
801 MRI.setRegClass(Reg, Info.D.RC);
802 if (Info.PreferredReg != 0)
803 MRI.setSimpleHint(Reg, Info.PreferredReg);
804 break;
806 break;
808 MRI.setRegBank(Reg, *Info.D.RegBank);
809 break;
810 }
811 };
812
814 const VRegInfo &Info = *P.second;
815 populateVRegInfo(Info, Twine(P.first()));
816 }
817
819 const VRegInfo &Info = *P.second;
820 populateVRegInfo(Info, Twine(P.first.id()));
821 }
822
823
825
826 if (MBB.isEHPad())
827 if (auto *RegMask = TRI->getCustomEHPadPreservedMask(MF))
828 MRI.addPhysRegsUsedFromRegMask(RegMask);
829
833 continue;
835 }
836 }
837 }
838
839 if (Errors.empty())
840 return false;
841
842
843 sort(Errors);
844 for (auto &E : Errors)
846 return true;
847}
848
877 return true;
881 return true;
883
884 std::vector CSIInfo;
885
887 int ObjectIdx;
890 Object.IsImmutable, Object.IsAliased);
891 else
893
895 return error(Object.ID.SourceRange.Start,
896 Twine("StackID is not supported by target"));
897 MFI.setStackID(ObjectIdx, Object.StackID);
900 ObjectIdx))
901 .second)
902 return error(Object.ID.SourceRange.Start,
903 Twine("redefinition of fixed stack object '%fixed-stack.") +
904 Twine(Object.ID.Value) + "'");
906 Object.CalleeSavedRestored, ObjectIdx))
907 return true;
909 return true;
910 }
911
917 return error(Error, Object.EntryValueRegister.SourceRange);
918 if (!Reg.isPhysical())
919 return error(Object.EntryValueRegister.SourceRange.Start,
920 "Expected physical register for entry value field");
922 PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
923 if (!MaybeInfo)
924 return true;
925 if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
927 Reg.asMCReg(), MaybeInfo->DILoc);
928 }
929
930
931 for (const auto &Object : YamlMF.StackObjects) {
932 int ObjectIdx;
935 if (!Name.Value.empty()) {
937 F.getValueSymbolTable()->lookup(Name.Value));
938 if (!Alloca)
939 return error(Name.SourceRange.Start,
940 "alloca instruction named '" + Name.Value +
941 "' isn't defined in the function '" + F.getName() +
942 "'");
943 }
945 return error(Object.ID.SourceRange.Start,
946 Twine("StackID is not supported by target"));
948 ObjectIdx =
950 else
952 Object.Size, Object.Alignment.valueOrOne(),
954 Object.StackID);
956
958 .second)
959 return error(Object.ID.SourceRange.Start,
960 Twine("redefinition of stack object '%stack.") +
961 Twine(Object.ID.Value) + "'");
963 Object.CalleeSavedRestored, ObjectIdx))
964 return true;
965 if (Object.LocalOffset)
968 return true;
969 }
971 if (!CSIInfo.empty())
973
974
975
978 int FI;
982 }
983
986 int FI;
990 }
991
992 return false;
993}
994
996 std::vector &CSIInfo,
997 const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx) {
998 if (RegisterSource.Value.empty())
999 return false;
1006 CSIInfo.push_back(CSI);
1007 return false;
1008}
1009
1010
1011template
1016 return false;
1018 if (!Result)
1019 return Parser.error(Source.SourceRange.Start,
1020 "expected a reference to a '" + TypeString +
1021 "' metadata node");
1022 return false;
1023}
1024
1028 MDNode *Var = nullptr;
1029 MDNode *Expr = nullptr;
1031 if (parseMDNode(PFS, Var, VarStr) || parseMDNode(PFS, Expr, ExprStr) ||
1032 parseMDNode(PFS, Loc, LocStr))
1033 return std::nullopt;
1037 if (typecheckMDNode(DIVar, Var, VarStr, "DILocalVariable", *this) ||
1038 typecheckMDNode(DIExpr, Expr, ExprStr, "DIExpression", *this) ||
1040 return std::nullopt;
1041 return VarExprLoc{DIVar, DIExpr, DILoc};
1042}
1043
1044template
1046 const T &Object, int FrameIdx) {
1047 std::optional MaybeInfo =
1048 parseVarExprLoc(PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
1049 if (!MaybeInfo)
1050 return true;
1051
1052
1053 if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
1055 MaybeInfo->DILoc);
1056 return false;
1057}
1058
1061 if (Source.Value.empty())
1062 return false;
1065 return error(Error, Source.SourceRange);
1066 return false;
1067}
1068
1075 for (const auto &YamlConstant : YamlMF.Constants) {
1076 if (YamlConstant.IsTargetSpecific)
1077
1078 return error(YamlConstant.Value.SourceRange.Start,
1079 "Can't parse target-specific constant pool entries yet");
1083 return error(Error, YamlConstant.Value.SourceRange);
1084 const Align PrefTypeAlign =
1085 M.getDataLayout().getPrefTypeAlign(Value->getType());
1086 const Align Alignment = YamlConstant.Alignment.value_or(PrefTypeAlign);
1087 unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
1088 if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
1089 .second)
1090 return error(YamlConstant.ID.SourceRange.Start,
1091 Twine("redefinition of constant pool item '%const.") +
1092 Twine(YamlConstant.ID.Value) + "'");
1093 }
1094 return false;
1095}
1096
1097
1100 const std::vectoryaml::SaveRestorePointEntry &YamlSRPoints,
1105 if (parseMBBReference(PFS, MBB, Entry.Point.Value))
1106 return true;
1107
1108 std::vector Registers;
1109 for (auto &RegStr : Entry.Registers) {
1112 return error(Error, RegStr.SourceRange);
1114 }
1116 }
1117 return false;
1118}
1119
1123 for (const auto &Entry : YamlJTI.Entries) {
1124 std::vector<MachineBasicBlock *> Blocks;
1125 for (const auto &MBBSource : Entry.Blocks) {
1127 if (parseMBBReference(PFS, MBB, MBBSource.Value))
1128 return true;
1129 Blocks.push_back(MBB);
1130 }
1133 .second)
1134 return error(Entry.ID.SourceRange.Start,
1135 Twine("redefinition of jump table entry '%jump-table.") +
1136 Twine(Entry.ID.Value) + "'");
1137 }
1138 return false;
1139}
1140
1146 return error(Error, Source.SourceRange);
1147 return false;
1148}
1149
1154 return error(Error, Source.SourceRange);
1155 return false;
1156}
1157
1162 if (parseMachineMetadata(PFS, MDS))
1163 return true;
1164 }
1165
1168 "use of undefined metadata '!" +
1170 return false;
1171}
1172
1180 if (parseMachineInst(MF, MILoc, CallI))
1181 return true;
1184 Twine(" called global should reference call "
1185 "instruction. Instruction at bb:") +
1187 " is not a call instruction");
1188
1189 auto Callee =
1190 F.getParent()->getValueSymbolTable().lookup(YamlCG.Callee.Value);
1191 if (!Callee)
1192 return error(YamlCG.Callee.SourceRange.Start,
1193 "use of undefined global '" + YamlCG.Callee.Value + "'");
1195 return error(YamlCG.Callee.SourceRange.Start,
1196 "use of non-global value '" + YamlCG.Callee.Value + "'");
1197
1199 }
1200
1201 return false;
1202}
1203
1206 assert(SourceRange.isValid() && "Invalid source range");
1208 bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
1209 *Loc.getPointer() == '\'';
1210
1211
1212 Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
1213 (HasQuote ? 1 : 0));
1214
1215
1217 Error.getFixIts());
1218}
1219
1223
1224
1225
1227 unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
1228 unsigned Column = Error.getColumnNo();
1231
1232
1233
1235 L != E; ++L) {
1236 if (L.line_number() == Line) {
1237 LineStr = *L;
1239 auto Indent = LineStr.find(Error.getLineContents());
1241 Column += Indent;
1242 break;
1243 }
1244 }
1245
1246 return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
1247 Error.getMessage(), LineStr, Error.getRanges(),
1248 Error.getFixIts());
1249}
1250
1253
1255
1256std::unique_ptr
1258 return Impl->parseIRModule(DataLayoutCallback);
1259}
1260
1262 return Impl->parseMachineFunctions(M, MMI);
1263}
1264
1267 return Impl->parseMachineFunctions(M, MMI, &MAM);
1268}
1269
1272 std::function<void(Function &)> ProcessIRFunction) {
1274 if (std::error_code EC = FileOrErr.getError()) {
1276 "Could not open input file: " + EC.message());
1277 return nullptr;
1278 }
1279 return createMIRParser(std::move(FileOrErr.get()), Context,
1280 ProcessIRFunction);
1281}
1282
1283std::unique_ptr
1286 std::function<void(Function &)> ProcessIRFunction) {
1287 auto Filename = Contents->getBufferIdentifier();
1288 if (Context.shouldDiscardValueNames()) {
1293 "Can't read MIR with a Context that discards named Values")));
1294 return nullptr;
1295 }
1296 return std::make_unique(std::make_unique(
1297 std::move(Contents), Filename, Context, ProcessIRFunction));
1298}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
static bool isSSA(const MachineFunction &MF)
Definition MIRParser.cpp:373
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
Definition MIRParser.cpp:201
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.
Definition MIRParser.cpp:1012
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register const TargetRegisterInfo * TRI
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
SI Pre allocate WWM Registers
an instruction to allocate memory on the stack
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 LLVM_ABI 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)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Module * getParent()
Get the module that this global value is contained inside of...
@ ExternalLinkage
Externally visible function.
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
This class implements the parsing of LLVM IR that's embedded inside a MIR file.
Definition MIRParser.cpp:51
bool error(const Twine &Message)
Report an error with the given message at unknown location.
Definition MIRParser.cpp:216
void reportDiagnostic(const SMDiagnostic &Diag)
Definition MIRParser.cpp:234
bool setupRegisterInfo(const PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition MIRParser.cpp:773
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition MIRParser.cpp:682
bool initializeFrameInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition MIRParser.cpp:849
Function * createDummyFunction(StringRef Name, Module &M)
Create an empty function with the given name.
Definition MIRParser.cpp:308
bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const T &Object, int FrameIdx)
Definition MIRParser.cpp:1045
bool initializeMachineFunction(const yaml::MachineFunction &YamlMF, MachineFunction &MF)
Initialize the machine function to the state that's described in the MIR file.
Definition MIRParser.cpp:551
std::unique_ptr< Module > parseIRModule(DataLayoutCallbackTy DataLayoutCallback)
Try to parse the optional LLVM module and the machine functions in the MIR file.
Definition MIRParser.cpp:254
bool initializeJumpTableInfo(PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI)
Definition MIRParser.cpp:1120
bool initializeConstantPool(PerFunctionMIParsingState &PFS, MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF)
Definition MIRParser.cpp:1069
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction)
Definition MIRParser.cpp:205
std::optional< VarExprLoc > parseVarExprLoc(PerFunctionMIParsingState &PFS, const yaml::StringValue &VarStr, const yaml::StringValue &ExprStr, const yaml::StringValue &LocStr)
Definition MIRParser.cpp:1025
bool parseCalledGlobals(PerFunctionMIParsingState &PFS, MachineFunction &MF, const yaml::MachineFunction &YMF)
Definition MIRParser.cpp:1173
bool parseCalleeSavedRegister(PerFunctionMIParsingState &PFS, std::vector< CalleeSavedInfo > &CSIInfo, const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx)
Definition MIRParser.cpp:995
bool parseMachineMetadataNodes(PerFunctionMIParsingState &PFS, MachineFunction &MF, const yaml::MachineFunction &YMF)
Definition MIRParser.cpp:1158
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition MIRParser.cpp:489
bool initializeSaveRestorePoints(PerFunctionMIParsingState &PFS, const std::vector< yaml::SaveRestorePointEntry > &YamlSRPoints, llvm::SaveRestorePoints &SaveRestorePoints)
Definition MIRParser.cpp:1098
bool parseMachineFunction(Module &M, MachineModuleInfo &MMI, ModuleAnalysisManager *FAM)
Parse the machine function in the current YAML document.
Definition MIRParser.cpp:322
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI, ModuleAnalysisManager *FAM=nullptr)
Definition MIRParser.cpp:293
LLVM_ABI MIRParser(std::unique_ptr< MIRParserImpl > Impl)
Definition MIRParser.cpp:1251
LLVM_ABI std::unique_ptr< Module > parseIRModule(DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Parses the optional LLVM IR module in the MIR file.
Definition MIRParser.cpp:1257
LLVM_ABI bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Parses MachineFunctions in the MIR file and add them to the given MachineModuleInfo MMI.
Definition MIRParser.cpp:1261
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)
LLVM_ABI 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)
LLVM_ABI 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.
LLVM_ABI 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 setSavePoints(SaveRestorePoints NewSavePoints)
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.
LLVM_ABI int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
void setRestorePoints(SaveRestorePoints NewRestorePoints)
LLVM_ABI 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 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 setHasEHContTarget(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
LLVM_ABI 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.
LLVM_ABI MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
const TargetMachine & getTarget() const
LLVM_ABI 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,...
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
LLVM_ABI 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
LLVM_ABI 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.
static constexpr size_t npos
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.
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.
virtual yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
virtual bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
unsigned EmitCallSiteInfo
The flag enables call site info production.
unsigned EmitCallGraphSection
Emit section containing call graph metadata.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual void mirFileLoaded(MachineFunction &MF) const
This is called after a .mir file was loaded.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI 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.
A forward iterator which reads text lines from a buffer.
The Input class is used to parse a yaml document into in-memory structs and vectors.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::enable_if_t< has_ScalarEnumerationTraits< T >::value, void > yamlize(IO &io, T &Val, bool, EmptyContext &Ctx)
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)
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;}, AsmParserContext *ParserContext=nullptr)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
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)
auto dyn_cast_or_null(const Y &Val)
DenseMap< MachineBasicBlock *, std::vector< CalleeSavedInfo > > SaveRestorePoints
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI 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.
Definition MIRParser.cpp:1270
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI 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.
Definition MIRParser.cpp:1284
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
@ Sub
Subtraction of integers.
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
LLVM_ABI 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.
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
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)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
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.
Definition MIRParser.cpp:140
DILocalVariable * DIVar
Definition MIRParser.cpp:141
DILocation * DILoc
Definition MIRParser.cpp:143
DIExpression * DIExpr
Definition MIRParser.cpp:142
SmallVector< ConstantInt *, 4 > CalleeTypeIds
Callee type ids.
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.
std::vector< SaveRestorePointEntry > RestorePoints
bool IsCalleeSavedInfoValid
unsigned MaxCallFrameSize
~0u means: not computed yet.
StringValue StackProtector
std::vector< SaveRestorePointEntry > SavePoints
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.