Skip to content

Commit 226c6e5

Browse files
committed
CodeGen: Move LibcallLoweringInfo to separate file
1 parent 90f3917 commit 226c6e5

File tree

6 files changed

+93
-67
lines changed

6 files changed

+93
-67
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//===- LibcallLoweringInfo.h ------------------------------------*- 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+
#include "llvm/IR/RuntimeLibcalls.h"
10+
11+
namespace llvm {
12+
13+
class LibcallLoweringInfo {
14+
private:
15+
LLVM_ABI const RTLIB::RuntimeLibcallsInfo &RTLCI;
16+
/// Stores the implementation choice for each each libcall.
17+
LLVM_ABI RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
18+
RTLIB::Unsupported};
19+
20+
public:
21+
LLVM_ABI LibcallLoweringInfo(const RTLIB::RuntimeLibcallsInfo &RTLCI);
22+
23+
/// Get the libcall routine name for the specified libcall.
24+
// FIXME: This should be removed. Only LibcallImpl should have a name.
25+
LLVM_ABI const char *getLibcallName(RTLIB::Libcall Call) const {
26+
// FIXME: Return StringRef
27+
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LibcallImpls[Call])
28+
.data();
29+
}
30+
31+
/// Return the lowering's selection of implementation call for \p Call
32+
LLVM_ABI RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
33+
return LibcallImpls[Call];
34+
}
35+
36+
/// Rename the default libcall routine name for the specified libcall.
37+
LLVM_ABI void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
38+
LibcallImpls[Call] = Impl;
39+
}
40+
41+
// FIXME: Remove this wrapper in favor of directly using
42+
// getLibcallImplCallingConv
43+
LLVM_ABI CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const {
44+
return RTLCI.LibcallImplCallingConvs[LibcallImpls[Call]];
45+
}
46+
47+
/// Get the CallingConv that should be used for the specified libcall.
48+
LLVM_ABI CallingConv::ID
49+
getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const {
50+
return RTLCI.LibcallImplCallingConvs[Call];
51+
}
52+
53+
/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
54+
/// unsupported.
55+
LLVM_ABI StringRef getMemcpyName() const {
56+
RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
57+
if (Memcpy != RTLIB::Unsupported)
58+
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Memcpy);
59+
60+
// Fallback to memmove if memcpy isn't available.
61+
return getLibcallName(RTLIB::MEMMOVE);
62+
}
63+
};
64+
65+
} // end namespace llvm

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/ADT/StringRef.h"
3030
#include "llvm/CodeGen/DAGCombine.h"
3131
#include "llvm/CodeGen/ISDOpcodes.h"
32+
#include "llvm/CodeGen/LibcallLoweringInfo.h"
3233
#include "llvm/CodeGen/LowLevelTypeUtils.h"
3334
#include "llvm/CodeGen/MachineRegisterInfo.h"
3435
#include "llvm/CodeGen/RuntimeLibcallUtil.h"

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -249,58 +249,6 @@ struct RuntimeLibcallsInfo {
249249

250250
} // namespace RTLIB
251251

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

306254
#endif // LLVM_IR_RUNTIME_LIBCALLS_H

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ add_llvm_component_library(LLVMCodeGen
8888
LatencyPriorityQueue.cpp
8989
LazyMachineBlockFrequencyInfo.cpp
9090
LexicalScopes.cpp
91+
LibcallLoweringInfo.cpp
9192
LiveDebugVariables.cpp
9293
LiveIntervals.cpp
9394
LiveInterval.cpp
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===- LibcallLoweringInfo.cpp - Interface for runtime libcalls -----------===//
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+
#include "llvm/CodeGen/LibcallLoweringInfo.h"
10+
11+
using namespace llvm;
12+
13+
LibcallLoweringInfo::LibcallLoweringInfo(
14+
const RTLIB::RuntimeLibcallsInfo &RTLCI)
15+
: RTLCI(RTLCI) {
16+
// TODO: This should be generated with lowering predicates, and assert the
17+
// call is available.
18+
for (RTLIB::LibcallImpl Impl : RTLIB::libcall_impls()) {
19+
if (RTLCI.isAvailable(Impl)) {
20+
RTLIB::Libcall LC = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl);
21+
// FIXME: Hack, assume the first available libcall wins.
22+
if (LibcallImpls[LC] == RTLIB::Unsupported)
23+
LibcallImpls[LC] = Impl;
24+
}
25+
}
26+
}

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,3 @@ 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)