[cfe-commits] r85991 - in /cfe/trunk: include/clang/Driver/Options.def include/clang/Frontend/CompileOptions.h lib/CodeGen/CGDecl.cpp lib/Driver/Tools.cpp tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Tue Nov 3 22:43:01 PST 2009
Hi Tanya,
On Tue, Nov 3, 2009 at 5:18 PM, Tanya Lattner <tonic at nondot.org> wrote:
> Author: tbrethou
> Date: Tue Nov 3 19:18:09 2009
> New Revision: 85991
>
> URL: http://llvm.org/viewvc/llvm-project?rev=85991&view=rev
> Log:
> Merge constant array and structures. This will create a global variables for arrays and structs that are constant and their initializer is constant. It is on by default but can be disable with the flag -fno-merge-all-constants.
Looks good, but it would be good to have a test case that demonstrates
the opt and verifies that -fno-merge-all-constants does the right
thing.
- Daniel
> Modified:
> cfe/trunk/include/clang/Driver/Options.def
> cfe/trunk/include/clang/Frontend/CompileOptions.h
> cfe/trunk/lib/CodeGen/CGDecl.cpp
> cfe/trunk/lib/Driver/Tools.cpp
> cfe/trunk/tools/clang-cc/clang-cc.cpp
>
> Modified: cfe/trunk/include/clang/Driver/Options.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.def?rev=85991&r1=85990&r2=85991&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Options.def (original)
> +++ cfe/trunk/include/clang/Driver/Options.def Tue Nov 3 19:18:09 2009
> @@ -404,6 +404,7 @@
> OPTION("-flimited-precision=", flimited_precision_EQ, Joined, f_Group, INVALID, "", 0, 0, 0)
> OPTION("-flto", flto, Flag, f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fmath-errno", fmath_errno, Flag, f_Group, INVALID, "", 0, 0, 0)
> +OPTION("-fmerge-all-constants", fmerge_all_constants, Flag, f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fmessage-length=", fmessage_length_EQ, Joined, f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fms-extensions", fms_extensions, Flag, f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fmudflapth", fmudflapth, Flag, f_Group, INVALID, "", 0, 0, 0)
> @@ -428,6 +429,7 @@
> OPTION("-fno-inline", fno_inline, Flag, clang_ignored_f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fno-keep-inline-functions", fno_keep_inline_functions, Flag, clang_ignored_f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fno-math-errno", fno_math_errno, Flag, f_Group, INVALID, "", 0, 0, 0)
> +OPTION("-fno-merge-all-constants", fno_merge_all_constants, Flag, f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fno-omit-frame-pointer", fno_omit_frame_pointer, Flag, f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fno-pascal-strings", fno_pascal_strings, Flag, f_Group, INVALID, "", 0, 0, 0)
> OPTION("-fno-rtti", fno_rtti, Flag, f_Group, INVALID, "", 0, 0, 0)
>
> Modified: cfe/trunk/include/clang/Frontend/CompileOptions.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompileOptions.h?rev=85991&r1=85990&r2=85991&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/CompileOptions.h (original)
> +++ cfe/trunk/include/clang/Frontend/CompileOptions.h Tue Nov 3 19:18:09 2009
> @@ -43,7 +43,8 @@
> unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
> unsigned DisableRedZone : 1; /// Set when -mno-red-zone is enabled.
> unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled.
> -
> + unsigned MergeAllConstants : 1; // Merge identical constants.
> +
> /// Inlining - The kind of inlining to perform.
> InliningMethod Inlining;
>
> @@ -67,6 +68,7 @@
> Inlining = NoInlining;
> DisableRedZone = 0;
> NoImplicitFloat = 0;
> + MergeAllConstants = 1;
> }
> };
>
>
> Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=85991&r1=85990&r2=85991&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Nov 3 19:18:09 2009
> @@ -19,6 +19,7 @@
> #include "clang/AST/DeclObjC.h"
> #include "clang/Basic/SourceManager.h"
> #include "clang/Basic/TargetInfo.h"
> +#include "clang/Frontend/CompileOptions.h"
> #include "llvm/GlobalVariable.h"
> #include "llvm/Intrinsics.h"
> #include "llvm/Target/TargetData.h"
> @@ -316,6 +317,20 @@
> llvm::Value *DeclPtr;
> if (Ty->isConstantSizeType()) {
> if (!Target.useGlobalsForAutomaticVariables()) {
> +
> + // All constant structs and arrays should be global if
> + // their initializer is constant and if the element type is POD.
> + if (CGM.getCompileOpts().MergeAllConstants) {
> + if (Ty.isConstant(getContext())
> + && (Ty->isArrayType() || Ty->isRecordType())
> + && (D.getInit()
> + && D.getInit()->isConstantInitializer(getContext()))
> + && Ty->isPODType()) {
> + EmitStaticBlockVarDecl(D);
> + return;
> + }
> + }
> +
> // A normal fixed sized variable becomes an alloca in the entry block.
> const llvm::Type *LTy = ConvertTypeForMem(Ty);
> Align = getContext().getDeclAlignInBytes(&D);
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=85991&r1=85990&r2=85991&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Tue Nov 3 19:18:09 2009
> @@ -703,6 +703,9 @@
> CmdArgs.push_back("--debug-pass=Structure");
> if (Args.hasArg(options::OPT_fdebug_pass_arguments))
> CmdArgs.push_back("--debug-pass=Arguments");
> + if (!Args.hasFlag(options::OPT_fmerge_all_constants,
> + options::OPT_fno_merge_all_constants))
> + CmdArgs.push_back("--no-merge-all-constants");
>
> // This is a coarse approximation of what llvm-gcc actually does, both
> // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
>
> 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=85991&r1=85990&r2=85991&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
> +++ cfe/trunk/tools/clang-cc/clang-cc.cpp Tue Nov 3 19:18:09 2009
> @@ -653,6 +653,10 @@
> NoElideConstructors("fno-elide-constructors",
> llvm::cl::desc("Disable C++ copy constructor elision"));
>
> +static llvm::cl::opt<bool>
> +NoMergeConstants("fno-merge-all-constants",
> + llvm::cl::desc("Disallow merging of constants."));
> +
> static llvm::cl::opt<std::string>
> TargetABI("target-abi",
> llvm::cl::desc("Target a particular ABI type"));
> @@ -1372,6 +1376,8 @@
>
> Opts.DisableRedZone = DisableRedZone;
> Opts.NoImplicitFloat = NoImplicitFloat;
> +
> + Opts.MergeAllConstants = !NoMergeConstants;
> }
>
> //===----------------------------------------------------------------------===//
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list