[llvm-commits] CVS: llvm/lib/Target/CBackend/CBackend.cpp

Anton Korobeynikov asl at math.spbu.ru
Sun Jan 28 05:32:20 PST 2007



Changes in directory llvm/lib/Target/CBackend:

CBackend.cpp updated: 1.320 -> 1.321
---
Log message:

Propagate changes from my local tree. This patch includes:
1. New parameter attribute called 'inreg'. It has meaning "place this 
parameter in registers, if possible". This is some generalization of 
gcc's regparm(n) attribute. It's currently used only in X86-32 backend.
2. Completely rewritten CC handling/lowering code inside X86 backend. 
Merged stdcall + c CCs and fastcall + fast CC.
3. Dropped CSRET CC. We cannot add struct return variant for each 
target-specific CC (e.g. stdcall + csretcc and so on).
4. Instead of CSRET CC introduced 'sret' parameter attribute. Setting in 
on first attribute has meaning 'This is hidden pointer to structure 
return. Handle it gently'.
5. Fixed small bug in llvm-extract + add new feature to 
FunctionExtraction pass, which relinks all internal-linkaged callees 
from deleted function to external linkage. This will allow further 
linking everything together.

NOTEs: 1. Documentation will be updated soon. 
       2. llvm-upgrade should be improved to translate csret => sret. 
          Before this, there will be some unexpected test fails.


---
Diffs of the changes:  (+17 -11)

 CBackend.cpp |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)


Index: llvm/lib/Target/CBackend/CBackend.cpp
diff -u llvm/lib/Target/CBackend/CBackend.cpp:1.320 llvm/lib/Target/CBackend/CBackend.cpp:1.321
--- llvm/lib/Target/CBackend/CBackend.cpp:1.320	Fri Jan 26 02:01:30 2007
+++ llvm/lib/Target/CBackend/CBackend.cpp	Sun Jan 28 07:31:35 2007
@@ -1748,8 +1748,8 @@
 }
 
 void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
-  /// isCStructReturn - Should this function actually return a struct by-value?
-  bool isCStructReturn = F->getCallingConv() == CallingConv::CSRet;
+  /// isStructReturn - Should this function actually return a struct by-value?
+  bool isStructReturn = F->getFunctionType()->isStructReturn();
   
   if (F->hasInternalLinkage()) Out << "static ";
   if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
@@ -1778,7 +1778,7 @@
       
       // If this is a struct-return function, don't print the hidden
       // struct-return argument.
-      if (isCStructReturn) {
+      if (isStructReturn) {
         assert(I != E && "Invalid struct return function!");
         ++I;
       }
@@ -1804,7 +1804,7 @@
     
     // If this is a struct-return function, don't print the hidden
     // struct-return argument.
-    if (isCStructReturn) {
+    if (isStructReturn) {
       assert(I != E && "Invalid struct return function!");
       ++I;
     }
@@ -1832,7 +1832,7 @@
   
   // Get the return tpe for the function.
   const Type *RetTy;
-  if (!isCStructReturn)
+  if (!isStructReturn)
     RetTy = F->getReturnType();
   else {
     // If this is a struct-return function, print the struct-return type.
@@ -1855,11 +1855,14 @@
 }
 
 void CWriter::printFunction(Function &F) {
+  /// isStructReturn - Should this function actually return a struct by-value?
+  bool isStructReturn = F.getFunctionType()->isStructReturn();
+
   printFunctionSignature(&F, false);
   Out << " {\n";
   
   // If this is a struct return function, handle the result with magic.
-  if (F.getCallingConv() == CallingConv::CSRet) {
+  if (isStructReturn) {
     const Type *StructTy =
       cast<PointerType>(F.arg_begin()->getType())->getElementType();
     Out << "  ";
@@ -1977,7 +1980,10 @@
 //
 void CWriter::visitReturnInst(ReturnInst &I) {
   // If this is a struct return function, return the temporary struct.
-  if (I.getParent()->getParent()->getCallingConv() == CallingConv::CSRet) {
+  bool isStructReturn = I.getParent()->getParent()->
+    getFunctionType()->isStructReturn();
+
+  if (isStructReturn) {
     Out << "  return StructReturn;\n";
     return;
   }
@@ -2468,9 +2474,12 @@
 
   Value *Callee = I.getCalledValue();
 
+  const PointerType  *PTy   = cast<PointerType>(Callee->getType());
+  const FunctionType *FTy   = cast<FunctionType>(PTy->getElementType());
+
   // If this is a call to a struct-return function, assign to the first
   // parameter instead of passing it to the call.
-  bool isStructRet = I.getCallingConv() == CallingConv::CSRet;
+  bool isStructRet = FTy->isStructReturn();
   if (isStructRet) {
     Out << "*(";
     writeOperand(I.getOperand(1));
@@ -2478,9 +2487,6 @@
   }
   
   if (I.isTailCall()) Out << " /*tail*/ ";
-
-  const PointerType  *PTy   = cast<PointerType>(Callee->getType());
-  const FunctionType *FTy   = cast<FunctionType>(PTy->getElementType());
   
   if (!WroteCallee) {
     // If this is an indirect call to a struct return function, we need to cast






More information about the llvm-commits mailing list