Add the byval attribute
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 6 Jul 2007 10:57:03 +0000 (10:57 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 6 Jul 2007 10:57:03 +0000 (10:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37940 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAGNodes.h
include/llvm/ParameterAttributes.h
lib/AsmParser/Lexer.l
lib/AsmParser/llvmAsmParser.y
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/Target/TargetCallingConv.td
lib/Target/X86/X86CallingConv.td
lib/VMCore/Function.cpp
lib/VMCore/Verifier.cpp
utils/TableGen/CallingConvEmitter.cpp

index d22ffca2ddb28f25c51b1baf7e7140388d708156..a85ec039871cf878a1fed2fd7a400a49864f8184 100644 (file)
@@ -63,6 +63,8 @@ namespace ISD {
     InRegOffs         = 2,
     StructReturn      = 1<<3,  ///< Hidden struct-return pointer
     StructReturnOffs  = 3,
+    ByVal             = 1<<4,  ///< Struct passed by value
+    ByValOffs         = 4,
     OrigAlignment     = 0x1F<<27,
     OrigAlignmentOffs = 27
   };
index c2d60786c259ff08446b0e228364fb6d4d73ff96..b1cb966e0afa600d1f1d5af9a3d81bc2d5729a41 100644 (file)
@@ -36,7 +36,8 @@ enum Attributes {
   InReg      = 1 << 3, ///< force argument to be passed in register
   StructRet  = 1 << 4, ///< hidden pointer to structure to return
   NoUnwind   = 1 << 5, ///< Function doesn't unwind stack
-  NoAlias    = 1 << 6  ///< Considered to not alias after call.
+  NoAlias    = 1 << 6, ///< Considered to not alias after call.
+  ByVal      = 1 << 7  ///< Pass structure by value
 };
 
 }
index 6391d17a52eb536c49cdf6173d69b139564f5db1..bc61e97ca95bc9553d1ca6a65f8b0cb934c36431 100644 (file)
@@ -230,6 +230,7 @@ sret            { return SRET;  }
 nounwind        { return NOUNWIND; }
 noreturn        { return NORETURN; }
 noalias         { return NOALIAS; }
+byval           { return BYVAL; }
 
 void            { RET_TY(Type::VoidTy,  VOID);  }
 float           { RET_TY(Type::FloatTy, FLOAT); }
index 94aeecaf831acf4b76c36be291b703e2a629d379..c8790819d33fc394afa0d279563382ed3bf31eae 100644 (file)
@@ -1101,7 +1101,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 %token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
 
 // Function Attributes
-%token NORETURN INREG SRET NOUNWIND NOALIAS
+%token NORETURN INREG SRET NOUNWIND NOALIAS BYVAL
 
 // Visibility Styles
 %token DEFAULT HIDDEN PROTECTED
@@ -1229,6 +1229,7 @@ ParamAttr     : ZEXT    { $$ = ParamAttr::ZExt;      }
               | INREG   { $$ = ParamAttr::InReg;     }
               | SRET    { $$ = ParamAttr::StructRet; }
               | NOALIAS { $$ = ParamAttr::NoAlias;   }
+              | BYVAL   { $$ = ParamAttr::ByVal;   }
               ;
 
 OptParamAttrs : /* empty */  { $$ = ParamAttr::None; }
index 182063fac28e5746353ac31611648e5f0e394014..8af76b1cd18fc31b2fe2db1f6520b16f7f7d9473 100644 (file)
@@ -3789,6 +3789,8 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
       Flags |= ISD::ParamFlags::InReg;
     if (Attrs && Attrs->paramHasAttr(j, ParamAttr::StructRet))
       Flags |= ISD::ParamFlags::StructReturn;
+    if (Attrs && Attrs->paramHasAttr(j, ParamAttr::ByVal))
+      Flags |= ISD::ParamFlags::ByVal;
     Flags |= (OriginalAlignment << ISD::ParamFlags::OrigAlignmentOffs);
     
     switch (getTypeAction(VT)) {
index e710ad08e7746de5a36186096e2fe2492ee73b35..94193200eaa40866ea4f754ec57e3cf65aa418ac 100644 (file)
@@ -32,6 +32,11 @@ class CCIf<string predicate, CCAction A> : CCPredicateAction<A> {
   string Predicate = predicate;
 }
 
+/// CCIfStruct - If the current argument is a struct, apply
+/// Action A.
+class CCIfStruct<CCAction A> : CCIf<"ArgFlags & ISD::ParamFlags::ByVal", A> {
+}
+
 /// CCIfCC - Match of the current calling convention is 'CC'.
 class CCIfCC<string CC, CCAction A>
   : CCIf<!strconcat("State.getCallingConv() == ", CC), A> {}
@@ -57,6 +62,12 @@ class CCAssignToStack<int size, int align> : CCAction {
   int Align = align;
 }
 
+/// CCStructAssign - This action always matches: it will use the C ABI and
+/// the register availability to decided whether to assign to a set of
+/// registers or to a stack slot.
+class CCStructAssign<list<Register> regList> : CCAction {
+  list<Register> RegList = regList;
+}
 
 /// CCPromoteToType - If applied, this promotes the specified current value to
 /// the specified type.
@@ -75,4 +86,3 @@ class CCDelegateTo<CallingConv cc> : CCAction {
 class CallingConv<list<CCAction> actions> {
   list<CCAction> Actions = actions;
 }
-
index c98b3a2aec5225fcfb167b2f2a31b58e44700546..39811bd7409de03007be2bbc2a599f723bb72ebf 100644 (file)
@@ -94,6 +94,8 @@ def CC_X86_64_C : CallingConv<[
   // Promote i8/i16 arguments to i32.
   CCIfType<[i8, i16], CCPromoteToType<i32>>,
   
+  CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8, R9 ]>>,
+
   // The first 6 integer arguments are passed in integer registers.
   CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
   CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
@@ -168,5 +170,3 @@ def CC_X86_32_FastCall : CallingConv<[
   // Otherwise, same as everything else.
   CCDelegateTo<CC_X86_32_Common>
 ]>;
-
-
index c10f8d75bd4730817836a1492d919e8fd406f4a3..ab12ae8bfe298e049503e53c3f52436ff7f3e466 100644 (file)
@@ -103,6 +103,8 @@ ParamAttrsList::getParamAttrsText(uint16_t Attrs) {
     Result += "noalias ";
   if (Attrs & ParamAttr::StructRet)
     Result += "sret ";  
+  if (Attrs & ParamAttr::ByVal)
+    Result += "byval ";
   return Result;
 }
 
index 3442149401c75ee040b3b657cf46fde2a2154c00..16e87f4f7a176337cd205b6430652fceec9a2c8b 100644 (file)
@@ -370,6 +370,9 @@ void Verifier::visitFunction(Function &F) {
       if (Attrs->paramHasAttr(Idx, ParamAttr::NoAlias))
         Assert1(isa<PointerType>(FT->getParamType(Idx-1)),
                 "Attribute NoAlias should only apply to Pointer type!", &F);
+      if (Attrs->paramHasAttr(Idx, ParamAttr::ByVal))
+        Assert1(isa<PointerType>(FT->getParamType(Idx-1)),
+                "Attribute ByVal should only apply to Pointer type!", &F);
     }
   }
 
index ae7dc91fc703ca4296e20157153e901f3dcf5da8..2929aba820b5023243276f08f0e41dc271a18f0b 100644 (file)
@@ -129,10 +129,11 @@ void CallingConvEmitter::EmitAction(Record *Action,
         << IndentStr << IndentStr << "LocInfo = CCValAssign::ZExt;\n"
         << IndentStr << "else\n"
         << IndentStr << IndentStr << "LocInfo = CCValAssign::AExt;\n";
+    } else if (Action->isSubClassOf("CCStructAssign")) {
+      O << "assert(0 && \"Not Implemented\");\n";
     } else {
       Action->dump();
       throw "Unknown CCAction!";
     }
   }
 }
-