Index: llvm/trunk/lib/Target/PowerPC/CMakeLists.txt =================================================================== --- llvm/trunk/lib/Target/PowerPC/CMakeLists.txt +++ llvm/trunk/lib/Target/PowerPC/CMakeLists.txt @@ -32,6 +32,7 @@ PPCLoopPreIncPrep.cpp PPCMCInstLower.cpp PPCMachineFunctionInfo.cpp + PPCMachineScheduler.cpp PPCMIPeephole.cpp PPCRegisterInfo.cpp PPCQPXLoadSplat.cpp Index: llvm/trunk/lib/Target/PowerPC/PPC.td =================================================================== --- llvm/trunk/lib/Target/PowerPC/PPC.td +++ llvm/trunk/lib/Target/PowerPC/PPC.td @@ -163,6 +163,12 @@ "Implement mftb using the mfspr instruction">; def FeatureFusion : SubtargetFeature<"fusion", "HasFusion", "true", "Target supports add/load integer fusion.">; +def FeaturePPCPreRASched: + SubtargetFeature<"ppc-prera-sched", "UsePPCPreRASchedStrategy", "true", + "Use PowerPC pre-RA scheduling strategy">; +def FeaturePPCPostRASched: + SubtargetFeature<"ppc-postra-sched", "UsePPCPostRASchedStrategy", "true", + "Use PowerPC post-RA scheduling strategy">; def FeatureFloat128 : SubtargetFeature<"float128", "HasFloat128", "true", "Enable the __float128 data type for IEEE-754R Binary128.", @@ -230,7 +236,7 @@ !listconcat(Power7FeatureList, Power8SpecificFeatures); list Power9SpecificFeatures = [DirectivePwr9, FeatureP9Altivec, FeatureP9Vector, FeatureISA3_0, - FeatureVectorsUseTwoUnits]; + FeatureVectorsUseTwoUnits, FeaturePPCPreRASched, FeaturePPCPostRASched]; list Power9FeatureList = !listconcat(Power8FeatureList, Power9SpecificFeatures); } Index: llvm/trunk/lib/Target/PowerPC/PPCMachineScheduler.h =================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCMachineScheduler.h +++ llvm/trunk/lib/Target/PowerPC/PPCMachineScheduler.h @@ -0,0 +1,42 @@ +//===- PPCMachineScheduler.h - Custom PowerPC MI scheduler --*- 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 +// +//===----------------------------------------------------------------------===// +// +// Custom PowerPC MI scheduler. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_POWERPC_POWERPCMACHINESCHEDULER_H +#define LLVM_LIB_TARGET_POWERPC_POWERPCMACHINESCHEDULER_H + +#include "llvm/CodeGen/MachineScheduler.h" + +namespace llvm { + +/// A MachineSchedStrategy implementation for PowerPC pre RA scheduling. +class PPCPreRASchedStrategy : public GenericScheduler { +public: + PPCPreRASchedStrategy(const MachineSchedContext *C) : + GenericScheduler(C) {} +}; + +/// A MachineSchedStrategy implementation for PowerPC post RA scheduling. +class PPCPostRASchedStrategy : public PostGenericScheduler { +public: + PPCPostRASchedStrategy(const MachineSchedContext *C) : + PostGenericScheduler(C) {} + +protected: + void initialize(ScheduleDAGMI *Dag) override; + SUnit *pickNode(bool &IsTopNode) override; + void enterMBB(MachineBasicBlock *MBB) override; + void leaveMBB() override; +}; + +} // end namespace llvm + +#endif // LLVM_LIB_TARGET_POWERPC_POWERPCMACHINESCHEDULER_H Index: llvm/trunk/lib/Target/PowerPC/PPCMachineScheduler.cpp =================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCMachineScheduler.cpp +++ llvm/trunk/lib/Target/PowerPC/PPCMachineScheduler.cpp @@ -0,0 +1,30 @@ +//===- PPCMachineScheduler.cpp - MI Scheduler for PowerPC -------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +#include "PPCMachineScheduler.h" +using namespace llvm; + +void PPCPostRASchedStrategy::enterMBB(MachineBasicBlock *MBB) { + // Custom PPC PostRA specific behavior here. + PostGenericScheduler::enterMBB(MBB); +} + +void PPCPostRASchedStrategy::leaveMBB() { + // Custom PPC PostRA specific behavior here. + PostGenericScheduler::leaveMBB(); +} + +void PPCPostRASchedStrategy::initialize(ScheduleDAGMI *Dag) { + // Custom PPC PostRA specific initialization here. + PostGenericScheduler::initialize(Dag); +} + +SUnit *PPCPostRASchedStrategy::pickNode(bool &IsTopNode) { + // Custom PPC PostRA specific scheduling here. + return PostGenericScheduler::pickNode(IsTopNode); +} + Index: llvm/trunk/lib/Target/PowerPC/PPCSubtarget.h =================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCSubtarget.h +++ llvm/trunk/lib/Target/PowerPC/PPCSubtarget.h @@ -136,6 +136,8 @@ bool UseLongCalls; bool SecurePlt; bool VectorsUseTwoUnits; + bool UsePPCPreRASchedStrategy; + bool UsePPCPostRASchedStrategy; POPCNTDKind HasPOPCNTD; @@ -268,6 +270,8 @@ bool hasInvariantFunctionDescriptors() const { return HasInvariantFunctionDescriptors; } + bool usePPCPreRASchedStrategy() const { return UsePPCPreRASchedStrategy; } + bool usePPCPostRASchedStrategy() const { return UsePPCPostRASchedStrategy; } bool hasPartwordAtomics() const { return HasPartwordAtomics; } bool hasDirectMove() const { return HasDirectMove; } Index: llvm/trunk/lib/Target/PowerPC/PPCSubtarget.cpp =================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCSubtarget.cpp +++ llvm/trunk/lib/Target/PowerPC/PPCSubtarget.cpp @@ -108,6 +108,8 @@ UseLongCalls = false; SecurePlt = false; VectorsUseTwoUnits = false; + UsePPCPreRASchedStrategy = false; + UsePPCPostRASchedStrategy = false; HasPOPCNTD = POPCNTD_Unavailable; } Index: llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp =================================================================== --- llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp +++ llvm/trunk/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -13,6 +13,7 @@ #include "PPCTargetMachine.h" #include "MCTargetDesc/PPCMCTargetDesc.h" #include "PPC.h" +#include "PPCMachineScheduler.h" #include "PPCSubtarget.h" #include "PPCTargetObjectFile.h" #include "PPCTargetTransformInfo.h" @@ -237,6 +238,23 @@ return CodeModel::Small; } + +static ScheduleDAGInstrs *createPPCMachineScheduler(MachineSchedContext *C) { + ScheduleDAGMILive *DAG = + new ScheduleDAGMILive(C, llvm::make_unique(C)); + // add DAG Mutations here. + DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI)); + return DAG; +} + +static ScheduleDAGInstrs *createPPCPostMachineScheduler( + MachineSchedContext *C) { + ScheduleDAGMI *DAG = + new ScheduleDAGMI(C, llvm::make_unique(C), true); + // add DAG Mutations here. + return DAG; +} + // The FeatureString here is a little subtle. We are modifying the feature // string with what are (currently) non-function specific overrides as it goes // into the LLVMTargetMachine constructor and then using the stored value in the @@ -330,6 +348,20 @@ void addPreRegAlloc() override; void addPreSched2() override; void addPreEmitPass() override; + ScheduleDAGInstrs * + createMachineScheduler(MachineSchedContext *C) const override { + const PPCSubtarget &ST = C->MF->getSubtarget(); + if (ST.usePPCPreRASchedStrategy()) + return createPPCMachineScheduler(C); + return nullptr; + } + ScheduleDAGInstrs * + createPostMachineScheduler(MachineSchedContext *C) const override { + const PPCSubtarget &ST = C->MF->getSubtarget(); + if (ST.usePPCPostRASchedStrategy()) + return createPPCPostMachineScheduler(C); + return nullptr; + } }; } // end anonymous namespace @@ -468,3 +500,13 @@ PPCTargetMachine::getTargetTransformInfo(const Function &F) { return TargetTransformInfo(PPCTTIImpl(this, F)); } + +static MachineSchedRegistry +PPCPreRASchedRegistry("ppc-prera", + "Run PowerPC PreRA specific scheduler", + createPPCMachineScheduler); + +static MachineSchedRegistry +PPCPostRASchedRegistry("ppc-postra", + "Run PowerPC PostRA specific scheduler", + createPPCPostMachineScheduler);