llvm.org GIT mirror llvm / aeb54b8
Add support for the llvm.unwind intrinsic, which we codegen to just do an abort until we implement unwinding. Add support for the invoke instruction, which codegens just like a call with a branch after it. The end effect of this change is that programs using the invoke instruction, but never unwinding, will work fine. Programs that unwind will abort until we get unwind support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8187 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
2 changed file(s) with 58 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
130130 void doCall(const ValueRecord &Ret, MachineInstr *CallMI,
131131 const std::vector &Args);
132132 void visitCallInst(CallInst &I);
133 void visitInvokeInst(InvokeInst &II);
133134 void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
134135
135136 // Arithmetic operators
993994 doCall(ValueRecord(DestReg, CI.getType()), TheCall, Args);
994995 }
995996
997
998 // visitInvokeInst - For now, we don't support the llvm.unwind intrinsic, so
999 // invoke's are just calls with an unconditional branch after them!
1000 void ISel::visitInvokeInst(InvokeInst &II) {
1001 MachineInstr *TheCall;
1002 if (Function *F = II.getCalledFunction()) {
1003 // Emit a CALL instruction with PC-relative displacement.
1004 TheCall = BuildMI(X86::CALLpcrel32, 1).addGlobalAddress(F, true);
1005 } else { // Emit an indirect call...
1006 unsigned Reg = getReg(II.getCalledValue());
1007 TheCall = BuildMI(X86::CALLr32, 1).addReg(Reg);
1008 }
1009
1010 std::vector Args;
1011 for (unsigned i = 3, e = II.getNumOperands(); i != e; ++i)
1012 Args.push_back(ValueRecord(II.getOperand(i)));
1013
1014 unsigned DestReg = II.getType() != Type::VoidTy ? getReg(II) : 0;
1015 doCall(ValueRecord(DestReg, II.getType()), TheCall, Args);
1016
1017 // If the normal destination is not the next basic block, emit a 'jmp'.
1018 if (II.getNormalDest() != getBlockAfter(II.getParent()))
1019 BuildMI(BB, X86::JMP, 1).addPCDisp(II.getNormalDest());
1020 }
1021
1022
9961023 void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
9971024 unsigned TmpReg1, TmpReg2;
9981025 switch (ID) {
10111038 addDirectMem(BuildMI(BB, X86::MOVrm32, 5), TmpReg2).addReg(TmpReg1);
10121039 return;
10131040
1041 case LLVMIntrinsic::unwind: // llvm.unwind is not supported yet!
10141042 case LLVMIntrinsic::longjmp:
10151043 case LLVMIntrinsic::siglongjmp:
1016 BuildMI(X86::CALLpcrel32, 1).addExternalSymbol("abort", true);
1044 BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true);
10171045 return;
10181046
10191047 case LLVMIntrinsic::setjmp:
130130 void doCall(const ValueRecord &Ret, MachineInstr *CallMI,
131131 const std::vector &Args);
132132 void visitCallInst(CallInst &I);
133 void visitInvokeInst(InvokeInst &II);
133134 void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
134135
135136 // Arithmetic operators
993994 doCall(ValueRecord(DestReg, CI.getType()), TheCall, Args);
994995 }
995996
997
998 // visitInvokeInst - For now, we don't support the llvm.unwind intrinsic, so
999 // invoke's are just calls with an unconditional branch after them!
1000 void ISel::visitInvokeInst(InvokeInst &II) {
1001 MachineInstr *TheCall;
1002 if (Function *F = II.getCalledFunction()) {
1003 // Emit a CALL instruction with PC-relative displacement.
1004 TheCall = BuildMI(X86::CALLpcrel32, 1).addGlobalAddress(F, true);
1005 } else { // Emit an indirect call...
1006 unsigned Reg = getReg(II.getCalledValue());
1007 TheCall = BuildMI(X86::CALLr32, 1).addReg(Reg);
1008 }
1009
1010 std::vector Args;
1011 for (unsigned i = 3, e = II.getNumOperands(); i != e; ++i)
1012 Args.push_back(ValueRecord(II.getOperand(i)));
1013
1014 unsigned DestReg = II.getType() != Type::VoidTy ? getReg(II) : 0;
1015 doCall(ValueRecord(DestReg, II.getType()), TheCall, Args);
1016
1017 // If the normal destination is not the next basic block, emit a 'jmp'.
1018 if (II.getNormalDest() != getBlockAfter(II.getParent()))
1019 BuildMI(BB, X86::JMP, 1).addPCDisp(II.getNormalDest());
1020 }
1021
1022
9961023 void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
9971024 unsigned TmpReg1, TmpReg2;
9981025 switch (ID) {
10111038 addDirectMem(BuildMI(BB, X86::MOVrm32, 5), TmpReg2).addReg(TmpReg1);
10121039 return;
10131040
1041 case LLVMIntrinsic::unwind: // llvm.unwind is not supported yet!
10141042 case LLVMIntrinsic::longjmp:
10151043 case LLVMIntrinsic::siglongjmp:
1016 BuildMI(X86::CALLpcrel32, 1).addExternalSymbol("abort", true);
1044 BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true);
10171045 return;
10181046
10191047 case LLVMIntrinsic::setjmp: