]> granicus.if.org Git - clang/commitdiff
Cause the mips16/nomips16 attribute to be passed to LLVM from Clang
authorReed Kotler <rkotler@mips.com>
Wed, 13 Mar 2013 20:40:30 +0000 (20:40 +0000)
committerReed Kotler <rkotler@mips.com>
Wed, 13 Mar 2013 20:40:30 +0000 (20:40 +0000)
in the LLVM assembly language output.

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

lib/CodeGen/TargetInfo.cpp
test/CodeGen/mips16-attr.c [new file with mode: 0644]

index 81267ca7671598f935533591d645e02cb30bd374..556999f61b3ea100d9e9ca493177d65951e13b08 100644 (file)
@@ -4321,11 +4321,17 @@ public:
 
   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.
-    //
+    const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
+    if (!FD) return;
+    llvm::Function *Fn = cast<llvm::Function>(GV);
+    if (FD->hasAttr<Mips16Attr>()) {
+      Fn->addFnAttr("mips16");
+    }
+    else if (FD->hasAttr<NoMips16Attr>()) {
+      Fn->addFnAttr("nomips16");
+    }
   }
+
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                llvm::Value *Address) const;
 
diff --git a/test/CodeGen/mips16-attr.c b/test/CodeGen/mips16-attr.c
new file mode 100644 (file)
index 0000000..326ee7b
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple mipsel-linux-gnu -emit-llvm  -o  - %s | FileCheck %s
+void __attribute__((mips16)) foo (void) {
+
+}
+
+// CHECK: define void @foo() [[MIPS16:#[0-9]+]]
+
+void __attribute__((nomips16)) nofoo (void) {
+
+}
+
+// CHECK: define void @nofoo() [[NOMIPS16:#[0-9]+]]
+
+// CHECK: attributes [[MIPS16]] = { nounwind "fp-contract-model"="standard" "mips16" {{.*}} }
+
+// CHECK: attributes [[NOMIPS16]]  = { nounwind "fp-contract-model"="standard" "nomips16" {{.*}} }
+