More cbe byval fixes.

llvm-svn: 45891
This commit is contained in:
Evan Cheng 2008-01-11 23:10:11 +00:00
parent 5a3deb99b3
commit b51d228e79
1 changed files with 25 additions and 13 deletions

View File

@ -1908,18 +1908,24 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
} else { } else {
// Loop over the arguments, printing them. // Loop over the arguments, printing them.
FunctionType::param_iterator I = FT->param_begin(), E = FT->param_end(); FunctionType::param_iterator I = FT->param_begin(), E = FT->param_end();
unsigned Idx = 1;
// If this is a struct-return function, don't print the hidden // If this is a struct-return function, don't print the hidden
// struct-return argument. // struct-return argument.
if (isStructReturn) { if (isStructReturn) {
assert(I != E && "Invalid struct return function!"); assert(I != E && "Invalid struct return function!");
++I; ++I;
++Idx;
} }
unsigned Idx = 1;
for (; I != E; ++I) { for (; I != E; ++I) {
if (PrintedArg) FunctionInnards << ", "; if (PrintedArg) FunctionInnards << ", ";
printType(FunctionInnards, *I, const Type *ArgTy = *I;
if (PAL && PAL->paramHasAttr(Idx, ParamAttr::ByVal)) {
assert(isa<PointerType>(ArgTy));
ArgTy = cast<PointerType>(ArgTy)->getElementType();
}
printType(FunctionInnards, ArgTy,
/*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt)); /*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt));
PrintedArg = true; PrintedArg = true;
++Idx; ++Idx;
@ -2628,9 +2634,11 @@ void CWriter::visitCallInst(CallInst &I) {
const ParamAttrsList *PAL = I.getParamAttrs(); const ParamAttrsList *PAL = I.getParamAttrs();
bool isStructRet = I.isStructReturn(); bool isStructRet = I.isStructReturn();
if (isStructRet) { if (isStructRet) {
Out << "*("; bool isByVal = ByValParams.count(I.getOperand(1));
if (!isByVal) Out << "*(";
writeOperand(I.getOperand(1)); writeOperand(I.getOperand(1));
Out << ") = "; if (!isByVal) Out << ")";
Out << " = ";
} }
if (I.isTailCall()) Out << " /*tail*/ "; if (I.isTailCall()) Out << " /*tail*/ ";
@ -2685,22 +2693,26 @@ void CWriter::visitCallInst(CallInst &I) {
} }
bool PrintedArg = false; bool PrintedArg = false;
unsigned Idx = 1; for (; AI != AE; ++AI, ++ArgNo) {
for (; AI != AE; ++AI, ++ArgNo, ++Idx) {
if (PrintedArg) Out << ", "; if (PrintedArg) Out << ", ";
if (ArgNo < NumDeclaredParams && if (ArgNo < NumDeclaredParams &&
(*AI)->getType() != FTy->getParamType(ArgNo)) { (*AI)->getType() != FTy->getParamType(ArgNo)) {
Out << '('; Out << '(';
printType(Out, FTy->getParamType(ArgNo), printType(Out, FTy->getParamType(ArgNo),
/*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt)); /*isSigned=*/PAL && PAL->paramHasAttr(ArgNo+1, ParamAttr::SExt));
Out << ')'; Out << ')';
} }
// If call is expecting argument to be passed by value, then do not // Check if the argument is expected to be passed by value.
// take its address. bool isOutByVal = PAL && PAL->paramHasAttr(ArgNo+1, ParamAttr::ByVal);
if (PAL && PAL->paramHasAttr(Idx, ParamAttr::ByVal)) // Check if this argument itself is passed in by reference.
writeOperandInternal(*AI); bool isInByVal = ByValParams.count(*AI);
else if (isOutByVal && !isInByVal)
Out << "*(";
else if (!isOutByVal && isInByVal)
Out << "&(";
writeOperand(*AI); writeOperand(*AI);
if (isOutByVal ^ isInByVal)
Out << ")";
PrintedArg = true; PrintedArg = true;
} }
Out << ')'; Out << ')';