r235396 - Provide alignment info on LLVM external symbols

Ulrich Weigand ulrich.weigand at de.ibm.com
Tue Apr 21 10:27:59 PDT 2015


Author: uweigand
Date: Tue Apr 21 12:27:59 2015
New Revision: 235396

URL: http://llvm.org/viewvc/llvm-project?rev=235396&view=rev
Log:
Provide alignment info on LLVM external symbols

Code in CodeGenModule::GetOrCreateLLVMGlobal that sets up GlobalValue
object for LLVM external symbols has this comment:

    // FIXME: This code is overly simple and should be merged with other global
    // handling.

One part does seems to be "overly simple" currently is that this code
never sets any alignment info on the GlobalValue, so that the emitted
IR does not have any align attribute on external globals.  This can
lead to unnecessarily inefficient code generation.

This patch adds a GV->setAlignment call to set alignment info.


Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/align-systemz.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=235396&r1=235395&r2=235396&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 21 12:27:59 2015
@@ -1777,6 +1777,8 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
     // handling.
     GV->setConstant(isTypeConstant(D->getType(), false));
 
+    GV->setAlignment(getContext().getDeclAlign(D).getQuantity());
+
     setLinkageAndVisibilityForGV(GV, D);
 
     if (D->getTLSKind()) {

Modified: cfe/trunk/test/CodeGen/align-systemz.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/align-systemz.c?rev=235396&r1=235395&r2=235396&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/align-systemz.c (original)
+++ cfe/trunk/test/CodeGen/align-systemz.c Tue Apr 21 12:27:59 2015
@@ -12,3 +12,16 @@ char c;
 struct test s;
 // CHECK-DAG: @s = common global %struct.test zeroinitializer, align 2
 
+extern char ec;
+// CHECK-DAG: @ec = external global i8, align 2
+
+extern struct test es;
+// CHECK-DAG: @es = external global %struct.test, align 2
+
+// Dummy function to make sure external symbols are used.
+void func (void)
+{
+  c = ec;
+  s = es;
+}
+





More information about the cfe-commits mailing list