[cfe-commits] r90652 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGen/decl.c

Chris Lattner sabre at nondot.org
Fri Dec 4 22:49:57 PST 2009


Author: lattner
Date: Sat Dec  5 00:49:57 2009
New Revision: 90652

URL: http://llvm.org/viewvc/llvm-project?rev=90652&view=rev
Log:
simplify a condition and add a testcase.

Added:
    cfe/trunk/test/CodeGen/decl.c
Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=90652&r1=90651&r2=90652&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Dec  5 00:49:57 2009
@@ -323,14 +323,16 @@
   if (Ty->isConstantSizeType()) {
     if (!Target.useGlobalsForAutomaticVariables()) {
       
-      // All constant structs and arrays should be global if
-      // their initializer is constant and if the element type is POD.
-      if (CGM.getCodeGenOpts().MergeAllConstants) {
-        if (Ty.isConstant(getContext())
-            && (Ty->isArrayType() || Ty->isRecordType())
-            && (D.getInit() 
-                && D.getInit()->isConstantInitializer(getContext()))
-            && Ty->isPODType()) {
+      // If this value is an array or struct, is POD, and if the initializer is
+      // a staticly determinable constant, try to optimize it.
+      if (D.getInit() &&
+          (Ty->isArrayType() || Ty->isRecordType()) &&
+          Ty->isPODType() &&
+          D.getInit()->isConstantInitializer(getContext())) {
+
+        // If this variable is marked 'const', emit the value as a global.
+        if (CGM.getCodeGenOpts().MergeAllConstants &&
+            Ty.isConstant(getContext())) {
           EmitStaticBlockVarDecl(D);
           return;
         }

Added: cfe/trunk/test/CodeGen/decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/decl.c?rev=90652&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/decl.c (added)
+++ cfe/trunk/test/CodeGen/decl.c Sat Dec  5 00:49:57 2009
@@ -0,0 +1,12 @@
+// RUN: clang-cc -emit-llvm < %s | FileCheck %s
+
+// CHECK: @test1.x = internal constant [12 x i32] [i32 1
+
+void test1() {
+  // This should codegen as a "@test1.x" global.
+  const int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23 };
+  foo(x);
+
+// CHECK: @test1()
+// CHECK: {{call.*@foo.*@test1.x}}
+}





More information about the cfe-commits mailing list