Skip to content

Commit

Permalink
Try to make f16 legal instead
Browse files Browse the repository at this point in the history
  • Loading branch information
JonPsson1 committed Oct 31, 2024
1 parent 9c0bc36 commit 44dffa4
Show file tree
Hide file tree
Showing 23 changed files with 906 additions and 246 deletions.
5 changes: 5 additions & 0 deletions clang/lib/Basic/Targets/SystemZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;

// True if the backend supports operations on the half LLVM IR type.
// By setting this to false, conversions will happen for _Float16 around
// a statement by default with operations done in float. However, if
// -ffloat16-excess-precision=none is given, no conversions will be made
// and instead the backend will promote each half operation to float
// individually.
HasLegalHalfType = false;
// Allow half arguments and return values.
HalfArgsAndReturns = true;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16548,7 +16548,7 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
PromoteType = QualType();
}
}
if (TInfo->getType()->isFloat16Type() || TInfo->getType()->isFloat32Type())
if (TInfo->getType()->isSpecificBuiltinType(BuiltinType::Float))
PromoteType = Context.DoubleTy;
if (!PromoteType.isNull())
DiagRuntimeBehavior(TInfo->getTypeLoc().getBeginLoc(), E,
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ foreach(arch ${BUILTIN_TEST_ARCH})
string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
endif()
else()
if (${arch} MATCHES "arm|armhf|aarch64|arm64|i?86|x86_64|AMD64|riscv32|riscv64" AND COMPILER_RT_HAS_${arch}_FLOAT16)
if (${arch} MATCHES "arm|armhf|aarch64|arm64|i?86|x86_64|AMD64|riscv32|riscv64|s390x" AND COMPILER_RT_HAS_${arch}_FLOAT16)
list(APPEND BUILTINS_TEST_TARGET_CFLAGS -DCOMPILER_RT_HAS_FLOAT16)
string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")
endif()
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/IR/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
setLibcallName(RTLIB::SRL_I128, nullptr);
setLibcallName(RTLIB::SHL_I128, nullptr);
setLibcallName(RTLIB::SRA_I128, nullptr);
setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
}

if (TT.isX86()) {
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum RegisterKind {
GRH32Reg,
GR64Reg,
GR128Reg,
FP16Reg,
FP32Reg,
FP64Reg,
FP128Reg,
Expand Down Expand Up @@ -356,6 +357,7 @@ class SystemZOperand : public MCParsedAsmOperand {
bool isADDR32() const { return isReg(GR32Reg); }
bool isADDR64() const { return isReg(GR64Reg); }
bool isADDR128() const { return false; }
bool isFP16() const { return isReg(FP16Reg); }
bool isFP32() const { return isReg(FP32Reg); }
bool isFP64() const { return isReg(FP64Reg); }
bool isFP128() const { return isReg(FP128Reg); }
Expand Down Expand Up @@ -534,6 +536,9 @@ class SystemZAsmParser : public MCTargetAsmParser {
ParseStatus parseADDR128(OperandVector &Operands) {
llvm_unreachable("Shouldn't be used as an operand");
}
ParseStatus parseFP16(OperandVector &Operands) {
return parseRegister(Operands, FP16Reg);
}
ParseStatus parseFP32(OperandVector &Operands) {
return parseRegister(Operands, FP32Reg);
}
Expand Down Expand Up @@ -829,6 +834,7 @@ ParseStatus SystemZAsmParser::parseRegister(OperandVector &Operands,
case GR128Reg:
Group = RegGR;
break;
case FP16Reg:
case FP32Reg:
case FP64Reg:
case FP128Reg:
Expand Down Expand Up @@ -882,6 +888,7 @@ ParseStatus SystemZAsmParser::parseRegister(OperandVector &Operands,
case GRH32Reg: Regs = SystemZMC::GRH32Regs; break;
case GR64Reg: Regs = SystemZMC::GR64Regs; break;
case GR128Reg: Regs = SystemZMC::GR128Regs; break;
case FP16Reg: Regs = SystemZMC::FP16Regs; break;
case FP32Reg: Regs = SystemZMC::FP32Regs; break;
case FP64Reg: Regs = SystemZMC::FP64Regs; break;
case FP128Reg: Regs = SystemZMC::FP128Regs; break;
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ const unsigned SystemZMC::GR128Regs[16] = {
SystemZ::R12Q, 0, SystemZ::R14Q, 0
};

const unsigned SystemZMC::FP16Regs[16] = {
SystemZ::F0H, SystemZ::F1H, SystemZ::F2H, SystemZ::F3H,
SystemZ::F4H, SystemZ::F5H, SystemZ::F6H, SystemZ::F7H,
SystemZ::F8H, SystemZ::F9H, SystemZ::F10H, SystemZ::F11H,
SystemZ::F12H, SystemZ::F13H, SystemZ::F14H, SystemZ::F15H
};

const unsigned SystemZMC::FP32Regs[16] = {
SystemZ::F0S, SystemZ::F1S, SystemZ::F2S, SystemZ::F3S,
SystemZ::F4S, SystemZ::F5S, SystemZ::F6S, SystemZ::F7S,
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extern const unsigned GR32Regs[16];
extern const unsigned GRH32Regs[16];
extern const unsigned GR64Regs[16];
extern const unsigned GR128Regs[16];
extern const unsigned FP16Regs[16];
extern const unsigned FP32Regs[16];
extern const unsigned FP64Regs[16];
extern const unsigned FP128Regs[16];
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Target/SystemZ/SystemZCallingConv.td
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def RetCC_SystemZ_ELF : CallingConv<[
// other floating-point argument registers available for code that
// doesn't care about the ABI. All floating-point argument registers
// are call-clobbered, so we can use all of them here.
CCIfType<[f16, f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
CCIfType<[f16], CCAssignToReg<[F0H, F2H, F4H, F6H]>>,
CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,

// Similarly for vectors, with V24 being the ABI-compliant choice.
Expand Down Expand Up @@ -115,7 +116,8 @@ def CC_SystemZ_ELF : CallingConv<[
CCIfType<[i64], CCAssignToReg<[R2D, R3D, R4D, R5D, R6D]>>,

// The first 4 float and double arguments are passed in even registers F0-F6.
CCIfType<[f16, f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
CCIfType<[f16], CCAssignToReg<[F0H, F2H, F4H, F6H]>>,
CCIfType<[f32], CCAssignToReg<[F0S, F2S, F4S, F6S]>>,
CCIfType<[f64], CCAssignToReg<[F0D, F2D, F4D, F6D]>>,

// The first 8 named vector arguments are passed in V24-V31. Sub-128 vectors
Expand Down
Loading

0 comments on commit 44dffa4

Please sign in to comment.