Replace stack_var_count and RETURN_VALUE_COUNT with a single counter
This commit is contained in:
parent
98ed962c7d
commit
014a84029c
@ -41,9 +41,6 @@ use crate::type_of::LayoutGccExt;
|
|||||||
// TODO(antoyo)
|
// TODO(antoyo)
|
||||||
type Funclet = ();
|
type Funclet = ();
|
||||||
|
|
||||||
// TODO(antoyo): remove this variable.
|
|
||||||
static mut RETURN_VALUE_COUNT: usize = 0;
|
|
||||||
|
|
||||||
enum ExtremumOperation {
|
enum ExtremumOperation {
|
||||||
Max,
|
Max,
|
||||||
Min,
|
Min,
|
||||||
@ -52,13 +49,18 @@ enum ExtremumOperation {
|
|||||||
pub struct Builder<'a: 'gcc, 'gcc, 'tcx> {
|
pub struct Builder<'a: 'gcc, 'gcc, 'tcx> {
|
||||||
pub cx: &'a CodegenCx<'gcc, 'tcx>,
|
pub cx: &'a CodegenCx<'gcc, 'tcx>,
|
||||||
pub block: Block<'gcc>,
|
pub block: Block<'gcc>,
|
||||||
stack_var_count: Cell<usize>,
|
|
||||||
pub location: Option<Location<'gcc>>,
|
pub location: Option<Location<'gcc>>,
|
||||||
|
value_counter: Cell<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
||||||
fn with_cx(cx: &'a CodegenCx<'gcc, 'tcx>, block: Block<'gcc>) -> Self {
|
fn with_cx(cx: &'a CodegenCx<'gcc, 'tcx>, block: Block<'gcc>) -> Self {
|
||||||
Builder { cx, block, stack_var_count: Cell::new(0), location: None }
|
Builder { cx, block, location: None, value_counter: Cell::new(0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_value_counter(&self) -> u64 {
|
||||||
|
self.value_counter.set(self.value_counter.get() + 1);
|
||||||
|
self.value_counter.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn atomic_extremum(
|
fn atomic_extremum(
|
||||||
@ -324,11 +326,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||||||
let void_type = self.context.new_type::<()>();
|
let void_type = self.context.new_type::<()>();
|
||||||
let current_func = self.block.get_function();
|
let current_func = self.block.get_function();
|
||||||
if return_type != void_type {
|
if return_type != void_type {
|
||||||
unsafe { RETURN_VALUE_COUNT += 1 };
|
|
||||||
let result = current_func.new_local(
|
let result = current_func.new_local(
|
||||||
self.location,
|
self.location,
|
||||||
return_type,
|
return_type,
|
||||||
&format!("returnValue{}", unsafe { RETURN_VALUE_COUNT }),
|
&format!("returnValue{}", self.next_value_counter()),
|
||||||
);
|
);
|
||||||
self.block.add_assignment(
|
self.block.add_assignment(
|
||||||
self.location,
|
self.location,
|
||||||
@ -384,7 +385,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||||||
let current_func = self.block.get_function();
|
let current_func = self.block.get_function();
|
||||||
|
|
||||||
if return_type != void_type {
|
if return_type != void_type {
|
||||||
unsafe { RETURN_VALUE_COUNT += 1 };
|
|
||||||
let return_value = self.cx.context.new_call_through_ptr(self.location, func_ptr, &args);
|
let return_value = self.cx.context.new_call_through_ptr(self.location, func_ptr, &args);
|
||||||
let return_value = llvm::adjust_intrinsic_return_value(
|
let return_value = llvm::adjust_intrinsic_return_value(
|
||||||
self,
|
self,
|
||||||
@ -397,7 +397,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||||||
let result = current_func.new_local(
|
let result = current_func.new_local(
|
||||||
self.location,
|
self.location,
|
||||||
return_value.get_type(),
|
return_value.get_type(),
|
||||||
&format!("ptrReturnValue{}", unsafe { RETURN_VALUE_COUNT }),
|
&format!("ptrReturnValue{}", self.next_value_counter()),
|
||||||
);
|
);
|
||||||
self.block.add_assignment(self.location, result, return_value);
|
self.block.add_assignment(self.location, result, return_value);
|
||||||
result.to_rvalue()
|
result.to_rvalue()
|
||||||
@ -446,11 +446,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
|||||||
let return_type = self.context.new_type::<bool>();
|
let return_type = self.context.new_type::<bool>();
|
||||||
let current_func = self.block.get_function();
|
let current_func = self.block.get_function();
|
||||||
// TODO(antoyo): return the new_call() directly? Since the overflow function has no side-effects.
|
// TODO(antoyo): return the new_call() directly? Since the overflow function has no side-effects.
|
||||||
unsafe { RETURN_VALUE_COUNT += 1 };
|
|
||||||
let result = current_func.new_local(
|
let result = current_func.new_local(
|
||||||
self.location,
|
self.location,
|
||||||
return_type,
|
return_type,
|
||||||
&format!("overflowReturnValue{}", unsafe { RETURN_VALUE_COUNT }),
|
&format!("overflowReturnValue{}", self.next_value_counter()),
|
||||||
);
|
);
|
||||||
self.block.add_assignment(
|
self.block.add_assignment(
|
||||||
self.location,
|
self.location,
|
||||||
@ -934,9 +933,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||||||
fn alloca(&mut self, size: Size, align: Align) -> RValue<'gcc> {
|
fn alloca(&mut self, size: Size, align: Align) -> RValue<'gcc> {
|
||||||
let ty = self.cx.type_array(self.cx.type_i8(), size.bytes()).get_aligned(align.bytes());
|
let ty = self.cx.type_array(self.cx.type_i8(), size.bytes()).get_aligned(align.bytes());
|
||||||
// TODO(antoyo): It might be better to return a LValue, but fixing the rustc API is non-trivial.
|
// TODO(antoyo): It might be better to return a LValue, but fixing the rustc API is non-trivial.
|
||||||
self.stack_var_count.set(self.stack_var_count.get() + 1);
|
|
||||||
self.current_func()
|
self.current_func()
|
||||||
.new_local(self.location, ty, &format!("stack_var_{}", self.stack_var_count.get()))
|
.new_local(self.location, ty, &format!("stack_var_{}", self.next_value_counter()))
|
||||||
.get_address(self.location)
|
.get_address(self.location)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -959,11 +957,10 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||||||
};
|
};
|
||||||
let ptr = self.context.new_cast(self.location, ptr, aligned_type.make_pointer());
|
let ptr = self.context.new_cast(self.location, ptr, aligned_type.make_pointer());
|
||||||
let deref = ptr.dereference(self.location).to_rvalue();
|
let deref = ptr.dereference(self.location).to_rvalue();
|
||||||
unsafe { RETURN_VALUE_COUNT += 1 };
|
|
||||||
let loaded_value = function.new_local(
|
let loaded_value = function.new_local(
|
||||||
self.location,
|
self.location,
|
||||||
aligned_type,
|
aligned_type,
|
||||||
&format!("loadedValue{}", unsafe { RETURN_VALUE_COUNT }),
|
&format!("loadedValue{}", self.next_value_counter()),
|
||||||
);
|
);
|
||||||
block.add_assignment(self.location, loaded_value, deref);
|
block.add_assignment(self.location, loaded_value, deref);
|
||||||
loaded_value.to_rvalue()
|
loaded_value.to_rvalue()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user