aboutsummaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorAlexis Perry-Holby <AlexisPerry@users.noreply.github.com>2024-07-16 09:48:24 -0600
committerGitHub <noreply@github.com>2024-07-16 16:48:24 +0100
commitf1d3fe7aae7867b5de96b84d6d26b5c9f02f209a (patch)
tree169ba28f1ef73acdfa79ccdcb1106ad470897d37 /flang
parent266a784cce959d475d3d79a877f0c5f39194a4c4 (diff)
downloadllvm-f1d3fe7aae7867b5de96b84d6d26b5c9f02f209a.zip
llvm-f1d3fe7aae7867b5de96b84d6d26b5c9f02f209a.tar.gz
llvm-f1d3fe7aae7867b5de96b84d6d26b5c9f02f209a.tar.bz2
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
Diffstat (limited to 'flang')
-rw-r--r--flang/include/flang/Frontend/TargetOptions.h3
-rw-r--r--flang/include/flang/Lower/Bridge.h6
-rw-r--r--flang/include/flang/Optimizer/CodeGen/CGPasses.td4
-rw-r--r--flang/include/flang/Optimizer/CodeGen/Target.h19
-rw-r--r--flang/include/flang/Optimizer/Dialect/Support/FIRContext.h7
-rw-r--r--flang/include/flang/Optimizer/Transforms/Passes.td5
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp4
-rw-r--r--flang/lib/Frontend/FrontendActions.cpp3
-rw-r--r--flang/lib/Lower/Bridge.cpp3
-rw-r--r--flang/lib/Optimizer/CodeGen/CodeGen.cpp3
-rw-r--r--flang/lib/Optimizer/CodeGen/Target.cpp11
-rw-r--r--flang/lib/Optimizer/CodeGen/TargetRewrite.cpp12
-rw-r--r--flang/lib/Optimizer/CodeGen/TypeConverter.cpp3
-rw-r--r--flang/lib/Optimizer/Dialect/Support/FIRContext.cpp18
-rw-r--r--flang/test/Driver/tune-cpu-fir.f9025
-rw-r--r--flang/test/Lower/tune-cpu-llvm.f908
-rw-r--r--flang/tools/bbc/bbc.cpp3
-rw-r--r--flang/tools/tco/tco.cpp4
-rw-r--r--flang/unittests/Optimizer/FIRContextTest.cpp3
19 files changed, 134 insertions, 10 deletions
diff --git a/flang/include/flang/Frontend/TargetOptions.h b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270..fa72c77 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ public:
/// If given, the name of the target CPU to generate code for.
std::string cpu;
+ /// If given, the name of the target CPU to tune code for.
+ std::string cpuToTuneFor;
+
/// The list of target specific features to enable or disable, as written on
/// the command line.
std::vector<std::string> featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h b/flang/include/flang/Lower/Bridge.h
index 52110b8..4379ed5 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ public:
const Fortran::lower::LoweringOptions &loweringOptions,
const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
const Fortran::common::LanguageFeatureControl &languageFeatures,
- const llvm::TargetMachine &targetMachine) {
+ const llvm::TargetMachine &targetMachine, llvm::StringRef tuneCPU) {
return LoweringBridge(ctx, semanticsContext, defaultKinds, intrinsics,
targetCharacteristics, allCooked, triple, kindMap,
loweringOptions, envDefaults, languageFeatures,
- targetMachine);
+ targetMachine, tuneCPU);
}
//===--------------------------------------------------------------------===//
@@ -148,7 +148,7 @@ private:
const Fortran::lower::LoweringOptions &loweringOptions,
const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
const Fortran::common::LanguageFeatureControl &languageFeatures,
- const llvm::TargetMachine &targetMachine);
+ const llvm::TargetMachine &targetMachine, const llvm::StringRef tuneCPU);
LoweringBridge() = delete;
LoweringBridge(const LoweringBridge &) = delete;
diff --git a/flang/include/flang/Optimizer/CodeGen/CGPasses.td b/flang/include/flang/Optimizer/CodeGen/CGPasses.td
index 9a4d327..989e394 100644
--- a/flang/include/flang/Optimizer/CodeGen/CGPasses.td
+++ b/flang/include/flang/Optimizer/CodeGen/CGPasses.td
@@ -31,6 +31,8 @@ def FIRToLLVMLowering : Pass<"fir-to-llvm-ir", "mlir::ModuleOp"> {
"Override module's data layout.">,
Option<"forcedTargetCPU", "target-cpu", "std::string", /*default=*/"",
"Override module's target CPU.">,
+ Option<"forcedTuneCPU", "tune-cpu", "std::string", /*default=*/"",
+ "Override module's tune CPU.">,
Option<"forcedTargetFeatures", "target-features", "std::string",
/*default=*/"", "Override module's target features.">,
Option<"applyTBAA", "apply-tbaa", "bool", /*default=*/"false",
@@ -68,6 +70,8 @@ def TargetRewritePass : Pass<"target-rewrite", "mlir::ModuleOp"> {
"Override module's target triple.">,
Option<"forcedTargetCPU", "target-cpu", "std::string", /*default=*/"",
"Override module's target CPU.">,
+ Option<"forcedTuneCPU", "tune-cpu", "std::string", /*default=*/"",
+ "Override module's tune CPU.">,
Option<"forcedTargetFeatures", "target-features", "std::string",
/*default=*/"", "Override module's target features.">,
Option<"noCharacterConversion", "no-character-conversion",
diff --git a/flang/include/flang/Optimizer/CodeGen/Target.h b/flang/include/flang/Optimizer/CodeGen/Target.h
index 3cf6a74..a716115 100644
--- a/flang/include/flang/Optimizer/CodeGen/Target.h
+++ b/flang/include/flang/Optimizer/CodeGen/Target.h
@@ -76,6 +76,11 @@ public:
llvm::StringRef targetCPU, mlir::LLVM::TargetFeaturesAttr targetFeatures,
const mlir::DataLayout &dl);
+ static std::unique_ptr<CodeGenSpecifics>
+ get(mlir::MLIRContext *ctx, llvm::Triple &&trp, KindMapping &&kindMap,
+ llvm::StringRef targetCPU, mlir::LLVM::TargetFeaturesAttr targetFeatures,
+ const mlir::DataLayout &dl, llvm::StringRef tuneCPU);
+
static TypeAndAttr getTypeAndAttr(mlir::Type t) { return TypeAndAttr{t, {}}; }
CodeGenSpecifics(mlir::MLIRContext *ctx, llvm::Triple &&trp,
@@ -83,7 +88,17 @@ public:
mlir::LLVM::TargetFeaturesAttr targetFeatures,
const mlir::DataLayout &dl)
: context{*ctx}, triple{std::move(trp)}, kindMap{std::move(kindMap)},
- targetCPU{targetCPU}, targetFeatures{targetFeatures}, dataLayout{&dl} {}
+ targetCPU{targetCPU}, targetFeatures{targetFeatures}, dataLayout{&dl},
+ tuneCPU{""} {}
+
+ CodeGenSpecifics(mlir::MLIRContext *ctx, llvm::Triple &&trp,
+ KindMapping &&kindMap, llvm::StringRef targetCPU,
+ mlir::LLVM::TargetFeaturesAttr targetFeatures,
+ const mlir::DataLayout &dl, llvm::StringRef tuneCPU)
+ : context{*ctx}, triple{std::move(trp)}, kindMap{std::move(kindMap)},
+ targetCPU{targetCPU}, targetFeatures{targetFeatures}, dataLayout{&dl},
+ tuneCPU{tuneCPU} {}
+
CodeGenSpecifics() = delete;
virtual ~CodeGenSpecifics() {}
@@ -165,6 +180,7 @@ public:
virtual unsigned char getCIntTypeWidth() const = 0;
llvm::StringRef getTargetCPU() const { return targetCPU; }
+ llvm::StringRef getTuneCPU() const { return tuneCPU; }
mlir::LLVM::TargetFeaturesAttr getTargetFeatures() const {
return targetFeatures;
@@ -182,6 +198,7 @@ protected:
llvm::StringRef targetCPU;
mlir::LLVM::TargetFeaturesAttr targetFeatures;
const mlir::DataLayout *dataLayout = nullptr;
+ llvm::StringRef tuneCPU;
};
} // namespace fir
diff --git a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
index 059a10c..bd31aa0 100644
--- a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
+++ b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
@@ -58,6 +58,13 @@ void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
/// Get the target CPU string from the Module or return a null reference.
llvm::StringRef getTargetCPU(mlir::ModuleOp mod);
+/// Set the tune CPU for the module. `cpu` must not be deallocated while
+/// module `mod` is still live.
+void setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
+
+/// Get the tune CPU string from the Module or return a null reference.
+llvm::StringRef getTuneCPU(mlir::ModuleOp mod);
+
/// Set the target features for the module.
void setTargetFeatures(mlir::ModuleOp mod, llvm::StringRef features);
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td
index b3ed9aca..786083f 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -411,7 +411,10 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> {
Option<"unsafeFPMath", "unsafe-fp-math",
"bool", /*default=*/"false",
"Set the unsafe-fp-math attribute on functions in the module.">,
- ];
+ Option<"tuneCPU", "tune-cpu",
+ "llvm::StringRef", /*default=*/"llvm::StringRef{}",
+ "Set the tune-cpu attribute on functions in the module.">,
+];
}
def AssumedRankOpConversion : Pass<"fir-assumed-rank-op", "mlir::ModuleOp"> {
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 37b5070..8c892d9 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -431,6 +431,10 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
args.getLastArg(clang::driver::options::OPT_target_cpu))
opts.cpu = a->getValue();
+ if (const llvm::opt::Arg *a =
+ args.getLastArg(clang::driver::options::OPT_tune_cpu))
+ opts.cpuToTuneFor = a->getValue();
+
for (const llvm::opt::Arg *currentArg :
args.filtered(clang::driver::options::OPT_target_feature))
opts.featuresAsWritten.emplace_back(currentArg->getValue());
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index a85ecd1..5c86bd9 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -297,7 +297,8 @@ bool CodeGenAction::beginSourceFileAction() {
ci.getParsing().allCooked(), ci.getInvocation().getTargetOpts().triple,
kindMap, ci.getInvocation().getLoweringOpts(),
ci.getInvocation().getFrontendOpts().envDefaults,
- ci.getInvocation().getFrontendOpts().features, targetMachine);
+ ci.getInvocation().getFrontendOpts().features, targetMachine,
+ ci.getInvocation().getTargetOpts().cpuToTuneFor);
// Fetch module from lb, so we can set
mlirModule = std::make_unique<mlir::ModuleOp>(lb.getModule());
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 267a355..77e038da 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -6025,7 +6025,7 @@ Fortran::lower::LoweringBridge::LoweringBridge(
const Fortran::lower::LoweringOptions &loweringOptions,
const std::vector<Fortran::lower::EnvironmentDefault> &envDefaults,
const Fortran::common::LanguageFeatureControl &languageFeatures,
- const llvm::TargetMachine &targetMachine)
+ const llvm::TargetMachine &targetMachine, const llvm::StringRef tuneCPU)
: semanticsContext{semanticsContext}, defaultKinds{defaultKinds},
intrinsics{intrinsics}, targetCharacteristics{targetCharacteristics},
cooked{&cooked}, context{context}, kindMap{kindMap},
@@ -6082,6 +6082,7 @@ Fortran::lower::LoweringBridge::LoweringBridge(
fir::setTargetTriple(*module.get(), triple);
fir::setKindMapping(*module.get(), kindMap);
fir::setTargetCPU(*module.get(), targetMachine.getTargetCPU());
+ fir::setTuneCPU(*module.get(), tuneCPU);
fir::setTargetFeatures(*module.get(), targetMachine.getTargetFeatureString());
fir::support::setMLIRDataLayout(*module.get(),
targetMachine.createDataLayout());
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 11535f0..f9ea92a 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -3595,6 +3595,9 @@ public:
if (!forcedTargetCPU.empty())
fir::setTargetCPU(mod, forcedTargetCPU);
+ if (!forcedTuneCPU.empty())
+ fir::setTuneCPU(mod, forcedTuneCPU);
+
if (!forcedTargetFeatures.empty())
fir::setTargetFeatures(mod, forcedTargetFeatures);
diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp
index 652e2bd..2514110 100644
--- a/flang/lib/Optimizer/CodeGen/Target.cpp
+++ b/flang/lib/Optimizer/CodeGen/Target.cpp
@@ -1113,3 +1113,14 @@ fir::CodeGenSpecifics::get(mlir::MLIRContext *ctx, llvm::Triple &&trp,
}
TODO(mlir::UnknownLoc::get(ctx), "target not implemented");
}
+
+std::unique_ptr<fir::CodeGenSpecifics> fir::CodeGenSpecifics::get(
+ mlir::MLIRContext *ctx, llvm::Triple &&trp, KindMapping &&kindMap,
+ llvm::StringRef targetCPU, mlir::LLVM::TargetFeaturesAttr targetFeatures,
+ const mlir::DataLayout &dl, llvm::StringRef tuneCPU) {
+ std::unique_ptr<fir::CodeGenSpecifics> CGS = fir::CodeGenSpecifics::get(
+ ctx, std::move(trp), std::move(kindMap), targetCPU, targetFeatures, dl);
+
+ CGS->tuneCPU = tuneCPU;
+ return CGS;
+}
diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
index 561d700..85bf90e 100644
--- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
@@ -89,6 +89,9 @@ public:
if (!forcedTargetCPU.empty())
fir::setTargetCPU(mod, forcedTargetCPU);
+ if (!forcedTuneCPU.empty())
+ fir::setTuneCPU(mod, forcedTuneCPU);
+
if (!forcedTargetFeatures.empty())
fir::setTargetFeatures(mod, forcedTargetFeatures);
@@ -106,7 +109,8 @@ public:
auto specifics = fir::CodeGenSpecifics::get(
mod.getContext(), fir::getTargetTriple(mod), fir::getKindMapping(mod),
- fir::getTargetCPU(mod), fir::getTargetFeatures(mod), *dl);
+ fir::getTargetCPU(mod), fir::getTargetFeatures(mod), *dl,
+ fir::getTuneCPU(mod));
setMembers(specifics.get(), &rewriter, &*dl);
@@ -672,12 +676,18 @@ public:
auto targetCPU = specifics->getTargetCPU();
mlir::StringAttr targetCPUAttr =
targetCPU.empty() ? nullptr : mlir::StringAttr::get(ctx, targetCPU);
+ auto tuneCPU = specifics->getTuneCPU();
+ mlir::StringAttr tuneCPUAttr =
+ tuneCPU.empty() ? nullptr : mlir::StringAttr::get(ctx, tuneCPU);
auto targetFeaturesAttr = specifics->getTargetFeatures();
for (auto fn : mod.getOps<mlir::func::FuncOp>()) {
if (targetCPUAttr)
fn->setAttr("target_cpu", targetCPUAttr);
+ if (tuneCPUAttr)
+ fn->setAttr("tune_cpu", tuneCPUAttr);
+
if (targetFeaturesAttr)
fn->setAttr("target_features", targetFeaturesAttr);
diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
index 7b46a1a..59f67f4 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp
@@ -35,7 +35,8 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA,
kindMapping(getKindMapping(module)),
specifics(CodeGenSpecifics::get(
module.getContext(), getTargetTriple(module), getKindMapping(module),
- getTargetCPU(module), getTargetFeatures(module), dl)),
+ getTargetCPU(module), getTargetFeatures(module), dl,
+ getTuneCPU(module))),
tbaaBuilder(std::make_unique<TBAABuilder>(module->getContext(), applyTBAA,
forceUnifiedTBAATree)),
dataLayout{&dl} {
diff --git a/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp b/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
index c4d0087..1aa631c 100644
--- a/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
+++ b/flang/lib/Optimizer/Dialect/Support/FIRContext.cpp
@@ -77,6 +77,24 @@ llvm::StringRef fir::getTargetCPU(mlir::ModuleOp mod) {
return {};
}
+static constexpr const char *tuneCpuName = "fir.tune_cpu";
+
+void fir::setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu) {
+ if (cpu.empty())
+ return;
+
+ auto *ctx = mod.getContext();
+
+ mod->setAttr(tuneCpuName, mlir::StringAttr::get(ctx, cpu));
+}
+
+llvm::StringRef fir::getTuneCPU(mlir::ModuleOp mod) {
+ if (auto attr = mod->getAttrOfType<mlir::StringAttr>(tuneCpuName))
+ return attr.getValue();
+
+ return {};
+}
+
static constexpr const char *targetFeaturesName = "fir.target_features";
void fir::setTargetFeatures(mlir::ModuleOp mod, llvm::StringRef features) {
diff --git a/flang/test/Driver/tune-cpu-fir.f90 b/flang/test/Driver/tune-cpu-fir.f90
new file mode 100644
index 0000000..43c13b4
--- /dev/null
+++ b/flang/test/Driver/tune-cpu-fir.f90
@@ -0,0 +1,25 @@
+! 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 %}
+! 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 %}
+! 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 %}
+
+! 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 %}
+! 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 %}
+! 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 %}
+
+! ALL: module attributes {
+
+! ARMCPU-SAME: fir.target_cpu = "aarch64"
+! ARMCPU-NOT: fir.tune_cpu = "neoverse-n1"
+
+! ARMTUNE-SAME: fir.tune_cpu = "neoverse-n1"
+
+! ARMBOTH-SAME: fir.target_cpu = "aarch64"
+! ARMBOTH-SAME: fir.tune_cpu = "neoverse-n1"
+
+! X86CPU-SAME: fir.target_cpu = "x86-64"
+! X86CPU-NOT: fir.tune_cpu = "pentium4"
+
+! X86TUNE-SAME: fir.tune_cpu = "pentium4"
+
+! X86BOTH-SAME: fir.target_cpu = "x86-64"
+! X86BOTH-SAME: fir.tune_cpu = "pentium4"
diff --git a/flang/test/Lower/tune-cpu-llvm.f90 b/flang/test/Lower/tune-cpu-llvm.f90
new file mode 100644
index 0000000..dc2a687
--- /dev/null
+++ b/flang/test/Lower/tune-cpu-llvm.f90
@@ -0,0 +1,8 @@
+! RUN: %if x86-registered-target %{ %flang -mtune=pentium4 -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,CHECK-X86 %}
+! RUN: %if aarch64-registered-target %{ %flang -mtune=neoverse-n1 -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,CHECK-ARM %}
+
+!ALL: attributes #{{[0-9]+}} = {
+!CHECK-X86-SAME: "tune-cpu"="pentium4"
+!CHECK-ARM-SAME: "tune-cpu"="neoverse-n1"
+subroutine a
+end subroutine a
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index e5e41ad..07eef065 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -367,11 +367,12 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
loweringOptions.setLowerToHighLevelFIR(useHLFIR || emitHLFIR);
loweringOptions.setNSWOnLoopVarInc(setNSW);
std::vector<Fortran::lower::EnvironmentDefault> envDefaults = {};
+ constexpr const char *tuneCPU = "";
auto burnside = Fortran::lower::LoweringBridge::create(
ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
semanticsContext.targetCharacteristics(), parsing.allCooked(),
targetTriple, kindMap, loweringOptions, envDefaults,
- semanticsContext.languageFeatures(), targetMachine);
+ semanticsContext.languageFeatures(), targetMachine, tuneCPU);
mlir::ModuleOp mlirModule = burnside.getModule();
if (enableOpenMP) {
if (enableOpenMPGPU && !enableOpenMPDevice) {
diff --git a/flang/tools/tco/tco.cpp b/flang/tools/tco/tco.cpp
index 34ac0e1..a8c6433 100644
--- a/flang/tools/tco/tco.cpp
+++ b/flang/tools/tco/tco.cpp
@@ -58,6 +58,9 @@ static cl::opt<std::string> targetTriple("target",
static cl::opt<std::string>
targetCPU("target-cpu", cl::desc("specify a target CPU"), cl::init(""));
+static cl::opt<std::string> tuneCPU("tune-cpu", cl::desc("specify a tune CPU"),
+ cl::init(""));
+
static cl::opt<std::string>
targetFeatures("target-features", cl::desc("specify the target features"),
cl::init(""));
@@ -113,6 +116,7 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
fir::setTargetTriple(*owningRef, targetTriple);
fir::setKindMapping(*owningRef, kindMap);
fir::setTargetCPU(*owningRef, targetCPU);
+ fir::setTuneCPU(*owningRef, tuneCPU);
fir::setTargetFeatures(*owningRef, targetFeatures);
// tco is a testing tool, so it will happily use the target independent
// data layout if none is on the module.
diff --git a/flang/unittests/Optimizer/FIRContextTest.cpp b/flang/unittests/Optimizer/FIRContextTest.cpp
index 49e1ebf..3f8b59a 100644
--- a/flang/unittests/Optimizer/FIRContextTest.cpp
+++ b/flang/unittests/Optimizer/FIRContextTest.cpp
@@ -34,6 +34,7 @@ public:
"i10:80,l3:24,a1:8,r54:Double,r62:X86_FP80,r11:PPC_FP128";
std::string target = "powerpc64le-unknown-linux-gnu";
std::string targetCPU = "gfx90a";
+ std::string tuneCPU = "generic";
std::string targetFeatures = "+gfx9-insts,+wavefrontsize64";
mlir::ModuleOp mod;
};
@@ -42,6 +43,7 @@ TEST_F(StringAttributesTests, moduleStringAttrTest) {
setTargetTriple(mod, target);
setKindMapping(mod, *kindMap);
setTargetCPU(mod, targetCPU);
+ setTuneCPU(mod, tuneCPU);
setTargetFeatures(mod, targetFeatures);
auto triple = getTargetTriple(mod);
@@ -61,6 +63,7 @@ TEST_F(StringAttributesTests, moduleStringAttrTest) {
EXPECT_TRUE(mapStr.find("r62:X86_FP80") != std::string::npos);
EXPECT_EQ(getTargetCPU(mod), targetCPU);
+ EXPECT_EQ(getTuneCPU(mod), tuneCPU);
auto features = getTargetFeatures(mod);
auto featuresList = features.getFeatures();