[llvm-commits] [llvm] r45864 - /llvm/trunk/lib/Target/CBackend/CBackend.cpp
Evan Cheng
evan.cheng at apple.com
Fri Jan 11 01:12:49 PST 2008
Author: evancheng
Date: Fri Jan 11 03:12:49 2008
New Revision: 45864
URL: http://llvm.org/viewvc/llvm-project?rev=45864&view=rev
Log:
Some C backend ByVal parameter attribute support. Not yet complete.
Modified:
llvm/trunk/lib/Target/CBackend/CBackend.cpp
Modified: llvm/trunk/lib/Target/CBackend/CBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=45864&r1=45863&r2=45864&view=diff
==============================================================================
--- llvm/trunk/lib/Target/CBackend/CBackend.cpp (original)
+++ llvm/trunk/lib/Target/CBackend/CBackend.cpp Fri Jan 11 03:12:49 2008
@@ -87,6 +87,7 @@
std::map<const Type *, std::string> TypeNames;
std::map<const ConstantFP *, unsigned> FPConstantMap;
std::set<Function*> intrinsicPrototypesAlreadyGenerated;
+ std::set<const Value*> ByValParams;
public:
static char ID;
@@ -113,14 +114,16 @@
printFloatingPointConstants(F);
printFunction(F);
- FPConstantMap.clear();
return false;
}
virtual bool doFinalization(Module &M) {
// Free memory...
delete Mang;
+ FPConstantMap.clear();
TypeNames.clear();
+ intrinsicPrototypesAlreadyGenerated.clear();
+ ByValParams.clear();
return false;
}
@@ -370,6 +373,10 @@
if (PrintedType)
FunctionInnards << ", ";
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), "");
PrintedType = true;
@@ -1885,6 +1892,12 @@
else
ArgName = "";
const Type *ArgTy = I->getType();
+ if (PAL && PAL->paramHasAttr(Idx, ParamAttr::ByVal)) {
+ assert(isa<PointerType>(ArgTy));
+ ArgTy = cast<PointerType>(ArgTy)->getElementType();
+ const Value *Arg = &(*I);
+ ByValParams.insert(Arg);
+ }
printType(FunctionInnards, ArgTy,
/*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt),
ArgName);
@@ -2384,6 +2397,13 @@
// Make sure we really get a sext from bool by subtracing the bool from 0
Out << "0-";
}
+ // If it's a byval parameter being casted, then takes its address.
+ bool isByVal = ByValParams.count(I.getOperand(0));
+ if (isByVal) {
+ assert(I.getOpcode() == Instruction::BitCast &&
+ "ByVal aggregate parameter must ptr type");
+ Out << '&';
+ }
writeOperand(I.getOperand(0));
if (DstTy == Type::Int1Ty &&
(I.getOpcode() == Instruction::Trunc ||
@@ -2675,7 +2695,12 @@
/*isSigned=*/PAL && PAL->paramHasAttr(Idx, ParamAttr::SExt));
Out << ')';
}
- writeOperand(*AI);
+ // If call is expecting argument to be passed by value, then do not
+ // take its address.
+ if (PAL && PAL->paramHasAttr(Idx, ParamAttr::ByVal))
+ writeOperandInternal(*AI);
+ else
+ writeOperand(*AI);
PrintedArg = true;
}
Out << ')';
@@ -2869,7 +2894,9 @@
// Print out the -> operator if possible...
if (TmpI != E && isa<StructType>(*TmpI)) {
- Out << (HasImplicitAddress ? "." : "->");
+ // Check if it's actually an aggregate parameter passed by value.
+ bool isByVal = ByValParams.count(Ptr);
+ Out << ((HasImplicitAddress || isByVal) ? "." : "->");
Out << "field" << cast<ConstantInt>(TmpI.getOperand())->getZExtValue();
I = ++TmpI;
}
More information about the llvm-commits
mailing list