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

Init canonicalize infrastructure #2

Merged
merged 81 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
21eee05
Cleanup
rikhuijzer Sep 25, 2024
47d1148
Update
rikhuijzer Sep 25, 2024
a9df3ca
Make region optional
rikhuijzer Sep 25, 2024
7da19e2
Recursion on `canonicalize`
rikhuijzer Sep 25, 2024
669fe92
Run multiple canonicalizations
rikhuijzer Sep 25, 2024
3853108
Update
rikhuijzer Sep 25, 2024
a34e4cd
Update
rikhuijzer Sep 25, 2024
fcb54dc
Update
rikhuijzer Sep 26, 2024
7793f98
Switch to `OpOperand`
rikhuijzer Sep 26, 2024
4c51014
Figure it out possibly
rikhuijzer Sep 26, 2024
4a78e33
Improve `function_arguments` parsing
rikhuijzer Sep 26, 2024
4c7bb95
Add `set_parent`
rikhuijzer Sep 26, 2024
d927f7e
Switch `operation.parent` to `Arc`
rikhuijzer Sep 26, 2024
2f8c73b
Set parent for op
rikhuijzer Sep 26, 2024
047f37a
Pass `parent` `Block` down
rikhuijzer Sep 26, 2024
61dc2e1
`Arc<Vec<Arc<Value>>>`
rikhuijzer Sep 26, 2024
816e21a
Refactor
rikhuijzer Sep 26, 2024
7d7261a
Improve error
rikhuijzer Sep 26, 2024
1f61321
Update
rikhuijzer Sep 26, 2024
7fa4049
Ensure operands always receive a `parent`
rikhuijzer Sep 26, 2024
7b4eba5
Fix `canonicalize_op`
rikhuijzer Sep 26, 2024
6e1d005
Immediately parse to `Arc<RwLock<...>>`
rikhuijzer Sep 26, 2024
8361409
Update `Operation`
rikhuijzer Sep 26, 2024
7e65cb0
I don't see it for today anymore
rikhuijzer Sep 26, 2024
f67727c
Refactor
rikhuijzer Sep 27, 2024
9d8e481
Fix `assignment`
rikhuijzer Sep 27, 2024
144250f
`error` return type `String`
rikhuijzer Sep 27, 2024
d80f20c
Move `operands`
rikhuijzer Sep 27, 2024
1ce67a7
Refactor
rikhuijzer Sep 27, 2024
9323a46
Define `OperationAttributes`
rikhuijzer Sep 27, 2024
f59fd54
Update
rikhuijzer Sep 27, 2024
976ad90
Rename
rikhuijzer Sep 27, 2024
d64262b
Fix compilation issues
rikhuijzer Sep 27, 2024
3c06d45
Fix globalop test
rikhuijzer Sep 27, 2024
9e31306
Update
rikhuijzer Sep 27, 2024
5f9ec55
Update
rikhuijzer Sep 27, 2024
7b5403f
Closer
rikhuijzer Sep 27, 2024
0d0a3ec
Get integer constant working again
rikhuijzer Sep 27, 2024
ad4ab76
Parse `ConstantOp` better
rikhuijzer Sep 27, 2024
8e1b857
`assign` can now find `OpResult`s
rikhuijzer Sep 27, 2024
70f4b57
Refactor to `Values`
rikhuijzer Sep 27, 2024
6497fae
Refactor again
rikhuijzer Sep 27, 2024
27c5dad
Update
rikhuijzer Sep 27, 2024
e8dad8b
Find root cause
rikhuijzer Sep 27, 2024
2f743f6
Update
rikhuijzer Sep 27, 2024
09b5392
Update
rikhuijzer Sep 27, 2024
d23736f
Find earlier problem
rikhuijzer Sep 30, 2024
c274a6d
Update
rikhuijzer Sep 30, 2024
0393514
Pass `parent` into `region`
rikhuijzer Oct 1, 2024
d410ae2
Refactor
rikhuijzer Oct 1, 2024
3208797
Remove `println!`s
rikhuijzer Oct 1, 2024
98baeba
Fix stackoverflow
rikhuijzer Oct 1, 2024
878daed
Add `defining_op` field
rikhuijzer Oct 1, 2024
f53d5af
Set defining op
rikhuijzer Oct 1, 2024
afa10bd
Get `lhs` and `rhs`
rikhuijzer Oct 2, 2024
5928fca
Add `attribute` to `Op`
rikhuijzer Oct 2, 2024
9fed4b6
Add `ConstOp.set_value`
rikhuijzer Oct 2, 2024
e6f5668
Refactor `ConstantOp` parsing
rikhuijzer Oct 2, 2024
9cf429e
Add code style
rikhuijzer Oct 2, 2024
512591d
Add panic
rikhuijzer Oct 2, 2024
ca12c57
Fix missing `set_defining_op`
rikhuijzer Oct 2, 2024
a0cc024
Fix loop
rikhuijzer Oct 2, 2024
a3af11a
Find problem
rikhuijzer Oct 2, 2024
2176c24
Update
rikhuijzer Oct 2, 2024
07a2fa4
Remove a few `write`s
rikhuijzer Oct 3, 2024
9ff55c9
Drop the read lock in `canonicalize_op`
rikhuijzer Oct 3, 2024
49542d1
Can modify IR
rikhuijzer Oct 3, 2024
f9b8151
Check results in verifier
rikhuijzer Oct 3, 2024
5012632
Change name of new const
rikhuijzer Oct 4, 2024
ce1a878
Write todo
rikhuijzer Oct 4, 2024
2d53a00
List plan of action
rikhuijzer Oct 7, 2024
b44b55d
Update
rikhuijzer Oct 7, 2024
9071b02
Extract func
rikhuijzer Oct 7, 2024
71b07a3
Replace the first addi
rikhuijzer Oct 7, 2024
dc14a28
Update
rikhuijzer Oct 7, 2024
95dcac4
Use deep clone instead of shallow clone for const attributes
rikhuijzer Oct 7, 2024
30695d9
Add `DeadCodeElimination` pass
rikhuijzer Oct 8, 2024
0a7757d
Refactor
rikhuijzer Oct 8, 2024
54fa755
Refactor
rikhuijzer Oct 8, 2024
2662c94
Fix
rikhuijzer Oct 8, 2024
282db0c
Update
rikhuijzer Oct 8, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
RUST_TOOLCHAIN: '1.80'
RUST_TOOLCHAIN: '1.81'

jobs:
test:
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ edition = "2021"
license = "Apache-2.0 with LLVM-exceptions"

[dependencies]
anyhow = "1.0.86"
anyhow = "1.0.86"

[dev-dependencies]
indoc = "2"
62 changes: 62 additions & 0 deletions src/canonicalize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::ir::ModuleOp;
use crate::ir::Op;

#[derive(Debug, PartialEq, Eq)]
pub enum CanonicalizeResult {
Changed,
Unchanged,
}

pub trait Canonicalize {
fn canonicalize(&self, op: &dyn Op) -> CanonicalizeResult;
}

struct CanonicalizeOp;

impl Canonicalize for CanonicalizeOp {
fn canonicalize(&self, op: &dyn Op) -> CanonicalizeResult {
op.canonicalize()
}
}

struct DeadCodeElimination;

impl Canonicalize for DeadCodeElimination {
fn canonicalize(&self, _op: &dyn Op) -> CanonicalizeResult {
CanonicalizeResult::Unchanged
}
}

fn canonicalize_op(op: &dyn Op) -> CanonicalizeResult {
let canonicalizers: Vec<&dyn Canonicalize> = vec![&CanonicalizeOp]; // &DeadCodeElimination];
let mut changed = CanonicalizeResult::Unchanged;
let ops = op.ops();
for canonicalizer in &canonicalizers {
for nested_op in ops.iter() {
let nested_op = nested_op.read().unwrap();
let result = canonicalize_op(&*nested_op);
if result == CanonicalizeResult::Changed {
changed = result;
}
let result = canonicalizer.canonicalize(op);
if result == CanonicalizeResult::Changed {
changed = result;
}
}
let result = canonicalizer.canonicalize(op);
if result == CanonicalizeResult::Changed {
changed = result;
}
}
changed
}

pub fn canonicalize(op: &ModuleOp) {
let max_iterations = 16;
for _ in 0..max_iterations {
let result = canonicalize_op(op);
if result == CanonicalizeResult::Unchanged {
break;
}
}
}
Loading