[llvm] r174345 - Add code to GlobalVariable.h so that global variables marked as
Chad Rosier
mcrosier at apple.com
Tue Feb 5 11:34:48 PST 2013
On Feb 4, 2013, at 10:53 PM, Michael Gottesman <mgottesman at apple.com> wrote:
> Author: mgottesman
> Date: Tue Feb 5 00:53:26 2013
> New Revision: 174345
>
> URL: http://llvm.org/viewvc/llvm-project?rev=174345&view=rev
> Log:
> Add code to GlobalVariable.h so that global variables marked as
> externally_initialized return false for hasDefiniteInitializer and
> hasUniqueInitializer.
>
> rdar://12580965.
>
> Added:
> llvm/trunk/test/Transforms/GlobalOpt/externally-initialized-global-ctr.ll
> Modified:
> llvm/trunk/include/llvm/IR/GlobalVariable.h
>
> Modified: llvm/trunk/include/llvm/IR/GlobalVariable.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalVariable.h?rev=174345&r1=174344&r2=174345&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/GlobalVariable.h (original)
> +++ llvm/trunk/include/llvm/IR/GlobalVariable.h Tue Feb 5 00:53:26 2013
> @@ -110,7 +110,10 @@ public:
> return hasInitializer() &&
> // The initializer of a global variable with weak linkage may change at
> // link time.
> - !mayBeOverridden();
> + !mayBeOverridden() &&
> + // The initializer of a global variable with the externally_initialized
> + // marker may change at runtime before cxx initializers are evaluated.
> + !isExternallyInitialized();
> }
>
> /// hasUniqueInitializer - Whether the global variable has an initializer, and
> @@ -123,7 +126,11 @@ public:
> // instead. It is wrong to modify the initializer of a global variable
> // with *_odr linkage because then different instances of the global may
> // have different initializers, breaking the One Definition Rule.
> - !isWeakForLinker();
> + !isWeakForLinker() &&
> + // It is not safe to modify initializers of global variables with the
> + // external_initializer marker since the value may be changed at runtime
> + // before cxx initializers are evaluated.
> + !isExternallyInitialized();
> }
>
> /// getInitializer - Return the initializer for this global variable. It is
>
> Added: llvm/trunk/test/Transforms/GlobalOpt/externally-initialized-global-ctr.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/externally-initialized-global-ctr.ll?rev=174345&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/GlobalOpt/externally-initialized-global-ctr.ll (added)
> +++ llvm/trunk/test/Transforms/GlobalOpt/externally-initialized-global-ctr.ll Tue Feb 5 00:53:26 2013
> @@ -0,0 +1,35 @@
> +; RUN: opt < %s -globalopt -S | FileCheck %s
> +; rdar://12580965.
> +; ObjC++ test case.
> +
> +%struct.ButtonInitData = type { i8* }
> +
> + at _ZL14buttonInitData = internal global [1 x %struct.ButtonInitData] zeroinitializer, align 4
> +
> +@"\01L_OBJC_METH_VAR_NAME_40" = internal global [7 x i8] c"print:\00", section "__TEXT,__objc_methname,cstring_literals", align 1
> +@"\01L_OBJC_SELECTOR_REFERENCES_41" = internal externally_initialized global i8* getelementptr inbounds ([7 x i8]* @"\01L_OBJC_METH_VAR_NAME_40", i32 0, i32 0), section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
> +
> + at llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
> + at llvm.used = appending global [2 x i8*] [i8* getelementptr inbounds ([7 x i8]* @"\01L_OBJC_METH_VAR_NAME_40", i32 0, i32 0), i8* bitcast (i8** @"\01L_OBJC_SELECTOR_REFERENCES_41" to i8*)]
> +
> +define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
> + %1 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_41", !invariant.load !2009
> + store i8* %1, i8** getelementptr inbounds ([1 x %struct.ButtonInitData]* @_ZL14buttonInitData, i32 0, i32 0, i32 0), align 4
> + ret void
> +}
> +
> +define internal void @_GLOBAL__I_a() section "__TEXT,__StaticInit,regular,pure_instructions" {
> + call void @__cxx_global_var_init()
> + ret void
> +}
> +
> +declare void @test(i8*)
> +
> +define void @print() {
> +; CHECK: %1 = load i8** getelementptr inbounds ([1 x %struct.ButtonInitData]* @_ZL14buttonInitData, i32 0, i32 0, i32 0), align 4
> + %1 = load i8** getelementptr inbounds ([1 x %struct.ButtonInitData]* @_ZL14buttonInitData, i32 0, i32 0, i32 0), align 4
> + call void @test(i8* %1)
> + ret void
> +}
> +
> +!2009 = metadata !{}
> \ No newline at end of file
Please add a newline at the end of the file.
Chad
>
> _______________________________________________
> 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