# HG changeset patch # User Frits van Bommel # Date 1238348797 -7200 # Node ID 34321f120882e5984b87503d7813af37a0f546ae # Parent 0b26cfb2d445c79b150028c580326a3e450c98f9# Parent cc1efa23030a0ed501d475c9a8f9bfdca14d9a9f Automated merge with http://hg.dsource.org/projects/ldc diff -r 0b26cfb2d445 -r 34321f120882 gen/cl_helpers.h --- a/gen/cl_helpers.h Sun Mar 29 19:19:32 2009 +0200 +++ b/gen/cl_helpers.h Sun Mar 29 19:46:37 2009 +0200 @@ -62,7 +62,23 @@ push_back(str.c_str()); } }; - + + /// Helper class to allow use of a parser with BoolOrDefault + class BoolOrDefaultAdapter { + cl::boolOrDefault value; + public: + operator cl::boolOrDefault() { + return value; + } + + void operator=(cl::boolOrDefault val) { + value = val; + } + + void operator=(bool val) { + *this = (val ? cl::BOU_TRUE : cl::BOU_FALSE); + } + }; } #endif diff -r 0b26cfb2d445 -r 34321f120882 gen/optimizer.cpp --- a/gen/optimizer.cpp Sun Mar 29 19:19:32 2009 +0200 +++ b/gen/optimizer.cpp Sun Mar 29 19:46:37 2009 +0200 @@ -1,4 +1,5 @@ #include "gen/optimizer.h" +#include "gen/cl_helpers.h" #include "llvm/PassManager.h" #include "llvm/LinkAllPasses.h" @@ -32,22 +33,26 @@ clEnumValEnd), cl::init(0)); -static cl::opt enableInlining("enable-inlining", - cl::desc("Enable function inlining (in -O, if given)"), - cl::ZeroOrMore, - cl::init(false)); +static cl::opt +enableInlining("inlining", + cl::desc("(*) Enable function inlining (in -O, if given)"), + cl::ZeroOrMore); -// Some accessors for the linker: (llvm-ld version only, currently unused?) +// Determine whether or not to run the inliner as part of the default list of +// optimization passes. +// If not explicitly specified, treat as false for -O0-2, and true for -O3. bool doInline() { - return enableInlining; + return enableInlining == cl::BOU_TRUE + || (enableInlining == cl::BOU_UNSET && optimizeLevel >= 3); } +// Some extra accessors for the linker: (llvm-ld version only, currently unused?) int optLevel() { return optimizeLevel; } bool optimize() { - return optimizeLevel || enableInlining || passList.empty(); + return optimizeLevel || doInline() || passList.empty(); } // this function inserts some or all of the std-compile-opts passes depending on the @@ -76,7 +81,7 @@ } // -inline - if (enableInlining) { + if (doInline()) { pm.add(createFunctionInliningPass()); } @@ -123,13 +128,13 @@ // Returns true if any optimization passes were invoked. bool ldc_optimize_module(llvm::Module* m) { - if (!enableInlining && optimizeLevel == 0 && passList.empty()) + if (!doInline() && optimizeLevel == 0 && passList.empty()) return false; PassManager pm; pm.add(new TargetData(m)); - bool optimize = optimizeLevel != 0 || enableInlining; + bool optimize = optimizeLevel != 0 || doInline(); unsigned optPos = optimizeLevel != 0 ? optimizeLevel.getPosition()