r176971 - Cause the mips16/nomips16 attribute to be passed to LLVM from Clang

Reed Kotler rkotler at mips.com
Wed Mar 13 13:40:30 PDT 2013


Author: rkotler
Date: Wed Mar 13 15:40:30 2013
New Revision: 176971

URL: http://llvm.org/viewvc/llvm-project?rev=176971&view=rev
Log:
Cause the mips16/nomips16 attribute to be passed to LLVM from Clang
in the LLVM assembly language output.


Added:
    cfe/trunk/test/CodeGen/mips16-attr.c
Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=176971&r1=176970&r2=176971&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Mar 13 15:40:30 2013
@@ -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;
 

Added: cfe/trunk/test/CodeGen/mips16-attr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips16-attr.c?rev=176971&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/mips16-attr.c (added)
+++ cfe/trunk/test/CodeGen/mips16-attr.c Wed Mar 13 15:40:30 2013
@@ -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" {{.*}} }
+





More information about the cfe-commits mailing list