[PATCH] D55304: [RISCV, WIP] Lower calls through PLT

Lewis Revill via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 11 12:52:20 PST 2018


lewis-revill updated this revision to Diff 177760.
lewis-revill added a comment.

Rebased to use D55560 <https://reviews.llvm.org/D55560> and with fewer dependencies


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55304/new/

https://reviews.llvm.org/D55304

Files:
  lib/Target/RISCV/RISCVISelLowering.cpp
  lib/Target/RISCV/RISCVMCInstLower.cpp
  lib/Target/RISCV/Utils/RISCVBaseInfo.h


Index: lib/Target/RISCV/Utils/RISCVBaseInfo.h
===================================================================
--- lib/Target/RISCV/Utils/RISCVBaseInfo.h
+++ lib/Target/RISCV/Utils/RISCVBaseInfo.h
@@ -50,6 +50,7 @@
 enum {
   MO_None,
   MO_CALL,
+  MO_PLT,
   MO_LO,
   MO_HI,
   MO_PCREL_HI,
Index: lib/Target/RISCV/RISCVMCInstLower.cpp
===================================================================
--- lib/Target/RISCV/RISCVMCInstLower.cpp
+++ lib/Target/RISCV/RISCVMCInstLower.cpp
@@ -40,6 +40,9 @@
   case RISCVII::MO_CALL:
     Kind = RISCVMCExpr::VK_RISCV_CALL;
     break;
+  case RISCVII::MO_PLT:
+    Kind = RISCVMCExpr::VK_RISCV_CALL_PLT;
+    break;
   case RISCVII::MO_LO:
     Kind = RISCVMCExpr::VK_RISCV_LO;
     break;
Index: lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- lib/Target/RISCV/RISCVISelLowering.cpp
+++ lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1417,11 +1417,21 @@
   // TargetGlobalAddress/TargetExternalSymbol node so that legalize won't
   // split it and then direct call can be matched by PseudoCALL.
   if (GlobalAddressSDNode *S = dyn_cast<GlobalAddressSDNode>(Callee)) {
-    Callee = DAG.getTargetGlobalAddress(S->getGlobal(), DL, PtrVT, 0,
-                                        RISCVII::MO_CALL);
+    const GlobalValue *GV = S->getGlobal();
+
+    unsigned OpFlags = RISCVII::MO_CALL;
+    if (!getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV))
+      OpFlags = RISCVII::MO_PLT;
+
+    Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags);
   } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
-    Callee =
-        DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT, RISCVII::MO_CALL);
+    unsigned OpFlags = RISCVII::MO_CALL;
+
+    if (!getTargetMachine().shouldAssumeDSOLocal(*MF.getFunction().getParent(),
+                                                 nullptr))
+      OpFlags = RISCVII::MO_PLT;
+
+    Callee = DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT, OpFlags);
   }
 
   // The first call operand is the chain and the second is the target address.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55304.177760.patch
Type: text/x-patch
Size: 2139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181211/5a3edead/attachment.bin>


More information about the llvm-commits mailing list