[lld] [llvm] [LLVM][LTO] Factor out RTLib calls and allow them to be dropped (PR #98512)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 12:06:59 PDT 2024


================
@@ -189,6 +189,436 @@ struct MemOp {
   }
 };
 
+struct LibcallsInfo {
+  explicit LibcallsInfo(const Triple &TT) {
+    initLibcalls(TT);
+    initCmpLibcallCCs();
+  }
+
+  /// Rename the default libcall routine name for the specified libcall.
+  void setLibcallName(RTLIB::Libcall Call, const char *Name) {
+    LibcallRoutineNames[Call] = Name;
+  }
+
+  void setLibcallName(ArrayRef<RTLIB::Libcall> Calls, const char *Name) {
+    for (auto Call : Calls)
+      setLibcallName(Call, Name);
+  }
+
+  /// Get the libcall routine name for the specified libcall.
+  const char *getLibcallName(RTLIB::Libcall Call) const {
+    return LibcallRoutineNames[Call];
+  }
+
+  /// Override the default CondCode to be used to test the result of the
+  /// comparison libcall against zero.
+  void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) {
+    CmpLibcallCCs[Call] = CC;
+  }
+
+  /// Get the CondCode that's to be used to test the result of the comparison
+  /// libcall against zero.
+  ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const {
+    return CmpLibcallCCs[Call];
+  }
+
+  /// Set the CallingConv that should be used for the specified libcall.
+  void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
+    LibcallCallingConvs[Call] = CC;
+  }
+
+  /// Get the CallingConv that should be used for the specified libcall.
+  CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
+    return LibcallCallingConvs[Call];
+  }
+
+  iterator_range<const char **> getLibcallNames() {
+    return llvm::make_range(LibcallRoutineNames,
+                            LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL);
+  }
+
+private:
+  /// Stores the name each libcall.
+  const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
+
+  /// The ISD::CondCode that should be used to test the result of each of the
+  /// comparison libcall against zero.
+  ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL];
+
+  /// Stores the CallingConv that should be used for each libcall.
+  CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
+
+  static bool darwinHasSinCos(const Triple &TT) {
+    assert(TT.isOSDarwin() && "should be called with darwin triple");
+    // Don't bother with 32 bit x86.
+    if (TT.getArch() == Triple::x86)
+      return false;
+    // Macos < 10.9 has no sincos_stret.
+    if (TT.isMacOSX())
+      return !TT.isMacOSXVersionLT(10, 9) && TT.isArch64Bit();
+    // iOS < 7.0 has no sincos_stret.
+    if (TT.isiOS())
+      return !TT.isOSVersionLT(7, 0);
+    // Any other darwin such as WatchOS/TvOS is new enough.
+    return true;
+  }
+
+  /// Sets default libcall calling conventions.
+  void initCmpLibcallCCs() {
+    std::fill(CmpLibcallCCs, CmpLibcallCCs + RTLIB::UNKNOWN_LIBCALL,
+              ISD::SETCC_INVALID);
+    CmpLibcallCCs[RTLIB::OEQ_F32] = ISD::SETEQ;
+    CmpLibcallCCs[RTLIB::OEQ_F64] = ISD::SETEQ;
+    CmpLibcallCCs[RTLIB::OEQ_F128] = ISD::SETEQ;
+    CmpLibcallCCs[RTLIB::OEQ_PPCF128] = ISD::SETEQ;
+    CmpLibcallCCs[RTLIB::UNE_F32] = ISD::SETNE;
+    CmpLibcallCCs[RTLIB::UNE_F64] = ISD::SETNE;
+    CmpLibcallCCs[RTLIB::UNE_F128] = ISD::SETNE;
+    CmpLibcallCCs[RTLIB::UNE_PPCF128] = ISD::SETNE;
+    CmpLibcallCCs[RTLIB::OGE_F32] = ISD::SETGE;
+    CmpLibcallCCs[RTLIB::OGE_F64] = ISD::SETGE;
+    CmpLibcallCCs[RTLIB::OGE_F128] = ISD::SETGE;
+    CmpLibcallCCs[RTLIB::OGE_PPCF128] = ISD::SETGE;
+    CmpLibcallCCs[RTLIB::OLT_F32] = ISD::SETLT;
+    CmpLibcallCCs[RTLIB::OLT_F64] = ISD::SETLT;
+    CmpLibcallCCs[RTLIB::OLT_F128] = ISD::SETLT;
+    CmpLibcallCCs[RTLIB::OLT_PPCF128] = ISD::SETLT;
+    CmpLibcallCCs[RTLIB::OLE_F32] = ISD::SETLE;
+    CmpLibcallCCs[RTLIB::OLE_F64] = ISD::SETLE;
+    CmpLibcallCCs[RTLIB::OLE_F128] = ISD::SETLE;
+    CmpLibcallCCs[RTLIB::OLE_PPCF128] = ISD::SETLE;
+    CmpLibcallCCs[RTLIB::OGT_F32] = ISD::SETGT;
+    CmpLibcallCCs[RTLIB::OGT_F64] = ISD::SETGT;
+    CmpLibcallCCs[RTLIB::OGT_F128] = ISD::SETGT;
+    CmpLibcallCCs[RTLIB::OGT_PPCF128] = ISD::SETGT;
+    CmpLibcallCCs[RTLIB::UO_F32] = ISD::SETNE;
+    CmpLibcallCCs[RTLIB::UO_F64] = ISD::SETNE;
+    CmpLibcallCCs[RTLIB::UO_F128] = ISD::SETNE;
+    CmpLibcallCCs[RTLIB::UO_PPCF128] = ISD::SETNE;
+  }
+
+  /// Set default libcall names.
+  void initLibcalls(const Triple &TT) {
----------------
jhuber6 wrote:

This would make `IRSymTab` need to depend on `CodeGen`. I didn't think it was justified and i couldn't think of anywhere better to put the class, so I just make it header-only.

https://github.com/llvm/llvm-project/pull/98512


More information about the llvm-commits mailing list