[PATCH] GlobalOpt enhancement optimization (hoisting of initialization code into constant global initializers).

Reid Kleckner rnk at google.com
Mon Aug 26 11:47:44 PDT 2013


I'm not really an owner of GlobalOpt, but this seems like a big ugly huge
special case, rather than something general that's part of the Evaluator
class.  You should be able to emulate stores to isInit in the usual way,
since it's internal.  Can you debug why that isn't firing?

I think it would be much more interesting to try to look at Itanium C++
dynamic initializers and try to fold those away.  This would imply
understanding what __cxx_acquire / release mean when -fno-builtin /
-ffreestanding aren't set.


On Mon, Aug 26, 2013 at 1:40 AM, Puyan Lotfi <plotfi at apple.com> wrote:

> All:
>
> Attached is a patch to GlobalOpt that adds an optimization that takes user
> written constant initialization code for global variables and hoists the
> initialization values into the global initializer. This optimization is
> only done on locally linked globals of integral types (scalars, arrays, and
> structs) that are constant initialized (and zero initialized prior to
> transformation).
>
> The idea is to transform the following code:
>
> A = internal global i32 0, align 4
> isInit = internal global i1 false
>
> define i32* foobar() {
>   %.b = load i1* isInit
>   %1 = zext i1 %.b to i8
>   %2 = trunc i8 %1 to i1
>   br i1 %2, BB4, label BB3
> BB3:
>   store i32 113, i32* A, align 4
>   store i1 true, i1* isInit
>   br label %4
> BB4:
>   ret i32* A
> }
>
> Into:
>
> A = internal global i32 113, align 4
>
> define i32* @_Z8initTestv() {
>   ret i32* A
> }
>
> Could someone on the list review my changes, provide feedback, and if
> possible submit my changes?
>
> I also have some test cases I've written but I am still trying to figure
> out how to add them to llvm/test/Transforms/GlobalOpt (I don't see a
> lit.local.cfg in that directory as the docs specify).
>
> Thanks
>
> -Puyan
>
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130826/681a036e/attachment.html>


More information about the llvm-commits mailing list