[cfe-commits] r72998 - in /cfe/trunk/lib/CodeGen: ABIInfo.h CGCall.cpp TargetABIInfo.cpp

Anton Korobeynikov asl at math.spbu.ru
Sat Jun 6 02:36:36 PDT 2009


Author: asl
Date: Sat Jun  6 04:36:29 2009
New Revision: 72998

URL: http://llvm.org/viewvc/llvm-project?rev=72998&view=rev
Log:
Add new ABIArgInfo kind: Extend. This allows target to implement its own argument
zero/sign extension logic (consider, e.g. target has only 64 bit registers and thus
i32's should be extended as well).

Modified:
    cfe/trunk/lib/CodeGen/ABIInfo.h
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/TargetABIInfo.cpp

Modified: cfe/trunk/lib/CodeGen/ABIInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ABIInfo.h?rev=72998&r1=72997&r2=72998&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/ABIInfo.h (original)
+++ cfe/trunk/lib/CodeGen/ABIInfo.h Sat Jun  6 04:36:29 2009
@@ -44,6 +44,9 @@
                  /// converted LLVM type. Complex and structure types
                  /// are passed using first class aggregates.
 
+      Extend,    /// Valid only for integer argument types. Same as 'direct'
+                 /// but also emit a zero/sign extension attribute.
+
       Indirect,  /// Pass the argument indirectly via a hidden pointer
                  /// with the specified alignment (0 indicates default
                  /// alignment).
@@ -79,6 +82,9 @@
     static ABIArgInfo getDirect() {
       return ABIArgInfo(Direct);
     }
+    static ABIArgInfo getExtend() {
+      return ABIArgInfo(Extend);
+    }
     static ABIArgInfo getIgnore() {
       return ABIArgInfo(Ignore);
     }
@@ -94,6 +100,7 @@
 
     Kind getKind() const { return TheKind; }
     bool isDirect() const { return TheKind == Direct; }
+    bool isExtend() const { return TheKind == Extend; }
     bool isIgnore() const { return TheKind == Ignore; }
     bool isCoerce() const { return TheKind == Coerce; }
     bool isIndirect() const { return TheKind == Indirect; }

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=72998&r1=72997&r2=72998&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Sat Jun  6 04:36:29 2009
@@ -314,6 +314,7 @@
   case ABIArgInfo::Expand:
     assert(0 && "Invalid ABI kind for return argument");
 
+  case ABIArgInfo::Extend:
   case ABIArgInfo::Direct:
     ResultType = ConvertType(RetTy);
     break;
@@ -353,7 +354,8 @@
       ArgTys.push_back(llvm::PointerType::getUnqual(LTy));
       break;
     }
-      
+
+    case ABIArgInfo::Extend:
     case ABIArgInfo::Direct:
       ArgTys.push_back(ConvertType(it->type));
       break;
@@ -394,14 +396,14 @@
   unsigned Index = 1;
   const ABIArgInfo &RetAI = FI.getReturnInfo();
   switch (RetAI.getKind()) {
+  case ABIArgInfo::Extend:
+   if (RetTy->isSignedIntegerType()) {
+     RetAttrs |= llvm::Attribute::SExt;
+   } else if (RetTy->isUnsignedIntegerType()) {
+     RetAttrs |= llvm::Attribute::ZExt;
+   }
+   // FALLTHROUGH
   case ABIArgInfo::Direct:
-    if (RetTy->isPromotableIntegerType()) {
-      if (RetTy->isSignedIntegerType()) {
-        RetAttrs |= llvm::Attribute::SExt;
-      } else if (RetTy->isUnsignedIntegerType()) {
-        RetAttrs |= llvm::Attribute::ZExt;
-      }
-    }
     break;
 
   case ABIArgInfo::Indirect:
@@ -452,15 +454,15 @@
       FuncAttrs &= ~(llvm::Attribute::ReadOnly |
                      llvm::Attribute::ReadNone);
       break;
-      
+
+    case ABIArgInfo::Extend:
+     if (ParamType->isSignedIntegerType()) {
+       Attributes |= llvm::Attribute::SExt;
+     } else if (ParamType->isUnsignedIntegerType()) {
+       Attributes |= llvm::Attribute::ZExt;
+     }
+     // FALLS THROUGH
     case ABIArgInfo::Direct:
-      if (ParamType->isPromotableIntegerType()) {
-        if (ParamType->isSignedIntegerType()) {
-          Attributes |= llvm::Attribute::SExt;
-        } else if (ParamType->isUnsignedIntegerType()) {
-          Attributes |= llvm::Attribute::ZExt;
-        }
-      }
       if (RegParm > 0 &&
           (ParamType->isIntegerType() || ParamType->isPointerType())) {
         RegParm -=
@@ -536,7 +538,8 @@
       EmitParmDecl(*Arg, V);      
       break;
     }
-      
+
+    case ABIArgInfo::Extend:
     case ABIArgInfo::Direct: {
       assert(AI != Fn->arg_end() && "Argument mismatch!");
       llvm::Value* V = AI;
@@ -618,10 +621,10 @@
   llvm::Value *RV = 0;
 
   // Functions with no result always return void.
-  if (ReturnValue) { 
+  if (ReturnValue) {
     QualType RetTy = FI.getReturnType();
     const ABIArgInfo &RetAI = FI.getReturnInfo();
-    
+
     switch (RetAI.getKind()) {
     case ABIArgInfo::Indirect:
       if (RetTy->isAnyComplexType()) {
@@ -630,11 +633,12 @@
       } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
         EmitAggregateCopy(CurFn->arg_begin(), ReturnValue, RetTy);
       } else {
-        EmitStoreOfScalar(Builder.CreateLoad(ReturnValue), CurFn->arg_begin(), 
+        EmitStoreOfScalar(Builder.CreateLoad(ReturnValue), CurFn->arg_begin(),
                           false, RetTy);
       }
       break;
 
+    case ABIArgInfo::Extend:
     case ABIArgInfo::Direct:
       // The internal return value temp always will have
       // pointer-to-return-type type.
@@ -705,6 +709,7 @@
       }
       break;
 
+    case ABIArgInfo::Extend:
     case ABIArgInfo::Direct:
       if (RV.isScalar()) {
         Args.push_back(RV.getScalarVal());
@@ -791,6 +796,7 @@
       return RValue::getAggregate(Args[0]);
     return RValue::get(EmitLoadOfScalar(Args[0], false, RetTy));
 
+  case ABIArgInfo::Extend:
   case ABIArgInfo::Direct:
     if (RetTy->isAnyComplexType()) {
       llvm::Value *Real = Builder.CreateExtractValue(CI, 0);

Modified: cfe/trunk/lib/CodeGen/TargetABIInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetABIInfo.cpp?rev=72998&r1=72997&r2=72998&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/TargetABIInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetABIInfo.cpp Sat Jun  6 04:36:29 2009
@@ -28,6 +28,9 @@
   case Direct:
     fprintf(stderr, "Direct");
     break;
+  case Extend:
+    fprintf(stderr, "Extend");
+    break;
   case Ignore:
     fprintf(stderr, "Ignore");
     break;
@@ -342,7 +345,8 @@
 
     return ABIArgInfo::getIndirect(0);
   } else {
-    return ABIArgInfo::getDirect();
+    return (RetTy->isPromotableIntegerType() ?
+            ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
   }
 }
 
@@ -371,7 +375,8 @@
 
     return ABIArgInfo::getIndirect(0);
   } else {
-    return ABIArgInfo::getDirect();
+    return (Ty->isPromotableIntegerType() ?
+            ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
   }
 }
 
@@ -750,8 +755,8 @@
     // Integer and pointer types will end up in a general purpose
     // register.
     if (Ty->isIntegralType() || Ty->isPointerType())
-      return ABIArgInfo::getDirect();
-
+      return (Ty->isPromotableIntegerType() ?
+              ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
   } else if (CoerceTo == llvm::Type::DoubleTy) {
     // FIXME: It would probably be better to make CGFunctionInfo only map using
     // canonical types than to canonize here.
@@ -771,7 +776,8 @@
   // If this is a scalar LLVM value then assume LLVM will pass it in the right
   // place naturally.
   if (!CodeGenFunction::hasAggregateLLVMType(Ty))
-    return ABIArgInfo::getDirect();
+    return (Ty->isPromotableIntegerType() ?
+            ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
 
   // FIXME: Set alignment correctly.
   return ABIArgInfo::getIndirect(0);
@@ -1267,7 +1273,8 @@
 ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty,
                                             ASTContext &Context) const {
   if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
-    return ABIArgInfo::getDirect();
+    return (Ty->isPromotableIntegerType() ?
+            ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
   }
   // FIXME: This is kind of nasty... but there isn't much choice because the ARM
   // backend doesn't support byval.
@@ -1299,7 +1306,8 @@
       return ABIArgInfo::getCoerce(llvm::Type::Int32Ty);
     return ABIArgInfo::getIndirect(0);
   } else {
-    return ABIArgInfo::getDirect();
+    return (RetTy->isPromotableIntegerType() ?
+            ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
   }
 }
 
@@ -1335,7 +1343,8 @@
   } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
     return ABIArgInfo::getIndirect(0);
   } else {
-    return ABIArgInfo::getDirect();
+    return (RetTy->isPromotableIntegerType() ?
+            ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
   }
 }
 
@@ -1344,7 +1353,8 @@
   if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
     return ABIArgInfo::getIndirect(0);
   } else {
-    return ABIArgInfo::getDirect();
+    return (Ty->isPromotableIntegerType() ?
+            ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
   }
 }
 





More information about the cfe-commits mailing list