[PATCH] D15777: [GlobalOpt] Globals used only in "main" can more easily be localized
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 25 11:07:14 PST 2015
Hi,
I don't fully agree with this. It is only applicable in C or C++
non-freestanding modes. We shouldn't break other front ends or languages
that happen to use the symbol 'main'.
Chandler has suggested a 'entry point' or 'noreentry' attribute to be a
corollary to norecurse. Perhaps that might help here?
As is, I don't think we can do this.
James
On Fri, 25 Dec 2015 at 14:54, Vaivaswatha Nagaraj via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> vaivaswatha created this revision.
> vaivaswatha added reviewers: jmolloy, hfinkel.
> vaivaswatha added a subscriber: llvm-commits.
>
> This change relaxes the condition for a global, that is only used in
> "main", to be localized. This relaxation partially undoes the change done
> in http://reviews.llvm.org/rL253168.
>
> This is required because the condition that was added earlier, that a
> store to the global needs to dominate all other references to it in the
> function is not necessary if the only function that accesses the global is
> "main". So, similar to the condition prior to the above mentioned change,
> this change allows "main" as an exception.
>
> http://reviews.llvm.org/D15777
>
> Files:
> lib/Transforms/IPO/GlobalOpt.cpp
> test/Transforms/GlobalOpt/load-store-global.ll
>
> Index: test/Transforms/GlobalOpt/load-store-global.ll
> ===================================================================
> --- test/Transforms/GlobalOpt/load-store-global.ll
> +++ test/Transforms/GlobalOpt/load-store-global.ll
> @@ -36,3 +36,16 @@
> ; CHECK-NOT: load
> }
>
> +; A global used only in "main" can always be localized.
> + at b = internal global i64 13, align 8
> +; CHECK-NOT: @b
> +
> +define i64 @main(i32 %argc, i8** %argv) norecurse {
> +; CHECK: %b = alloca
> +; CHECK store i64 13
> + %a = load i64, i64* @b
> +; CHECK %a = load i64
> + store i64 27, i64* @b
> +; CHECK store i64 27
> + ret i64 %a
> +}
> Index: lib/Transforms/IPO/GlobalOpt.cpp
> ===================================================================
> --- lib/Transforms/IPO/GlobalOpt.cpp
> +++ lib/Transforms/IPO/GlobalOpt.cpp
> @@ -1883,8 +1883,9 @@
> GV->getType()->getAddressSpace() == 0 &&
> !GV->isExternallyInitialized() &&
> allNonInstructionUsersCanBeMadeInstructions(GV) &&
> - GS.AccessingFunction->doesNotRecurse() &&
> - isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV) ) {
> + ((GS.AccessingFunction->doesNotRecurse() &&
> + isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV)) ||
> + (GS.AccessingFunction->getName() == "main"))) {
> DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV << "\n");
> Instruction &FirstI = const_cast<Instruction&>(*GS.AccessingFunction
>
> ->getEntryBlock().begin());
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151225/7c88b63e/attachment.html>
More information about the llvm-commits
mailing list