If we support structs as va_list, we must pass pointers to them to va_copy

See last commit for LangRef, this implements it on all targets.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22273 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrew Lenharth 2005-06-22 21:04:42 +00:00
parent d0a4c62a03
commit 213e557cef
9 changed files with 43 additions and 66 deletions

View File

@ -749,14 +749,12 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
} }
if (ObsoleteVarArgs && NewVarArgs) if (ObsoleteVarArgs && NewVarArgs)
{ ThrowException("This file is corrupt in that it uses both new and old style varargs");
std::cerr << "This file is corrupt in that it uses both new and old style varargs\n";
abort();
}
if(ObsoleteVarArgs) { if(ObsoleteVarArgs) {
if(Function* F = Result->getNamedFunction("llvm.va_start")) { if(Function* F = Result->getNamedFunction("llvm.va_start")) {
assert(F->arg_size() == 0 && "Obsolete va_start takes 0 argument!"); if (F->arg_size() != 0)
ThrowException("Obsolete va_start takes 0 argument!");
//foo = va_start() //foo = va_start()
// -> // ->
@ -782,7 +780,9 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
} }
if(Function* F = Result->getNamedFunction("llvm.va_end")) { if(Function* F = Result->getNamedFunction("llvm.va_end")) {
assert(F->arg_size() == 1 && "Obsolete va_end takes 1 argument!"); if(F->arg_size() != 1)
ThrowException("Obsolete va_end takes 1 argument!");
//vaend foo //vaend foo
// -> // ->
//bar = alloca 1 of typeof(foo) //bar = alloca 1 of typeof(foo)
@ -804,24 +804,29 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
} }
if(Function* F = Result->getNamedFunction("llvm.va_copy")) { if(Function* F = Result->getNamedFunction("llvm.va_copy")) {
assert(F->arg_size() == 1 && "Obsolete va_copy takes 1 argument!"); if(F->arg_size() != 1)
ThrowException("Obsolete va_copy takes 1 argument!");
//foo = vacopy(bar) //foo = vacopy(bar)
// -> // ->
//a = alloca 1 of typeof(foo) //a = alloca 1 of typeof(foo)
//vacopy(a, bar) //b = alloca 1 of typeof(foo)
//store bar -> b
//vacopy(a, b)
//foo = load a //foo = load a
const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID); const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
const Type* ArgTy = F->getFunctionType()->getReturnType(); const Type* ArgTy = F->getFunctionType()->getReturnType();
const Type* ArgTyPtr = PointerType::get(ArgTy); const Type* ArgTyPtr = PointerType::get(ArgTy);
Function* NF = Result->getOrInsertFunction("llvm.va_copy", Function* NF = Result->getOrInsertFunction("llvm.va_copy",
RetTy, ArgTyPtr, ArgTy, 0); RetTy, ArgTyPtr, ArgTyPtr, 0);
while (!F->use_empty()) { while (!F->use_empty()) {
CallInst* CI = cast<CallInst>(F->use_back()); CallInst* CI = cast<CallInst>(F->use_back());
AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI); AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
new CallInst(NF, a, CI->getOperand(1), "", CI); AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
Value* foo = new LoadInst(a, "vacopy.fix.2", CI); new StoreInst(CI->getOperand(1), b, CI);
new CallInst(NF, a, b, "", CI);
Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
CI->replaceAllUsesWith(foo); CI->replaceAllUsesWith(foo);
CI->getParent()->getInstList().erase(CI); CI->getParent()->getInstList().erase(CI);
} }

View File

@ -221,20 +221,24 @@ static ModuleProvider* CheckVarargs(ModuleProvider* MP) {
//foo = vacopy(bar) //foo = vacopy(bar)
// -> // ->
//a = alloca 1 of typeof(foo) //a = alloca 1 of typeof(foo)
//vacopy(a, bar) //b = alloca 1 of typeof(foo)
//store bar -> b
//vacopy(a, b)
//foo = load a //foo = load a
const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID); const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
const Type* ArgTy = F->getFunctionType()->getReturnType(); const Type* ArgTy = F->getFunctionType()->getReturnType();
const Type* ArgTyPtr = PointerType::get(ArgTy); const Type* ArgTyPtr = PointerType::get(ArgTy);
Function* NF = M->getOrInsertFunction("llvm.va_copy", Function* NF = M->getOrInsertFunction("llvm.va_copy",
RetTy, ArgTyPtr, ArgTy, 0); RetTy, ArgTyPtr, ArgTyPtr, 0);
for(Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E;) for(Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E;)
if (CallInst* CI = dyn_cast<CallInst>(*I++)) { if (CallInst* CI = dyn_cast<CallInst>(*I++)) {
AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI); AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
new CallInst(NF, a, CI->getOperand(1), "", CI); AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
Value* foo = new LoadInst(a, "vacopy.fix.2", CI); new StoreInst(CI->getOperand(1), b, CI);
new CallInst(NF, a, b, "", CI);
Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
CI->replaceAllUsesWith(foo); CI->replaceAllUsesWith(foo);
CI->getParent()->getInstList().erase(CI); CI->getParent()->getInstList().erase(CI);
} }

View File

@ -855,10 +855,11 @@ SDOperand TargetLowering::LowerVAEnd(SDOperand Chain, SDOperand L,
std::pair<SDOperand,SDOperand> std::pair<SDOperand,SDOperand>
TargetLowering::LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest, TargetLowering::LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest,
SelectionDAG &DAG) { SelectionDAG &DAG) {
// We have no sane default behavior, just emit a useful error message and bail //Default to returning the input list
// out. SDOperand Val = DAG.getLoad(getPointerTy(), Chain, Src, DAG.getSrcValue(NULL));
std::cerr << "Variable arguments handling not implemented on this target!\n"; SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
abort(); Val, Dest, DAG.getSrcValue(NULL));
return std::make_pair(Result, Result);
} }
std::pair<SDOperand,SDOperand> std::pair<SDOperand,SDOperand>

View File

@ -1495,7 +1495,7 @@ void CWriter::visitCallInst(CallInst &I) {
Out << "0; "; Out << "0; ";
Out << "va_copy(*(va_list*)"; Out << "va_copy(*(va_list*)";
writeOperand(I.getOperand(1)); writeOperand(I.getOperand(1));
Out << ", *(va_list*)&"; Out << ", *(va_list*)";
writeOperand(I.getOperand(2)); writeOperand(I.getOperand(2));
Out << ')'; Out << ')';
return; return;

View File

@ -1495,7 +1495,7 @@ void CWriter::visitCallInst(CallInst &I) {
Out << "0; "; Out << "0; ";
Out << "va_copy(*(va_list*)"; Out << "va_copy(*(va_list*)";
writeOperand(I.getOperand(1)); writeOperand(I.getOperand(1));
Out << ", *(va_list*)&"; Out << ", *(va_list*)";
writeOperand(I.getOperand(2)); writeOperand(I.getOperand(2));
Out << ')'; Out << ')';
return; return;

View File

@ -120,10 +120,6 @@ namespace {
LowerVAArgNext(SDOperand Chain, SDOperand VAList, LowerVAArgNext(SDOperand Chain, SDOperand VAList,
const Type *ArgTy, SelectionDAG &DAG); const Type *ArgTy, SelectionDAG &DAG);
virtual std::pair<SDOperand,SDOperand>
LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest,
SelectionDAG &DAG);
virtual std::pair<SDOperand, SDOperand> virtual std::pair<SDOperand, SDOperand>
LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth, LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
SelectionDAG &DAG); SelectionDAG &DAG);
@ -413,15 +409,6 @@ LowerVAArgNext(SDOperand Chain, SDOperand VAList,
return std::make_pair(Result, Chain); return std::make_pair(Result, Chain);
} }
std::pair<SDOperand,SDOperand>
IA64TargetLowering::LowerVACopy(SDOperand Chain, SDOperand Src,
SDOperand Dest, SelectionDAG &DAG)
{
SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Chain,
Src, Dest, DAG.getSrcValue(NULL));
return std::make_pair(Result, Result);
}
std::pair<SDOperand, SDOperand> IA64TargetLowering:: std::pair<SDOperand, SDOperand> IA64TargetLowering::
LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth, LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
SelectionDAG &DAG) { SelectionDAG &DAG) {

View File

@ -104,10 +104,6 @@ namespace {
LowerVAArgNext(SDOperand Chain, SDOperand VAList, LowerVAArgNext(SDOperand Chain, SDOperand VAList,
const Type *ArgTy, SelectionDAG &DAG); const Type *ArgTy, SelectionDAG &DAG);
virtual std::pair<SDOperand,SDOperand>
LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest,
SelectionDAG &DAG);
virtual std::pair<SDOperand, SDOperand> virtual std::pair<SDOperand, SDOperand>
LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth, LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
SelectionDAG &DAG); SelectionDAG &DAG);
@ -390,16 +386,6 @@ LowerVAArgNext(SDOperand Chain, SDOperand VAList,
return std::make_pair(Result, Chain); return std::make_pair(Result, Chain);
} }
std::pair<SDOperand,SDOperand>
PPC64TargetLowering::LowerVACopy(SDOperand Chain, SDOperand Src,
SDOperand Dest, SelectionDAG &DAG)
{
SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Chain,
Src, Dest, DAG.getSrcValue(NULL));
return std::make_pair(Result, Result);
}
std::pair<SDOperand, SDOperand> PPC64TargetLowering:: std::pair<SDOperand, SDOperand> PPC64TargetLowering::
LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth, LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
SelectionDAG &DAG) { SelectionDAG &DAG) {

View File

@ -2881,11 +2881,18 @@ static bool CodeGenIntrinsic(Intrinsic::ID iid, CallInst &callInstr,
return true; // no-op on SparcV9 return true; // no-op on SparcV9
case Intrinsic::vacopy: case Intrinsic::vacopy:
// Simple store of current va_list (arg2) to new va_list (arg1) {
mvec.push_back(BuildMI(V9::STXi, 3). MachineCodeForInstruction& m1 = MachineCodeForInstruction::get(&callInstr);
addReg(callInstr.getOperand(2)). TmpInstruction* VReg =
addReg(callInstr.getOperand(1)).addSImm(0)); new TmpInstruction(m1, callInstr.getOperand(1)->getType());
return true;
// Simple store of current va_list (arg2) to new va_list (arg1)
mvec.push_back(BuildMI(V9::LDXi, 3).
addReg(callInstr.getOperand(2)).addSImm(0).addRegDef(VReg));
mvec.push_back(BuildMI(V9::STXi, 3).
addReg(VReg).addReg(callInstr.getOperand(1)).addSImm(0));
return true;
}
} }
} }

View File

@ -182,10 +182,6 @@ namespace {
LowerVAArgNext(SDOperand Chain, SDOperand VAList, LowerVAArgNext(SDOperand Chain, SDOperand VAList,
const Type *ArgTy, SelectionDAG &DAG); const Type *ArgTy, SelectionDAG &DAG);
virtual std::pair<SDOperand,SDOperand>
LowerVACopy(SDOperand Chain, SDOperand Src, SDOperand Dest,
SelectionDAG &DAG);
virtual std::pair<SDOperand, SDOperand> virtual std::pair<SDOperand, SDOperand>
LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth, LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
SelectionDAG &DAG); SelectionDAG &DAG);
@ -475,15 +471,6 @@ X86TargetLowering::LowerVAArgNext(SDOperand Chain, SDOperand VAList,
return std::make_pair(Result, Chain); return std::make_pair(Result, Chain);
} }
std::pair<SDOperand,SDOperand>
X86TargetLowering::LowerVACopy(SDOperand Chain, SDOperand Src,
SDOperand Dest, SelectionDAG &DAG)
{
SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Chain,
Src, Dest, DAG.getSrcValue(NULL));
return std::make_pair(Result, Result);
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Fast Calling Convention implementation // Fast Calling Convention implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//