Skip to content

Commit 5fa4b1d

Browse files
authored
[SPARC] Consume tune-cpu directive in the backend (#77195)
This lets the backend read the `tune-cpu` directive that is emitted by the frontend. No changes are needed for clang as it is already emits it.
1 parent 7dd4d28 commit 5fa4b1d

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5172,7 +5172,7 @@ def module_file_info : Flag<["-"], "module-file-info">, Flags<[]>,
51725172
HelpText<"Provide information about a particular module file">;
51735173
def mthumb : Flag<["-"], "mthumb">, Group<m_Group>;
51745174
def mtune_EQ : Joined<["-"], "mtune=">, Group<m_Group>,
5175-
HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
5175+
HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and X86">;
51765176
def multi__module : Flag<["-"], "multi_module">;
51775177
def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
51785178
def multiply__defined : Separate<["-"], "multiply_defined">;

llvm/lib/Target/Sparc/SparcSubtarget.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "SparcSubtarget.h"
1414
#include "Sparc.h"
15+
#include "llvm/ADT/StringRef.h"
1516
#include "llvm/MC/TargetRegistry.h"
1617
#include "llvm/Support/MathExtras.h"
1718

@@ -25,15 +26,18 @@ using namespace llvm;
2526

2627
void SparcSubtarget::anchor() { }
2728

28-
SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
29-
StringRef FS) {
29+
SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(
30+
StringRef CPU, StringRef TuneCPU, StringRef FS) {
3031
// Determine default and user specified characteristics
3132
std::string CPUName = std::string(CPU);
3233
if (CPUName.empty())
3334
CPUName = (Is64Bit) ? "v9" : "v8";
3435

36+
if (TuneCPU.empty())
37+
TuneCPU = CPUName;
38+
3539
// Parse features string.
36-
ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
40+
ParseSubtargetFeatures(CPUName, TuneCPU, FS);
3741

3842
// Popc is a v9-only instruction.
3943
if (!IsV9)
@@ -42,11 +46,12 @@ SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
4246
return *this;
4347
}
4448

45-
SparcSubtarget::SparcSubtarget(const Triple &TT, const std::string &CPU,
46-
const std::string &FS, const TargetMachine &TM,
49+
SparcSubtarget::SparcSubtarget(const StringRef &CPU, const StringRef &TuneCPU,
50+
const StringRef &FS, const TargetMachine &TM,
4751
bool is64Bit)
48-
: SparcGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TargetTriple(TT),
49-
Is64Bit(is64Bit), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
52+
: SparcGenSubtargetInfo(TM.getTargetTriple(), CPU, TuneCPU, FS),
53+
TargetTriple(TM.getTargetTriple()), Is64Bit(is64Bit),
54+
InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
5055
TLInfo(TM, *this), FrameLowering(*this) {}
5156

5257
int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {

llvm/lib/Target/Sparc/SparcSubtarget.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
4444
SparcFrameLowering FrameLowering;
4545

4646
public:
47-
SparcSubtarget(const Triple &TT, const std::string &CPU,
48-
const std::string &FS, const TargetMachine &TM, bool is64bit);
47+
SparcSubtarget(const StringRef &CPU, const StringRef &TuneCPU,
48+
const StringRef &FS, const TargetMachine &TM, bool is64bit);
4949

5050
const SparcInstrInfo *getInstrInfo() const override { return &InstrInfo; }
5151
const TargetFrameLowering *getFrameLowering() const override {
@@ -70,7 +70,9 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
7070
/// ParseSubtargetFeatures - Parses features string setting specified
7171
/// subtarget options. Definition of function is auto generated by tblgen.
7272
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
73-
SparcSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
73+
SparcSubtarget &initializeSubtargetDependencies(StringRef CPU,
74+
StringRef TuneCPU,
75+
StringRef FS);
7476

7577
bool is64Bit() const { return Is64Bit; }
7678

llvm/lib/Target/Sparc/SparcTargetMachine.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,13 @@ SparcTargetMachine::~SparcTargetMachine() = default;
116116
const SparcSubtarget *
117117
SparcTargetMachine::getSubtargetImpl(const Function &F) const {
118118
Attribute CPUAttr = F.getFnAttribute("target-cpu");
119+
Attribute TuneAttr = F.getFnAttribute("tune-cpu");
119120
Attribute FSAttr = F.getFnAttribute("target-features");
120121

121122
std::string CPU =
122123
CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
124+
std::string TuneCPU =
125+
TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
123126
std::string FS =
124127
FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
125128

@@ -137,8 +140,8 @@ SparcTargetMachine::getSubtargetImpl(const Function &F) const {
137140
// creation will depend on the TM and the code generation flags on the
138141
// function that reside in TargetOptions.
139142
resetTargetOptions(F);
140-
I = std::make_unique<SparcSubtarget>(TargetTriple, CPU, FS, *this,
141-
this->is64Bit);
143+
I = std::make_unique<SparcSubtarget>(CPU, TuneCPU, FS, *this,
144+
this->is64Bit);
142145
}
143146
return I.get();
144147
}

0 commit comments

Comments
 (0)