Skip to content

Commit 73ae3c8

Browse files
committed
CodeGen: Move LibcallLoweringInfo to separate file
1 parent 660887e commit 73ae3c8

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
@@ -238,58 +238,6 @@ struct RuntimeLibcallsInfo {
238238

239239
} // namespace RTLIB
240240

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-
293241
} // namespace llvm
294242

295243
#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)