brg

InstSelectSimple.cpp: First draft of visitCallInst method, handling
 int/float args.
X86InstrInfo.def: Add entries for CALL with 32-bit pc relative arg, and
 PUSH with 32-bit reg arg.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4838 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp
index 20fc69a..0493634 100644
--- a/lib/Target/X86/InstSelectSimple.cpp
+++ b/lib/Target/X86/InstSelectSimple.cpp
@@ -363,10 +363,30 @@
     }
 }
 
-/// visitCallInst - Have to push args and do a procedure call
-/// instruction, if the target address is known.
-void ISel::visitCallInst (CallInst &CI) {
-  visitInstruction (CI);
+/// visitCallInst - Push args on stack and do a procedure call instruction.
+void
+ISel::visitCallInst (CallInst & CI)
+{
+  // Push the arguments on the stack in reverse order, as specified by
+  // the ABI.
+  for (unsigned i = CI.getNumOperands (); i >= 1; --i)
+    {
+      Value *v = CI.getOperand (i);
+      unsigned argReg = getReg (v);
+      switch (getClass (v->getType ()))
+	{
+	case cInt:
+	case cFloat:
+	  BuildMI (BB, X86::PUSHr32, 1).addReg (argReg);
+	  break;
+	default:
+	  // FIXME
+	  visitInstruction (CI);
+	  break;
+	}
+    }
+  // Emit a CALL instruction with PC-relative displacement.
+  BuildMI (BB, X86::CALLpcrel32, 1).addPCDisp (CI.getCalledValue ());
 }
 
 /// visitSimpleBinary - Implement simple binary operators for integral types...