Skip to content

Commit 607d900

Browse files
committed
[CodeGen] Port selection dag isel to new pass manager
1 parent 5f77461 commit 607d900

File tree

10 files changed

+274
-69
lines changed

10 files changed

+274
-69
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"
@@ -229,6 +230,7 @@ class SelectionDAG {
229230
const TargetLibraryInfo *LibInfo = nullptr;
230231
const FunctionVarLocs *FnVarLocs = nullptr;
231232
MachineFunction *MF;
233+
MachineFunctionAnalysisManager *MFAM = nullptr;
232234
Pass *SDAGISelPass = nullptr;
233235
LLVMContext *Context;
234236
CodeGenOptLevel OptLevel;
@@ -458,6 +460,15 @@ class SelectionDAG {
458460
UniformityInfo *UA, ProfileSummaryInfo *PSIin,
459461
BlockFrequencyInfo *BFIin, FunctionVarLocs const *FnVarLocs);
460462

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

469480
MachineFunction &getMachineFunction() const { return *MF; }
470481
const Pass *getPass() const { return SDAGISelPass; }
482+
MachineFunctionAnalysisManager *getMFAM() { return MFAM; }
471483

472484
const DataLayout &getDataLayout() const { return MF->getDataLayout(); }
473485
const TargetMachine &getTarget() const { return TM; }

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 40 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,8 @@ class SelectionDAGISel : public MachineFunctionPass {
5154
AAResults *AA = nullptr;
5255
AssumptionCache *AC = nullptr;
5356
GCFunctionInfo *GFI = nullptr;
57+
SSPLayoutInfo *SP = nullptr;
58+
TargetTransformInfo *TTI = nullptr;
5459
CodeGenOptLevel OptLevel;
5560
const TargetInstrInfo *TII;
5661
const TargetLowering *TLI;
@@ -67,16 +72,22 @@ class SelectionDAGISel : public MachineFunctionPass {
6772
/// functions. Storing the filter result here so that we only need to do the
6873
/// filtering once.
6974
bool MatchFilterFuncName = false;
75+
StringRef FuncName;
7076

71-
explicit SelectionDAGISel(char &ID, TargetMachine &tm,
77+
explicit SelectionDAGISel(TargetMachine &tm,
7278
CodeGenOptLevel OL = CodeGenOptLevel::Default);
73-
~SelectionDAGISel() override;
79+
~SelectionDAGISel();
7480

7581
const TargetLowering *getTargetLowering() const { return TLI; }
7682

77-
void getAnalysisUsage(AnalysisUsage &AU) const override;
83+
void initialize(MachineFunctionAnalysisManager &MFAM);
84+
void initialize(MachineFunctionPass &MFP);
7885

79-
bool runOnMachineFunction(MachineFunction &MF) override;
86+
/// Subclasses can override this function to set Subtarget
87+
/// before running the pass.
88+
virtual void prepare(MachineFunction &MF) {}
89+
90+
bool runOnMachineFunction(MachineFunction &mf, bool Skipped);
8091

8192
virtual void emitFunctionEntryCode() {}
8293

@@ -517,6 +528,30 @@ class SelectionDAGISel : public MachineFunctionPass {
517528
bool isMorphNodeTo);
518529
};
519530

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

522557
#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.

0 commit comments

Comments
 (0)