[llvm-commits] [llvm-gcc-4.2] r98626 - /llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
Chris Lattner
clattner at apple.com
Tue Mar 16 10:52:14 PDT 2010
Hi Duncan,
This is not safe, please revert it.
I originally tried to do this for llvm-gcc 3 and was defeated by libstdc++. It assumes (and it turns out the c++ standard allows this) that global variables are zero initialized before the constructor for a type is run on it.
-Chris
On Mar 16, 2010, at 4:35 AM, Duncan Sands wrote:
> Author: baldrick
> Date: Tue Mar 16 06:35:32 2010
> New Revision: 98626
>
> URL: http://llvm.org/viewvc/llvm-project?rev=98626&view=rev
> Log:
> If a global variable is initialized by a code sequence, then do not zero
> initialize it: using 'undef' makes it easier for the optimizers to sink
> initialization code into the initializer for the global. It is not clear
> if this is always correct, since it relies on the code sequence not somehow
> making use of the global being zero initialized. My limited experiments
> suggest that everything is fine. This is partial progress towards getting
> better code out of the testcase in PR6551.
>
> Modified:
> llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
>
> Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=98626&r1=98625&r2=98626&view=diff
> ==============================================================================
> --- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
> +++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Tue Mar 16 06:35:32 2010
> @@ -1320,10 +1320,17 @@
> // Convert the initializer over.
> Constant *Init;
> if (DECL_INITIAL(decl) == 0 || DECL_INITIAL(decl) == error_mark_node) {
> - // This global should be zero initialized. Reconvert the type in case the
> + // This global does not have an explicit initializer. This usually means
> + // that it should be zero initialized. Reconvert the type in case the
> // forward def of the global and the real def differ in type (e.g. declared
> // as 'int A[]', and defined as 'int A[100]').
> - Init = Constant::getNullValue(ConvertType(TREE_TYPE(decl)));
> + if (TYPE_NEEDS_CONSTRUCTING(TREE_TYPE(decl))) {
> + // The global will be initialized by a code sequence - it does not need to
> + // be zero initialized.
> + Init = UndefValue::get(ConvertType(TREE_TYPE(decl)));
> + } else {
> + Init = Constant::getNullValue(ConvertType(TREE_TYPE(decl)));
> + }
> } else {
> assert((TREE_CONSTANT(DECL_INITIAL(decl)) ||
> TREE_CODE(DECL_INITIAL(decl)) == STRING_CST) &&
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list