Skip to content

Commit c11cff5

Browse files
AlexisPerryyuxuanchen1997
authored andcommitted
Add basic -mtune support (#98517)
Initial implementation for the -mtune flag in Flang. This PR is a clean version of PR #96688, which is a re-land of PR #95043
1 parent 8cfdf33 commit c11cff5

File tree

26 files changed

+186
-14
lines changed

26 files changed

+186
-14
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5456,6 +5456,7 @@ def module_file_info : Flag<["-"], "module-file-info">, Flags<[]>,
54565456
HelpText<"Provide information about a particular module file">;
54575457
def mthumb : Flag<["-"], "mthumb">, Group<m_Group>;
54585458
def mtune_EQ : Joined<["-"], "mtune=">, Group<m_Group>,
5459+
Visibility<[ClangOption, FlangOption]>,
54595460
HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and X86">;
54605461
def multi__module : Flag<["-"], "multi_module">;
54615462
def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6783,9 +6784,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, Group<Action_Group>,
67836784

67846785
let Visibility = [CC1Option, CC1AsOption] in {
67856786

6786-
def tune_cpu : Separate<["-"], "tune-cpu">,
6787-
HelpText<"Tune for a specific cpu type">,
6788-
MarshallingInfoString<TargetOpts<"TuneCPU">>;
67896787
def target_abi : Separate<["-"], "target-abi">,
67906788
HelpText<"Target a particular ABI type">,
67916789
MarshallingInfoString<TargetOpts<"ABI">>;
@@ -6812,6 +6810,9 @@ def darwin_target_variant_triple : Separate<["-"], "darwin-target-variant-triple
68126810

68136811
let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
68146812

6813+
def tune_cpu : Separate<["-"], "tune-cpu">,
6814+
HelpText<"Tune for a specific cpu type">,
6815+
MarshallingInfoString<TargetOpts<"TuneCPU">>;
68156816
def target_cpu : Separate<["-"], "target-cpu">,
68166817
HelpText<"Target a specific cpu type">,
68176818
MarshallingInfoString<TargetOpts<"CPU">>;

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/Frontend/Debug/Options.h"
1616
#include "llvm/Support/FileSystem.h"
1717
#include "llvm/Support/Path.h"
18+
#include "llvm/TargetParser/Host.h"
1819
#include "llvm/TargetParser/RISCVISAInfo.h"
1920
#include "llvm/TargetParser/RISCVTargetParser.h"
2021

@@ -419,6 +420,13 @@ void Flang::addTargetOptions(const ArgList &Args,
419420
}
420421

421422
// TODO: Add target specific flags, ABI, mtune option etc.
423+
if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
424+
CmdArgs.push_back("-tune-cpu");
425+
if (A->getValue() == StringRef{"native"})
426+
CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
427+
else
428+
CmdArgs.push_back(A->getValue());
429+
}
422430
}
423431

424432
void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs,
@@ -815,7 +823,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
815823
case CodeGenOptions::FramePointerKind::None:
816824
FPKeepKindStr = "-mframe-pointer=none";
817825
break;
818-
case CodeGenOptions::FramePointerKind::Reserved:
826+
case CodeGenOptions::FramePointerKind::Reserved:
819827
FPKeepKindStr = "-mframe-pointer=reserved";
820828
break;
821829
case CodeGenOptions::FramePointerKind::NonLeaf:

flang/include/flang/Frontend/TargetOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class TargetOptions {
3232
/// If given, the name of the target CPU to generate code for.
3333
std::string cpu;
3434

35+
/// If given, the name of the target CPU to tune code for.
36+
std::string cpuToTuneFor;
37+
3538
/// The list of target specific features to enable or disable, as written on
3639
/// the command line.
3740
std::vector<std::string> featuresAsWritten;

flang/include/flang/Lower/Bridge.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ class LoweringBridge {
6565
const Fortran::lower::LoweringOptions &loweringOptions,
6666
const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
6767
const Fortran::common::LanguageFeatureControl &languageFeatures,
68-
const llvm::TargetMachine &targetMachine) {
68+
const llvm::TargetMachine &targetMachine, llvm::StringRef tuneCPU) {
6969
return LoweringBridge(ctx, semanticsContext, defaultKinds, intrinsics,
7070
targetCharacteristics, allCooked, triple, kindMap,
7171
loweringOptions, envDefaults, languageFeatures,
72-
targetMachine);
72+
targetMachine, tuneCPU);
7373
}
7474

7575
//===--------------------------------------------------------------------===//
@@ -148,7 +148,7 @@ class LoweringBridge {
148148
const Fortran::lower::LoweringOptions &loweringOptions,
149149
const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
150150
const Fortran::common::LanguageFeatureControl &languageFeatures,
151-
const llvm::TargetMachine &targetMachine);
151+
const llvm::TargetMachine &targetMachine, const llvm::StringRef tuneCPU);
152152
LoweringBridge() = delete;
153153
LoweringBridge(const LoweringBridge &) = delete;
154154

flang/include/flang/Optimizer/CodeGen/CGPasses.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def FIRToLLVMLowering : Pass<"fir-to-llvm-ir", "mlir::ModuleOp"> {
3131
"Override module's data layout.">,
3232
Option<"forcedTargetCPU", "target-cpu", "std::string", /*default=*/"",
3333
"Override module's target CPU.">,
34+
Option<"forcedTuneCPU", "tune-cpu", "std::string", /*default=*/"",
35+
"Override module's tune CPU.">,
3436
Option<"forcedTargetFeatures", "target-features", "std::string",
3537
/*default=*/"", "Override module's target features.">,
3638
Option<"applyTBAA", "apply-tbaa", "bool", /*default=*/"false",
@@ -68,6 +70,8 @@ def TargetRewritePass : Pass<"target-rewrite", "mlir::ModuleOp"> {
6870
"Override module's target triple.">,
6971
Option<"forcedTargetCPU", "target-cpu", "std::string", /*default=*/"",
7072
"Override module's target CPU.">,
73+
Option<"forcedTuneCPU", "tune-cpu", "std::string", /*default=*/"",
74+
"Override module's tune CPU.">,
7175
Option<"forcedTargetFeatures", "target-features", "std::string",
7276
/*default=*/"", "Override module's target features.">,
7377
Option<"noCharacterConversion", "no-character-conversion",

flang/include/flang/Optimizer/CodeGen/Target.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,29 @@ class CodeGenSpecifics {
7676
llvm::StringRef targetCPU, mlir::LLVM::TargetFeaturesAttr targetFeatures,
7777
const mlir::DataLayout &dl);
7878

79+
static std::unique_ptr<CodeGenSpecifics>
80+
get(mlir::MLIRContext *ctx, llvm::Triple &&trp, KindMapping &&kindMap,
81+
llvm::StringRef targetCPU, mlir::LLVM::TargetFeaturesAttr targetFeatures,
82+
const mlir::DataLayout &dl, llvm::StringRef tuneCPU);
83+
7984
static TypeAndAttr getTypeAndAttr(mlir::Type t) { return TypeAndAttr{t, {}}; }
8085

8186
CodeGenSpecifics(mlir::MLIRContext *ctx, llvm::Triple &&trp,
8287
KindMapping &&kindMap, llvm::StringRef targetCPU,
8388
mlir::LLVM::TargetFeaturesAttr targetFeatures,
8489
const mlir::DataLayout &dl)
8590
: context{*ctx}, triple{std::move(trp)}, kindMap{std::move(kindMap)},
86-
targetCPU{targetCPU}, targetFeatures{targetFeatures}, dataLayout{&dl} {}
91+
targetCPU{targetCPU}, targetFeatures{targetFeatures}, dataLayout{&dl},
92+
tuneCPU{""} {}
93+
94+
CodeGenSpecifics(mlir::MLIRContext *ctx, llvm::Triple &&trp,
95+
KindMapping &&kindMap, llvm::StringRef targetCPU,
96+
mlir::LLVM::TargetFeaturesAttr targetFeatures,
97+
const mlir::DataLayout &dl, llvm::StringRef tuneCPU)
98+
: context{*ctx}, triple{std::move(trp)}, kindMap{std::move(kindMap)},
99+
targetCPU{targetCPU}, targetFeatures{targetFeatures}, dataLayout{&dl},
100+
tuneCPU{tuneCPU} {}
101+
87102
CodeGenSpecifics() = delete;
88103
virtual ~CodeGenSpecifics() {}
89104

@@ -165,6 +180,7 @@ class CodeGenSpecifics {
165180
virtual unsigned char getCIntTypeWidth() const = 0;
166181

167182
llvm::StringRef getTargetCPU() const { return targetCPU; }
183+
llvm::StringRef getTuneCPU() const { return tuneCPU; }
168184

169185
mlir::LLVM::TargetFeaturesAttr getTargetFeatures() const {
170186
return targetFeatures;
@@ -182,6 +198,7 @@ class CodeGenSpecifics {
182198
llvm::StringRef targetCPU;
183199
mlir::LLVM::TargetFeaturesAttr targetFeatures;
184200
const mlir::DataLayout *dataLayout = nullptr;
201+
llvm::StringRef tuneCPU;
185202
};
186203

187204
} // namespace fir

flang/include/flang/Optimizer/Dialect/Support/FIRContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
5858
/// Get the target CPU string from the Module or return a null reference.
5959
llvm::StringRef getTargetCPU(mlir::ModuleOp mod);
6060

61+
/// Set the tune CPU for the module. `cpu` must not be deallocated while
62+
/// module `mod` is still live.
63+
void setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
64+
65+
/// Get the tune CPU string from the Module or return a null reference.
66+
llvm::StringRef getTuneCPU(mlir::ModuleOp mod);
67+
6168
/// Set the target features for the module.
6269
void setTargetFeatures(mlir::ModuleOp mod, llvm::StringRef features);
6370

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> {
411411
Option<"unsafeFPMath", "unsafe-fp-math",
412412
"bool", /*default=*/"false",
413413
"Set the unsafe-fp-math attribute on functions in the module.">,
414-
];
414+
Option<"tuneCPU", "tune-cpu",
415+
"llvm::StringRef", /*default=*/"llvm::StringRef{}",
416+
"Set the tune-cpu attribute on functions in the module.">,
417+
];
415418
}
416419

417420
def AssumedRankOpConversion : Pass<"fir-assumed-rank-op", "mlir::ModuleOp"> {

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
431431
args.getLastArg(clang::driver::options::OPT_target_cpu))
432432
opts.cpu = a->getValue();
433433

434+
if (const llvm::opt::Arg *a =
435+
args.getLastArg(clang::driver::options::OPT_tune_cpu))
436+
opts.cpuToTuneFor = a->getValue();
437+
434438
for (const llvm::opt::Arg *currentArg :
435439
args.filtered(clang::driver::options::OPT_target_feature))
436440
opts.featuresAsWritten.emplace_back(currentArg->getValue());

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ bool CodeGenAction::beginSourceFileAction() {
297297
ci.getParsing().allCooked(), ci.getInvocation().getTargetOpts().triple,
298298
kindMap, ci.getInvocation().getLoweringOpts(),
299299
ci.getInvocation().getFrontendOpts().envDefaults,
300-
ci.getInvocation().getFrontendOpts().features, targetMachine);
300+
ci.getInvocation().getFrontendOpts().features, targetMachine,
301+
ci.getInvocation().getTargetOpts().cpuToTuneFor);
301302

302303
// Fetch module from lb, so we can set
303304
mlirModule = std::make_unique<mlir::ModuleOp>(lb.getModule());

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6025,7 +6025,7 @@ Fortran::lower::LoweringBridge::LoweringBridge(
60256025
const Fortran::lower::LoweringOptions &loweringOptions,
60266026
const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
60276027
const Fortran::common::LanguageFeatureControl &languageFeatures,
6028-
const llvm::TargetMachine &targetMachine)
6028+
const llvm::TargetMachine &targetMachine, const llvm::StringRef tuneCPU)
60296029
: semanticsContext{semanticsContext}, defaultKinds{defaultKinds},
60306030
intrinsics{intrinsics}, targetCharacteristics{targetCharacteristics},
60316031
cooked{&cooked}, context{context}, kindMap{kindMap},
@@ -6082,6 +6082,7 @@ Fortran::lower::LoweringBridge::LoweringBridge(
60826082
fir::setTargetTriple(*module.get(), triple);
60836083
fir::setKindMapping(*module.get(), kindMap);
60846084
fir::setTargetCPU(*module.get(), targetMachine.getTargetCPU());
6085+
fir::setTuneCPU(*module.get(), tuneCPU);
60856086
fir::setTargetFeatures(*module.get(), targetMachine.getTargetFeatureString());
60866087
fir::support::setMLIRDataLayout(*module.get(),
60876088
targetMachine.createDataLayout());

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,6 +3595,9 @@ class FIRToLLVMLowering
35953595
if (!forcedTargetCPU.empty())
35963596
fir::setTargetCPU(mod, forcedTargetCPU);
35973597

3598+
if (!forcedTuneCPU.empty())
3599+
fir::setTuneCPU(mod, forcedTuneCPU);
3600+
35983601
if (!forcedTargetFeatures.empty())
35993602
fir::setTargetFeatures(mod, forcedTargetFeatures);
36003603

flang/lib/Optimizer/CodeGen/Target.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,3 +1113,14 @@ fir::CodeGenSpecifics::get(mlir::MLIRContext *ctx, llvm::Triple &&trp,
11131113
}
11141114
TODO(mlir::UnknownLoc::get(ctx), "target not implemented");
11151115
}
1116+
1117+
std::unique_ptr<fir::CodeGenSpecifics> fir::CodeGenSpecifics::get(
1118+
mlir::MLIRContext *ctx, llvm::Triple &&trp, KindMapping &&kindMap,
1119+
llvm::StringRef targetCPU, mlir::LLVM::TargetFeaturesAttr targetFeatures,
1120+
const mlir::DataLayout &dl, llvm::StringRef tuneCPU) {
1121+
std::unique_ptr<fir::CodeGenSpecifics> CGS = fir::CodeGenSpecifics::get(
1122+
ctx, std::move(trp), std::move(kindMap), targetCPU, targetFeatures, dl);
1123+
1124+
CGS->tuneCPU = tuneCPU;
1125+
return CGS;
1126+
}

flang/lib/Optimizer/CodeGen/TargetRewrite.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
8989
if (!forcedTargetCPU.empty())
9090
fir::setTargetCPU(mod, forcedTargetCPU);
9191

92+
if (!forcedTuneCPU.empty())
93+
fir::setTuneCPU(mod, forcedTuneCPU);
94+
9295
if (!forcedTargetFeatures.empty())
9396
fir::setTargetFeatures(mod, forcedTargetFeatures);
9497

@@ -106,7 +109,8 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
106109

107110
auto specifics = fir::CodeGenSpecifics::get(
108111
mod.getContext(), fir::getTargetTriple(mod), fir::getKindMapping(mod),
109-
fir::getTargetCPU(mod), fir::getTargetFeatures(mod), *dl);
112+
fir::getTargetCPU(mod), fir::getTargetFeatures(mod), *dl,
113+
fir::getTuneCPU(mod));
110114

111115
setMembers(specifics.get(), &rewriter, &*dl);
112116

@@ -672,12 +676,18 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
672676
auto targetCPU = specifics->getTargetCPU();
673677
mlir::StringAttr targetCPUAttr =
674678
targetCPU.empty() ? nullptr : mlir::StringAttr::get(ctx, targetCPU);
679+
auto tuneCPU = specifics->getTuneCPU();
680+
mlir::StringAttr tuneCPUAttr =
681+
tuneCPU.empty() ? nullptr : mlir::StringAttr::get(ctx, tuneCPU);
675682
auto targetFeaturesAttr = specifics->getTargetFeatures();
676683

677684
for (auto fn : mod.getOps<mlir::func::FuncOp>()) {
678685
if (targetCPUAttr)
679686
fn->setAttr("target_cpu", targetCPUAttr);
680687

688+
if (tuneCPUAttr)
689+
fn->setAttr("tune_cpu", tuneCPUAttr);
690+
681691
if (targetFeaturesAttr)
682692
fn->setAttr("target_features", targetFeaturesAttr);
683693

flang/lib/Optimizer/CodeGen/TypeConverter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA,
3535
kindMapping(getKindMapping(module)),
3636
specifics(CodeGenSpecifics::get(
3737
module.getContext(), getTargetTriple(module), getKindMapping(module),
38-
getTargetCPU(module), getTargetFeatures(module), dl)),
38+
getTargetCPU(module), getTargetFeatures(module), dl,
39+
getTuneCPU(module))),
3940
tbaaBuilder(std::make_unique<TBAABuilder>(module->getContext(), applyTBAA,
4041
forceUnifiedTBAATree)),
4142
dataLayout{&dl} {

flang/lib/Optimizer/Dialect/Support/FIRContext.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ llvm::StringRef fir::getTargetCPU(mlir::ModuleOp mod) {
7777
return {};
7878
}
7979

80+
static constexpr const char *tuneCpuName = "fir.tune_cpu";
81+
82+
void fir::setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu) {
83+
if (cpu.empty())
84+
return;
85+
86+
auto *ctx = mod.getContext();
87+
88+
mod->setAttr(tuneCpuName, mlir::StringAttr::get(ctx, cpu));
89+
}
90+
91+
llvm::StringRef fir::getTuneCPU(mlir::ModuleOp mod) {
92+
if (auto attr = mod->getAttrOfType<mlir::StringAttr>(tuneCpuName))
93+
return attr.getValue();
94+
95+
return {};
96+
}
97+
8098
static constexpr const char *targetFeaturesName = "fir.target_features";
8199

82100
void fir::setTargetFeatures(mlir::ModuleOp mod, llvm::StringRef features) {

flang/test/Driver/tune-cpu-fir.f90

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! RUN: %if aarch64-registered-target %{ %flang_fc1 -emit-fir -triple aarch64-unknown-linux-gnu -target-cpu aarch64 %s -o - | FileCheck %s --check-prefixes=ALL,ARMCPU %}
2+
! RUN: %if aarch64-registered-target %{ %flang_fc1 -emit-fir -triple aarch64-unknown-linux-gnu -tune-cpu neoverse-n1 %s -o - | FileCheck %s --check-prefixes=ALL,ARMTUNE %}
3+
! RUN: %if aarch64-registered-target %{ %flang_fc1 -emit-fir -triple aarch64-unknown-linux-gnu -target-cpu aarch64 -tune-cpu neoverse-n1 %s -o - | FileCheck %s --check-prefixes=ALL,ARMBOTH %}
4+
5+
! RUN: %if x86-registered-target %{ %flang_fc1 -emit-fir -triple x86_64-unknown-linux-gnu -target-cpu x86-64 %s -o - | FileCheck %s --check-prefixes=ALL,X86CPU %}
6+
! RUN: %if x86-registered-target %{ %flang_fc1 -emit-fir -triple x86_64-unknown-linux-gnu -tune-cpu pentium4 %s -o - | FileCheck %s --check-prefixes=ALL,X86TUNE %}
7+
! RUN: %if x86-registered-target %{ %flang_fc1 -emit-fir -triple x86_64-unknown-linux-gnu -target-cpu x86-64 -tune-cpu pentium4 %s -o - | FileCheck %s --check-prefixes=ALL,X86BOTH %}
8+
9+
! ALL: module attributes {
10+
11+
! ARMCPU-SAME: fir.target_cpu = "aarch64"
12+
! ARMCPU-NOT: fir.tune_cpu = "neoverse-n1"
13+
14+
! ARMTUNE-SAME: fir.tune_cpu = "neoverse-n1"
15+
16+
! ARMBOTH-SAME: fir.target_cpu = "aarch64"
17+
! ARMBOTH-SAME: fir.tune_cpu = "neoverse-n1"
18+
19+
! X86CPU-SAME: fir.target_cpu = "x86-64"
20+
! X86CPU-NOT: fir.tune_cpu = "pentium4"
21+
22+
! X86TUNE-SAME: fir.tune_cpu = "pentium4"
23+
24+
! X86BOTH-SAME: fir.target_cpu = "x86-64"
25+
! X86BOTH-SAME: fir.tune_cpu = "pentium4"

flang/test/Lower/tune-cpu-llvm.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
! RUN: %if x86-registered-target %{ %flang -mtune=pentium4 -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,CHECK-X86 %}
2+
! RUN: %if aarch64-registered-target %{ %flang -mtune=neoverse-n1 -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,CHECK-ARM %}
3+
4+
!ALL: attributes #{{[0-9]+}} = {
5+
!CHECK-X86-SAME: "tune-cpu"="pentium4"
6+
!CHECK-ARM-SAME: "tune-cpu"="neoverse-n1"
7+
subroutine a
8+
end subroutine a

flang/tools/bbc/bbc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,12 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
367367
loweringOptions.setLowerToHighLevelFIR(useHLFIR || emitHLFIR);
368368
loweringOptions.setNSWOnLoopVarInc(setNSW);
369369
std::vector<Fortran::lower::EnvironmentDefault> envDefaults = {};
370+
constexpr const char *tuneCPU = "";
370371
auto burnside = Fortran::lower::LoweringBridge::create(
371372
ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
372373
semanticsContext.targetCharacteristics(), parsing.allCooked(),
373374
targetTriple, kindMap, loweringOptions, envDefaults,
374-
semanticsContext.languageFeatures(), targetMachine);
375+
semanticsContext.languageFeatures(), targetMachine, tuneCPU);
375376
mlir::ModuleOp mlirModule = burnside.getModule();
376377
if (enableOpenMP) {
377378
if (enableOpenMPGPU && !enableOpenMPDevice) {

flang/tools/tco/tco.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ static cl::opt<std::string> targetTriple("target",
5858
static cl::opt<std::string>
5959
targetCPU("target-cpu", cl::desc("specify a target CPU"), cl::init(""));
6060

61+
static cl::opt<std::string> tuneCPU("tune-cpu", cl::desc("specify a tune CPU"),
62+
cl::init(""));
63+
6164
static cl::opt<std::string>
6265
targetFeatures("target-features", cl::desc("specify the target features"),
6366
cl::init(""));
@@ -113,6 +116,7 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
113116
fir::setTargetTriple(*owningRef, targetTriple);
114117
fir::setKindMapping(*owningRef, kindMap);
115118
fir::setTargetCPU(*owningRef, targetCPU);
119+
fir::setTuneCPU(*owningRef, tuneCPU);
116120
fir::setTargetFeatures(*owningRef, targetFeatures);
117121
// tco is a testing tool, so it will happily use the target independent
118122
// data layout if none is on the module.

0 commit comments

Comments
 (0)