[llvm] r193436 - Handle calls and invokes in GlobalStatus.

Rafael Espindola rafael.espindola at gmail.com
Fri Oct 25 14:29:52 PDT 2013


Author: rafael
Date: Fri Oct 25 16:29:52 2013
New Revision: 193436

URL: http://llvm.org/viewvc/llvm-project?rev=193436&view=rev
Log:
Handle calls and invokes in GlobalStatus.

This patch teaches GlobalStatus to analyze a call that uses the global value as
a callee, not as an argument.

With this change internalize call handle the common use of linkonce_odr
functions. This reduces the number of linkonce_odr functions in a LTO build of
clang (checked with the emit-llvm gold plugin option) from 1730 to 60.

Added:
    llvm/trunk/test/Transforms/Internalize/linkonce_odr_func.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp

Modified: llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp?rev=193436&r1=193435&r2=193436&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp Fri Oct 25 16:29:52 2013
@@ -11,6 +11,7 @@
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/IntrinsicInst.h"
+#include "llvm/Support/CallSite.h"
 #include "llvm/Transforms/Utils/GlobalStatus.h"
 
 using namespace llvm;
@@ -148,6 +149,10 @@ static bool analyzeGlobalAux(const Value
         if (MSI->isVolatile())
           return true;
         GS.StoredType = GlobalStatus::Stored;
+      } else if (ImmutableCallSite C = I) {
+        if (!C.isCallee(UI))
+          return true;
+        GS.IsLoaded = true;
       } else {
         return true; // Any other non-load instruction might take address!
       }

Added: llvm/trunk/test/Transforms/Internalize/linkonce_odr_func.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Internalize/linkonce_odr_func.ll?rev=193436&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Internalize/linkonce_odr_func.ll (added)
+++ llvm/trunk/test/Transforms/Internalize/linkonce_odr_func.ll Fri Oct 25 16:29:52 2013
@@ -0,0 +1,37 @@
+; RUN: opt < %s -internalize -internalize-dso-list foo1,foo2,foo3,foo4 -S | FileCheck %s
+
+; CHECK: define internal void @foo1(
+define linkonce_odr void @foo1() noinline {
+  ret void
+}
+
+; CHECK: define linkonce_odr void @foo2(
+define linkonce_odr void @foo2() noinline {
+  ret void
+}
+
+; CHECK: define internal void @foo3(
+define linkonce_odr void @foo3() noinline {
+  ret void
+}
+
+; CHECK: define linkonce_odr void @foo4(
+define linkonce_odr void @foo4() noinline {
+  ret void
+}
+
+declare void @f(void()*)
+
+define void @bar() {
+bb0:
+  call void @foo1()
+  call void @f(void()* @foo2)
+  invoke void @foo3() to label %bb1 unwind label %clean
+bb1:
+  invoke void @f(void()* @foo4) to label %bb2 unwind label %clean
+bb2:
+  ret void
+clean:
+  landingpad i32 personality i8* null cleanup
+  ret void
+}





More information about the llvm-commits mailing list