Handle lowering invoke to call correctly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34492 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Laskey 2007-02-22 15:38:06 +00:00
parent 2bc210d99f
commit 735b6f8cc3

View File

@ -484,6 +484,7 @@ public:
unsigned Opc);
bool isExportableFromCurrentBlock(Value *V, const BasicBlock *FromBB);
void ExportFromCurrentBlock(Value *V);
void LowerCallTo(CallInst &I, SDOperand Callee, unsigned OpIdx);
// Terminator instructions.
void visitRet(ReturnInst &I);
@ -1117,17 +1118,7 @@ void SelectionDAGLowering::visitInvoke(InvokeInst &I) {
DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, getRoot(),
DAG.getConstant(BeginLabel, MVT::i32)));
// Insert a normal call instruction.
std::vector<Value*> Args;
for (InvokeInst::op_iterator OI = I.op_begin() + 3, E = I.op_end();
OI != E; ++OI) {
Args.push_back(*OI);
}
CallInst *NewCall = new CallInst(I.getCalledValue(), &Args[0], Args.size(),
I.getName(), &I);
NewCall->setCallingConv(I.getCallingConv());
I.replaceAllUsesWith(NewCall);
visitCall(*NewCall);
LowerCallTo((CallInst&)I, getValue(I.getOperand(0)), 3);
// Insert a label before the invoke call to mark the try range.
// This can be used to detect deletion of the invoke via the
@ -2086,6 +2077,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
case Intrinsic::eh_exception: {
MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
if (MMI) {
// Add a label to mark the beginning of the landing pad. Deletion of the
// landing pad can thus be detected via the MachineModuleInfo.
unsigned LabelID = MMI->addLandingPad(CurMBB);
@ -2093,8 +2085,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
DAG.getConstant(LabelID, MVT::i32)));
// Mark exception register as live in.
const MRegisterInfo *MRI = DAG.getTarget().getRegisterInfo();
unsigned Reg = MRI->getEHExceptionRegister();
unsigned Reg = TLI.getExceptionAddressRegister();
if (Reg) CurMBB->addLiveIn(Reg);
// Insert the EXCEPTIONADDR instruction.
@ -2104,13 +2095,14 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
SDOperand Op = DAG.getNode(ISD::EXCEPTIONADDR, VTs, Ops, 1);
setValue(&I, Op);
DAG.setRoot(Op.getValue(1));
}
return 0;
}
case Intrinsic::eh_handlers: {
MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
if (MMI) {
// Inform the MachineModuleInfo of the personality for this landing pad.
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(2))) {
if (CE->getOpcode() == Instruction::BitCast) {
@ -2135,8 +2127,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
MMI->addCatchTypeInfo(CurMBB, TyInfo);
// Mark exception selector register as live in.
const MRegisterInfo *MRI = DAG.getTarget().getRegisterInfo();
unsigned Reg = MRI->getEHHandlerRegister();
unsigned Reg = TLI.getExceptionSelectorRegister();
if (Reg) CurMBB->addLiveIn(Reg);
// Insert the EHSELECTION instruction.
@ -2147,15 +2138,17 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
SDOperand Op = DAG.getNode(ISD::EHSELECTION, VTs, Ops, 2);
setValue(&I, Op);
DAG.setRoot(Op.getValue(1));
}
return 0;
}
case Intrinsic::eh_typeid_for: {
GlobalVariable *GV = NULL;
// Find the type id for the given typeinfo.
MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
if (MMI) {
// Find the type id for the given typeinfo.
GlobalVariable *GV = NULL;
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(1))) {
if (CE->getOpcode() == Instruction::BitCast) {
GV = cast<GlobalVariable>(CE->getOperand(0));
@ -2164,6 +2157,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
unsigned TypeID = MMI->getTypeIDFor(GV);
setValue(&I, DAG.getConstant(TypeID, MVT::i32));
}
return 0;
}
@ -2246,6 +2240,35 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
}
void SelectionDAGLowering::LowerCallTo(CallInst &I,
SDOperand Callee, unsigned OpIdx) {
const PointerType *PT = cast<PointerType>(I.getCalledValue()->getType());
const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
TargetLowering::ArgListTy Args;
TargetLowering::ArgListEntry Entry;
Args.reserve(I.getNumOperands());
for (unsigned i = OpIdx, e = I.getNumOperands(); i != e; ++i) {
Value *Arg = I.getOperand(i);
SDOperand ArgNode = getValue(Arg);
Entry.Node = ArgNode; Entry.Ty = Arg->getType();
Entry.isSigned = FTy->paramHasAttr(i, FunctionType::SExtAttribute);
Entry.isInReg = FTy->paramHasAttr(i, FunctionType::InRegAttribute);
Entry.isSRet = FTy->paramHasAttr(i, FunctionType::StructRetAttribute);
Args.push_back(Entry);
}
std::pair<SDOperand,SDOperand> Result =
TLI.LowerCallTo(getRoot(), I.getType(),
FTy->paramHasAttr(0,FunctionType::SExtAttribute),
FTy->isVarArg(), I.getCallingConv(), I.isTailCall(),
Callee, Args, DAG);
if (I.getType() != Type::VoidTy)
setValue(&I, Result.first);
DAG.setRoot(Result.second);
}
void SelectionDAGLowering::visitCall(CallInst &I) {
const char *RenameFn = 0;
if (Function *F = I.getCalledFunction()) {
@ -2298,37 +2321,16 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
return;
}
const PointerType *PT = cast<PointerType>(I.getCalledValue()->getType());
const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
SDOperand Callee;
if (!RenameFn)
Callee = getValue(I.getOperand(0));
else
Callee = DAG.getExternalSymbol(RenameFn, TLI.getPointerTy());
TargetLowering::ArgListTy Args;
TargetLowering::ArgListEntry Entry;
Args.reserve(I.getNumOperands());
for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) {
Value *Arg = I.getOperand(i);
SDOperand ArgNode = getValue(Arg);
Entry.Node = ArgNode; Entry.Ty = Arg->getType();
Entry.isSigned = FTy->paramHasAttr(i, FunctionType::SExtAttribute);
Entry.isInReg = FTy->paramHasAttr(i, FunctionType::InRegAttribute);
Entry.isSRet = FTy->paramHasAttr(i, FunctionType::StructRetAttribute);
Args.push_back(Entry);
}
std::pair<SDOperand,SDOperand> Result =
TLI.LowerCallTo(getRoot(), I.getType(),
FTy->paramHasAttr(0,FunctionType::SExtAttribute),
FTy->isVarArg(), I.getCallingConv(), I.isTailCall(),
Callee, Args, DAG);
if (I.getType() != Type::VoidTy)
setValue(&I, Result.first);
DAG.setRoot(Result.second);
LowerCallTo(I, Callee, 1);
}
SDOperand RegsForValue::getCopyFromRegs(SelectionDAG &DAG,
SDOperand &Chain, SDOperand &Flag)const{
SDOperand Val = DAG.getCopyFromReg(Chain, Regs[0], RegVT, Flag);