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
8 changes: 0 additions & 8 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,14 +1013,6 @@ class TargetInfo : public TransferrableTargetInfo,
return ComplexLongDoubleUsesFP2Ret;
}

/// Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used
/// to convert to and from __fp16.
/// FIXME: This function should be removed once all targets stop using the
/// conversion intrinsics.
virtual bool useFP16ConversionIntrinsics() const {
return true;
}

/// Specify if mangling based on address space map should be used or
/// not for language specific address spaces
bool useAddressSpaceMapMangling() const {
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Basic/Targets/AArch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {

llvm::APInt getFMVPriority(ArrayRef<StringRef> Features) const override;

bool useFP16ConversionIntrinsics() const override {
return false;
}

void getTargetDefinesARMV81A(const LangOptions &Opts,
MacroBuilder &Builder) const;
void getTargetDefinesARMV82A(const LangOptions &Opts,
Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Basic/Targets/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {

llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;

bool useFP16ConversionIntrinsics() const override { return false; }

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;

Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Basic/Targets/ARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public TargetInfo {

bool setFPMath(StringRef Name) override;

bool useFP16ConversionIntrinsics() const override {
return false;
}

void getTargetDefinesARMV81A(const LangOptions &Opts,
MacroBuilder &Builder) const;
void getTargetDefinesARMV82A(const LangOptions &Opts,
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Basic/Targets/DirectX.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo {
resetDataLayout();
TheCXXABI.set(TargetCXXABI::GenericItanium);
}
bool useFP16ConversionIntrinsics() const override { return false; }
void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;

Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Basic/Targets/LoongArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {

bool hasBFloat16Type() const override { return true; }

bool useFP16ConversionIntrinsics() const override { return false; }

bool handleTargetFeatures(std::vector<std::string> &Features,
DiagnosticsEngine &Diags) override;

Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Basic/Targets/NVPTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {

llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;

bool useFP16ConversionIntrinsics() const override { return false; }

bool
initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
StringRef CPU,
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Basic/Targets/RISCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ class RISCVTargetInfo : public TargetInfo {

CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;

bool useFP16ConversionIntrinsics() const override {
return false;
}

bool isValidCPUName(StringRef Name) const override;
void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
bool isValidTuneCPUName(StringRef Name) const override;
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRTargetInfo : public TargetInfo {
}

public:
// SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
// memcpy as per section 3 of the SPIR spec.
bool useFP16ConversionIntrinsics() const override { return false; }

llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override {
return {};
}
Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Basic/Targets/SystemZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {

unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override;

bool useFP16ConversionIntrinsics() const override { return false; }

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;

Expand Down
1 change: 0 additions & 1 deletion clang/lib/Basic/Targets/WebAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {

StringRef getABI() const override;
bool setABI(const std::string &Name) override;
bool useFP16ConversionIntrinsics() const override { return !HasFP16; }

protected:
void getTargetDefines(const LangOptions &Opts,
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Basic/Targets/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,6 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
return "";
}

bool useFP16ConversionIntrinsics() const override {
return false;
}

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;

Expand Down
10 changes: 1 addition & 9 deletions clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1793,18 +1793,10 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
return cir::IntAttr::get(ty, value.getInt());
}
case APValue::Float: {
const llvm::APFloat &init = value.getFloat();
if (&init.getSemantics() == &llvm::APFloat::IEEEhalf() &&
!cgm.getASTContext().getLangOpts().NativeHalfType &&
cgm.getASTContext().getTargetInfo().useFP16ConversionIntrinsics()) {
cgm.errorNYI("ConstExprEmitter::tryEmitPrivate half");
return {};
}

mlir::Type ty = cgm.convertType(destType);
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
"expected floating-point type");
return cir::FPAttr::get(ty, init);
return cir::FPAttr::get(ty, value.getFloat());
}
case APValue::Array: {
const ArrayType *arrayTy = cgm.getASTContext().getAsArrayType(destType);
Expand Down
24 changes: 6 additions & 18 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,19 +924,12 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
if (srcType->isHalfType() &&
!cgf.getContext().getLangOpts().NativeHalfType) {
// Cast to FP using the intrinsic if the half type itself isn't supported.
if (mlir::isa<cir::FPTypeInterface>(mlirDstType)) {
if (cgf.getContext().getTargetInfo().useFP16ConversionIntrinsics())
cgf.getCIRGenModule().errorNYI(loc,
"cast via llvm.convert.from.fp16");
} else {
// Cast to other types through float, using either the intrinsic or
// FPExt, depending on whether the half type itself is supported (as
// opposed to operations on half, available with NativeHalfType).
if (cgf.getContext().getTargetInfo().useFP16ConversionIntrinsics())
cgf.getCIRGenModule().errorNYI(loc,
"cast via llvm.convert.from.fp16");
// FIXME(cir): For now lets pretend we shouldn't use the conversion
// intrinsics and insert a cast here unconditionally.
if (!mlir::isa<cir::FPTypeInterface>(mlirDstType)) {
// Cast to other types through float, using FPExt, depending on whether
// the half type itself is supported (as opposed to operations on half,
// available with NativeHalfType). FIXME(cir): For now lets pretend we
// shouldn't use the conversion intrinsics and insert a cast here
// unconditionally.
src = builder.createCast(cgf.getLoc(loc), cir::CastKind::floating, src,
cgf.floatTy);
srcType = cgf.getContext().FloatTy;
Expand Down Expand Up @@ -994,11 +987,6 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
res = emitScalarCast(src, srcType, dstType, mlirSrcType, mlirDstType, opts);

if (mlirDstType != resTy) {
if (cgf.getContext().getTargetInfo().useFP16ConversionIntrinsics()) {
cgf.getCIRGenModule().errorNYI(loc, "cast via llvm.convert.to.fp16");
}
// FIXME(cir): For now we never use FP16 conversion intrinsics even if
// required by the target. Change that once this is implemented
res = builder.createCast(cgf.getLoc(loc), cir::CastKind::floating, res,
resTy);
}
Expand Down
8 changes: 1 addition & 7 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,7 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
resultType = cgm.fP16Ty;
break;
case BuiltinType::Half:
if (astContext.getLangOpts().NativeHalfType ||
!astContext.getTargetInfo().useFP16ConversionIntrinsics()) {
resultType = cgm.fP16Ty;
} else {
cgm.errorNYI(SourceLocation(), "processing of built-in type", type);
resultType = cgm.sInt32Ty;
}
resultType = cgm.fP16Ty;
break;
case BuiltinType::BFloat16:
resultType = cgm.bFloat16Ty;
Expand Down
12 changes: 2 additions & 10 deletions clang/lib/CodeGen/CGExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2469,16 +2469,8 @@ ConstantEmitter::tryEmitPrivate(const APValue &Value, QualType DestType,
llvm::StructType::get(Complex[0]->getType(), Complex[1]->getType());
return llvm::ConstantStruct::get(STy, Complex);
}
case APValue::Float: {
const llvm::APFloat &Init = Value.getFloat();
if (&Init.getSemantics() == &llvm::APFloat::IEEEhalf() &&
!CGM.getContext().getLangOpts().NativeHalfType &&
CGM.getContext().getTargetInfo().useFP16ConversionIntrinsics())
return llvm::ConstantInt::get(CGM.getLLVMContext(),
Init.bitcastToAPInt());
else
return llvm::ConstantFP::get(CGM.getLLVMContext(), Init);
}
case APValue::Float:
return llvm::ConstantFP::get(CGM.getLLVMContext(), Value.getFloat());
case APValue::ComplexFloat: {
llvm::Constant *Complex[2];

Expand Down
48 changes: 5 additions & 43 deletions clang/lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1596,23 +1596,11 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
// Cast from half through float if half isn't a native type.
if (SrcType->isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
// Cast to FP using the intrinsic if the half type itself isn't supported.
if (DstTy->isFloatingPointTy()) {
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics())
return Builder.CreateCall(
CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_from_fp16, DstTy),
Src);
} else {
if (!DstTy->isFloatingPointTy()) {
// Cast to other types through float, using either the intrinsic or FPExt,
// depending on whether the half type itself is supported
// (as opposed to operations on half, available with NativeHalfType).
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics()) {
Src = Builder.CreateCall(
CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_from_fp16,
CGF.CGM.FloatTy),
Src);
} else {
Src = Builder.CreateFPExt(Src, CGF.CGM.FloatTy, "conv");
}
Src = Builder.CreateFPExt(Src, CGF.CGM.FloatTy, "conv");
SrcType = CGF.getContext().FloatTy;
SrcTy = CGF.FloatTy;
}
Expand Down Expand Up @@ -1723,11 +1711,6 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
if (DstType->isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
// Make sure we cast in a single step if from another FP type.
if (SrcTy->isFloatingPointTy()) {
// Use the intrinsic if the half type itself isn't supported
// (as opposed to operations on half, available with NativeHalfType).
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics())
return Builder.CreateCall(
CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_to_fp16, SrcTy), Src);
// If the half type is supported, just use an fptrunc.
return Builder.CreateFPTrunc(Src, DstTy);
}
Expand All @@ -1737,14 +1720,7 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
Res = EmitScalarCast(Src, SrcType, DstType, SrcTy, DstTy, Opts);

if (DstTy != ResTy) {
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics()) {
assert(ResTy->isIntegerTy(16) && "Only half FP requires extra conversion");
Res = Builder.CreateCall(
CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_to_fp16, CGF.CGM.FloatTy),
Res);
} else {
Res = Builder.CreateFPTrunc(Res, ResTy, "conv");
}
Res = Builder.CreateFPTrunc(Res, ResTy, "conv");
}

if (Opts.EmitImplicitIntegerTruncationChecks)
Expand Down Expand Up @@ -3399,14 +3375,7 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,

if (type->isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
// Another special case: half FP increment should be done via float
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics()) {
value = Builder.CreateCall(
CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_from_fp16,
CGF.CGM.FloatTy),
input, "incdec.conv");
} else {
value = Builder.CreateFPExt(input, CGF.CGM.FloatTy, "incdec.conv");
}
value = Builder.CreateFPExt(input, CGF.CGM.FloatTy, "incdec.conv");
}

if (value->getType()->isFloatTy())
Expand Down Expand Up @@ -3439,14 +3408,7 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
value = Builder.CreateFAdd(value, amt, isInc ? "inc" : "dec");

if (type->isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics()) {
value = Builder.CreateCall(
CGF.CGM.getIntrinsic(llvm::Intrinsic::convert_to_fp16,
CGF.CGM.FloatTy),
value, "incdec.conv");
} else {
value = Builder.CreateFPTrunc(value, input->getType(), "incdec.conv");
}
value = Builder.CreateFPTrunc(value, input->getType(), "incdec.conv");
}

// Fixed-point types.
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/CodeGen/CodeGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,8 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {

case BuiltinType::Half:
// Half FP can either be storage-only (lowered to i16) or native.
ResultType = getTypeForFormat(
getLLVMContext(), Context.getFloatTypeSemantics(T),
Context.getLangOpts().NativeHalfType ||
!Context.getTargetInfo().useFP16ConversionIntrinsics());
ResultType = getTypeForFormat(getLLVMContext(),
Context.getFloatTypeSemantics(T), true);
break;
case BuiltinType::LongDouble:
LongDoubleReferenced = true;
Expand Down
22 changes: 2 additions & 20 deletions clang/lib/CodeGen/TargetBuiltins/NVPTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,23 +375,8 @@ static Value *MakeCpAsync(unsigned IntrinsicID, unsigned IntrinsicIDS,
CGF.EmitScalarExpr(E->getArg(1))});
}

static bool EnsureNativeHalfSupport(unsigned BuiltinID, const CallExpr *E,
CodeGenFunction &CGF) {
auto &C = CGF.CGM.getContext();
if (!C.getLangOpts().NativeHalfType &&
C.getTargetInfo().useFP16ConversionIntrinsics()) {
CGF.CGM.Error(E->getExprLoc(), C.BuiltinInfo.getQuotedName(BuiltinID) +
" requires native half type support.");
return false;
}
return true;
}

static Value *MakeHalfType(Function *Intrinsic, unsigned BuiltinID,
const CallExpr *E, CodeGenFunction &CGF) {
if (!EnsureNativeHalfSupport(BuiltinID, E, CGF))
return nullptr;

SmallVector<Value *, 16> Args;
auto *FTy = Intrinsic->getFunctionType();
unsigned ICEArguments = 0;
Expand Down Expand Up @@ -1069,13 +1054,10 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
EmitScalarExpr(E->getArg(0)));
case NVPTX::BI__nvvm_ldg_h:
case NVPTX::BI__nvvm_ldg_h2:
return EnsureNativeHalfSupport(BuiltinID, E, *this) ? MakeLdg(*this, E)
: nullptr;
return MakeLdg(*this, E);
case NVPTX::BI__nvvm_ldu_h:
case NVPTX::BI__nvvm_ldu_h2:
return EnsureNativeHalfSupport(BuiltinID, E, *this)
? MakeLdu(Intrinsic::nvvm_ldu_global_f, *this, E)
: nullptr;
return MakeLdu(Intrinsic::nvvm_ldu_global_f, *this, E);
case NVPTX::BI__nvvm_cp_async_ca_shared_global_4:
return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_4,
Intrinsic::nvvm_cp_async_ca_shared_global_4_s, *this, E,
Expand Down
20 changes: 5 additions & 15 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5763,22 +5763,12 @@ bool Sema::BuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs,
if (OrigArg->isTypeDependent())
return false;

// Usual Unary Conversions will convert half to float, which we want for
// machines that use fp16 conversion intrinsics. Else, we wnat to leave the
// type how it is, but do normal L->Rvalue conversions.
if (Context.getTargetInfo().useFP16ConversionIntrinsics()) {
ExprResult Res = UsualUnaryConversions(OrigArg);

if (!Res.isUsable())
return true;
OrigArg = Res.get();
} else {
ExprResult Res = DefaultFunctionArrayLvalueConversion(OrigArg);
// We want to leave the type how it is, but do normal L->Rvalue conversions.
ExprResult Res = DefaultFunctionArrayLvalueConversion(OrigArg);
if (!Res.isUsable())
return true;
OrigArg = Res.get();

if (!Res.isUsable())
return true;
OrigArg = Res.get();
}
TheCall->setArg(FPArgNo, OrigArg);

QualType VectorResultTy;
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15213,8 +15213,7 @@ static ExprResult convertHalfVecBinOp(Sema &S, ExprResult LHS, ExprResult RHS,
/// is needed.
static bool needsConversionOfHalfVec(bool OpRequiresConversion, ASTContext &Ctx,
Expr *E0, Expr *E1 = nullptr) {
if (!OpRequiresConversion || Ctx.getLangOpts().NativeHalfType ||
Ctx.getTargetInfo().useFP16ConversionIntrinsics())
if (!OpRequiresConversion || Ctx.getLangOpts().NativeHalfType)
return false;

auto HasVectorOfHalfType = [&Ctx](Expr *E) {
Expand Down
Loading