From 6ea0c0a28343b2676baf480db490b5a27fa11d7c Mon Sep 17 00:00:00 2001 From: paperchalice Date: Tue, 30 Apr 2024 09:54:48 +0800 Subject: [NewPM][CodeGen] Add `MachineFunctionAnalysis` (#88610) In new pass system, `MachineFunction` could be an analysis result again, machine module pass can now fetch them from analysis manager. `MachineModuleInfo` no longer owns them. Remove `FreeMachineFunctionPass`, replaced by `InvalidateAnalysisPass`. Now `FreeMachineFunction` is replaced by `InvalidateAnalysisPass`, the workaround in `MachineFunctionPassManager` is no longer needed, there is no difference between `unittests/MIR/PassBuilderCallbacksTest.cpp` and `unittests/IR/PassBuilderCallbacksTest.cpp`. --- llvm/lib/CodeGen/MachineFunctionAnalysis.cpp | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 llvm/lib/CodeGen/MachineFunctionAnalysis.cpp (limited to 'llvm/lib/CodeGen/MachineFunctionAnalysis.cpp') diff --git a/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp b/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp new file mode 100644 index 0000000..519a77c --- /dev/null +++ b/llvm/lib/CodeGen/MachineFunctionAnalysis.cpp @@ -0,0 +1,46 @@ +//===- MachineFunctionAnalysis.cpp ----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains the definitions of the MachineFunctionAnalysis +// members. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/MachineFunctionAnalysis.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineModuleInfo.h" +#include "llvm/Target/TargetMachine.h" + +using namespace llvm; + +AnalysisKey MachineFunctionAnalysis::Key; + +bool MachineFunctionAnalysis::Result::invalidate( + Function &, const PreservedAnalyses &PA, + FunctionAnalysisManager::Invalidator &) { + // Unless it is invalidated explicitly, it should remain preserved. + auto PAC = PA.getChecker(); + return !PAC.preservedWhenStateless(); +} + +MachineFunctionAnalysis::Result +MachineFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) { + auto &Context = F.getContext(); + const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(F); + auto &MMI = FAM.getResult(F) + .getCachedResult(*F.getParent()) + ->getMMI(); + auto MF = std::make_unique( + F, *TM, STI, Context.generateMachineFunctionNum(F), MMI); + MF->initTargetMachineFunctionInfo(STI); + + // MRI callback for target specific initializations. + TM->registerMachineRegisterInfoCallback(*MF); + + return Result(std::move(MF)); +} -- cgit v1.1