1 | #include <algorithm> |
2 | #include "triton/ir/function.h" |
3 | #include "triton/ir/type.h" |
4 | #include "triton/ir/module.h" |
5 | |
6 | namespace triton{ |
7 | namespace ir{ |
8 | |
9 | |
10 | /* Argument */ |
11 | |
12 | argument::argument(type *ty, const std::string &name, function *parent, unsigned arg_no) |
13 | : value(ty, name), parent_(parent), arg_no_(arg_no) { } |
14 | |
15 | argument *argument::create(type *ty, const std::string &name, |
16 | function *parent, unsigned arg_no) { |
17 | return new argument(ty, name, parent, arg_no); |
18 | } |
19 | |
20 | function* argument::get_parent() const { |
21 | return parent_; |
22 | } |
23 | |
24 | unsigned argument::get_arg_no() const { |
25 | return arg_no_; |
26 | } |
27 | |
28 | void argument::accept(visitor *v) { |
29 | v->visit_argument(this); |
30 | } |
31 | |
32 | |
33 | /* function */ |
34 | function::function(function_type *ty, linkage_types_t linkage, |
35 | const std::string &name, module *parent) |
36 | : global_object(ty, 0, linkage, name), parent_(parent), fn_ty_(ty), is_kernel_(false) { |
37 | unsigned num_params = fn_ty_->get_num_params(); |
38 | if(parent) |
39 | parent->push_function(this); |
40 | // skip if no parameter |
41 | if(num_params == 0) |
42 | return; |
43 | // create arguments |
44 | args_.resize(num_params); |
45 | for(unsigned i = 0; i < num_params; i++){ |
46 | type *param_ty = fn_ty_->get_param_ty(i); |
47 | args_[i] = argument::create(param_ty, "" , this, i); |
48 | } |
49 | } |
50 | |
51 | /* basic block */ |
52 | void function::insert_block(basic_block *block, basic_block *next) { |
53 | auto it = std::find(blocks_.begin(), blocks_.end(), next); |
54 | blocks_.insert(it, block); |
55 | } |
56 | |
57 | |
58 | function *function::create(function_type *ty, linkage_types_t linkage, |
59 | const std::string &name, module *mod) { |
60 | return new function(ty, linkage, name, mod); |
61 | } |
62 | |
63 | |
64 | } |
65 | } |
66 | |
67 | |