mips16/nomips16 attributes - please review

Reed Kotler rkotler at mips.com
Tue Mar 12 13:44:35 PDT 2013


Use the new attribute scheme to pass mips16/nomips16 attributes from 
clang to llvm


-------------- next part --------------
Index: test/CodeGen/mips16-attr.c
===================================================================
--- test/CodeGen/mips16-attr.c	(revision 0)
+++ test/CodeGen/mips16-attr.c	(revision 0)
@@ -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" {{.*}} }
+
Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp	(revision 176874)
+++ lib/CodeGen/TargetInfo.cpp	(working copy)
@@ -4321,10 +4321,30 @@
 
   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.
-    //
+    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+      if (FD->hasAttr<Mips16Attr>()) {
+        // Get the LLVM function.
+        llvm::Function *Fn = cast<llvm::Function>(GV);
+        llvm::AttrBuilder B;
+        B.addAttribute("mips16");
+        Fn->addAttributes(
+          llvm::AttributeSet::FunctionIndex,
+          llvm::AttributeSet::get(CGM.getLLVMContext(),
+                                  llvm::AttributeSet::FunctionIndex,
+                                  B));
+      }
+      else if (FD->hasAttr<NoMips16Attr>()) {
+          // Get the LLVM function.
+          llvm::Function *Fn = cast<llvm::Function>(GV);
+          llvm::AttrBuilder B;
+          B.addAttribute("nomips16");
+          Fn->addAttributes(
+            llvm::AttributeSet::FunctionIndex,
+            llvm::AttributeSet::get(CGM.getLLVMContext(),
+                                    llvm::AttributeSet::FunctionIndex,
+                                    B));
+      }
+    }
   }
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                llvm::Value *Address) const;


More information about the cfe-commits mailing list