[llvm] 50b26de - [SystemZ] Add support for tune-cpu attribute
Kai Nacke via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 30 09:51:05 PDT 2022
Author: Kai Nacke
Date: 2022-06-30T12:50:11-04:00
New Revision: 50b26de3c528bf3316127f11cb5d4835fb9fa4f8
URL: https://github.com/llvm/llvm-project/commit/50b26de3c528bf3316127f11cb5d4835fb9fa4f8
DIFF: https://github.com/llvm/llvm-project/commit/50b26de3c528bf3316127f11cb5d4835fb9fa4f8.diff
LOG: [SystemZ] Add support for tune-cpu attribute
clang (like gcc) has the `-mtune=` command line option. This option
adds the `"tune-cpu"` attribute to a function. The intended functionality
is that the scheduling model of that cpu is used. E.g. `-mtune=z15 -march=z14`
generates only instructions supported on z14 but uses the scheduling model
of z15 for it.
This PR adds the infrastructure to support this.
Reviewed By: uweigand
Differential Revision: https://reviews.llvm.org/D128910
Added:
Modified:
llvm/lib/Target/SystemZ/SystemZSubtarget.cpp
llvm/lib/Target/SystemZ/SystemZSubtarget.h
llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp b/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp
index 75c0d454d9047..f6889035b654c 100644
--- a/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp
@@ -27,13 +27,14 @@ static cl::opt<bool> UseSubRegLiveness(
// Pin the vtable to this file.
void SystemZSubtarget::anchor() {}
-SystemZSubtarget &
-SystemZSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
- StringRef CPUName = CPU;
- if (CPUName.empty())
- CPUName = "generic";
+SystemZSubtarget &SystemZSubtarget::initializeSubtargetDependencies(
+ StringRef CPU, StringRef TuneCPU, StringRef FS) {
+ if (CPU.empty())
+ CPU = "generic";
+ if (TuneCPU.empty())
+ TuneCPU = CPU;
// Parse features string.
- ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
+ ParseSubtargetFeatures(CPU, TuneCPU, FS);
// -msoft-float implies -mno-vx.
if (HasSoftFloat)
@@ -64,9 +65,10 @@ SystemZSubtarget::initializeSpecialRegisters() {
}
SystemZSubtarget::SystemZSubtarget(const Triple &TT, const std::string &CPU,
+ const std::string &TuneCPU,
const std::string &FS,
const TargetMachine &TM)
- : SystemZGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
+ : SystemZGenSubtargetInfo(TT, CPU, TuneCPU, FS),
HasDistinctOps(false), HasLoadStoreOnCond(false), HasHighWord(false),
HasFPExtension(false), HasPopulationCount(false),
HasMessageSecurityAssist3(false), HasMessageSecurityAssist4(false),
@@ -88,8 +90,8 @@ SystemZSubtarget::SystemZSubtarget(const Triple &TT, const std::string &CPU,
HasResetDATProtection(false), HasProcessorActivityInstrumentation(false),
HasSoftFloat(false), TargetTriple(TT),
SpecialRegisters(initializeSpecialRegisters()),
- InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
- FrameLowering(SystemZFrameLowering::create(*this)) {}
+ InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
+ TLInfo(TM, *this), FrameLowering(SystemZFrameLowering::create(*this)) {}
bool SystemZSubtarget::enableSubRegLiveness() const {
return UseSubRegLiveness;
diff --git a/llvm/lib/Target/SystemZ/SystemZSubtarget.h b/llvm/lib/Target/SystemZ/SystemZSubtarget.h
index 98f7094fcb48d..cd16c19f9bfa4 100644
--- a/llvm/lib/Target/SystemZ/SystemZSubtarget.h
+++ b/llvm/lib/Target/SystemZ/SystemZSubtarget.h
@@ -84,12 +84,14 @@ class SystemZSubtarget : public SystemZGenSubtargetInfo {
std::unique_ptr<const SystemZFrameLowering> FrameLowering;
SystemZSubtarget &initializeSubtargetDependencies(StringRef CPU,
+ StringRef TuneCPU,
StringRef FS);
SystemZCallingConventionRegisters *initializeSpecialRegisters();
public:
SystemZSubtarget(const Triple &TT, const std::string &CPU,
- const std::string &FS, const TargetMachine &TM);
+ const std::string &TuneCPU, const std::string &FS,
+ const TargetMachine &TM);
SystemZCallingConventionRegisters *getSpecialRegisters() const {
assert(SpecialRegisters && "Unsupported SystemZ calling convention");
diff --git a/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp b/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
index d571c17ee1fba..31f8ee2f894d0 100644
--- a/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
@@ -187,10 +187,13 @@ SystemZTargetMachine::~SystemZTargetMachine() = default;
const SystemZSubtarget *
SystemZTargetMachine::getSubtargetImpl(const Function &F) const {
Attribute CPUAttr = F.getFnAttribute("target-cpu");
+ Attribute TuneAttr = F.getFnAttribute("tune-cpu");
Attribute FSAttr = F.getFnAttribute("target-features");
std::string CPU =
CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
+ std::string TuneCPU =
+ TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
std::string FS =
FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
@@ -202,13 +205,14 @@ SystemZTargetMachine::getSubtargetImpl(const Function &F) const {
if (softFloat)
FS += FS.empty() ? "+soft-float" : ",+soft-float";
- auto &I = SubtargetMap[CPU + FS];
+ auto &I = SubtargetMap[CPU + TuneCPU + FS];
if (!I) {
// This needs to be done before we create a new subtarget since any
// creation will depend on the TM and the code generation flags on the
// function that reside in TargetOptions.
resetTargetOptions(F);
- I = std::make_unique<SystemZSubtarget>(TargetTriple, CPU, FS, *this);
+ I = std::make_unique<SystemZSubtarget>(TargetTriple, CPU, TuneCPU, FS,
+ *this);
}
return I.get();
More information about the llvm-commits
mailing list