Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exit beta type #28

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/ops/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ impl ControlFlowOp {

/// β (beta): a CFG basic block node. The signature is that of the internal Dataflow graph.
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct BasicBlockOp {
pub inputs: TypeRow,
pub outputs: TypeRow,
pub enum BasicBlockOp {
Beta { inputs: TypeRow, outputs: TypeRow },
Exit { outputs: TypeRow },
ss2165 marked this conversation as resolved.
Show resolved Hide resolved
}

impl BasicBlockOp {
Expand All @@ -77,11 +77,17 @@ impl BasicBlockOp {

/// The name of the operation
pub fn name(&self) -> SmolStr {
"β".into()
match self {
BasicBlockOp::Beta { .. } => "β".into(),
BasicBlockOp::Exit { .. } => "β_e".into(),
}
}

/// The description of the operation
pub fn description(&self) -> &str {
"A CFG basic block node"
match self {
BasicBlockOp::Beta { .. } => "A CFG basic block node",
BasicBlockOp::Exit { .. } => "A CFG exit block node",
}
}
}
31 changes: 22 additions & 9 deletions src/ops/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,22 @@ impl ModuleOp {
impl BasicBlockOp {
/// Returns the set of allowed parent operation types.
fn validity_flags(&self) -> OpValidityFlags {
OpValidityFlags {
allowed_parents: ValidOpSet::CfgNode,
allowed_first_child: ValidOpSet::Input,
allowed_last_child: ValidOpSet::Output,
is_container: true,
is_df_container: true,
requires_children: true,
requires_dag: true,
match self {
BasicBlockOp::Beta { .. } => OpValidityFlags {
allowed_parents: ValidOpSet::CfgNode,
allowed_first_child: ValidOpSet::Input,
allowed_last_child: ValidOpSet::Output,
is_container: true,
is_df_container: true,
requires_children: true,
requires_dag: true,
},
BasicBlockOp::Exit { .. } => OpValidityFlags {
allowed_parents: ValidOpSet::CfgNode,
allowed_first_child: ValidOpSet::None,
allowed_last_child: ValidOpSet::None,
..Default::default()
},
}
}

Expand All @@ -248,7 +256,12 @@ impl BasicBlockOp {
) -> Result<(), ChildrenValidationError> {
// TODO: The output signature of a basic block should be a sum of the different possible outputs.
// This is not yet implemented in the type system.
validate_io_nodes(&self.inputs, None, "basic block graph", children)
match self {
BasicBlockOp::Beta { inputs, .. } => {
validate_io_nodes(inputs, None, "basic block graph", children)
}
BasicBlockOp::Exit { .. } => Ok(()),
}
}
}

Expand Down