21
21
#include " llvm/CodeGen/MachineConstantPool.h"
22
22
#include " llvm/CodeGen/MachineFrameInfo.h"
23
23
#include " llvm/CodeGen/MachineFunction.h"
24
+ #include " llvm/CodeGen/MachineFunctionAnalysis.h"
24
25
#include " llvm/CodeGen/MachineModuleInfo.h"
25
26
#include " llvm/CodeGen/MachineRegisterInfo.h"
26
27
#include " llvm/CodeGen/TargetFrameLowering.h"
@@ -97,13 +98,15 @@ class MIRParserImpl {
97
98
// / Create an empty function with the given name.
98
99
Function *createDummyFunction (StringRef Name, Module &M);
99
100
100
- bool parseMachineFunctions (Module &M, MachineModuleInfo &MMI);
101
+ bool parseMachineFunctions (Module &M, MachineModuleInfo &MMI,
102
+ ModuleAnalysisManager *FAM = nullptr );
101
103
102
104
// / Parse the machine function in the current YAML document.
103
105
// /
104
106
// /
105
107
// / Return true if an error occurred.
106
- bool parseMachineFunction (Module &M, MachineModuleInfo &MMI);
108
+ bool parseMachineFunction (Module &M, MachineModuleInfo &MMI,
109
+ ModuleAnalysisManager *FAM);
107
110
108
111
// / Initialize the machine function to the state that's described in the MIR
109
112
// / file.
@@ -275,13 +278,14 @@ MIRParserImpl::parseIRModule(DataLayoutCallbackTy DataLayoutCallback) {
275
278
return M;
276
279
}
277
280
278
- bool MIRParserImpl::parseMachineFunctions (Module &M, MachineModuleInfo &MMI) {
281
+ bool MIRParserImpl::parseMachineFunctions (Module &M, MachineModuleInfo &MMI,
282
+ ModuleAnalysisManager *MAM) {
279
283
if (NoMIRDocuments)
280
284
return false ;
281
285
282
286
// Parse the machine functions.
283
287
do {
284
- if (parseMachineFunction (M, MMI))
288
+ if (parseMachineFunction (M, MMI, MAM ))
285
289
return true ;
286
290
In.nextDocument ();
287
291
} while (In.setCurrentDocument ());
@@ -303,7 +307,8 @@ Function *MIRParserImpl::createDummyFunction(StringRef Name, Module &M) {
303
307
return F;
304
308
}
305
309
306
- bool MIRParserImpl::parseMachineFunction (Module &M, MachineModuleInfo &MMI) {
310
+ bool MIRParserImpl::parseMachineFunction (Module &M, MachineModuleInfo &MMI,
311
+ ModuleAnalysisManager *MAM) {
307
312
// Parse the yaml.
308
313
yaml::MachineFunction YamlMF;
309
314
yaml::EmptyContext Ctx;
@@ -327,14 +332,28 @@ bool MIRParserImpl::parseMachineFunction(Module &M, MachineModuleInfo &MMI) {
327
332
" ' isn't defined in the provided LLVM IR" );
328
333
}
329
334
}
330
- if (MMI.getMachineFunction (*F) != nullptr )
331
- return error (Twine (" redefinition of machine function '" ) + FunctionName +
332
- " '" );
333
335
334
- // Create the MachineFunction.
335
- MachineFunction &MF = MMI.getOrCreateMachineFunction (*F);
336
- if (initializeMachineFunction (YamlMF, MF))
337
- return true ;
336
+ if (!MAM) {
337
+ if (MMI.getMachineFunction (*F) != nullptr )
338
+ return error (Twine (" redefinition of machine function '" ) + FunctionName +
339
+ " '" );
340
+
341
+ // Create the MachineFunction.
342
+ MachineFunction &MF = MMI.getOrCreateMachineFunction (*F);
343
+ if (initializeMachineFunction (YamlMF, MF))
344
+ return true ;
345
+ } else {
346
+ auto &FAM =
347
+ MAM->getResult <FunctionAnalysisManagerModuleProxy>(M).getManager ();
348
+ if (FAM.getCachedResult <MachineFunctionAnalysis>(*F))
349
+ return error (Twine (" redefinition of machine function '" ) + FunctionName +
350
+ " '" );
351
+
352
+ // Create the MachineFunction.
353
+ MachineFunction &MF = FAM.getResult <MachineFunctionAnalysis>(*F).getMF ();
354
+ if (initializeMachineFunction (YamlMF, MF))
355
+ return true ;
356
+ }
338
357
339
358
return false ;
340
359
}
@@ -1101,6 +1120,11 @@ bool MIRParser::parseMachineFunctions(Module &M, MachineModuleInfo &MMI) {
1101
1120
return Impl->parseMachineFunctions (M, MMI);
1102
1121
}
1103
1122
1123
+ bool MIRParser::parseMachineFunctions (Module &M, ModuleAnalysisManager &MAM) {
1124
+ auto &MMI = MAM.getResult <MachineModuleAnalysis>(M).getMMI ();
1125
+ return Impl->parseMachineFunctions (M, MMI, &MAM);
1126
+ }
1127
+
1104
1128
std::unique_ptr<MIRParser> llvm::createMIRParserFromFile (
1105
1129
StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
1106
1130
std::function<void (Function &)> ProcessIRFunction) {
0 commit comments