1//===- MachineFunctionAnalysis.cpp ----------------------------------------===//
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 contains the definitions of the MachineFunctionAnalysis
10// members.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/MachineFunctionAnalysis.h"
15#include "llvm/CodeGen/MachineFunction.h"
16#include "llvm/CodeGen/MachineModuleInfo.h"
17#include "llvm/IR/Function.h"
18#include "llvm/Target/TargetMachine.h"
19
20using namespace llvm;
21
22AnalysisKey MachineFunctionAnalysis::Key;
23
24bool MachineFunctionAnalysis::Result::invalidate(
25 Function &, const PreservedAnalyses &PA,
26 FunctionAnalysisManager::Invalidator &) {
27 // Unless it is invalidated explicitly, it should remain preserved.
28 auto PAC = PA.getChecker<MachineFunctionAnalysis>();
29 return !PAC.preservedWhenStateless();
30}
31
32MachineFunctionAnalysis::Result
33MachineFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
34 auto &Context = F.getContext();
35 const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(F);
36 auto &MMI = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(IR&: F)
37 .getCachedResult<MachineModuleAnalysis>(IR&: *F.getParent())
38 ->getMMI();
39 auto MF = std::make_unique<MachineFunction>(
40 args&: F, args: *TM, args: STI, args: Context.generateMachineFunctionNum(F), args&: MMI);
41 MF->initTargetMachineFunctionInfo(STI);
42
43 // MRI callback for target specific initializations.
44 TM->registerMachineRegisterInfoCallback(MF&: *MF);
45
46 return Result(std::move(MF));
47}
48