mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Propagate "-O" to Clang (as "-Os").
It affects Clang IRGen, among other things.
This commit is contained in:
@@ -47,6 +47,10 @@ public:
|
|||||||
/// header, place it in this directory.
|
/// header, place it in this directory.
|
||||||
std::string PrecompiledHeaderOutputDir;
|
std::string PrecompiledHeaderOutputDir;
|
||||||
|
|
||||||
|
/// The optimizaton setting. This doesn't typically matter for
|
||||||
|
/// import, but it can affect Clang's IR generation of static functions.
|
||||||
|
std::string Optimization;
|
||||||
|
|
||||||
/// Disable validating the persistent PCH.
|
/// Disable validating the persistent PCH.
|
||||||
bool PCHDisableValidation = false;
|
bool PCHDisableValidation = false;
|
||||||
|
|
||||||
|
|||||||
@@ -686,6 +686,10 @@ addCommonInvocationArguments(std::vector<std::string> &invocationArgStrs,
|
|||||||
invocationArgStrs.push_back("-march=z196");
|
invocationArgStrs.push_back("-march=z196");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!importerOpts.Optimization.empty()) {
|
||||||
|
invocationArgStrs.push_back(importerOpts.Optimization);
|
||||||
|
}
|
||||||
|
|
||||||
const std::string &overrideResourceDir = importerOpts.OverrideResourceDir;
|
const std::string &overrideResourceDir = importerOpts.OverrideResourceDir;
|
||||||
if (overrideResourceDir.empty()) {
|
if (overrideResourceDir.empty()) {
|
||||||
llvm::SmallString<128> resourceDir(searchPathOpts.RuntimeResourcePath);
|
llvm::SmallString<128> resourceDir(searchPathOpts.RuntimeResourcePath);
|
||||||
@@ -868,6 +872,7 @@ ClangImporter::create(ASTContext &ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const char *> invocationArgs;
|
std::vector<const char *> invocationArgs;
|
||||||
|
invocationArgs.reserve(invocationArgStrs.size());
|
||||||
for (auto &argStr : invocationArgStrs)
|
for (auto &argStr : invocationArgStrs)
|
||||||
invocationArgs.push_back(argStr.c_str());
|
invocationArgs.push_back(argStr.c_str());
|
||||||
|
|
||||||
|
|||||||
@@ -1352,7 +1352,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
|
|||||||
IRGenOptions &IRGenOpts,
|
IRGenOptions &IRGenOpts,
|
||||||
FrontendOptions &FEOpts,
|
FrontendOptions &FEOpts,
|
||||||
DiagnosticEngine &Diags,
|
DiagnosticEngine &Diags,
|
||||||
const llvm::Triple &Triple) {
|
const llvm::Triple &Triple,
|
||||||
|
ClangImporterOptions &ClangOpts) {
|
||||||
using namespace options;
|
using namespace options;
|
||||||
|
|
||||||
if (const Arg *A = Args.getLastArg(OPT_sil_inline_threshold)) {
|
if (const Arg *A = Args.getLastArg(OPT_sil_inline_threshold)) {
|
||||||
@@ -1408,6 +1409,10 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
|
|||||||
IRGenOpts.Optimize = true;
|
IRGenOpts.Optimize = true;
|
||||||
Opts.Optimization = SILOptions::SILOptMode::Optimize;
|
Opts.Optimization = SILOptions::SILOptMode::Optimize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IRGenOpts.Optimize) {
|
||||||
|
ClangOpts.Optimization = "-Os";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Args.getLastArg(OPT_AssumeSingleThreaded)) {
|
if (Args.getLastArg(OPT_AssumeSingleThreaded)) {
|
||||||
@@ -1799,7 +1804,7 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts, Diags,
|
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts, Diags,
|
||||||
LangOpts.Target)) {
|
LangOpts.Target, ClangImporterOpts)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,3 +20,7 @@ static inline void log_a_thing(const a_thing thing) {
|
|||||||
useInt(thing.val[0]);
|
useInt(thing.val[0]);
|
||||||
useInt(thing.val[7]);
|
useInt(thing.val[7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline unsigned int return7(void) {
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
|||||||
14
test/IRGen/clang_inline_opt.swift
Normal file
14
test/IRGen/clang_inline_opt.swift
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// RUN: %target-swift-frontend -import-objc-header %S/Inputs/c_functions.h -primary-file %s -O -emit-ir -disable-llvm-optzns | %FileCheck %s
|
||||||
|
|
||||||
|
func return10() -> UInt32 {
|
||||||
|
return return7() + 3
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanity check that we tell Clang to generate optimizable code when
|
||||||
|
// we're optimizing.
|
||||||
|
|
||||||
|
// CHECK: define internal i32 @return7() [[CLANG_ATTRS:#[0-9]+]] {
|
||||||
|
|
||||||
|
// CHECK: attributes [[CLANG_ATTRS]] = {
|
||||||
|
// CHECK-NOT: noinline
|
||||||
|
// CHECK-SAME: }
|
||||||
Reference in New Issue
Block a user