aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2002-11-29 12:01:58 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2002-11-29 12:01:58 +0000
commit18a20212d98fbe5f014b3c910ae37c6d74801f02 (patch)
treec29272340b914c6f0997a1222c324ee1aaefaf0e /lib
parent0e2cf7606d3276c07b26ff2329c18bc739fddbde (diff)
downloadexternal_llvm-18a20212d98fbe5f014b3c910ae37c6d74801f02.zip
external_llvm-18a20212d98fbe5f014b3c910ae37c6d74801f02.tar.gz
external_llvm-18a20212d98fbe5f014b3c910ae37c6d74801f02.tar.bz2
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
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/X86/InstSelectSimple.cpp28
-rw-r--r--lib/Target/X86/X86ISelSimple.cpp28
-rw-r--r--lib/Target/X86/X86InstrInfo.def3
3 files changed, 51 insertions, 8 deletions
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 @@ ISel::visitBranchInst (BranchInst & BI)
}
}
-/// 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...
diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp
index 20fc69a..0493634 100644
--- a/lib/Target/X86/X86ISelSimple.cpp
+++ b/lib/Target/X86/X86ISelSimple.cpp
@@ -363,10 +363,30 @@ ISel::visitBranchInst (BranchInst & BI)
}
}
-/// 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...
diff --git a/lib/Target/X86/X86InstrInfo.def b/lib/Target/X86/X86InstrInfo.def
index 4731d4d..bbbff33 100644
--- a/lib/Target/X86/X86InstrInfo.def
+++ b/lib/Target/X86/X86InstrInfo.def
@@ -39,6 +39,7 @@ I(RET , "ret", 0xCB, M_RET_FLAG, X86II::RawFrm | X86II::Void)
I(JMP , "jmp", 0xE9, M_BRANCH_FLAG, X86II::Void) // jmp foo
I(JNE , "jne", 0x85, M_BRANCH_FLAG, X86II::TB | X86II::Void)
I(JE , "je", 0x84, M_BRANCH_FLAG, X86II::TB | X86II::Void)
+I(CALLpcrel32 , "call", 0xE8, M_BRANCH_FLAG, X86II::Void)
// Misc instructions
I(LEAVE , "leave", 0xC9, 0, X86II::RawFrm) // leave
@@ -58,6 +59,8 @@ I(MOVrm16 , "movw", 0x89, 0, X86II::MRMDestMem | X86II::Void |
X86II::OpSize)
I(MOVrm32 , "movl", 0x89, 0, X86II::MRMDestMem | X86II::Void) // [mem] = R32 89/r
+I(PUSHr32 , "pushl", 0x50, 0, X86II::AddRegFrm | X86II::Void)
+
// Arithmetic instructions
I(ADDrr8 , "addb", 0x00, 0, X86II::MRMDestReg) // R8 += R8
I(ADDrr16 , "addw", 0x01, 0, X86II::MRMDestReg | X86II::OpSize) // R16 += R16