Add clang-cc support for -disable-llvm-optzns.
- Avoids running any LLVM optimizations, even at -O2, etc., while still keeping
any language changes these optimizations imply.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72742 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index a0ccafa..0e0a072 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -667,6 +667,10 @@
OptSize("Os", llvm::cl::desc("Optimize for size"));
static llvm::cl::opt<bool>
+DisableLLVMOptimizations("disable-llvm-optzns",
+ llvm::cl::desc("Don't run LLVM optimization passes"));
+
+static llvm::cl::opt<bool>
NoCommon("fno-common",
llvm::cl::desc("Compile common globals like normal definitions"),
llvm::cl::ValueDisallowed);
@@ -1420,16 +1424,26 @@
const llvm::StringMap<bool> &Features) {
Opts.OptimizeSize = OptSize;
Opts.DebugInfo = GenerateDebugInfo;
- if (OptSize) {
- // -Os implies -O2
- // FIXME: Diagnose conflicting options.
- Opts.OptimizationLevel = 2;
+
+ if (DisableLLVMOptimizations) {
+ Opts.OptimizationLevel = 0;
+ Opts.Inlining = CompileOptions::NoInlining;
} else {
- Opts.OptimizationLevel = OptLevel;
+ if (OptSize) {
+ // -Os implies -O2
+ Opts.OptimizationLevel = 2;
+ } else {
+ Opts.OptimizationLevel = OptLevel;
+ }
+
+ // We must always run at least the always inlining pass.
+ if (Opts.OptimizationLevel > 1)
+ Opts.Inlining = CompileOptions::NormalInlining;
+ else
+ Opts.Inlining = CompileOptions::OnlyAlwaysInlining;
}
// FIXME: There are llvm-gcc options to control these selectively.
- Opts.InlineFunctions = (Opts.OptimizationLevel > 1);
Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Opts.SimplifyLibCalls = !LangOpts.NoBuiltin;