]> granicus.if.org Git - clang/commitdiff
Provide alignment info on LLVM external symbols
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 21 Apr 2015 17:27:59 +0000 (17:27 +0000)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 21 Apr 2015 17:27:59 +0000 (17:27 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235396 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/align-systemz.c

index 17b7ddc7683dc61ae03dfd7a7d655c37f21525c4..b30885d4cdb215280b94e7d1acd89154e8a2b3a2 100644 (file)
@@ -1777,6 +1777,8 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
     // handling.
     GV->setConstant(isTypeConstant(D->getType(), false));
 
+    GV->setAlignment(getContext().getDeclAlign(D).getQuantity());
+
     setLinkageAndVisibilityForGV(GV, D);
 
     if (D->getTLSKind()) {
index 277492c0601188735e41eadb75861beffe8b4958..68a21e39ab36fd0d3b4e0fd8ca7bc286bac78329 100644 (file)
@@ -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;
+}
+