Skip to content

Commit

Permalink
TargetLibraryInfo: Assume no libcalls in the default constructor (#92400
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
arsenm authored May 17, 2024
1 parent f43deca commit 5b7088c
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,28 @@ bool TargetLibraryInfoImpl::isCallingConvCCompatible(Function *F) {
F->getFunctionType());
}

static void initializeBase(TargetLibraryInfoImpl &TLI, const Triple &T) {
bool ShouldExtI32Param, ShouldExtI32Return;
bool ShouldSignExtI32Param, ShouldSignExtI32Return;
TargetLibraryInfo::initExtensionsForTriple(
ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param,
ShouldSignExtI32Return, T);
TLI.setShouldExtI32Param(ShouldExtI32Param);
TLI.setShouldExtI32Return(ShouldExtI32Return);
TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
TLI.setShouldSignExtI32Return(ShouldSignExtI32Return);

// Let's assume by default that the size of int is 32 bits, unless the target
// is a 16-bit architecture because then it most likely is 16 bits. If that
// isn't true for a target those defaults should be overridden below.
TLI.setIntSize(T.isArch16Bit() ? 16 : 32);
}

/// Initialize the set of available library functions based on the specified
/// target triple. This should be carefully written so that a missing target
/// triple gets a sane set of defaults.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
ArrayRef<StringLiteral> StandardNames) {
static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
ArrayRef<StringLiteral> StandardNames) {
// Set IO unlocked variants as unavailable
// Set them as available per system below
TLI.setUnavailable(LibFunc_getc_unlocked);
Expand All @@ -178,20 +195,6 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_fputs_unlocked);
TLI.setUnavailable(LibFunc_fgets_unlocked);

bool ShouldExtI32Param, ShouldExtI32Return;
bool ShouldSignExtI32Param, ShouldSignExtI32Return;
TargetLibraryInfo::initExtensionsForTriple(ShouldExtI32Param,
ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return, T);
TLI.setShouldExtI32Param(ShouldExtI32Param);
TLI.setShouldExtI32Return(ShouldExtI32Return);
TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
TLI.setShouldSignExtI32Return(ShouldSignExtI32Return);

// Let's assume by default that the size of int is 32 bits, unless the target
// is a 16-bit architecture because then it most likely is 16 bits. If that
// isn't true for a target those defaults should be overridden below.
TLI.setIntSize(T.isArch16Bit() ? 16 : 32);

// There is really no runtime library on AMDGPU, apart from
// __kmpc_alloc/free_shared.
if (T.isAMDGPU()) {
Expand Down Expand Up @@ -882,11 +885,19 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary, T);
}

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

initialize(*this, Triple(), StandardNames);
TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
// Default to nothing being available.
memset(AvailableArray, 0, sizeof(AvailableArray));
initializeBase(*this, Triple());
}

TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
Expand Down

0 comments on commit 5b7088c

Please sign in to comment.