Skip to content

Commit d2cdc8a

Browse files
authored
[NewPM][CodeGen] Port selection dag isel to new pass manager (#83567)
Port selection dag isel to new pass manager. Only `AMDGPU` and `X86` support new pass version. `-verify-machineinstrs` in new pass manager belongs to verify instrumentation, it is enabled by default.
1 parent 0310f7f commit d2cdc8a

File tree

122 files changed

+783
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+783
-280
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/CodeGen/ISDOpcodes.h"
3030
#include "llvm/CodeGen/MachineFunction.h"
3131
#include "llvm/CodeGen/MachineMemOperand.h"
32+
#include "llvm/CodeGen/MachinePassManager.h"
3233
#include "llvm/CodeGen/SelectionDAGNodes.h"
3334
#include "llvm/CodeGen/ValueTypes.h"
3435
#include "llvm/CodeGenTypes/MachineValueType.h"
@@ -230,6 +231,7 @@ class SelectionDAG {
230231
const TargetLibraryInfo *LibInfo = nullptr;
231232
const FunctionVarLocs *FnVarLocs = nullptr;
232233
MachineFunction *MF;
234+
MachineFunctionAnalysisManager *MFAM = nullptr;
233235
Pass *SDAGISelPass = nullptr;
234236
LLVMContext *Context;
235237
CodeGenOptLevel OptLevel;
@@ -459,6 +461,15 @@ class SelectionDAG {
459461
UniformityInfo *UA, ProfileSummaryInfo *PSIin,
460462
BlockFrequencyInfo *BFIin, FunctionVarLocs const *FnVarLocs);
461463

464+
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE,
465+
MachineFunctionAnalysisManager &AM,
466+
const TargetLibraryInfo *LibraryInfo, UniformityInfo *UA,
467+
ProfileSummaryInfo *PSIin, BlockFrequencyInfo *BFIin,
468+
FunctionVarLocs const *FnVarLocs) {
469+
init(NewMF, NewORE, nullptr, LibraryInfo, UA, PSIin, BFIin, FnVarLocs);
470+
MFAM = &AM;
471+
}
472+
462473
void setFunctionLoweringInfo(FunctionLoweringInfo * FuncInfo) {
463474
FLI = FuncInfo;
464475
}
@@ -469,6 +480,7 @@ class SelectionDAG {
469480

470481
MachineFunction &getMachineFunction() const { return *MF; }
471482
const Pass *getPass() const { return SDAGISelPass; }
483+
MachineFunctionAnalysisManager *getMFAM() { return MFAM; }
472484

473485
CodeGenOptLevel getOptLevel() const { return OptLevel; }
474486
const DataLayout &getDataLayout() const { return MF->getDataLayout(); }

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_CODEGEN_SELECTIONDAGISEL_H
1616

1717
#include "llvm/CodeGen/MachineFunctionPass.h"
18+
#include "llvm/CodeGen/MachinePassManager.h"
1819
#include "llvm/CodeGen/SelectionDAG.h"
1920
#include "llvm/IR/BasicBlock.h"
2021
#include <memory>
@@ -24,21 +25,23 @@ class AAResults;
2425
class AssumptionCache;
2526
class TargetInstrInfo;
2627
class TargetMachine;
28+
class SSPLayoutInfo;
2729
class SelectionDAGBuilder;
2830
class SDValue;
2931
class MachineRegisterInfo;
3032
class MachineFunction;
3133
class OptimizationRemarkEmitter;
3234
class TargetLowering;
3335
class TargetLibraryInfo;
36+
class TargetTransformInfo;
3437
class FunctionLoweringInfo;
3538
class SwiftErrorValueTracking;
3639
class GCFunctionInfo;
3740
class ScheduleDAGSDNodes;
3841

3942
/// SelectionDAGISel - This is the common base class used for SelectionDAG-based
4043
/// pattern-matching instruction selectors.
41-
class SelectionDAGISel : public MachineFunctionPass {
44+
class SelectionDAGISel {
4245
public:
4346
TargetMachine &TM;
4447
const TargetLibraryInfo *LibInfo;
@@ -51,6 +54,10 @@ class SelectionDAGISel : public MachineFunctionPass {
5154
AAResults *AA = nullptr;
5255
AssumptionCache *AC = nullptr;
5356
GCFunctionInfo *GFI = nullptr;
57+
SSPLayoutInfo *SP = nullptr;
58+
#ifndef NDEBUG
59+
TargetTransformInfo *TTI = nullptr;
60+
#endif
5461
CodeGenOptLevel OptLevel;
5562
const TargetInstrInfo *TII;
5663
const TargetLowering *TLI;
@@ -67,16 +74,18 @@ class SelectionDAGISel : public MachineFunctionPass {
6774
/// functions. Storing the filter result here so that we only need to do the
6875
/// filtering once.
6976
bool MatchFilterFuncName = false;
77+
StringRef FuncName;
7078

71-
explicit SelectionDAGISel(char &ID, TargetMachine &tm,
79+
explicit SelectionDAGISel(TargetMachine &tm,
7280
CodeGenOptLevel OL = CodeGenOptLevel::Default);
73-
~SelectionDAGISel() override;
81+
~SelectionDAGISel();
7482

7583
const TargetLowering *getTargetLowering() const { return TLI; }
7684

77-
void getAnalysisUsage(AnalysisUsage &AU) const override;
85+
void initializeAnalysisResults(MachineFunctionAnalysisManager &MFAM);
86+
void initializeAnalysisResults(MachineFunctionPass &MFP);
7887

79-
bool runOnMachineFunction(MachineFunction &MF) override;
88+
virtual bool runOnMachineFunction(MachineFunction &mf);
8089

8190
virtual void emitFunctionEntryCode() {}
8291

@@ -517,6 +526,30 @@ class SelectionDAGISel : public MachineFunctionPass {
517526
bool isMorphNodeTo);
518527
};
519528

529+
class SelectionDAGISelLegacy : public MachineFunctionPass {
530+
std::unique_ptr<SelectionDAGISel> Selector;
531+
532+
public:
533+
SelectionDAGISelLegacy(char &ID, std::unique_ptr<SelectionDAGISel> S);
534+
535+
~SelectionDAGISelLegacy() override = default;
536+
537+
void getAnalysisUsage(AnalysisUsage &AU) const override;
538+
539+
bool runOnMachineFunction(MachineFunction &MF) override;
540+
};
541+
542+
class SelectionDAGISelPass : public PassInfoMixin<SelectionDAGISelPass> {
543+
std::unique_ptr<SelectionDAGISel> Selector;
544+
545+
protected:
546+
SelectionDAGISelPass(std::unique_ptr<SelectionDAGISel> Selector)
547+
: Selector(std::move(Selector)) {}
548+
549+
public:
550+
PreservedAnalyses run(MachineFunction &MF,
551+
MachineFunctionAnalysisManager &MFAM);
552+
};
520553
}
521554

522555
#endif /* LLVM_CODEGEN_SELECTIONDAGISEL_H */

llvm/include/llvm/CodeGen/StackProtector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class StackProtector : public FunctionPass {
109109

110110
StackProtector();
111111

112+
SSPLayoutInfo &getLayoutInfo() { return LayoutInfo; }
113+
112114
void getAnalysisUsage(AnalysisUsage &AU) const override;
113115

114116
// Return true if StackProtector is supposed to be handled by SelectionDAG.

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
140140
}
141141

142142
protected:
143+
template <typename PassT>
144+
using has_required_t = decltype(std::declval<PassT &>().isRequired());
145+
143146
template <typename PassT>
144147
using is_module_pass_t = decltype(std::declval<PassT &>().run(
145148
std::declval<Module &>(), std::declval<ModuleAnalysisManager &>()));
@@ -170,8 +173,10 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
170173
static_assert((is_detected<is_function_pass_t, PassT>::value ||
171174
is_detected<is_module_pass_t, PassT>::value) &&
172175
"Only module pass and function pass are supported.");
173-
174-
if (!PB.runBeforeAdding(Name))
176+
bool Required = false;
177+
if constexpr (is_detected<has_required_t, PassT>::value)
178+
Required = PassT::isRequired();
179+
if (!PB.runBeforeAdding(Name) && !Required)
175180
return;
176181

177182
// Add Function Pass

0 commit comments

Comments
 (0)