forked from OSchip/llvm-project
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.
llvm-svn: 85991
This commit is contained in:
parent
b9c9b351e9
commit
f9d41df093
|
@ -404,6 +404,7 @@ OPTION("-flax-vector-conversions", flax_vector_conversions, Flag, f_Group, INVAL
|
||||||
OPTION("-flimited-precision=", flimited_precision_EQ, Joined, f_Group, INVALID, "", 0, 0, 0)
|
OPTION("-flimited-precision=", flimited_precision_EQ, Joined, f_Group, INVALID, "", 0, 0, 0)
|
||||||
OPTION("-flto", flto, Flag, 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("-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("-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("-fms-extensions", fms_extensions, Flag, f_Group, INVALID, "", 0, 0, 0)
|
||||||
OPTION("-fmudflapth", fmudflapth, Flag, f_Group, INVALID, "", 0, 0, 0)
|
OPTION("-fmudflapth", fmudflapth, Flag, f_Group, INVALID, "", 0, 0, 0)
|
||||||
|
@ -428,6 +429,7 @@ OPTION("-fno-inline-functions", fno_inline_functions, Flag, clang_ignored_f_Grou
|
||||||
OPTION("-fno-inline", fno_inline, Flag, clang_ignored_f_Group, INVALID, "", 0, 0, 0)
|
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-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-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-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-pascal-strings", fno_pascal_strings, Flag, f_Group, INVALID, "", 0, 0, 0)
|
||||||
OPTION("-fno-rtti", fno_rtti, Flag, f_Group, INVALID, "", 0, 0, 0)
|
OPTION("-fno-rtti", fno_rtti, Flag, f_Group, INVALID, "", 0, 0, 0)
|
||||||
|
|
|
@ -43,7 +43,8 @@ public:
|
||||||
unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
|
unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
|
||||||
unsigned DisableRedZone : 1; /// Set when -mno-red-zone is enabled.
|
unsigned DisableRedZone : 1; /// Set when -mno-red-zone is enabled.
|
||||||
unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float 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.
|
/// Inlining - The kind of inlining to perform.
|
||||||
InliningMethod Inlining;
|
InliningMethod Inlining;
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ public:
|
||||||
Inlining = NoInlining;
|
Inlining = NoInlining;
|
||||||
DisableRedZone = 0;
|
DisableRedZone = 0;
|
||||||
NoImplicitFloat = 0;
|
NoImplicitFloat = 0;
|
||||||
|
MergeAllConstants = 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "clang/AST/DeclObjC.h"
|
#include "clang/AST/DeclObjC.h"
|
||||||
#include "clang/Basic/SourceManager.h"
|
#include "clang/Basic/SourceManager.h"
|
||||||
#include "clang/Basic/TargetInfo.h"
|
#include "clang/Basic/TargetInfo.h"
|
||||||
|
#include "clang/Frontend/CompileOptions.h"
|
||||||
#include "llvm/GlobalVariable.h"
|
#include "llvm/GlobalVariable.h"
|
||||||
#include "llvm/Intrinsics.h"
|
#include "llvm/Intrinsics.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
@ -316,6 +317,20 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
|
||||||
llvm::Value *DeclPtr;
|
llvm::Value *DeclPtr;
|
||||||
if (Ty->isConstantSizeType()) {
|
if (Ty->isConstantSizeType()) {
|
||||||
if (!Target.useGlobalsForAutomaticVariables()) {
|
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.
|
// A normal fixed sized variable becomes an alloca in the entry block.
|
||||||
const llvm::Type *LTy = ConvertTypeForMem(Ty);
|
const llvm::Type *LTy = ConvertTypeForMem(Ty);
|
||||||
Align = getContext().getDeclAlignInBytes(&D);
|
Align = getContext().getDeclAlignInBytes(&D);
|
||||||
|
|
|
@ -703,6 +703,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
CmdArgs.push_back("--debug-pass=Structure");
|
CmdArgs.push_back("--debug-pass=Structure");
|
||||||
if (Args.hasArg(options::OPT_fdebug_pass_arguments))
|
if (Args.hasArg(options::OPT_fdebug_pass_arguments))
|
||||||
CmdArgs.push_back("--debug-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
|
// This is a coarse approximation of what llvm-gcc actually does, both
|
||||||
// -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
|
// -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
|
||||||
|
|
|
@ -653,6 +653,10 @@ static llvm::cl::opt<bool>
|
||||||
NoElideConstructors("fno-elide-constructors",
|
NoElideConstructors("fno-elide-constructors",
|
||||||
llvm::cl::desc("Disable C++ copy constructor elision"));
|
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>
|
static llvm::cl::opt<std::string>
|
||||||
TargetABI("target-abi",
|
TargetABI("target-abi",
|
||||||
llvm::cl::desc("Target a particular ABI type"));
|
llvm::cl::desc("Target a particular ABI type"));
|
||||||
|
@ -1372,6 +1376,8 @@ static void InitializeCompileOptions(CompileOptions &Opts,
|
||||||
|
|
||||||
Opts.DisableRedZone = DisableRedZone;
|
Opts.DisableRedZone = DisableRedZone;
|
||||||
Opts.NoImplicitFloat = NoImplicitFloat;
|
Opts.NoImplicitFloat = NoImplicitFloat;
|
||||||
|
|
||||||
|
Opts.MergeAllConstants = !NoMergeConstants;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
Loading…
Reference in New Issue