[cfe-commits] patch for review

Reed Kotler rkotler at mips.com
Sat Jan 12 06:32:30 PST 2013


I don't have commit access to the clang list (as far as I know; just llvm).

Please commit if you approve the patch.

This patch is the first step to adding function attributes mips16 and 
nomips16 to the mips
target.

Tia.

Reed



-------------- next part --------------
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
index 858df3a..d5c7ab3 100644
--- a/include/clang/Basic/Attr.td
+++ b/include/clang/Basic/Attr.td
@@ -403,6 +403,10 @@ def MBlazeSaveVolatiles : InheritableAttr {
   let SemaHandler = 0;
 }
 
+def Mips16 : InheritableAttr {
+  let Spellings = [GNU<"mips16">];
+}
+
 def Mode : Attr {
   let Spellings = [GNU<"mode">];
   let Args = [IdentifierArgument<"Mode">];
@@ -441,6 +445,10 @@ def NoInline : InheritableAttr {
   let Spellings = [GNU<"noinline">];
 }
 
+def NoMips16 : InheritableAttr {
+  let Spellings = [GNU<"nomips16">];
+}
+
 def NonNull : InheritableAttr {
   let Spellings = [GNU<"nonnull">];
   let Args = [VariadicUnsignedArgument<"Args">];
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
index 5f2bd52..47005e7 100644
--- a/lib/CodeGen/TargetInfo.cpp
+++ b/lib/CodeGen/TargetInfo.cpp
@@ -3846,6 +3846,13 @@ public:
     return 29;
   }
 
+  void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+                           CodeGen::CodeGenModule &CGM) const {
+    //
+    // can fill this in when new attribute work in llvm is done.
+    // attributes mips16 and nomips16 need to be handled here.
+    //
+  }
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                llvm::Value *Address) const;
 
diff --git a/lib/Sema/TargetAttributesSema.cpp b/lib/Sema/TargetAttributesSema.cpp
index 94f240c..566acee 100644
--- a/lib/Sema/TargetAttributesSema.cpp
+++ b/lib/Sema/TargetAttributesSema.cpp
@@ -262,6 +262,24 @@ namespace {
   };
 }
 
+namespace {
+  class MipsAttributesSema : public TargetAttributesSema {
+  public:
+    MipsAttributesSema() { }
+    bool ProcessDeclAttribute(Scope *scope, Decl *D, const AttributeList &Attr,
+                              Sema &S) const {
+      if (Attr.getName()->getName() == "mips16") {
+        D->addAttr(::new (S.Context) Mips16Attr(Attr.getRange(), S.Context));
+        return true;
+      } else if (Attr.getName()->getName() == "nomips16") {
+        D->addAttr(::new (S.Context) NoMips16Attr(Attr.getRange(), S.Context));
+        return true;
+      }
+      return false;
+    }
+  };
+}
+
 const TargetAttributesSema &Sema::getTargetAttributesSema() const {
   if (TheTargetAttributesSema)
     return *TheTargetAttributesSema;
@@ -275,6 +293,9 @@ const TargetAttributesSema &Sema::getTargetAttributesSema() const {
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
     return *(TheTargetAttributesSema = new X86AttributesSema);
+  case llvm::Triple::mips:
+  case llvm::Triple::mipsel:
+    return *(TheTargetAttributesSema = new MipsAttributesSema);
   default:
     return *(TheTargetAttributesSema = new TargetAttributesSema);
   }
diff --git a/test/Sema/mips16_attr_allowed.c b/test/Sema/mips16_attr_allowed.c
new file mode 100644
index 0000000..a868daf
--- /dev/null
+++ b/test/Sema/mips16_attr_allowed.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple mipsel-linux-gnu -fsyntax-only -verify %s
+
+void __attribute__((nomips16)) foo32(); // expected-no-diagnostics
+void __attribute__((mips16)) foo16(); // expected-no-diagnostics
+
+
+int main() {
+  foo32();
+  foo16();
+}
diff --git a/test/Sema/mips16_attr_not_allowed.c b/test/Sema/mips16_attr_not_allowed.c
new file mode 100644
index 0000000..23a23fb
--- /dev/null
+++ b/test/Sema/mips16_attr_not_allowed.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
+
+void __attribute__((nomips16)) foo32(); // expected-warning {{unknown attribute 'nomips16' ignored}}
+void __attribute__((mips16)) foo16(); // expected-warning {{unknown attribute 'mips16' ignored}}
+
+
+int main() {
+  foo32();
+  foo16();
+}


More information about the cfe-commits mailing list