pub struct Scope { /* private fields */ }Expand description
The scope represents the region currently being parsed, as well as the current insertion point. It is created from scratch for the initial codegen phase, or rebuilt from an existing scope and a rewriter for passes/conversions.
All state apart from the insertion point is shared. Global state like the type map and errors are stored in the context’s auxiliary storage, so they can be reconstructed from the rewriter state.
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn device_properties(&self, properties: &DeviceProperties)
pub fn device_properties(&self, properties: &DeviceProperties)
Set the device properties.
pub fn state(&self) -> &GlobalState
pub fn state_mut(&self) -> &mut GlobalState
pub fn expand_state(&self) -> Ref<'_, ExpandState>
pub fn expand_state_mut(&self) -> RefMut<'_, ExpandState>
pub fn ctx(&self) -> &Context
pub fn ctx_mut(&self) -> &mut Context
pub fn inserter(&self) -> &mut dyn Inserter
Sourcepub fn root(settings: KernelSettings) -> Scope
pub fn root(settings: KernelSettings) -> Scope
Create a parse scope that is at the root of a kernel definition.
A local scope can be created with the child method.
Sourcepub fn dummy() -> Scope
pub fn dummy() -> Scope
Create a parse scope that only exists for type registration in the kernel builder. The state will be incomplete and should never be used for actual codegen.
Sourcepub fn from_context_and_inserter(
ctx: &mut Context,
inserter: &mut (impl Inserter + 'static),
) -> Scope
pub fn from_context_and_inserter( ctx: &mut Context, inserter: &mut (impl Inserter + 'static), ) -> Scope
Create a rewrite scope from an existing context and inserter/rewriter
Sourcepub fn create_local_mut(
&self,
value_ty: impl Into<TypeHandle>,
init: Option<Box<dyn Attribute>>,
) -> Value
pub fn create_local_mut( &self, value_ty: impl Into<TypeHandle>, init: Option<Box<dyn Attribute>>, ) -> Value
Create a new mutable local variable of type specified by value_ty.
initializer is a constant attribute and has the same rules as OpConstant. This is because
SPIR-V does not allow non-constant (technically non-global, but constants are the only
non-pointer globals) initializers.
Create a shared variable of the given item type.
pub fn func_ident(&self, label: Option<&str>) -> Identifier
Sourcepub fn register_func(&self, func: FuncOp)
pub fn register_func(&self, func: FuncOp)
Create a new function.
Sourcepub fn register_with_result(
&self,
op: &(dyn OneResultInterface + 'static),
) -> Value
pub fn register_with_result( &self, op: &(dyn OneResultInterface + 'static), ) -> Value
Register an [Instruction] into the scope and return its result.
Sourcepub fn terminate_yield(&self)
pub fn terminate_yield(&self)
Terminate block with a cube.yield if not already terminated
pub fn set_break_return(&self, children: &[Scope])
pub fn set_may_return(&self, children: &[Scope])
pub fn set_may_break(&self, children: &[Scope])
Sourcepub fn create_kernel_ref<'a, T>(&self, value: T) -> &'a mut Twhere
T: 'a,
pub fn create_kernel_ref<'a, T>(&self, value: T) -> &'a mut Twhere
T: 'a,
Add a value to the global arena so we can create a kernel-wide reference to it. The reference is the same as the type for simplicity, but is only valid for the duration of the root scope. Ensure the reference lifetime is shortened to the lifetime of the underlying variable being referenced.
Sourcepub fn resolve_type<T>(&self) -> Option<ElemType>where
T: 'static,
pub fn resolve_type<T>(&self) -> Option<ElemType>where
T: 'static,
Resolve the element type of the given generic type.
Sourcepub fn resolve_size<T>(&self) -> Option<usize>where
T: 'static,
pub fn resolve_size<T>(&self) -> Option<usize>where
T: 'static,
Resolve the comptime size of the given generic size.
Sourcepub fn register_type<T>(&self, elem: ElemType)where
T: 'static,
pub fn register_type<T>(&self, elem: ElemType)where
T: 'static,
Register the element type for the given generic type.
Sourcepub fn register_size<T>(&self, size: usize)where
T: 'static,
pub fn register_size<T>(&self, size: usize)where
T: 'static,
Register the comptime size for the given generic size.
Sourcepub fn register_value_type<T, N>(&self, value: impl Typed)where
T: 'static,
N: 'static,
pub fn register_value_type<T, N>(&self, value: impl Typed)where
T: 'static,
N: 'static,
Register the type and size of a scalarizable type
Sourcepub fn loop_child(&self, inserter: impl Inserter + 'static) -> Scope
pub fn loop_child(&self, inserter: impl Inserter + 'static) -> Scope
Create a child scope with a new break condition.
Sourcepub fn func_child(&self, inserter: impl Inserter + 'static) -> Scope
pub fn func_child(&self, inserter: impl Inserter + 'static) -> Scope
Create a child that’s at the root of a new function
pub fn push_error(&self, msg: impl Into<String>)
Sourcepub fn pop_errors(&self) -> Vec<String>
pub fn pop_errors(&self) -> Vec<String>
Returns all validation errors.
Sourcepub fn global(
&self,
buffer_pos: usize,
ext_meta_pos: Option<usize>,
value_ty: TypeHandle,
) -> Value
pub fn global( &self, buffer_pos: usize, ext_meta_pos: Option<usize>, value_ty: TypeHandle, ) -> Value
Obtain the index-th buffer
Sourcepub fn tensor_map(&self, buffer_pos: usize, ext_meta_pos: usize) -> Value
pub fn tensor_map(&self, buffer_pos: usize, ext_meta_pos: usize) -> Value
Obtain the index-th tensor map
pub fn kernel_arg(&self, idx: usize) -> Value
pub fn extract_field(&self, aggregate: Value, field: usize) -> Value
pub fn const_usize(&self, value: usize) -> Value
pub fn const_bool(&self, value: bool) -> Value
pub fn into_context(self) -> Option<Context>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Scope
impl !RefUnwindSafe for Scope
impl !Send for Scope
impl !Sync for Scope
impl !UnwindSafe for Scope
impl Unpin for Scope
impl UnsafeUnpin for Scope
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.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