Skip to content

Commit 146c075

Browse files
committed
Add f16 and f128 support to rustc_codegen_llvm
1 parent edf40ed commit 146c075

File tree

7 files changed

+24
-2
lines changed

7 files changed

+24
-2
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
523523
}
524524
}
525525
}
526-
abi::F32 | abi::F64 => {}
526+
abi::F16 | abi::F32 | abi::F64 | abi::F128 => {}
527527
}
528528
}
529529

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+3
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,12 @@ impl MsvcBasicName for ty::UintTy {
656656

657657
impl MsvcBasicName for ty::FloatTy {
658658
fn msvc_basic_name(self) -> &'static str {
659+
// TODO: MSVC doesn't support these types, so what is this function?
659660
match self {
661+
ty::FloatTy::F16 => "half",
660662
ty::FloatTy::F32 => "float",
661663
ty::FloatTy::F64 => "double",
664+
ty::FloatTy::F128 => "fp128",
662665
}
663666
}
664667
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ fn tag_base_type<'ll, 'tcx>(
122122
// Niche tags are always normalized to unsized integers of the correct size.
123123
match tag.primitive() {
124124
Primitive::Int(t, _) => t,
125+
Primitive::F16 => Integer::I16,
125126
Primitive::F32 => Integer::I32,
126127
Primitive::F64 => Integer::I64,
128+
Primitive::F128 => Integer::I128,
127129
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
128130
Primitive::Pointer(_) => {
129131
// If the niche is the NULL value of a reference, then `discr_enum_ty` will be

compiler/rustc_codegen_llvm/src/intrinsic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
156156
}
157157
// `va_arg` should never be used with the return type f32.
158158
Primitive::F32 => bug!("the va_arg intrinsic does not work with `f32`"),
159+
Primitive::F16 | Primitive::F128 => {
160+
todo!("does this work with these types? probably not")
161+
}
159162
}
160163
}
161164
_ => bug!("the va_arg intrinsic does not work with non-scalar types"),

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,10 @@ extern "C" {
850850
pub fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;
851851

852852
// Operations on real types
853+
pub fn LLVMHalfTypeInContext(C: &Context) -> &Type;
853854
pub fn LLVMFloatTypeInContext(C: &Context) -> &Type;
854855
pub fn LLVMDoubleTypeInContext(C: &Context) -> &Type;
856+
pub fn LLVMFP128TypeInContext(C: &Context) -> &Type;
855857

856858
// Operations on function types
857859
pub fn LLVMFunctionType<'a>(

compiler/rustc_codegen_llvm/src/type_.rs

+10
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ impl<'ll> CodegenCx<'ll, '_> {
107107

108108
pub(crate) fn type_float_from_ty(&self, t: ty::FloatTy) -> &'ll Type {
109109
match t {
110+
ty::FloatTy::F16 => self.type_f16(),
110111
ty::FloatTy::F32 => self.type_f32(),
111112
ty::FloatTy::F64 => self.type_f64(),
113+
ty::FloatTy::F128 => self.type_f128(),
112114
}
113115
}
114116

@@ -156,6 +158,10 @@ impl<'ll, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
156158
self.isize_ty
157159
}
158160

161+
fn type_f16(&self) -> &'ll Type {
162+
unsafe { llvm::LLVMHalfTypeInContext(self.llcx) }
163+
}
164+
159165
fn type_f32(&self) -> &'ll Type {
160166
unsafe { llvm::LLVMFloatTypeInContext(self.llcx) }
161167
}
@@ -164,6 +170,10 @@ impl<'ll, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
164170
unsafe { llvm::LLVMDoubleTypeInContext(self.llcx) }
165171
}
166172

173+
fn type_f128(&self) -> &'ll Type {
174+
unsafe { llvm::LLVMFP128TypeInContext(self.llcx) }
175+
}
176+
167177
fn type_func(&self, args: &[&'ll Type], ret: &'ll Type) -> &'ll Type {
168178
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, False) }
169179
}

compiler/rustc_codegen_llvm/src/type_of.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
88
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
99
use rustc_target::abi::HasDataLayout;
1010
use rustc_target::abi::{Abi, Align, FieldsShape};
11-
use rustc_target::abi::{Int, Pointer, F32, F64};
11+
use rustc_target::abi::{Int, Pointer, F128, F16, F32, F64};
1212
use rustc_target::abi::{PointeeInfo, Scalar, Size, TyAbiInterface, Variants};
1313
use smallvec::{smallvec, SmallVec};
1414

@@ -291,8 +291,10 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
291291
fn scalar_llvm_type_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, scalar: Scalar) -> &'a Type {
292292
match scalar.primitive() {
293293
Int(i, _) => cx.type_from_integer(i),
294+
F16 => cx.type_f16(),
294295
F32 => cx.type_f32(),
295296
F64 => cx.type_f64(),
297+
F128 => cx.type_f128(),
296298
Pointer(address_space) => cx.type_ptr_ext(address_space),
297299
}
298300
}

0 commit comments

Comments
 (0)