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 20 using namespace llvm; 21 22 AnalysisKey MachineFunctionAnalysis::Key; 23 24 bool 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 32 MachineFunctionAnalysis::Result 33 MachineFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) { 34 auto &Context = F.getContext(); 35 const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(F); 36 auto &MMI = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F) 37 .getCachedResult<MachineModuleAnalysis>(*F.getParent()) 38 ->getMMI(); 39 auto MF = std::make_unique<MachineFunction>( 40 F, *TM, STI, Context.generateMachineFunctionNum(F), MMI); 41 MF->initTargetMachineFunctionInfo(STI); 42 43 // MRI callback for target specific initializations. 44 TM->registerMachineRegisterInfoCallback(*MF); 45 46 return Result(std::move(MF)); 47 } 48