Skip to content

Commit 740161a

Browse files
committed
Revert "[LLVM][LTO] Factor out RTLib calls and allow them to be dropped (#98512)"
This reverts commit c05126b. (llvmorg-19-init-17714-gc05126bdfc3b) See #99610
1 parent 2d756d9 commit 740161a

37 files changed

+568
-676
lines changed

lld/COFF/Driver.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,12 +2428,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
24282428
// file's symbol table. If any of those library functions are defined in a
24292429
// bitcode file in an archive member, we need to arrange to use LTO to
24302430
// compile those archive members by adding them to the link beforehand.
2431-
if (!ctx.bitcodeFileInstances.empty()) {
2432-
llvm::Triple TT(
2433-
ctx.bitcodeFileInstances.front()->obj->getTargetTriple());
2434-
for (auto *s : lto::LTO::getRuntimeLibcallSymbols(TT))
2431+
if (!ctx.bitcodeFileInstances.empty())
2432+
for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
24352433
ctx.symtab.addLibcall(s);
2436-
}
24372434

24382435
// Windows specific -- if __load_config_used can be resolved, resolve it.
24392436
if (ctx.symtab.findUnderscore("_load_config_used"))

lld/ELF/Driver.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,11 +2884,9 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
28842884
// to, i.e. if the symbol's definition is in bitcode. Any other required
28852885
// libcall symbols will be added to the link after LTO when we add the LTO
28862886
// object file to the link.
2887-
if (!ctx.bitcodeFiles.empty()) {
2888-
llvm::Triple TT(ctx.bitcodeFiles.front()->obj->getTargetTriple());
2889-
for (auto *s : lto::LTO::getRuntimeLibcallSymbols(TT))
2887+
if (!ctx.bitcodeFiles.empty())
2888+
for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
28902889
handleLibcall(s);
2891-
}
28922890

28932891
// Archive members defining __wrap symbols may be extracted.
28942892
std::vector<WrappedSymbol> wrapped = addWrappedSymbols(args);

lld/wasm/Driver.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,11 +1320,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
13201320
// We only need to add libcall symbols to the link before LTO if the symbol's
13211321
// definition is in bitcode. Any other required libcall symbols will be added
13221322
// to the link after LTO when we add the LTO object file to the link.
1323-
if (!ctx.bitcodeFiles.empty()) {
1324-
llvm::Triple TT(ctx.bitcodeFiles.front()->obj->getTargetTriple());
1325-
for (auto *s : lto::LTO::getRuntimeLibcallSymbols(TT))
1323+
if (!ctx.bitcodeFiles.empty())
1324+
for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
13261325
handleLibcall(s);
1327-
}
13281326
if (errorCount())
13291327
return;
13301328

llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "llvm/CodeGen/GlobalISel/CallLowering.h"
2424
#include "llvm/CodeGen/GlobalISel/GISelKnownBits.h"
25-
#include "llvm/CodeGen/RuntimeLibcallUtil.h"
25+
#include "llvm/CodeGen/RuntimeLibcalls.h"
2626
#include "llvm/CodeGen/TargetOpcodes.h"
2727

2828
namespace llvm {

llvm/include/llvm/CodeGen/RuntimeLibcallUtil.h

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//===-- CodeGen/RuntimeLibcalls.h - Runtime Library Calls -------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the enum representing the list of runtime library calls
10+
// the backend may emit during code generation, and also some helper functions.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CODEGEN_RUNTIMELIBCALLS_H
15+
#define LLVM_CODEGEN_RUNTIMELIBCALLS_H
16+
17+
#include "llvm/CodeGen/ValueTypes.h"
18+
#include "llvm/Support/AtomicOrdering.h"
19+
20+
namespace llvm {
21+
namespace RTLIB {
22+
/// RTLIB::Libcall enum - This enum defines all of the runtime library calls
23+
/// the backend can emit. The various long double types cannot be merged,
24+
/// because 80-bit library functions use "xf" and 128-bit use "tf".
25+
///
26+
/// When adding PPCF128 functions here, note that their names generally need
27+
/// to be overridden for Darwin with the xxx$LDBL128 form. See
28+
/// PPCISelLowering.cpp.
29+
///
30+
enum Libcall {
31+
#define HANDLE_LIBCALL(code, name) code,
32+
#include "llvm/IR/RuntimeLibcalls.def"
33+
#undef HANDLE_LIBCALL
34+
};
35+
36+
/// GetFPLibCall - Helper to return the right libcall for the given floating
37+
/// point type, or UNKNOWN_LIBCALL if there is none.
38+
Libcall getFPLibCall(EVT VT,
39+
Libcall Call_F32,
40+
Libcall Call_F64,
41+
Libcall Call_F80,
42+
Libcall Call_F128,
43+
Libcall Call_PPCF128);
44+
45+
/// getFPEXT - Return the FPEXT_*_* value for the given types, or
46+
/// UNKNOWN_LIBCALL if there is none.
47+
Libcall getFPEXT(EVT OpVT, EVT RetVT);
48+
49+
/// getFPROUND - Return the FPROUND_*_* value for the given types, or
50+
/// UNKNOWN_LIBCALL if there is none.
51+
Libcall getFPROUND(EVT OpVT, EVT RetVT);
52+
53+
/// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
54+
/// UNKNOWN_LIBCALL if there is none.
55+
Libcall getFPTOSINT(EVT OpVT, EVT RetVT);
56+
57+
/// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
58+
/// UNKNOWN_LIBCALL if there is none.
59+
Libcall getFPTOUINT(EVT OpVT, EVT RetVT);
60+
61+
/// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
62+
/// UNKNOWN_LIBCALL if there is none.
63+
Libcall getSINTTOFP(EVT OpVT, EVT RetVT);
64+
65+
/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
66+
/// UNKNOWN_LIBCALL if there is none.
67+
Libcall getUINTTOFP(EVT OpVT, EVT RetVT);
68+
69+
/// getPOWI - Return the POWI_* value for the given types, or
70+
/// UNKNOWN_LIBCALL if there is none.
71+
Libcall getPOWI(EVT RetVT);
72+
73+
/// getLDEXP - Return the LDEXP_* value for the given types, or
74+
/// UNKNOWN_LIBCALL if there is none.
75+
Libcall getLDEXP(EVT RetVT);
76+
77+
/// getFREXP - Return the FREXP_* value for the given types, or
78+
/// UNKNOWN_LIBCALL if there is none.
79+
Libcall getFREXP(EVT RetVT);
80+
81+
/// Return the SYNC_FETCH_AND_* value for the given opcode and type, or
82+
/// UNKNOWN_LIBCALL if there is none.
83+
Libcall getSYNC(unsigned Opc, MVT VT);
84+
85+
/// Return the outline atomics value for the given atomic ordering, access
86+
/// size and set of libcalls for a given atomic, or UNKNOWN_LIBCALL if there
87+
/// is none.
88+
Libcall getOutlineAtomicHelper(const Libcall (&LC)[5][4],
89+
AtomicOrdering Order, uint64_t MemSize);
90+
91+
/// Return the outline atomics value for the given opcode, atomic ordering
92+
/// and type, or UNKNOWN_LIBCALL if there is none.
93+
Libcall getOUTLINE_ATOMIC(unsigned Opc, AtomicOrdering Order, MVT VT);
94+
95+
/// getMEMCPY_ELEMENT_UNORDERED_ATOMIC - Return
96+
/// MEMCPY_ELEMENT_UNORDERED_ATOMIC_* value for the given element size or
97+
/// UNKNOW_LIBCALL if there is none.
98+
Libcall getMEMCPY_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize);
99+
100+
/// getMEMMOVE_ELEMENT_UNORDERED_ATOMIC - Return
101+
/// MEMMOVE_ELEMENT_UNORDERED_ATOMIC_* value for the given element size or
102+
/// UNKNOW_LIBCALL if there is none.
103+
Libcall getMEMMOVE_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize);
104+
105+
/// getMEMSET_ELEMENT_UNORDERED_ATOMIC - Return
106+
/// MEMSET_ELEMENT_UNORDERED_ATOMIC_* value for the given element size or
107+
/// UNKNOW_LIBCALL if there is none.
108+
Libcall getMEMSET_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize);
109+
110+
}
111+
}
112+
113+
#endif

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "llvm/CodeGen/ISDOpcodes.h"
3232
#include "llvm/CodeGen/LowLevelTypeUtils.h"
3333
#include "llvm/CodeGen/MachineRegisterInfo.h"
34-
#include "llvm/CodeGen/RuntimeLibcallUtil.h"
34+
#include "llvm/CodeGen/RuntimeLibcalls.h"
3535
#include "llvm/CodeGen/SelectionDAG.h"
3636
#include "llvm/CodeGen/SelectionDAGNodes.h"
3737
#include "llvm/CodeGen/TargetCallingConv.h"
@@ -45,7 +45,6 @@
4545
#include "llvm/IR/InlineAsm.h"
4646
#include "llvm/IR/Instruction.h"
4747
#include "llvm/IR/Instructions.h"
48-
#include "llvm/IR/RuntimeLibcalls.h"
4948
#include "llvm/IR/Type.h"
5049
#include "llvm/Support/Alignment.h"
5150
#include "llvm/Support/AtomicOrdering.h"
@@ -3415,40 +3414,44 @@ class TargetLoweringBase {
34153414
return nullptr;
34163415
}
34173416

3417+
//===--------------------------------------------------------------------===//
3418+
// Runtime Library hooks
3419+
//
3420+
34183421
/// Rename the default libcall routine name for the specified libcall.
34193422
void setLibcallName(RTLIB::Libcall Call, const char *Name) {
3420-
Libcalls.setLibcallName(Call, Name);
3423+
LibcallRoutineNames[Call] = Name;
34213424
}
3422-
34233425
void setLibcallName(ArrayRef<RTLIB::Libcall> Calls, const char *Name) {
3424-
Libcalls.setLibcallName(Calls, Name);
3426+
for (auto Call : Calls)
3427+
setLibcallName(Call, Name);
34253428
}
34263429

34273430
/// Get the libcall routine name for the specified libcall.
34283431
const char *getLibcallName(RTLIB::Libcall Call) const {
3429-
return Libcalls.getLibcallName(Call);
3432+
return LibcallRoutineNames[Call];
34303433
}
34313434

34323435
/// Override the default CondCode to be used to test the result of the
34333436
/// comparison libcall against zero.
34343437
void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) {
3435-
Libcalls.setCmpLibcallCC(Call, CC);
3438+
CmpLibcallCCs[Call] = CC;
34363439
}
34373440

34383441
/// Get the CondCode that's to be used to test the result of the comparison
34393442
/// libcall against zero.
34403443
ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const {
3441-
return Libcalls.getCmpLibcallCC(Call);
3444+
return CmpLibcallCCs[Call];
34423445
}
34433446

34443447
/// Set the CallingConv that should be used for the specified libcall.
34453448
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) {
3446-
Libcalls.setLibcallCallingConv(Call, CC);
3449+
LibcallCallingConvs[Call] = CC;
34473450
}
34483451

34493452
/// Get the CallingConv that should be used for the specified libcall.
34503453
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
3451-
return Libcalls.getLibcallCallingConv(Call);
3454+
return LibcallCallingConvs[Call];
34523455
}
34533456

34543457
/// Execute target specific actions to finalize target lowering.
@@ -3627,8 +3630,18 @@ class TargetLoweringBase {
36273630
std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType>
36283631
PromoteToType;
36293632

3630-
/// The list of libcalls that the target will use.
3631-
RTLIB::RuntimeLibcallsInfo Libcalls;
3633+
/// Stores the name each libcall.
3634+
const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];
3635+
3636+
/// The ISD::CondCode that should be used to test the result of each of the
3637+
/// comparison libcall against zero.
3638+
ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL];
3639+
3640+
/// Stores the CallingConv that should be used for each libcall.
3641+
CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL];
3642+
3643+
/// Set default libcall names and calling conventions.
3644+
void InitLibcalls(const Triple &TT);
36323645

36333646
/// The bits of IndexedModeActions used to store the legalisation actions
36343647
/// We store the data as | ML | MS | L | S | each taking 4 bits.

0 commit comments

Comments
 (0)