From 2c87f5341dd0e0614d5b1e423e3dc1168cfedf44 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Mon, 22 May 2017 12:47:43 +0000 Subject: [PATCH] [mips] Support `micromips` attribute This patch adds support for the `micromips` and `nomicromips` attributes for MIPS targets. Differential revision: https://reviews.llvm.org/D33363 llvm-svn: 303546 --- clang/include/clang/Basic/Attr.td | 12 ++++++++++++ clang/include/clang/Basic/AttrDocs.td | 13 +++++++++++++ clang/lib/CodeGen/TargetInfo.cpp | 5 +++++ clang/lib/Sema/SemaDeclAttr.cpp | 10 ++++++++-- clang/test/CodeGen/micromips-attr.c | 12 ++++++++++++ .../Misc/pragma-attribute-supported-attributes-list.test | 4 +++- clang/test/Sema/attr-micromips.c | 15 +++++++++++++++ 7 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/micromips-attr.c create mode 100644 clang/test/Sema/attr-micromips.c diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 4eb958e..a885ede 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1179,6 +1179,12 @@ def MipsInterrupt : InheritableAttr, TargetSpecificAttr { let Documentation = [MipsInterruptDocs]; } +def MicroMips : InheritableAttr, TargetSpecificAttr { + let Spellings = [GCC<"micromips">]; + let Subjects = SubjectList<[Function], ErrorDiag>; + let Documentation = [MicroMipsDocs]; +} + def Mode : Attr { let Spellings = [GCC<"mode">]; let Subjects = SubjectList<[Var, Enum, TypedefName, Field], ErrorDiag, @@ -1261,6 +1267,12 @@ def NoMips16 : InheritableAttr, TargetSpecificAttr { let Documentation = [Undocumented]; } +def NoMicroMips : InheritableAttr, TargetSpecificAttr { + let Spellings = [GCC<"nomicromips">]; + let Subjects = SubjectList<[Function], ErrorDiag>; + let Documentation = [MicroMipsDocs]; +} + // This is not a TargetSpecificAttr so that is silently accepted and // ignored on other targets as encouraged by the OpenCL spec. // diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 9e2fdf4..58b2fcc 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -1269,6 +1269,19 @@ The semantics are as follows: }]; } +def MicroMipsDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +Clang supports the GNU style ``__attribute__((micromips))`` and +``__attribute__((nomicromips))`` attributes on MIPS targets. These attributes +may be attached to a function definition and instructs the backend to generate +or not to generate microMIPS code for that function. + +These attributes override the -mmicromips and -mno-micromips options +on the command line. + }]; +} + def AVRInterruptDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index e47b480..83aa1fd 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -6557,6 +6557,11 @@ public: Fn->addFnAttr("nomips16"); } + if (FD->hasAttr()) + Fn->addFnAttr("micromips"); + else if (FD->hasAttr()) + Fn->addFnAttr("nomicromips"); + const MipsInterruptAttr *Attr = FD->getAttr(); if (!Attr) return; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 3de792e..1cac2a9 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5935,12 +5935,18 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, handleDLLAttr(S, D, Attr); break; case AttributeList::AT_Mips16: - handleSimpleAttributeWithExclusions(S, D, - Attr); + handleSimpleAttributeWithExclusions(S, D, Attr); break; case AttributeList::AT_NoMips16: handleSimpleAttribute(S, D, Attr); break; + case AttributeList::AT_MicroMips: + handleSimpleAttributeWithExclusions(S, D, Attr); + break; + case AttributeList::AT_NoMicroMips: + handleSimpleAttribute(S, D, Attr); + break; case AttributeList::AT_AMDGPUFlatWorkGroupSize: handleAMDGPUFlatWorkGroupSizeAttr(S, D, Attr); break; diff --git a/clang/test/CodeGen/micromips-attr.c b/clang/test/CodeGen/micromips-attr.c new file mode 100644 index 0000000..96ba774 --- /dev/null +++ b/clang/test/CodeGen/micromips-attr.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple mips-linux-gnu -emit-llvm -o - %s | FileCheck %s + +void __attribute__((micromips)) foo (void) {} + +// CHECK: define void @foo() [[MICROMIPS:#[0-9]+]] + +void __attribute__((nomicromips)) nofoo (void) {} + +// CHECK: define void @nofoo() [[NOMICROMIPS:#[0-9]+]] + +// CHECK: attributes [[MICROMIPS]] = { noinline nounwind {{.*}} "micromips" {{.*}} } +// CHECK: attributes [[NOMICROMIPS]] = { noinline nounwind {{.*}} "nomicromips" {{.*}} } diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test index 0db17bd..d698276 100644 --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -2,7 +2,7 @@ // The number of supported attributes should never go down! -// CHECK: #pragma clang attribute supports 60 attributes: +// CHECK: #pragma clang attribute supports 62 attributes: // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function) // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function) // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function) @@ -30,8 +30,10 @@ // CHECK-NEXT: IFunc (SubjectMatchRule_function) // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record) // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record) +// CHECK-NEXT: MicroMips (SubjectMatchRule_function) // CHECK-NEXT: NoDebug (SubjectMatchRule_hasType_functionType, SubjectMatchRule_objc_method, SubjectMatchRule_variable_not_is_parameter) // CHECK-NEXT: NoDuplicate (SubjectMatchRule_function) +// CHECK-NEXT: NoMicroMips (SubjectMatchRule_function) // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global) // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, SubjectMatchRule_variable_is_global) // CHECK-NEXT: NoSplitStack (SubjectMatchRule_function) diff --git a/clang/test/Sema/attr-micromips.c b/clang/test/Sema/attr-micromips.c new file mode 100644 index 0000000..95f22a5 --- /dev/null +++ b/clang/test/Sema/attr-micromips.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple mips-linux-gnu -fsyntax-only -verify %s + +__attribute__((nomicromips(0))) void foo1(); // expected-error {{'nomicromips' attribute takes no arguments}} +__attribute__((micromips(1))) void foo2(); // expected-error {{'micromips' attribute takes no arguments}} + +__attribute((nomicromips)) int a; // expected-error {{attribute only applies to functions}} +__attribute((micromips)) int b; // expected-error {{attribute only applies to functions}} + +__attribute__((micromips,mips16)) void foo5(); // expected-error {{'micromips' and 'mips16' attributes are not compatible}} \ + // expected-note {{conflicting attribute is here}} +__attribute__((mips16,micromips)) void foo6(); // expected-error {{'mips16' and 'micromips' attributes are not compatible}} \ + // expected-note {{conflicting attribute is here}} + +__attribute((micromips)) void foo7(); +__attribute((nomicromips)) void foo8(); -- 2.7.4