Skip to content

Commit f6c4b7f

Browse files
committed
[CodeGen] Port selection dag isel to new pass manager
1 parent 7ff3f97 commit f6c4b7f

File tree

12 files changed

+278
-70
lines changed

12 files changed

+278
-70
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

@@ -513,6 +524,30 @@ class SelectionDAGISel : public MachineFunctionPass {
513524
bool isMorphNodeTo);
514525
};
515526

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

518553
#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/lib/CodeGen/GCRootLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class GCMachineCodeAnalysis : public MachineFunctionPass {
8181

8282
PreservedAnalyses GCLoweringPass::run(Function &F,
8383
FunctionAnalysisManager &FAM) {
84+
if (!F.hasGC())
85+
return PreservedAnalyses::all();
86+
8487
auto &Info = FAM.getResult<GCFunctionAnalysis>(F);
8588

8689
bool Changed = DoLowering(F, Info.getStrategy());

llvm/lib/CodeGen/MachinePassManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ModuleToMachineFunctionPassAdaptor::run(Module &M, ModuleAnalysisManager &AM) {
7979
for (Function &F : M) {
8080
// Do not codegen any 'available_externally' functions at all, they have
8181
// definitions outside the translation unit.
82-
if (F.hasAvailableExternallyLinkage())
82+
if (F.hasAvailableExternallyLinkage() || F.isDeclaration())
8383
continue;
8484

8585
MachineFunction &MF = MMI.getOrCreateMachineFunction(F);

0 commit comments

Comments
 (0)