Skip to content

Commit 6c59852

Browse files
committed
CodeGen: Move LibcallLoweringInfo to separate file
1 parent 712ae69 commit 6c59852

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

232232
} // namespace RTLIB
233233

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

288236
#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
@@ -73,18 +73,3 @@ bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) {
7373
return false;
7474
}
7575
}
76-
77-
LibcallLoweringInfo::LibcallLoweringInfo(
78-
const RTLIB::RuntimeLibcallsInfo &RTLCI)
79-
: RTLCI(RTLCI) {
80-
// TODO: This should be generated with lowering predicates, and assert the
81-
// call is available.
82-
for (RTLIB::LibcallImpl Impl : RTLIB::libcall_impls()) {
83-
if (RTLCI.isAvailable(Impl)) {
84-
RTLIB::Libcall LC = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl);
85-
// FIXME: Hack, assume the first available libcall wins.
86-
if (LibcallImpls[LC] == RTLIB::Unsupported)
87-
LibcallImpls[LC] = Impl;
88-
}
89-
}
90-
}

0 commit comments

Comments
 (0)