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