diff --git a/libc/src/__support/FPUtil/nearest_integer.h b/libc/src/__support/FPUtil/nearest_integer.h index bc98667c8a3b3a..f9d952cfa163b9 100644 --- a/libc/src/__support/FPUtil/nearest_integer.h +++ b/libc/src/__support/FPUtil/nearest_integer.h @@ -17,6 +17,18 @@ #include "x86_64/nearest_integer.h" #elif defined(LIBC_TARGET_ARCH_IS_AARCH64) #include "aarch64/nearest_integer.h" +#elif defined(LIBC_TARGET_ARCH_IS_GPU) + +namespace LIBC_NAMESPACE { +namespace fputil { + +LIBC_INLINE float nearest_integer(float x) { return __builtin_rintf(x); } + +LIBC_INLINE double nearest_integer(double x) { return __builtin_rint(x); } + +} // namespace fputil +} // namespace LIBC_NAMESPACE + #else namespace LIBC_NAMESPACE { diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp index e84ddc65e2b703..d8414623d302b1 100644 --- a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp @@ -97,29 +97,32 @@ RISCVSubtarget::RISCVSubtarget(const Triple &TT, StringRef CPU, RVVVectorBitsMin(RVVVectorBitsMin), RVVVectorBitsMax(RVVVectorBitsMax), FrameLowering( initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)), - InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) { - CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering())); - Legalizer.reset(new RISCVLegalizerInfo(*this)); - - auto *RBI = new RISCVRegisterBankInfo(getHwMode()); - RegBankInfo.reset(RBI); - InstSelector.reset(createRISCVInstructionSelector( - *static_cast(&TM), *this, *RBI)); -} + InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {} const CallLowering *RISCVSubtarget::getCallLowering() const { + if (!CallLoweringInfo) + CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering())); return CallLoweringInfo.get(); } InstructionSelector *RISCVSubtarget::getInstructionSelector() const { + if (!InstSelector) { + InstSelector.reset(createRISCVInstructionSelector( + *static_cast(&TLInfo.getTargetMachine()), + *this, *static_cast(getRegBankInfo()))); + } return InstSelector.get(); } const LegalizerInfo *RISCVSubtarget::getLegalizerInfo() const { + if (!Legalizer) + Legalizer.reset(new RISCVLegalizerInfo(*this)); return Legalizer.get(); } const RegisterBankInfo *RISCVSubtarget::getRegBankInfo() const { + if (!RegBankInfo) + RegBankInfo.reset(new RISCVRegisterBankInfo(getHwMode())); return RegBankInfo.get(); } diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h index 347c1bc3c278fd..b146f48f81b724 100644 --- a/llvm/lib/Target/RISCV/RISCVSubtarget.h +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h @@ -245,10 +245,10 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo { protected: // GlobalISel related APIs. - std::unique_ptr CallLoweringInfo; - std::unique_ptr InstSelector; - std::unique_ptr Legalizer; - std::unique_ptr RegBankInfo; + mutable std::unique_ptr CallLoweringInfo; + mutable std::unique_ptr InstSelector; + mutable std::unique_ptr Legalizer; + mutable std::unique_ptr RegBankInfo; // Return the known range for the bit length of RVV data registers as set // at the command line. A value of 0 means nothing is known about that particular