[llvm-commits] [llvm-gcc-4.2] r59108 - in /llvm-gcc-4.2/trunk/gcc: c-common.c llvm-convert.cpp

Tanya Lattner tonic at nondot.org
Tue Nov 11 23:23:10 PST 2008


Author: tbrethou
Date: Wed Nov 12 01:23:09 2008
New Revision: 59108

URL: http://llvm.org/viewvc/llvm-project?rev=59108&view=rev
Log:
Add the ability to annotate structs in a generic way.

Modified:
    llvm-gcc-4.2/trunk/gcc/c-common.c
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/c-common.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-common.c?rev=59108&r1=59107&r2=59108&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-common.c (original)
+++ llvm-gcc-4.2/trunk/gcc/c-common.c Wed Nov 12 01:23:09 2008
@@ -6380,6 +6380,7 @@
   id = TREE_VALUE (args);
 
   if (TREE_CODE (*node) == FUNCTION_DECL ||
+      TREE_CODE (*node) == FIELD_DECL ||
       TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == PARM_DECL)  
   {
   

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=59108&r1=59107&r2=59108&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Nov 12 01:23:09 2008
@@ -6022,7 +6022,59 @@
       const StructLayout *SL = TD.getStructLayout(cast<StructType>(StructTy));
       BitStart -= SL->getElementOffset(MemberIndex) * 8;
     }
-
+      
+    // If the FIELD_DECL has an annotate attribute on it, emit it.
+      
+    // Handle annotate attribute on global.
+    if (tree AnnotateAttr = 
+        lookup_attribute("annotate", DECL_ATTRIBUTES(FieldDecl))) {
+        
+        const Type *OrigPtrTy = FieldPtr->getType();
+        
+        Function *Fn = Intrinsic::getDeclaration(TheModule, 
+                                                 Intrinsic::ptr_annotation,
+                                                 &OrigPtrTy, 1);
+        
+        // Get file and line number.  FIXME: Should this be for the decl or the
+        // use.  Is there a location info for the use?
+        Constant *LineNo = ConstantInt::get(Type::Int32Ty,
+                                            DECL_SOURCE_LINE(FieldDecl));
+        Constant *File = ConvertMetadataStringToGV(DECL_SOURCE_FILE(FieldDecl));
+        const Type *SBP = PointerType::getUnqual(Type::Int8Ty);
+        File = TheFolder->CreateBitCast(File, SBP);
+        
+        // There may be multiple annotate attributes. Pass return of lookup_attr 
+        //  to successive lookups.
+        while (AnnotateAttr) {
+            // Each annotate attribute is a tree list.
+            // Get value of list which is our linked list of args.
+            tree args = TREE_VALUE(AnnotateAttr);
+            
+            // Each annotate attribute may have multiple args.
+            // Treat each arg as if it were a separate annotate attribute.
+            for (tree a = args; a; a = TREE_CHAIN(a)) {
+                // Each element of the arg list is a tree list, so get value
+                tree val = TREE_VALUE(a);
+                
+                // Assert its a string, and then get that string.
+                assert(TREE_CODE(val) == STRING_CST &&
+                       "Annotate attribute arg should always be a string");
+                
+                const Type *SBP = PointerType::getUnqual(Type::Int8Ty);
+                Constant *strGV = TreeConstantToLLVM::EmitLV_STRING_CST(val);
+                Value *Ops[4] = {
+                    FieldPtr, BitCastToType(strGV, SBP), File,  LineNo
+                };
+                
+                FieldPtr = Builder.CreateCall(Fn, Ops, Ops+4);
+            }
+            
+            // Get next annotate attribute.
+            AnnotateAttr = TREE_CHAIN(AnnotateAttr);
+            if (AnnotateAttr)
+                AnnotateAttr = lookup_attribute("annotate", AnnotateAttr);
+        }
+    }      
   } else {
     Value *Offset = Emit(field_offset, 0);
 
@@ -7242,6 +7294,7 @@
       const StructLayout *SL = TD.getStructLayout(cast<StructType>(StructTy));
       BitStart -= SL->getElementOffset(MemberIndex) * 8;
     }
+      
   } else {
     Constant *Offset = Convert(field_offset);
     Constant *Ptr = TheFolder->CreatePtrToInt(StructAddrLV, Offset->getType());





More information about the llvm-commits mailing list