Author: qcolombet
Date: Thu Nov  1 18:55:47 2012
New Revision: 167266

URL: http://llvm.org/viewvc/llvm-project?rev=167266&view=rev
Log:
Update the front end to use minsize attribute

Added:
    cfe/trunk/test/CodeGen/attr-minsize.cpp
      - copied, changed from r167249, cfe/trunk/test/CodeGen/attr-minsize.c
    cfe/trunk/test/CodeGenObjC/attr-minsize.m
    cfe/trunk/test/Sema/attr-minsize.c
Removed:
    cfe/trunk/test/CodeGen/attr-minsize.c
Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=167266&r1=167265&r2=167266&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Nov  1 18:55:47 2012
@@ -341,6 +341,11 @@
   let SemaHandler = 0;
 }
 
+def MinSize : InheritableAttr {
+  let Spellings = [GNU<"minsize">];
+  let Subjects = [Function];
+}
+
 def Format : InheritableAttr {
   let Spellings = [GNU<"format">];
   let Args = [StringArgument<"Type">, IntArgument<"FormatIdx">,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=167266&r1=167265&r2=167266&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Nov  1 18:55:47 2012
@@ -583,6 +583,9 @@
   if (D->hasAttr<ColdAttr>())
     F->addFnAttr(llvm::Attributes::OptimizeForSize);
 
+  if (D->hasAttr<MinSizeAttr>())
+    F->addFnAttr(llvm::Attributes::MinSize);
+
   if (isa<CXXConstructorDecl>(D) || isa<CXXDestructorDecl>(D))
     F->setUnnamedAddr(true);
 

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=167266&r1=167265&r2=167266&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Nov  1 18:55:47 2012
@@ -1523,6 +1523,20 @@
                                          Str->getString()));
 }
 
+static void handleMinSizeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+  // Check the attribute arguments.
+  if (!checkAttributeNumArgs(S, Attr, 0))
+    return;
+
+  if (!isa<FunctionDecl>(D) && !isa<ObjCMethodDecl>(D)) {
+    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
+      << Attr.getName() << ExpectedFunctionOrMethod;
+    return;
+  }
+
+  D->addAttr(::new (S.Context) MinSizeAttr(Attr.getRange(), S.Context));
+}
+
 static void handleColdAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   // Check the attribute arguments.
   if (!checkAttributeNumArgs(S, Attr, 0))
@@ -4285,6 +4299,9 @@
   case AttributeList::AT_ExtVectorType:
     handleExtVectorTypeAttr(S, scope, D, Attr);
     break;
+  case AttributeList::AT_MinSize:
+    handleMinSizeAttr(S, D, Attr);
+    break;
   case AttributeList::AT_Format:      handleFormatAttr      (S, D, Attr); 
break;
   case AttributeList::AT_FormatArg:   handleFormatArgAttr   (S, D, Attr); 
break;
   case AttributeList::AT_CUDAGlobal:  handleGlobalAttr      (S, D, Attr); 
break;

Removed: cfe/trunk/test/CodeGen/attr-minsize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-minsize.c?rev=167265&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/attr-minsize.c (original)
+++ cfe/trunk/test/CodeGen/attr-minsize.c (removed)
@@ -1,26 +0,0 @@
-// RUN: %clang_cc1 -Oz -emit-llvm %s -o - | FileCheck %s -check-prefix=Oz
-// RUN: %clang_cc1 -O0 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
-// RUN: %clang_cc1 -O1 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
-// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
-// RUN: %clang_cc1 -O3 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
-// RUN: %clang_cc1 -Os -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
-// Check that we set the minsize attribute on each function
-// when Oz optimization level is set.
-
-int test1() {
-  return 42;
-// Oz: @test1{{.*}}minsize
-// Oz: ret
-// OTHER: @test1
-// OTHER-NOT: minsize
-// OTHER: ret
-}
-
-int test2() {
-  return 42;
-// Oz: @test2{{.*}}minsize
-// Oz: ret
-// OTHER: @test2
-// OTHER-NOT: minsize
-// OTHER: ret
-}

Copied: cfe/trunk/test/CodeGen/attr-minsize.cpp (from r167249, 
cfe/trunk/test/CodeGen/attr-minsize.c)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-minsize.cpp?p2=cfe/trunk/test/CodeGen/attr-minsize.cpp&p1=cfe/trunk/test/CodeGen/attr-minsize.c&r1=167249&r2=167266&rev=167266&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attr-minsize.c (original)
+++ cfe/trunk/test/CodeGen/attr-minsize.cpp Thu Nov  1 18:55:47 2012
@@ -9,18 +9,67 @@
 
 int test1() {
   return 42;
-// Oz: @test1{{.*}}minsize
+// Oz: @{{.*}}test1{{.*}}minsize
 // Oz: ret
-// OTHER: @test1
+// OTHER: @{{.*}}test1
 // OTHER-NOT: minsize
 // OTHER: ret
 }
 
 int test2() {
   return 42;
-// Oz: @test2{{.*}}minsize
+// Oz: @{{.*}}test2{{.*}}minsize
 // Oz: ret
-// OTHER: @test2
+// OTHER: @{{.*}}test2
 // OTHER-NOT: minsize
 // OTHER: ret
 }
+
+__attribute__((minsize))
+int test3() {
+  return 42;
+// Oz: @{{.*}}test3{{.*}}minsize
+// OTHER: @{{.*}}test3{{.*}}minsize
+}
+
+// Check that the minsize attribute is well propagated through
+// template instantiation
+
+template<typename T>
+__attribute__((minsize))
+void test4(T arg) {
+  return;
+}
+
+template
+void test4<int>(int arg);
+// Oz: define{{.*}}void @{{.*}}test4
+// Oz: minsize
+// OTHER: define{{.*}}void @{{.*}}test4
+// OTHER: minsize
+
+template
+void test4<float>(float arg);
+// Oz: define{{.*}}void @{{.*}}test4
+// Oz: minsize
+// OTHER: define{{.*}}void @{{.*}}test4
+// OTHER: minsize
+
+template<typename T>
+void test5(T arg) {
+  return;
+}
+
+template
+void test5<int>(int arg);
+// Oz: define{{.*}}void @{{.*}}test5
+// Oz: minsize
+// OTHER: define{{.*}}void @{{.*}}test5
+// OTHER-NOT: minsize
+
+template
+void test5<float>(float arg);
+// Oz: define{{.*}}void @{{.*}}test5
+// Oz: minsize
+// OTHER: define{{.*}}void @{{.*}}test5
+// OTHER-NOT: minsize

Added: cfe/trunk/test/CodeGenObjC/attr-minsize.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/attr-minsize.m?rev=167266&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/attr-minsize.m (added)
+++ cfe/trunk/test/CodeGenObjC/attr-minsize.m Thu Nov  1 18:55:47 2012
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+@interface Test
+- (void)test;
+@end
+
+@implementation Test
+- (void)test __attribute__((minsize)) {
+    // CHECK: define{{.*}}Test test
+    // CHECK: minsize
+}
+@end

Added: cfe/trunk/test/Sema/attr-minsize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-minsize.c?rev=167266&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-minsize.c (added)
+++ cfe/trunk/test/Sema/attr-minsize.c Thu Nov  1 18:55:47 2012
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int foo() __attribute__((__minsize__));
+
+int var1 __attribute__((__minsize__)); // expected-error{{'__minsize__' 
attribute only applies to functions and methods}}


_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to