From 6e49a4b814e7bc51f8fed7871e0c9ef207de9fd2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 13 Dec 2002 14:13:27 +0000 Subject: [PATCH] Implement indirect function calls git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5024 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/InstSelectSimple.cpp | 10 ++++++++-- lib/Target/X86/X86ISelSimple.cpp | 10 ++++++++-- lib/Target/X86/X86InstrInfo.def | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp index d9759c4eb84..4a44dbf419b 100644 --- a/lib/Target/X86/InstSelectSimple.cpp +++ b/lib/Target/X86/InstSelectSimple.cpp @@ -577,8 +577,14 @@ ISel::visitCallInst (CallInst & CI) break; } } - // Emit a CALL instruction with PC-relative displacement. - BuildMI (BB, X86::CALLpcrel32, 1).addPCDisp (CI.getCalledValue ()); + + if (Function *F = CI.getCalledFunction()) { + // Emit a CALL instruction with PC-relative displacement. + BuildMI(BB, X86::CALLpcrel32, 1).addPCDisp(F); + } else { + unsigned Reg = getReg(CI.getCalledValue()); + BuildMI(BB, X86::CALLr32, 1).addReg(Reg); + } // Adjust the stack by `bytesPushed' amount if non-zero if (bytesPushed > 0) diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp index d9759c4eb84..4a44dbf419b 100644 --- a/lib/Target/X86/X86ISelSimple.cpp +++ b/lib/Target/X86/X86ISelSimple.cpp @@ -577,8 +577,14 @@ ISel::visitCallInst (CallInst & CI) break; } } - // Emit a CALL instruction with PC-relative displacement. - BuildMI (BB, X86::CALLpcrel32, 1).addPCDisp (CI.getCalledValue ()); + + if (Function *F = CI.getCalledFunction()) { + // Emit a CALL instruction with PC-relative displacement. + BuildMI(BB, X86::CALLpcrel32, 1).addPCDisp(F); + } else { + unsigned Reg = getReg(CI.getCalledValue()); + BuildMI(BB, X86::CALLr32, 1).addReg(Reg); + } // Adjust the stack by `bytesPushed' amount if non-zero if (bytesPushed > 0) diff --git a/lib/Target/X86/X86InstrInfo.def b/lib/Target/X86/X86InstrInfo.def index 2b0432b27fd..cdf848d87bd 100644 --- a/lib/Target/X86/X86InstrInfo.def +++ b/lib/Target/X86/X86InstrInfo.def @@ -66,6 +66,10 @@ I(JNE , "jne", 0x85, M_BRANCH_FLAG, X86II::RawFrm | X86II::TB | X86II: I(JE , "je", 0x84, M_BRANCH_FLAG, X86II::RawFrm | X86II::TB | X86II::Void, NoIR, NoIR) // je foo I(CALLpcrel32 , "call", 0xE8, M_BRANCH_FLAG, X86II::Void, NoIR, NoIR) // call pc+42 +I(CALLr32 , "call", 0xFF, M_BRANCH_FLAG, X86II::Void | X86II::MRMS2r | X86II::Arg32, + NoIR, NoIR) // call [r32] +I(CALLm32 , "call", 0xFF, M_BRANCH_FLAG, X86II::Void | X86II::MRMS2m | X86II::Arg32, + NoIR, NoIR) // call [m32] // Misc instructions I(LEAVE , "leave", 0xC9, 0, X86II::RawFrm, O_EBP, O_EBP) // leave