Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace llvm {

class TargetSubtargetInfo;

class LibcallLoweringInfo {
private:
const RTLIB::RuntimeLibcallsInfo &RTLCI;
Expand All @@ -21,7 +23,12 @@ class LibcallLoweringInfo {
RTLIB::Unsupported};

public:
LLVM_ABI LibcallLoweringInfo(const RTLIB::RuntimeLibcallsInfo &RTLCI);
LLVM_ABI LibcallLoweringInfo(const RTLIB::RuntimeLibcallsInfo &RTLCI,
const TargetSubtargetInfo &Subtarget);

const RTLIB::RuntimeLibcallsInfo &getRuntimeLibcallsInfo() const {
return RTLCI;
}

/// Get the libcall routine name for the specified libcall.
// FIXME: This should be removed. Only LibcallImpl should have a name.
Expand Down
6 changes: 4 additions & 2 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ class LLVM_ABI TargetLoweringBase {
llvm_unreachable("Invalid content kind");
}

explicit TargetLoweringBase(const TargetMachine &TM);
explicit TargetLoweringBase(const TargetMachine &TM,
const TargetSubtargetInfo &STI);
TargetLoweringBase(const TargetLoweringBase &) = delete;
TargetLoweringBase &operator=(const TargetLoweringBase &) = delete;
virtual ~TargetLoweringBase();
Expand Down Expand Up @@ -3977,7 +3978,8 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
TargetLowering(const TargetLowering &) = delete;
TargetLowering &operator=(const TargetLowering &) = delete;

explicit TargetLowering(const TargetMachine &TM);
explicit TargetLowering(const TargetMachine &TM,
const TargetSubtargetInfo &STI);
~TargetLowering() override;

bool isPositionIndependent() const;
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/CodeGen/TargetSubtargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class InstrItineraryData;
struct InstrStage;
class InstructionSelector;
class LegalizerInfo;
class LibcallLoweringInfo;
class MachineInstr;
struct MachineSchedPolicy;
struct MCReadAdvanceEntry;
Expand Down Expand Up @@ -139,6 +140,12 @@ class LLVM_ABI TargetSubtargetInfo : public MCSubtargetInfo {
return nullptr;
}

/// Configure the LibcallLoweringInfo for this subtarget. The libcalls will be
/// pre-configured with defaults based on RuntimeLibcallsInfo. This may be
/// used to override those decisions, such as disambiguating alternative
/// implementations.
virtual void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const {}

/// Resolve a SchedClass at runtime, where SchedClass identifies an
/// MCSchedClassDesc with the isVariant property. This may return the ID of
/// another variant SchedClass, but repeated invocation must quickly terminate
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/CodeGen/LibcallLoweringInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
//===----------------------------------------------------------------------===//

#include "llvm/CodeGen/LibcallLoweringInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"

using namespace llvm;

LibcallLoweringInfo::LibcallLoweringInfo(
const RTLIB::RuntimeLibcallsInfo &RTLCI)
const RTLIB::RuntimeLibcallsInfo &RTLCI,
const TargetSubtargetInfo &Subtarget)
: RTLCI(RTLCI) {
// TODO: This should be generated with lowering predicates, and assert the
// call is available.
Expand All @@ -23,4 +25,6 @@ LibcallLoweringInfo::LibcallLoweringInfo(
LibcallImpls[LC] = Impl;
}
}

Subtarget.initLibcallLoweringInfo(*this);
}
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ using namespace llvm;
using namespace llvm::SDPatternMatch;

/// NOTE: The TargetMachine owns TLOF.
TargetLowering::TargetLowering(const TargetMachine &tm)
: TargetLoweringBase(tm) {}
TargetLowering::TargetLowering(const TargetMachine &tm,
const TargetSubtargetInfo &sti)
: TargetLoweringBase(tm, sti) {}

// Define the virtual destructor out-of-line for build efficiency.
TargetLowering::~TargetLowering() = default;
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,13 @@ ISD::CondCode TargetLoweringBase::getSoftFloatCmpLibcallPredicate(
}

/// NOTE: The TargetMachine owns TLOF.
TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm)
TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm,
const TargetSubtargetInfo &STI)
: TM(tm),
RuntimeLibcallInfo(TM.getTargetTriple(), TM.Options.ExceptionModel,
TM.Options.FloatABIType, TM.Options.EABIVersion,
TM.Options.MCOptions.getABIName(), TM.Options.VecLib),
Libcalls(RuntimeLibcallInfo) {
Libcalls(RuntimeLibcallInfo, STI) {
initActions();

// Perform these initializations only once.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ extractPtrauthBlendDiscriminators(SDValue Disc, SelectionDAG *DAG) {

AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
const AArch64Subtarget &STI)
: TargetLowering(TM), Subtarget(&STI) {
: TargetLowering(TM, STI), Subtarget(&STI) {
// AArch64 doesn't have comparisons which set GPRs or setcc instructions, so
// we have to make something up. Arbitrarily, choose ZeroOrOne.
setBooleanContents(ZeroOrOneBooleanContent);
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ unsigned AMDGPUTargetLowering::numBitsSigned(SDValue Op, SelectionDAG &DAG) {
}

AMDGPUTargetLowering::AMDGPUTargetLowering(const TargetMachine &TM,
const AMDGPUSubtarget &STI)
: TargetLowering(TM), Subtarget(&STI) {
const TargetSubtargetInfo &STI,
const AMDGPUSubtarget &AMDGPUSTI)
: TargetLowering(TM, STI), Subtarget(&AMDGPUSTI) {
// Always lower memset, memcpy, and memmove intrinsics to load/store
// instructions, rather then generating calls to memset, mempcy or memmove.
MaxStoresPerMemset = MaxStoresPerMemsetOptSize = ~0U;
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ class AMDGPUTargetLowering : public TargetLowering {
const SmallVectorImpl<ISD::InputArg> &Ins) const;

public:
AMDGPUTargetLowering(const TargetMachine &TM, const AMDGPUSubtarget &STI);
AMDGPUTargetLowering(const TargetMachine &TM, const TargetSubtargetInfo &STI,
const AMDGPUSubtarget &AMDGPUSTI);

bool mayIgnoreSignedZero(SDValue Op) const;

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/AMDGPU/R600ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ using namespace llvm;

R600TargetLowering::R600TargetLowering(const TargetMachine &TM,
const R600Subtarget &STI)
: AMDGPUTargetLowering(TM, STI), Subtarget(&STI), Gen(STI.getGeneration()) {
: AMDGPUTargetLowering(TM, STI, STI), Subtarget(&STI),
Gen(STI.getGeneration()) {
addRegisterClass(MVT::f32, &R600::R600_Reg32RegClass);
addRegisterClass(MVT::i32, &R600::R600_Reg32RegClass);
addRegisterClass(MVT::v2f32, &R600::R600_Reg64RegClass);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static unsigned findFirstFreeSGPR(CCState &CCInfo) {

SITargetLowering::SITargetLowering(const TargetMachine &TM,
const GCNSubtarget &STI)
: AMDGPUTargetLowering(TM, STI), Subtarget(&STI) {
: AMDGPUTargetLowering(TM, STI, STI), Subtarget(&STI) {
addRegisterClass(MVT::i1, &AMDGPU::VReg_1RegClass);
addRegisterClass(MVT::i64, &AMDGPU::SReg_64RegClass);

Expand Down
70 changes: 1 addition & 69 deletions llvm/lib/Target/ARM/ARMISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ const ARMBaseTargetMachine &ARMTargetLowering::getTM() const {

ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
const ARMSubtarget &STI)
: TargetLowering(TM_), Subtarget(&STI),
: TargetLowering(TM_, STI), Subtarget(&STI),
RegInfo(Subtarget->getRegisterInfo()),
Itins(Subtarget->getInstrItineraryData()) {
const auto &TM = static_cast<const ARMBaseTargetMachine &>(TM_);
Expand All @@ -518,74 +518,6 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,

const Triple &TT = TM.getTargetTriple();

if (TT.isOSBinFormatMachO()) {
// Uses VFP for Thumb libfuncs if available.
if (Subtarget->isThumb() && Subtarget->hasVFP2Base() &&
Subtarget->hasARMOps() && !Subtarget->useSoftFloat()) {
// clang-format off
static const struct {
const RTLIB::Libcall Op;
const RTLIB::LibcallImpl Impl;
} LibraryCalls[] = {
// Single-precision floating-point arithmetic.
{ RTLIB::ADD_F32, RTLIB::impl___addsf3vfp },
{ RTLIB::SUB_F32, RTLIB::impl___subsf3vfp },
{ RTLIB::MUL_F32, RTLIB::impl___mulsf3vfp },
{ RTLIB::DIV_F32, RTLIB::impl___divsf3vfp },

// Double-precision floating-point arithmetic.
{ RTLIB::ADD_F64, RTLIB::impl___adddf3vfp },
{ RTLIB::SUB_F64, RTLIB::impl___subdf3vfp },
{ RTLIB::MUL_F64, RTLIB::impl___muldf3vfp },
{ RTLIB::DIV_F64, RTLIB::impl___divdf3vfp },

// Single-precision comparisons.
{ RTLIB::OEQ_F32, RTLIB::impl___eqsf2vfp },
{ RTLIB::UNE_F32, RTLIB::impl___nesf2vfp },
{ RTLIB::OLT_F32, RTLIB::impl___ltsf2vfp },
{ RTLIB::OLE_F32, RTLIB::impl___lesf2vfp },
{ RTLIB::OGE_F32, RTLIB::impl___gesf2vfp },
{ RTLIB::OGT_F32, RTLIB::impl___gtsf2vfp },
{ RTLIB::UO_F32, RTLIB::impl___unordsf2vfp },

// Double-precision comparisons.
{ RTLIB::OEQ_F64, RTLIB::impl___eqdf2vfp },
{ RTLIB::UNE_F64, RTLIB::impl___nedf2vfp },
{ RTLIB::OLT_F64, RTLIB::impl___ltdf2vfp },
{ RTLIB::OLE_F64, RTLIB::impl___ledf2vfp },
{ RTLIB::OGE_F64, RTLIB::impl___gedf2vfp },
{ RTLIB::OGT_F64, RTLIB::impl___gtdf2vfp },
{ RTLIB::UO_F64, RTLIB::impl___unorddf2vfp },

// Floating-point to integer conversions.
// i64 conversions are done via library routines even when generating VFP
// instructions, so use the same ones.
{ RTLIB::FPTOSINT_F64_I32, RTLIB::impl___fixdfsivfp },
{ RTLIB::FPTOUINT_F64_I32, RTLIB::impl___fixunsdfsivfp },
{ RTLIB::FPTOSINT_F32_I32, RTLIB::impl___fixsfsivfp },
{ RTLIB::FPTOUINT_F32_I32, RTLIB::impl___fixunssfsivfp },

// Conversions between floating types.
{ RTLIB::FPROUND_F64_F32, RTLIB::impl___truncdfsf2vfp },
{ RTLIB::FPEXT_F32_F64, RTLIB::impl___extendsfdf2vfp },

// Integer to floating-point conversions.
// i64 conversions are done via library routines even when generating VFP
// instructions, so use the same ones.
// FIXME: There appears to be some naming inconsistency in ARM libgcc:
// e.g., __floatunsidf vs. __floatunssidfvfp.
{ RTLIB::SINTTOFP_I32_F64, RTLIB::impl___floatsidfvfp },
{ RTLIB::UINTTOFP_I32_F64, RTLIB::impl___floatunssidfvfp },
{ RTLIB::SINTTOFP_I32_F32, RTLIB::impl___floatsisfvfp },
{ RTLIB::UINTTOFP_I32_F32, RTLIB::impl___floatunssisfvfp },
};
// clang-format on

for (const auto &LC : LibraryCalls)
setLibcallImpl(LC.Op, LC.Impl);
}
}

if (Subtarget->isThumb1Only())
addRegisterClass(MVT::i32, &ARM::tGPRRegClass);
else
Expand Down
70 changes: 70 additions & 0 deletions llvm/lib/Target/ARM/ARMSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,76 @@ const RegisterBankInfo *ARMSubtarget::getRegBankInfo() const {
return RegBankInfo.get();
}

void ARMSubtarget::initLibcallLoweringInfo(LibcallLoweringInfo &Info) const {
const Triple &TT = getTargetTriple();
if (TT.isOSBinFormatMachO()) {
// Uses VFP for Thumb libfuncs if available.
if (isThumb() && hasVFP2Base() && hasARMOps() && !useSoftFloat()) {
// clang-format off
static const struct {
const RTLIB::Libcall Op;
const RTLIB::LibcallImpl Impl;
} LibraryCalls[] = {
// Single-precision floating-point arithmetic.
{ RTLIB::ADD_F32, RTLIB::impl___addsf3vfp },
{ RTLIB::SUB_F32, RTLIB::impl___subsf3vfp },
{ RTLIB::MUL_F32, RTLIB::impl___mulsf3vfp },
{ RTLIB::DIV_F32, RTLIB::impl___divsf3vfp },

// Double-precision floating-point arithmetic.
{ RTLIB::ADD_F64, RTLIB::impl___adddf3vfp },
{ RTLIB::SUB_F64, RTLIB::impl___subdf3vfp },
{ RTLIB::MUL_F64, RTLIB::impl___muldf3vfp },
{ RTLIB::DIV_F64, RTLIB::impl___divdf3vfp },

// Single-precision comparisons.
{ RTLIB::OEQ_F32, RTLIB::impl___eqsf2vfp },
{ RTLIB::UNE_F32, RTLIB::impl___nesf2vfp },
{ RTLIB::OLT_F32, RTLIB::impl___ltsf2vfp },
{ RTLIB::OLE_F32, RTLIB::impl___lesf2vfp },
{ RTLIB::OGE_F32, RTLIB::impl___gesf2vfp },
{ RTLIB::OGT_F32, RTLIB::impl___gtsf2vfp },
{ RTLIB::UO_F32, RTLIB::impl___unordsf2vfp },

// Double-precision comparisons.
{ RTLIB::OEQ_F64, RTLIB::impl___eqdf2vfp },
{ RTLIB::UNE_F64, RTLIB::impl___nedf2vfp },
{ RTLIB::OLT_F64, RTLIB::impl___ltdf2vfp },
{ RTLIB::OLE_F64, RTLIB::impl___ledf2vfp },
{ RTLIB::OGE_F64, RTLIB::impl___gedf2vfp },
{ RTLIB::OGT_F64, RTLIB::impl___gtdf2vfp },
{ RTLIB::UO_F64, RTLIB::impl___unorddf2vfp },

// Floating-point to integer conversions.
// i64 conversions are done via library routines even when generating VFP
// instructions, so use the same ones.
{ RTLIB::FPTOSINT_F64_I32, RTLIB::impl___fixdfsivfp },
{ RTLIB::FPTOUINT_F64_I32, RTLIB::impl___fixunsdfsivfp },
{ RTLIB::FPTOSINT_F32_I32, RTLIB::impl___fixsfsivfp },
{ RTLIB::FPTOUINT_F32_I32, RTLIB::impl___fixunssfsivfp },

// Conversions between floating types.
{ RTLIB::FPROUND_F64_F32, RTLIB::impl___truncdfsf2vfp },
{ RTLIB::FPEXT_F32_F64, RTLIB::impl___extendsfdf2vfp },

// Integer to floating-point conversions.
// i64 conversions are done via library routines even when generating VFP
// instructions, so use the same ones.
// FIXME: There appears to be some naming inconsistency in ARM libgcc:
// e.g., __floatunsidf vs. __floatunssidfvfp.
{ RTLIB::SINTTOFP_I32_F64, RTLIB::impl___floatsidfvfp },
{ RTLIB::UINTTOFP_I32_F64, RTLIB::impl___floatunssidfvfp },
{ RTLIB::SINTTOFP_I32_F32, RTLIB::impl___floatsisfvfp },
{ RTLIB::UINTTOFP_I32_F32, RTLIB::impl___floatunssisfvfp },
};
// clang-format on

for (const auto &LC : LibraryCalls)
Info.setLibcallImpl(LC.Op, LC.Impl);
}
}
}

bool ARMSubtarget::isXRaySupported() const {
// We don't currently suppport Thumb, but Windows requires Thumb.
return hasV6Ops() && hasARMOps() && !isTargetWindows();
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/ARM/ARMSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
InstructionSelector *getInstructionSelector() const override;
const LegalizerInfo *getLegalizerInfo() const override;
const RegisterBankInfo *getRegBankInfo() const override;
void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override;

private:
ARMSelectionDAGInfo TSInfo;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AVR/AVRISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace llvm {

AVRTargetLowering::AVRTargetLowering(const AVRTargetMachine &TM,
const AVRSubtarget &STI)
: TargetLowering(TM), Subtarget(STI) {
: TargetLowering(TM, STI), Subtarget(STI) {
// Set up the register classes.
addRegisterClass(MVT::i8, &AVR::GPR8RegClass);
addRegisterClass(MVT::i16, &AVR::DREGSRegClass);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/BPF/BPFISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void fail(const SDLoc &DL, SelectionDAG &DAG, const Twine &Msg,

BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
const BPFSubtarget &STI)
: TargetLowering(TM) {
: TargetLowering(TM, STI) {

// Set up the register classes.
addRegisterClass(MVT::i64, &BPF::GPRRegClass);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ DirectXTargetMachine::getTargetTransformInfo(const Function &F) const {

DirectXTargetLowering::DirectXTargetLowering(const DirectXTargetMachine &TM,
const DirectXSubtarget &STI)
: TargetLowering(TM) {
: TargetLowering(TM, STI) {
addRegisterClass(MVT::i32, &dxil::DXILClassRegClass);
computeRegisterProperties(STI.getRegisterInfo());
}
4 changes: 2 additions & 2 deletions llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,8 +1504,8 @@ HexagonTargetLowering::LowerGlobalTLSAddress(SDValue Op,

HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM,
const HexagonSubtarget &ST)
: TargetLowering(TM), HTM(static_cast<const HexagonTargetMachine&>(TM)),
Subtarget(ST) {
: TargetLowering(TM, ST),
HTM(static_cast<const HexagonTargetMachine &>(TM)), Subtarget(ST) {
auto &HRI = *Subtarget.getRegisterInfo();

setPrefLoopAlignment(Align(16));
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Lanai/LanaiISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static cl::opt<int> LanaiLowerConstantMulThreshold(

LanaiTargetLowering::LanaiTargetLowering(const TargetMachine &TM,
const LanaiSubtarget &STI)
: TargetLowering(TM) {
: TargetLowering(TM, STI) {
// Set up the register classes.
addRegisterClass(MVT::i32, &Lanai::GPRRegClass);

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static cl::opt<bool> ZeroDivCheck("loongarch-check-zero-division", cl::Hidden,

LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
const LoongArchSubtarget &STI)
: TargetLowering(TM), Subtarget(STI) {
: TargetLowering(TM, STI), Subtarget(STI) {

MVT GRLenVT = Subtarget.getGRLenVT();

Expand Down
Loading
Loading