[llvm-commits] CVS: llvm/lib/Target/X86/InstSelectSimple.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Aug 28 16:24:01 PDT 2003


Changes in directory llvm/lib/Target/X86:

InstSelectSimple.cpp updated: 1.123 -> 1.124

---
Log message:

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.



---
Diffs of the changes:

Index: llvm/lib/Target/X86/InstSelectSimple.cpp
diff -u llvm/lib/Target/X86/InstSelectSimple.cpp:1.123 llvm/lib/Target/X86/InstSelectSimple.cpp:1.124
--- llvm/lib/Target/X86/InstSelectSimple.cpp:1.123	Sun Aug 24 14:19:47 2003
+++ llvm/lib/Target/X86/InstSelectSimple.cpp	Thu Aug 28 16:23:43 2003
@@ -131,6 +131,7 @@
     void doCall(const ValueRecord &Ret, MachineInstr *CallMI,
 		const std::vector<ValueRecord> &Args);
     void visitCallInst(CallInst &I);
+    void visitInvokeInst(InvokeInst &II);
     void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
 
     // Arithmetic operators
@@ -994,6 +995,32 @@
   doCall(ValueRecord(DestReg, CI.getType()), TheCall, Args);
 }	 
 
+
+// visitInvokeInst - For now, we don't support the llvm.unwind intrinsic, so
+// invoke's are just calls with an unconditional branch after them!
+void ISel::visitInvokeInst(InvokeInst &II) {
+  MachineInstr *TheCall;
+  if (Function *F = II.getCalledFunction()) {
+    // Emit a CALL instruction with PC-relative displacement.
+    TheCall = BuildMI(X86::CALLpcrel32, 1).addGlobalAddress(F, true);
+  } else {  // Emit an indirect call...
+    unsigned Reg = getReg(II.getCalledValue());
+    TheCall = BuildMI(X86::CALLr32, 1).addReg(Reg);
+  }
+
+  std::vector<ValueRecord> Args;
+  for (unsigned i = 3, e = II.getNumOperands(); i != e; ++i)
+    Args.push_back(ValueRecord(II.getOperand(i)));
+
+  unsigned DestReg = II.getType() != Type::VoidTy ? getReg(II) : 0;
+  doCall(ValueRecord(DestReg, II.getType()), TheCall, Args);
+
+  // If the normal destination is not the next basic block, emit a 'jmp'.
+  if (II.getNormalDest() != getBlockAfter(II.getParent()))
+    BuildMI(BB, X86::JMP, 1).addPCDisp(II.getNormalDest());
+}
+
+
 void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
   unsigned TmpReg1, TmpReg2;
   switch (ID) {
@@ -1012,9 +1039,10 @@
     addDirectMem(BuildMI(BB, X86::MOVrm32, 5), TmpReg2).addReg(TmpReg1);
     return;
 
+  case LLVMIntrinsic::unwind:     // llvm.unwind is not supported yet!
   case LLVMIntrinsic::longjmp:
   case LLVMIntrinsic::siglongjmp:
-    BuildMI(X86::CALLpcrel32, 1).addExternalSymbol("abort", true); 
+    BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true); 
     return;
 
   case LLVMIntrinsic::setjmp:





More information about the llvm-commits mailing list