-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[NewPM][CodeGen] Add MachineFunctionAnalysis
#88610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//===- llvm/CodeGen/MachineFunctionAnalysis.h -------------------*- C++ -*-===// | ||
// | ||
// 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 declares the MachineFunctionAnalysis class. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CODEGEN_MACHINEFUNCTIONANALYSIS | ||
#define LLVM_CODEGEN_MACHINEFUNCTIONANALYSIS | ||
|
||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
|
||
class MachineFunction; | ||
class LLVMTargetMachine; | ||
|
||
/// This analysis create MachineFunction for given Function. | ||
/// To release the MachineFunction, users should invalidate it explicitly. | ||
class MachineFunctionAnalysis | ||
: public AnalysisInfoMixin<MachineFunctionAnalysis> { | ||
friend AnalysisInfoMixin<MachineFunctionAnalysis>; | ||
|
||
static AnalysisKey Key; | ||
|
||
const LLVMTargetMachine *TM; | ||
|
||
public: | ||
class Result { | ||
std::unique_ptr<MachineFunction> MF; | ||
|
||
public: | ||
Result(std::unique_ptr<MachineFunction> MF) : MF(std::move(MF)) {} | ||
MachineFunction &getMF() { return *MF; }; | ||
bool invalidate(Function &, const PreservedAnalyses &PA, | ||
FunctionAnalysisManager::Invalidator &); | ||
}; | ||
|
||
MachineFunctionAnalysis(const LLVMTargetMachine *TM) : TM(TM){}; | ||
Result run(Function &F, FunctionAnalysisManager &FAM); | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_CODEGEN_MachineFunctionAnalysis |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,15 @@ bool MachineFunctionAnalysisManagerModuleProxy::Result::invalidate( | |
ModuleAnalysisManager::Invalidator &Inv); | ||
extern template class InnerAnalysisManagerProxy<MachineFunctionAnalysisManager, | ||
Module>; | ||
using MachineFunctionAnalysisManagerFunctionProxy = | ||
InnerAnalysisManagerProxy<MachineFunctionAnalysisManager, Function>; | ||
|
||
template <> | ||
bool MachineFunctionAnalysisManagerFunctionProxy::Result::invalidate( | ||
Function &F, const PreservedAnalyses &PA, | ||
FunctionAnalysisManager::Invalidator &Inv); | ||
extern template class InnerAnalysisManagerProxy<MachineFunctionAnalysisManager, | ||
Function>; | ||
|
||
extern template class OuterAnalysisManagerProxy<ModuleAnalysisManager, | ||
MachineFunction>; | ||
|
@@ -129,16 +138,6 @@ class FunctionAnalysisManagerMachineFunctionProxy | |
Arg.FAM = nullptr; | ||
} | ||
|
||
~Result() { | ||
// FAM is cleared in a moved from state where there is nothing to do. | ||
if (!FAM) | ||
return; | ||
|
||
// Clear out the analysis manager if we're being destroyed -- it means we | ||
// didn't even see an invalidate call when we got invalidated. | ||
FAM->clear(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes double free. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you know why? I know that the analysis managers have to be declared in a specific order due to these sorts of things. does this still occur even with the following order:
? I haven't thought too hard about whether or not this is actually required (meaning maybe we can't just remove this code for correctness)... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be the circular reference between Consider: MachineFunctionAnalysisManager MFAM;
// ...
FunctionAnalysisManager FAM;
// Fetch some analysis proxies
FAM.clear();
MFAM.clear();
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah this code was copied from |
||
Result &operator=(Result &&RHS) { | ||
FAM = RHS.FAM; | ||
// We have to null out the analysis manager in the moved-from state | ||
|
@@ -187,18 +186,18 @@ class FunctionAnalysisManagerMachineFunctionProxy | |
FunctionAnalysisManager *FAM; | ||
}; | ||
|
||
class ModuleToMachineFunctionPassAdaptor | ||
: public PassInfoMixin<ModuleToMachineFunctionPassAdaptor> { | ||
class FunctionToMachineFunctionPassAdaptor | ||
: public PassInfoMixin<FunctionToMachineFunctionPassAdaptor> { | ||
public: | ||
using PassConceptT = | ||
detail::PassConcept<MachineFunction, MachineFunctionAnalysisManager>; | ||
|
||
explicit ModuleToMachineFunctionPassAdaptor( | ||
explicit FunctionToMachineFunctionPassAdaptor( | ||
std::unique_ptr<PassConceptT> Pass) | ||
: Pass(std::move(Pass)) {} | ||
|
||
/// Runs the function pass across every function in the module. | ||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); | ||
/// Runs the function pass across every function in the function. | ||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); | ||
void printPipeline(raw_ostream &OS, | ||
function_ref<StringRef(StringRef)> MapClassName2PassName); | ||
|
||
|
@@ -209,14 +208,14 @@ class ModuleToMachineFunctionPassAdaptor | |
}; | ||
|
||
template <typename MachineFunctionPassT> | ||
ModuleToMachineFunctionPassAdaptor | ||
createModuleToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass) { | ||
FunctionToMachineFunctionPassAdaptor | ||
createFunctionToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass) { | ||
using PassModelT = detail::PassModel<MachineFunction, MachineFunctionPassT, | ||
MachineFunctionAnalysisManager>; | ||
// Do not use make_unique, it causes too many template instantiations, | ||
// causing terrible compile times. | ||
return ModuleToMachineFunctionPassAdaptor( | ||
std::unique_ptr<ModuleToMachineFunctionPassAdaptor::PassConceptT>( | ||
return FunctionToMachineFunctionPassAdaptor( | ||
std::unique_ptr<FunctionToMachineFunctionPassAdaptor::PassConceptT>( | ||
new PassModelT(std::forward<MachineFunctionPassT>(Pass)))); | ||
} | ||
|
||
|
@@ -244,6 +243,10 @@ extern template class PassManager<MachineFunction>; | |
/// Convenience typedef for a pass manager over functions. | ||
using MachineFunctionPassManager = PassManager<MachineFunction>; | ||
|
||
/// Returns the minimum set of Analyses that all machine function passes must | ||
/// preserve. | ||
PreservedAnalyses getMachineFunctionPassPreservedAnalyses(); | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_CODEGEN_MACHINEPASSMANAGER_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ DeadMachineInstructionElimPass::run(MachineFunction &MF, | |
MachineFunctionAnalysisManager &) { | ||
if (!DeadMachineInstructionElimImpl().runImpl(MF)) | ||
return PreservedAnalyses::all(); | ||
PreservedAnalyses PA; | ||
PreservedAnalyses PA = getMachineFunctionPassPreservedAnalyses(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should have an assert in the function -> machine function adaptor that function analyses were not invalidated, but can do that in a followup patch |
||
PA.preserveSet<CFGAnalyses>(); | ||
return PA; | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this name is confusing because we have
MachineFunctionAnalysisManager
which is at a different levelbut I'm not sure of a better name :)