pub struct CContext {
pub hoisted_declarations: Vec<String>,
/* private fields */
}Expand description
Context for C code generation, tracking variable names and SSA inlining.
Fields§
§hoisted_declarations: Vec<String>Function-scope declarations for hoisted variables (emitted before kernel body).
Implementations§
Source§impl CContext
impl CContext
pub fn new( ref_counts: HashMap<u64, usize>, scope_escaping: HashSet<u64>, ) -> Self
Sourcepub fn get(&self, uop: &Arc<UOp>) -> &str
pub fn get(&self, uop: &Arc<UOp>) -> &str
Get the C expression for a UOp. Panics if not registered.
Sourcepub fn should_inline(&self, id: u64) -> bool
pub fn should_inline(&self, id: u64) -> bool
Check if a value should be inlined (single-use, expression-safe).
Sourcepub fn next_name(&mut self, prefix: &str) -> String
pub fn next_name(&mut self, prefix: &str) -> String
Generate a unique variable name with given prefix.
Sourcepub fn push_indent(&mut self)
pub fn push_indent(&mut self)
Increase indentation depth.
Sourcepub fn pop_indent(&mut self)
pub fn pop_indent(&mut self)
Decrease indentation depth.
Sourcepub fn register_reduce_pending(
&mut self,
reduce_id: u64,
acc_name: String,
dtype: DType,
)
pub fn register_reduce_pending( &mut self, reduce_id: u64, acc_name: String, dtype: DType, )
Register a pending reduce final load.
Sourcepub fn take_pending_reduces(&mut self) -> HashMap<u64, (String, DType)>
pub fn take_pending_reduces(&mut self) -> HashMap<u64, (String, DType)>
Take all pending reduces.
Sourcepub fn emit_expr(
&mut self,
uop: &Arc<UOp>,
expr: String,
prefix: &str,
kernel: &mut Vec<String>,
) -> String
pub fn emit_expr( &mut self, uop: &Arc<UOp>, expr: String, prefix: &str, kernel: &mut Vec<String>, ) -> String
Emit a C expression, either as an inline expression or a variable declaration. Returns the name/expression to reference this value.
Variables that escape their declaration scope are hoisted: declared at function scope and assigned at current depth. This prevents “use of undeclared identifier” errors when the linearizer places a shared node inside a loop but consumers exist outside the loop.
Auto Trait Implementations§
impl Freeze for CContext
impl RefUnwindSafe for CContext
impl Send for CContext
impl Sync for CContext
impl Unpin for CContext
impl UnsafeUnpin for CContext
impl UnwindSafe for CContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more