diff options
| author | antoyo <antoyo@users.noreply.github.com> | 2025-06-25 08:52:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-25 08:52:27 -0400 |
| commit | 79564c86d1249af6630a92ef4b4f8d2280dbf029 (patch) | |
| tree | 314dc0bb1494bf2ec34d2c005c7b354dac81906f | |
| parent | 54b1ff50275f3f38cc15b4c68b0aa85f364051dc (diff) | |
| parent | b03f7f87ff67d9589c51e56beac3734b0fb5349e (diff) | |
| download | rust-79564c86d1249af6630a92ef4b4f8d2280dbf029.tar.gz rust-79564c86d1249af6630a92ef4b4f8d2280dbf029.zip | |
Merge pull request #720 from FractalFir/func_refactor
Refactored the codebase to use Function instead of RValue where possible.
| -rw-r--r-- | src/builder.rs | 3 | ||||
| -rw-r--r-- | src/context.rs | 12 | ||||
| -rw-r--r-- | src/debuginfo.rs | 6 | ||||
| -rw-r--r-- | src/declare.rs | 5 | ||||
| -rw-r--r-- | src/intrinsic/mod.rs | 7 |
5 files changed, 14 insertions, 19 deletions
diff --git a/src/builder.rs b/src/builder.rs index 38ebf9974bf..cad7f1db8ea 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -520,8 +520,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { self.block } - fn append_block(cx: &'a CodegenCx<'gcc, 'tcx>, func: RValue<'gcc>, name: &str) -> Block<'gcc> { - let func = cx.rvalue_as_function(func); + fn append_block(_: &'a CodegenCx<'gcc, 'tcx>, func: Function<'gcc>, name: &str) -> Block<'gcc> { func.new_block(name) } diff --git a/src/context.rs b/src/context.rs index 8454e49c66e..8d20ae6f0e3 100644 --- a/src/context.rs +++ b/src/context.rs @@ -382,8 +382,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> { type Value = RValue<'gcc>; type Metadata = RValue<'gcc>; - // TODO(antoyo): change to Function<'gcc>. - type Function = RValue<'gcc>; + type Function = Function<'gcc>; type BasicBlock = Block<'gcc>; type Type = Type<'gcc>; @@ -401,11 +400,10 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { &self.vtables } - fn get_fn(&self, instance: Instance<'tcx>) -> RValue<'gcc> { + fn get_fn(&self, instance: Instance<'tcx>) -> Function<'gcc> { let func = get_fn(self, instance); *self.current_func.borrow_mut() = Some(func); - // FIXME(antoyo): this is a wrong cast. That requires changing the compiler API. - unsafe { std::mem::transmute(func) } + func } fn get_fn_addr(&self, instance: Instance<'tcx>) -> RValue<'gcc> { @@ -494,11 +492,11 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { self.codegen_unit } - fn set_frame_pointer_type(&self, _llfn: RValue<'gcc>) { + fn set_frame_pointer_type(&self, _llfn: Function<'gcc>) { // TODO(antoyo) } - fn apply_target_cpu_attr(&self, _llfn: RValue<'gcc>) { + fn apply_target_cpu_attr(&self, _llfn: Function<'gcc>) { // TODO(antoyo) } diff --git a/src/debuginfo.rs b/src/debuginfo.rs index e0597d0030d..66ef12d2a85 100644 --- a/src/debuginfo.rs +++ b/src/debuginfo.rs @@ -1,7 +1,7 @@ use std::ops::Range; use std::sync::Arc; -use gccjit::{Location, RValue}; +use gccjit::{Function, Location, RValue}; use rustc_abi::Size; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind}; use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoCodegenMethods}; @@ -225,7 +225,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { &self, instance: Instance<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, - llfn: RValue<'gcc>, + llfn: Function<'gcc>, mir: &mir::Body<'tcx>, ) -> Option<FunctionDebugContext<'tcx, Self::DIScope, Self::DILocation>> { if self.sess().opts.debuginfo == DebugInfo::None { @@ -276,7 +276,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { &self, _instance: Instance<'tcx>, _fn_abi: &FnAbi<'tcx, Ty<'tcx>>, - _maybe_definition_llfn: Option<RValue<'gcc>>, + _maybe_definition_llfn: Option<Function<'gcc>>, ) -> Self::DIScope { // TODO(antoyo): implement. } diff --git a/src/declare.rs b/src/declare.rs index bed82073e2c..691fd8729e3 100644 --- a/src/declare.rs +++ b/src/declare.rs @@ -94,7 +94,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { _fn_type: Type<'gcc>, #[cfg(feature = "master")] callconv: Option<FnAttribute<'gcc>>, #[cfg(not(feature = "master"))] callconv: Option<()>, - ) -> RValue<'gcc> { + ) -> Function<'gcc> { // TODO(antoyo): use the fn_type parameter. let const_string = self.context.new_type::<u8>().make_pointer().make_pointer(); let return_type = self.type_i32(); @@ -111,8 +111,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { // NOTE: it is needed to set the current_func here as well, because get_fn() is not called // for the main function. *self.current_func.borrow_mut() = Some(func); - // FIXME(antoyo): this is a wrong cast. That requires changing the compiler API. - unsafe { std::mem::transmute(func) } + func } pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Function<'gcc> { diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index ba85bc2beff..8401e78bd2f 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -1484,10 +1484,9 @@ fn gen_fn<'a, 'gcc, 'tcx>( // FIXME(eddyb) find a nicer way to do this. cx.linkage.set(FunctionType::Internal); let func = cx.declare_fn(name, fn_abi); - let func_val = unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) }; - cx.set_frame_pointer_type(func_val); - cx.apply_target_cpu_attr(func_val); - let block = Builder::append_block(cx, func_val, "entry-block"); + cx.set_frame_pointer_type(func); + cx.apply_target_cpu_attr(func); + let block = Builder::append_block(cx, func, "entry-block"); let bx = Builder::build(cx, block); codegen(bx); (return_type, func) |
