nak/nir: Add a few more NIR helpers

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30402>
This commit is contained in:
Faith Ekstrand
2024-07-26 17:05:43 -05:00
committed by Marge Bot
parent f66ca6edc3
commit cb5e10d0aa
+15
View File
@@ -570,6 +570,7 @@ pub trait NirBlock {
fn successors(&self) -> [Option<&nir_block>; 2];
fn following_if(&self) -> Option<&nir_if>;
fn following_loop(&self) -> Option<&nir_loop>;
fn parent(&self) -> &nir_cf_node;
}
impl NirBlock for nir_block {
@@ -593,6 +594,10 @@ impl NirBlock for nir_block {
let self_ptr = self as *const _ as *mut _;
unsafe { nir_block_get_following_loop(self_ptr).as_ref() }
}
fn parent(&self) -> &nir_cf_node {
self.cf_node.parent().unwrap()
}
}
pub trait NirIf {
@@ -623,6 +628,7 @@ impl NirIf for nir_if {
pub trait NirLoop {
fn iter_body(&self) -> ExecListIter<nir_cf_node>;
fn first_block(&self) -> &nir_block;
fn following_block(&self) -> &nir_block;
}
@@ -631,6 +637,10 @@ impl NirLoop for nir_loop {
ExecListIter::new(&self.body, offset_of!(nir_cf_node, node))
}
fn first_block(&self) -> &nir_block {
self.iter_body().next().unwrap().as_block().unwrap()
}
fn following_block(&self) -> &nir_block {
self.cf_node.next().unwrap().as_block().unwrap()
}
@@ -642,6 +652,7 @@ pub trait NirCfNode {
fn as_loop(&self) -> Option<&nir_loop>;
fn next(&self) -> Option<&nir_cf_node>;
fn prev(&self) -> Option<&nir_cf_node>;
fn parent(&self) -> Option<&nir_cf_node>;
}
impl NirCfNode for nir_cf_node {
@@ -680,6 +691,10 @@ impl NirCfNode for nir_cf_node {
ExecListIter::at(&self.node, offset_of!(nir_cf_node, node), true);
iter.next()
}
fn parent(&self) -> Option<&nir_cf_node> {
NonNull::new(self.parent).map(|b| unsafe { b.as_ref() })
}
}
pub trait NirFunctionImpl {