Skip sret attribute while preparing attribute list for

new function and new call sites.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47896 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2008-03-04 19:12:58 +00:00
parent 52f8ed8368
commit 544b92bb3c

View File

@@ -205,9 +205,14 @@ Function *SRETPromotion::cloneFunctionBody(Function *F,
unsigned ParamIndex = 1; // 0th parameter attribute is reserved for return type. unsigned ParamIndex = 1; // 0th parameter attribute is reserved for return type.
while (I != E) { while (I != E) {
Params.push_back(I->getType()); Params.push_back(I->getType());
if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(ParamIndex) : ParameterAttributes Attrs;
ParamAttr::None) if (PAL) {
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), attrs)); Attrs = PAL->getParamAttrs(ParamIndex);
if (ParamIndex == 1) // Skip sret attribute
Attrs = Attrs ^ ParamAttr::StructRet;
}
if (Attrs != ParamAttr::None)
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex, Attrs));
++I; ++I;
++ParamIndex; ++ParamIndex;
} }
@@ -240,7 +245,7 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) {
SmallVector<Value*, 16> Args; SmallVector<Value*, 16> Args;
// ParamAttrs - Keep track of the parameter attributes for the arguments. // ParamAttrs - Keep track of the parameter attributes for the arguments.
ParamAttrsVector ParamAttrsVec; ParamAttrsVector ArgAttrsVec;
for (Value::use_iterator FUI = F->use_begin(), FUE = F->use_end(); FUI != FUE;) { for (Value::use_iterator FUI = F->use_begin(), FUE = F->use_end(); FUI != FUE;) {
CallSite CS = CallSite::get(*FUI); CallSite CS = CallSite::get(*FUI);
@@ -250,7 +255,7 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) {
const ParamAttrsList *PAL = F->getParamAttrs(); const ParamAttrsList *PAL = F->getParamAttrs();
// Add any return attributes. // Add any return attributes.
if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None) if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None)
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs)); ArgAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
// Copy arguments, however skip first one. // Copy arguments, however skip first one.
CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end(); CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
@@ -259,9 +264,14 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) {
unsigned ParamIndex = 1; // 0th parameter attribute is reserved for return type. unsigned ParamIndex = 1; // 0th parameter attribute is reserved for return type.
while (AI != AE) { while (AI != AE) {
Args.push_back(*AI); Args.push_back(*AI);
if (ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(ParamIndex) : ParameterAttributes Attrs;
ParamAttr::None) if (PAL) {
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs)); Attrs = PAL->getParamAttrs(ParamIndex);
if (ParamIndex == 1) // Skip sret attribute
Attrs = Attrs ^ ParamAttr::StructRet;
}
if (Attrs != ParamAttr::None)
ArgAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
++ParamIndex; ++ParamIndex;
++AI; ++AI;
} }
@@ -272,16 +282,16 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
Args.begin(), Args.end(), "", Call); Args.begin(), Args.end(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setParamAttrs(ParamAttrsList::get(ParamAttrsVec)); cast<InvokeInst>(New)->setParamAttrs(ParamAttrsList::get(ArgAttrsVec));
} else { } else {
New = new CallInst(NF, Args.begin(), Args.end(), "", Call); New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setParamAttrs(ParamAttrsList::get(ParamAttrsVec)); cast<CallInst>(New)->setParamAttrs(ParamAttrsList::get(ArgAttrsVec));
if (cast<CallInst>(Call)->isTailCall()) if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall(); cast<CallInst>(New)->setTailCall();
} }
Args.clear(); Args.clear();
ParamAttrsVec.clear(); ArgAttrsVec.clear();
New->takeName(Call); New->takeName(Call);
// Update all users of sret parameter to extract value using getresult. // Update all users of sret parameter to extract value using getresult.