[cfe-commits] r72742 - in /cfe/trunk: include/clang/Frontend/CompileOptions.h lib/Frontend/Backend.cpp test/CodeGen/always_inline.c tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Tue Jun 2 15:08:00 PDT 2009
Author: ddunbar
Date: Tue Jun 2 17:07:45 2009
New Revision: 72742
URL: http://llvm.org/viewvc/llvm-project?rev=72742&view=rev
Log:
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.
Added:
cfe/trunk/test/CodeGen/always_inline.c
Modified:
cfe/trunk/include/clang/Frontend/CompileOptions.h
cfe/trunk/lib/Frontend/Backend.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Frontend/CompileOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompileOptions.h?rev=72742&r1=72741&r2=72742&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompileOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CompileOptions.h Tue Jun 2 17:07:45 2009
@@ -23,12 +23,17 @@
/// is optimized and passed to the backend.
class CompileOptions {
public:
+ enum InliningMethod {
+ NoInlining, // Perform no inlining whatsoever.
+ NormalInlining, // Use the standard function inlining pass.
+ OnlyAlwaysInlining // Only run the always inlining pass.
+ };
+
unsigned OptimizationLevel : 3; /// The -O[0-4] option specified.
unsigned OptimizeSize : 1; /// If -Os is specified.
unsigned DebugInfo : 1; /// Should generate deubg info (-g).
unsigned UnitAtATime : 1; /// Unused. For mirroring GCC
/// optimization selection.
- unsigned InlineFunctions : 1; /// Should functions be inlined?
unsigned SimplifyLibCalls : 1; /// Should standard library calls be
/// treated specially.
unsigned UnrollLoops : 1; /// Control whether loops are unrolled.
@@ -37,6 +42,9 @@
unsigned TimePasses : 1; /// Set when -ftime-report is enabled.
unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
+ /// Inlining - The kind of inlining to perform.
+ InliningMethod Inlining;
+
/// CPU - An optional CPU to target.
std::string CPU;
@@ -50,10 +58,11 @@
OptimizeSize = 0;
DebugInfo = 0;
UnitAtATime = 1;
- InlineFunctions = SimplifyLibCalls = UnrollLoops = 0;
+ SimplifyLibCalls = UnrollLoops = 0;
VerifyModule = 1;
TimePasses = 0;
NoCommon = 0;
+ Inlining = NoInlining;
}
};
Modified: cfe/trunk/lib/Frontend/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Backend.cpp?rev=72742&r1=72741&r2=72742&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Backend.cpp (original)
+++ cfe/trunk/lib/Frontend/Backend.cpp Tue Jun 2 17:07:45 2009
@@ -294,10 +294,16 @@
PM->add(createPruneEHPass()); // Remove dead EH info
PM->add(createFunctionAttrsPass()); // Set readonly/readnone attrs
}
- if (CompileOpts.InlineFunctions)
+ switch (CompileOpts.Inlining) {
+ case CompileOptions::NoInlining:
+ break;
+ case CompileOptions::NormalInlining:
PM->add(createFunctionInliningPass()); // Inline small functions
- else
+ break;
+ case CompileOptions::OnlyAlwaysInlining:
PM->add(createAlwaysInlinerPass()); // Respect always_inline
+ break;
+ }
if (CompileOpts.OptimizationLevel > 2)
PM->add(createArgumentPromotionPass()); // Scalarize uninlined fn args
if (CompileOpts.SimplifyLibCalls)
@@ -341,7 +347,16 @@
if (CompileOpts.OptimizationLevel > 1 && CompileOpts.UnitAtATime)
PM->add(createConstantMergePass()); // Merge dup global constants
} else {
- PM->add(createAlwaysInlinerPass());
+ switch (CompileOpts.Inlining) {
+ case CompileOptions::NoInlining:
+ break;
+ case CompileOptions::NormalInlining:
+ PM->add(createFunctionInliningPass()); // Inline small functions
+ break;
+ case CompileOptions::OnlyAlwaysInlining:
+ PM->add(createAlwaysInlinerPass()); // Respect always_inline
+ break;
+ }
}
}
Added: cfe/trunk/test/CodeGen/always_inline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/always_inline.c?rev=72742&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/always_inline.c (added)
+++ cfe/trunk/test/CodeGen/always_inline.c Tue Jun 2 17:07:45 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -emit-llvm -o %t %s &&
+// RUN: grep '@f0' %t | count 0 &&
+// RUN: clang-cc -disable-llvm-optzns -emit-llvm -o %t %s &&
+// RUN: grep '@f0' %t | count 2
+
+//static int f0() {
+static int __attribute__((always_inline)) f0() {
+ return 1;
+}
+
+int f1() {
+ return f0();
+}
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=72742&r1=72741&r2=72742&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Tue Jun 2 17:07:45 2009
@@ -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;
More information about the cfe-commits
mailing list