1 | #include <iostream> |
2 | #include <algorithm> |
3 | #include "triton/ir/module.h" |
4 | #include "triton/ir/function.h" |
5 | #include "triton/ir/basic_block.h" |
6 | #include "triton/ir/instructions.h" |
7 | #include "triton/codegen/transform/reorder.h" |
8 | |
9 | namespace triton { |
10 | namespace codegen{ |
11 | namespace transform{ |
12 | |
13 | void reorder::run(ir::module& mod){ |
14 | // ir::builder &builder = mod.get_builder(); |
15 | // std::vector<std::pair<ir::instruction*, ir::value*>> to_replace; |
16 | |
17 | // for(ir::function *fn: mod.get_function_list()) |
18 | // for(ir::basic_block *block: fn->blocks()) |
19 | // for(ir::instruction* i: block->get_inst_list()){ |
20 | // if(auto* ld = dynamic_cast<ir::masked_load_inst*>(i)){ |
21 | // ir::value* _ptr = ld->get_pointer_operand(); |
22 | // ir::value* _msk = ld->get_mask_operand(); |
23 | // ir::value* _val = ld->get_false_value_operand(); |
24 | // auto ptr = std::find(block->begin(), block->end(), _ptr); |
25 | // auto msk = std::find(block->begin(), block->end(), _msk); |
26 | // auto val = std::find(block->begin(), block->end(), _val); |
27 | // if(ptr == block->end() || msk == block->end() || val == block->end()) |
28 | // continue; |
29 | // auto it = std::find(block->begin(), block->end(), i); |
30 | // int dist_ptr = std::distance(ptr, it); |
31 | // int dist_msk = std::distance(msk, it); |
32 | // int dist_val = std::distance(val, it); |
33 | // if(dist_ptr < dist_msk && dist_ptr < dist_val) |
34 | // builder.set_insert_point(++ptr); |
35 | // if(dist_msk < dist_ptr && dist_msk < dist_val) |
36 | // builder.set_insert_point(++msk); |
37 | // if(dist_val < dist_ptr && dist_val < dist_msk) |
38 | // builder.set_insert_point(++val); |
39 | // ir::value* new_ld = builder.create_masked_load(_ptr, _msk, _val); |
40 | // to_replace.push_back(std::make_pair(ld, new_ld)); |
41 | // } |
42 | // } |
43 | |
44 | // for(auto& x: to_replace) |
45 | // x.first->replace_all_uses_with(x.second); |
46 | |
47 | } |
48 | |
49 | } |
50 | } |
51 | } |
52 | |