From a59868519b385e0b77eca6510b6a875056189a9a Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Mon, 20 Nov 2006 10:46:14 +0000 Subject: [PATCH] We should perform extra load for dllimported calls git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31874 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelLowering.cpp | 38 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 80fe1be685b..77a4b539cfe 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -35,6 +35,8 @@ #include "llvm/ADT/StringExtras.h" using namespace llvm; +static bool WindowsGVRequiresExtraLoad(GlobalValue *GV); + // FIXME: temporary. static cl::opt EnableFastCC("enable-x86-fastcc", cl::Hidden, cl::desc("Enable fastcc on X86")); @@ -651,9 +653,12 @@ SDOperand X86TargetLowering::LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG) { // If the callee is a GlobalAddress node (quite common, every direct call is) // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. - if (GlobalAddressSDNode *G = dyn_cast(Callee)) - Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); - else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) + if (GlobalAddressSDNode *G = dyn_cast(Callee)) { + // We should use extra load for direct calls to dllimported functions + if (!((Subtarget->isTargetCygwin() || Subtarget->isTargetWindows()) && + WindowsGVRequiresExtraLoad(G->getGlobal()))) + Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); + } else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); std::vector NodeTys; @@ -1186,9 +1191,12 @@ X86TargetLowering::LowerX86_64CCCCallTo(SDOperand Op, SelectionDAG &DAG) { // If the callee is a GlobalAddress node (quite common, every direct call is) // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. - if (GlobalAddressSDNode *G = dyn_cast(Callee)) - Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); - else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) + if (GlobalAddressSDNode *G = dyn_cast(Callee)) { + // We should use extra load for direct calls to dllimported functions + if (!((Subtarget->isTargetCygwin() || Subtarget->isTargetWindows()) && + WindowsGVRequiresExtraLoad(G->getGlobal()))) + Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); + } else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); std::vector NodeTys; @@ -1681,9 +1689,12 @@ SDOperand X86TargetLowering::LowerFastCCCallTo(SDOperand Op, SelectionDAG &DAG, // If the callee is a GlobalAddress node (quite common, every direct call is) // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. - if (GlobalAddressSDNode *G = dyn_cast(Callee)) - Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); - else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) + if (GlobalAddressSDNode *G = dyn_cast(Callee)) { + // We should use extra load for direct calls to dllimported functions + if (!((Subtarget->isTargetCygwin() || Subtarget->isTargetWindows()) && + WindowsGVRequiresExtraLoad(G->getGlobal()))) + Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); + } else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); std::vector NodeTys; @@ -1977,9 +1988,12 @@ SDOperand X86TargetLowering::LowerStdCallCCCallTo(SDOperand Op, // If the callee is a GlobalAddress node (quite common, every direct call is) // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. - if (GlobalAddressSDNode *G = dyn_cast(Callee)) - Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); - else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) + if (GlobalAddressSDNode *G = dyn_cast(Callee)) { + // We should use extra load for direct calls to dllimported functions + if (!((Subtarget->isTargetCygwin() || Subtarget->isTargetWindows()) && + WindowsGVRequiresExtraLoad(G->getGlobal()))) + Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); + } else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); std::vector NodeTys;