Skip to content

Commit 660887e

Browse files
committed
CodeGen: Move LibcallLoweringInfo to be with RuntimeLibcallInfo
Eventually this will be program dependent state, so it should not be part of TargetLowering. It's easiest to have this as part of the analysis that will provide RuntimeLibcallInfo. In principle we would also need this to more precisely refine the set of libcalls that full LTO could trim based on the subtarget.
1 parent 8c6ed4e commit 660887e

File tree

4 files changed

+70
-69
lines changed

4 files changed

+70
-69
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -193,58 +193,6 @@ struct MemOp {
193193
}
194194
};
195195

196-
class LibcallLoweringInfo {
197-
private:
198-
LLVM_ABI const RTLIB::RuntimeLibcallsInfo &RTLCI;
199-
/// Stores the implementation choice for each each libcall.
200-
LLVM_ABI RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
201-
RTLIB::Unsupported};
202-
203-
public:
204-
LLVM_ABI LibcallLoweringInfo(const RTLIB::RuntimeLibcallsInfo &RTLCI);
205-
206-
/// Get the libcall routine name for the specified libcall.
207-
// FIXME: This should be removed. Only LibcallImpl should have a name.
208-
LLVM_ABI const char *getLibcallName(RTLIB::Libcall Call) const {
209-
// FIXME: Return StringRef
210-
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LibcallImpls[Call])
211-
.data();
212-
}
213-
214-
/// Return the lowering's selection of implementation call for \p Call
215-
LLVM_ABI RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
216-
return LibcallImpls[Call];
217-
}
218-
219-
/// Rename the default libcall routine name for the specified libcall.
220-
LLVM_ABI void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
221-
LibcallImpls[Call] = Impl;
222-
}
223-
224-
// FIXME: Remove this wrapper in favor of directly using
225-
// getLibcallImplCallingConv
226-
LLVM_ABI CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
227-
return RTLCI.LibcallImplCallingConvs[LibcallImpls[Call]];
228-
}
229-
230-
/// Get the CallingConv that should be used for the specified libcall.
231-
LLVM_ABI CallingConv::ID
232-
getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const {
233-
return RTLCI.LibcallImplCallingConvs[Call];
234-
}
235-
236-
/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
237-
/// unsupported.
238-
LLVM_ABI StringRef getMemcpyName() const {
239-
RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
240-
if (Memcpy != RTLIB::Unsupported)
241-
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Memcpy);
242-
243-
// Fallback to memmove if memcpy isn't available.
244-
return getLibcallName(RTLIB::MEMMOVE);
245-
}
246-
};
247-
248196
/// This base class for TargetLowering contains the SelectionDAG-independent
249197
/// parts that can be used from the rest of CodeGen.
250198
class LLVM_ABI TargetLoweringBase {

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434

3535
namespace llvm {
3636

37-
class LibcallLoweringInfo;
38-
3937
template <> struct enum_iteration_traits<RTLIB::Libcall> {
4038
static constexpr bool is_iterable = true;
4139
};
@@ -44,6 +42,8 @@ template <> struct enum_iteration_traits<RTLIB::LibcallImpl> {
4442
static constexpr bool is_iterable = true;
4543
};
4644

45+
class LibcallLoweringInfo;
46+
4747
namespace RTLIB {
4848

4949
// Return an iterator over all Libcall values.
@@ -237,6 +237,59 @@ struct RuntimeLibcallsInfo {
237237
};
238238

239239
} // namespace RTLIB
240+
241+
class LibcallLoweringInfo {
242+
private:
243+
LLVM_ABI const RTLIB::RuntimeLibcallsInfo &RTLCI;
244+
/// Stores the implementation choice for each each libcall.
245+
LLVM_ABI RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
246+
RTLIB::Unsupported};
247+
248+
public:
249+
LLVM_ABI LibcallLoweringInfo(const RTLIB::RuntimeLibcallsInfo &RTLCI);
250+
251+
/// Get the libcall routine name for the specified libcall.
252+
// FIXME: This should be removed. Only LibcallImpl should have a name.
253+
LLVM_ABI const char *getLibcallName(RTLIB::Libcall Call) const {
254+
// FIXME: Return StringRef
255+
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LibcallImpls[Call])
256+
.data();
257+
}
258+
259+
/// Return the lowering's selection of implementation call for \p Call
260+
LLVM_ABI RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
261+
return LibcallImpls[Call];
262+
}
263+
264+
/// Rename the default libcall routine name for the specified libcall.
265+
LLVM_ABI void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
266+
LibcallImpls[Call] = Impl;
267+
}
268+
269+
// FIXME: Remove this wrapper in favor of directly using
270+
// getLibcallImplCallingConv
271+
LLVM_ABI CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
272+
return RTLCI.LibcallImplCallingConvs[LibcallImpls[Call]];
273+
}
274+
275+
/// Get the CallingConv that should be used for the specified libcall.
276+
LLVM_ABI CallingConv::ID
277+
getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const {
278+
return RTLCI.LibcallImplCallingConvs[Call];
279+
}
280+
281+
/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
282+
/// unsupported.
283+
LLVM_ABI StringRef getMemcpyName() const {
284+
RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
285+
if (Memcpy != RTLIB::Unsupported)
286+
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Memcpy);
287+
288+
// Fallback to memmove if memcpy isn't available.
289+
return getLibcallName(RTLIB::MEMMOVE);
290+
}
291+
};
292+
240293
} // namespace llvm
241294

242295
#endif // LLVM_IR_RUNTIME_LIBCALLS_H

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -695,21 +695,6 @@ ISD::CondCode TargetLoweringBase::getSoftFloatCmpLibcallPredicate(
695695
}
696696
}
697697

698-
LibcallLoweringInfo::LibcallLoweringInfo(
699-
const RTLIB::RuntimeLibcallsInfo &RTLCI)
700-
: RTLCI(RTLCI) {
701-
// TODO: This should be generated with lowering predicates, and assert the
702-
// call is available.
703-
for (RTLIB::LibcallImpl Impl : RTLIB::libcall_impls()) {
704-
if (RTLCI.isAvailable(Impl)) {
705-
RTLIB::Libcall LC = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl);
706-
// FIXME: Hack, assume the first available libcall wins.
707-
if (LibcallImpls[LC] == RTLIB::Unsupported)
708-
LibcallImpls[LC] = Impl;
709-
}
710-
}
711-
}
712-
713698
/// NOTE: The TargetMachine owns TLOF.
714699
TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm)
715700
: TM(tm),

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,18 @@ RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT,
152152

153153
return {};
154154
}
155+
156+
LibcallLoweringInfo::LibcallLoweringInfo(
157+
const RTLIB::RuntimeLibcallsInfo &RTLCI)
158+
: RTLCI(RTLCI) {
159+
// TODO: This should be generated with lowering predicates, and assert the
160+
// call is available.
161+
for (RTLIB::LibcallImpl Impl : RTLIB::libcall_impls()) {
162+
if (RTLCI.isAvailable(Impl)) {
163+
RTLIB::Libcall LC = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl);
164+
// FIXME: Hack, assume the first available libcall wins.
165+
if (LibcallImpls[LC] == RTLIB::Unsupported)
166+
LibcallImpls[LC] = Impl;
167+
}
168+
}
169+
}

0 commit comments

Comments
 (0)