|
| 1 | +//===- FunctionToMachineFunctionAnalysis.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 FunctionToMachineFunctionAnalysis |
| 10 | +// members. |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#include "llvm/CodeGen/FunctionToMachineFunctionAnalysis.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 FunctionToMachineFunctionAnalysis::Key; |
| 22 | + |
| 23 | +bool FunctionToMachineFunctionAnalysis::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<FunctionToMachineFunctionAnalysis>(); |
| 28 | + return !PAC.preservedWhenStateless(); |
| 29 | +} |
| 30 | + |
| 31 | +FunctionToMachineFunctionAnalysis::Result |
| 32 | +FunctionToMachineFunctionAnalysis::run(Function &F, |
| 33 | + 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 | +} |
0 commit comments