-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automatic early return when writing strategy is set
- Loading branch information
1 parent
a20ac61
commit 029adb5
Showing
6 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::ir::{macros::cpa, Branch, Elem, Item, Scope, Variable, Vectorization}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Perform a check bound on the index (lhs) of value (rhs) | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
#[allow(missing_docs)] | ||
pub struct EarlyReturn { | ||
pub global: Variable, | ||
pub position: Variable, | ||
} | ||
|
||
impl EarlyReturn { | ||
#[allow(missing_docs)] | ||
pub fn expand(self, scope: &mut Scope) { | ||
let variable = self.global; | ||
let index = self.position; | ||
|
||
let array_len = scope.create_local(Item::new(Elem::UInt)); | ||
let outside_bound = scope.create_local(Item::new(Elem::Bool)); | ||
|
||
cpa!(scope, array_len = len(variable)); | ||
cpa!(scope, outside_bound = index >= array_len); | ||
|
||
cpa!(scope, if(outside_bound).then(|scope| { | ||
scope.register(Branch::Return); | ||
})); | ||
} | ||
|
||
pub(crate) fn vectorize(&self, vectorization: Vectorization) -> Self { | ||
Self { | ||
global: self.global.vectorize(vectorization), | ||
position: self.position.vectorize(vectorization), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
mod assign; | ||
mod base; | ||
mod early_return; | ||
mod index; | ||
mod read; | ||
mod write; | ||
|
||
pub use assign::*; | ||
pub use base::*; | ||
pub use early_return::*; | ||
pub use index::*; | ||
pub use read::*; | ||
pub use write::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters