Commit f9990047 authored by qinsoon's avatar qinsoon

copy propagation - analysis only

parent fbfe7dba
Pipeline #1400 failed with stages
in 21 minutes and 37 seconds
......@@ -104,6 +104,7 @@ impl Default for CompilerPolicy {
// ir level passes
passes.push(Box::new(passes::RetSink::new()));
passes.push(Box::new(passes::Inlining::new()));
passes.push(Box::new(passes::CopyPropagation::new()));
passes.push(Box::new(passes::InjectRuntime::new()));
passes.push(Box::new(passes::DefUse::new()));
passes.push(Box::new(passes::TreeGen::new()));
......
This diff is collapsed.
......@@ -23,6 +23,10 @@ use std::any::Any;
mod inlining;
pub use compiler::passes::inlining::Inlining;
/// A pass to do copy propagation for values that are passed between blocks
mod copy_propagation;
pub use compiler::passes::copy_propagation::CopyPropagation;
/// A pass to check and rewrite RET instructions to ensure a single return sink for every function
mod ret_sink;
pub use compiler::passes::ret_sink::RetSink;
......
......@@ -31,3 +31,4 @@ mod test_convop;
mod test_int128;
mod test_misc;
mod test_opt;
mod test_copy_propagation;
\ No newline at end of file
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
extern crate mu;
use mu::ast::types::*;
use mu::ast::ir::*;
use mu::ast::inst::*;
use mu::ast::op::*;
use mu::vm::*;
use mu::compiler::*;
use mu::utils::LinkedHashMap;
use std::sync::Arc;
#[test]
fn test_copy_propagation1() {
VM::start_logging_trace();
let vm = Arc::new(copy_propagation_test1());
let compiler = Compiler::new(CompilerPolicy::default(), &vm);
let func_id = vm.id_of("test1");
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&func_id).unwrap().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
let mut func_ver = func_vers
.get(&func.cur_ver.unwrap())
.unwrap()
.write()
.unwrap();
compiler.compile(&mut func_ver);
}
fn copy_propagation_test1() -> VM {
let vm = VM::new();
typedef! ((vm) int1 = mu_int(1));
typedef! ((vm) int64 = mu_int(64));
funcsig! ((vm) sig = (int64, int64, int64) -> ());
funcdecl! ((vm) <sig> test1);
funcdef! ((vm) <sig> test1 VERSION test1_v1);
// we try to have a test case to cover actual copies, fake merge, actual merge
// x - copy, y - fake merge, z - actual merge
// b0 (x0 y0 z0): goto b1 (x0 y0 z0)
// b1 (x1 y1 z1): goto b2 (x1 y1 z1)
// b2 (x2 y2 z2): z4 = x2 + y2; if (x2 == y2) goto end(x2 y2 z4) else goto b1 (x2 y2 z4)
// end (x3 y3 z3)
// b0
block! ((vm, test1_v1) b0);
ssa! ((vm, test1_v1) <int64> x0);
ssa! ((vm, test1_v1) <int64> y0);
ssa! ((vm, test1_v1) <int64> z0);
block! ((vm, test1_v1) b1);
inst! ((vm, test1_v1) b0_goto:
BRANCH b1 (x0, y0, z0)
);
define_block!((vm, test1_v1) b0 (x0, y0, z0) {
b0_goto
});
// b1
ssa! ((vm, test1_v1) <int64> x1);
ssa! ((vm, test1_v1) <int64> y1);
ssa! ((vm, test1_v1) <int64> z1);
block! ((vm, test1_v1) b2);
inst! ((vm, test1_v1) b1_goto:
BRANCH b2 (x1, y1, z1)
);
define_block!((vm, test1_v1) b1 (x1, y1, z1) {
b1_goto
});
// b2
ssa! ((vm, test1_v1) <int64> x2);
ssa! ((vm, test1_v1) <int64> y2);
ssa! ((vm, test1_v1) <int64> z2);
ssa! ((vm, test1_v1) <int64> z_);
inst! ((vm, test1_v1) b2_add:
z_ = BINOP (BinOp::Add) x2 y2
);
ssa! ((vm, test1_v1) <int1> cond);
inst! ((vm, test1_v1) b2_cmp:
cond = CMPOP (CmpOp::EQ) x2 y2
);
block! ((vm, test1_v1) b3);
inst! ((vm, test1_v1) b2_branch2:
BRANCH2 (cond, x2, y2, z_)
IF (OP 0)
THEN b3 (vec![1, 2, 3]) WITH 0.7f32,
ELSE b1 (vec![1, 2, 3])
);
define_block!((vm, test1_v1) b2 (x2, y2, z2) {
b2_add,
b2_cmp,
b2_branch2
});
// b3
ssa! ((vm, test1_v1) <int64> x3);
ssa! ((vm, test1_v1) <int64> y3);
ssa! ((vm, test1_v1) <int64> z3);
inst! ((vm, test1_v1) b3_ret:
RET
);
define_block!((vm, test1_v1) b3 (x3, y3, z3) {
b3_ret
});
define_func_ver!((vm) test1_v1 (entry: b0) {
b0, b1, b2, b3
});
vm
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment