Skip to content

Commit 5b7088c

Browse files
authored
TargetLibraryInfo: Assume no libcalls in the default constructor (llvm#92400)
The only tricky point here is PlaceSafepoints has an awful hack where it's creating a legacy PassManager inside it's runImpl, which was not propagating the incoming TLI. This means there's an implicit bug fix, where PlaceSafepoints would have been treating too many calls as builtins. I'm trying to delete the default constructor altogether, but this seems to be more difficult.
1 parent f43deca commit 5b7088c

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,28 @@ bool TargetLibraryInfoImpl::isCallingConvCCompatible(Function *F) {
160160
F->getFunctionType());
161161
}
162162

163+
static void initializeBase(TargetLibraryInfoImpl &TLI, const Triple &T) {
164+
bool ShouldExtI32Param, ShouldExtI32Return;
165+
bool ShouldSignExtI32Param, ShouldSignExtI32Return;
166+
TargetLibraryInfo::initExtensionsForTriple(
167+
ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param,
168+
ShouldSignExtI32Return, T);
169+
TLI.setShouldExtI32Param(ShouldExtI32Param);
170+
TLI.setShouldExtI32Return(ShouldExtI32Return);
171+
TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
172+
TLI.setShouldSignExtI32Return(ShouldSignExtI32Return);
173+
174+
// Let's assume by default that the size of int is 32 bits, unless the target
175+
// is a 16-bit architecture because then it most likely is 16 bits. If that
176+
// isn't true for a target those defaults should be overridden below.
177+
TLI.setIntSize(T.isArch16Bit() ? 16 : 32);
178+
}
179+
163180
/// Initialize the set of available library functions based on the specified
164181
/// target triple. This should be carefully written so that a missing target
165182
/// triple gets a sane set of defaults.
166-
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
167-
ArrayRef<StringLiteral> StandardNames) {
183+
static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
184+
ArrayRef<StringLiteral> StandardNames) {
168185
// Set IO unlocked variants as unavailable
169186
// Set them as available per system below
170187
TLI.setUnavailable(LibFunc_getc_unlocked);
@@ -178,20 +195,6 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
178195
TLI.setUnavailable(LibFunc_fputs_unlocked);
179196
TLI.setUnavailable(LibFunc_fgets_unlocked);
180197

181-
bool ShouldExtI32Param, ShouldExtI32Return;
182-
bool ShouldSignExtI32Param, ShouldSignExtI32Return;
183-
TargetLibraryInfo::initExtensionsForTriple(ShouldExtI32Param,
184-
ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return, T);
185-
TLI.setShouldExtI32Param(ShouldExtI32Param);
186-
TLI.setShouldExtI32Return(ShouldExtI32Return);
187-
TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
188-
TLI.setShouldSignExtI32Return(ShouldSignExtI32Return);
189-
190-
// Let's assume by default that the size of int is 32 bits, unless the target
191-
// is a 16-bit architecture because then it most likely is 16 bits. If that
192-
// isn't true for a target those defaults should be overridden below.
193-
TLI.setIntSize(T.isArch16Bit() ? 16 : 32);
194-
195198
// There is really no runtime library on AMDGPU, apart from
196199
// __kmpc_alloc/free_shared.
197200
if (T.isAMDGPU()) {
@@ -882,11 +885,19 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
882885
TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary, T);
883886
}
884887

885-
TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
886-
// Default to everything being available.
887-
memset(AvailableArray, -1, sizeof(AvailableArray));
888+
/// Initialize the set of available library functions based on the specified
889+
/// target triple. This should be carefully written so that a missing target
890+
/// triple gets a sane set of defaults.
891+
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
892+
ArrayRef<StringLiteral> StandardNames) {
893+
initializeBase(TLI, T);
894+
initializeLibCalls(TLI, T, StandardNames);
895+
}
888896

889-
initialize(*this, Triple(), StandardNames);
897+
TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
898+
// Default to nothing being available.
899+
memset(AvailableArray, 0, sizeof(AvailableArray));
900+
initializeBase(*this, Triple());
890901
}
891902

892903
TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {

0 commit comments

Comments
 (0)