1#pragma once
2
3#ifndef _TRITON_IR_VALUE_H_
4#define _TRITON_IR_VALUE_H_
5
6#include <string>
7#include <vector>
8#include <set>
9
10namespace triton{
11namespace ir{
12
13class type;
14class use;
15class user;
16class visitor;
17
18//===----------------------------------------------------------------------===//
19// value class
20//===----------------------------------------------------------------------===//
21
22class value {
23public:
24 typedef std::vector<user*> users_t;
25
26public:
27 // constructor
28 value(type *ty, const std::string &name = "");
29 virtual ~value(){ }
30 // uses
31 void add_use(user* arg);
32 users_t::iterator erase_use(user* arg);
33 const std::vector<user*> &get_users() { return users_; }
34 void replace_all_uses_with(value *target);
35 // name
36 void set_name(const std::string &name);
37 const std::string &get_name() const { return name_; }
38 bool has_name() const { return !name_.empty(); }
39 type* get_type() const { return ty_; }
40 // visitor
41 virtual void accept(visitor *v) = 0;
42
43private:
44 std::string name_;
45
46protected:
47 type *ty_;
48 users_t users_;
49};
50
51//===----------------------------------------------------------------------===//
52// user class
53//===----------------------------------------------------------------------===//
54
55class user: public value{
56public:
57 typedef std::vector<value*> ops_t;
58 typedef ops_t::iterator op_iterator;
59 typedef ops_t::const_iterator const_op_iterator;
60
61protected:
62 void resize_ops(unsigned num_ops) { ops_.resize(num_ops + num_hidden_); num_ops_ = num_ops; }
63 void resize_hidden(unsigned num_hidden) { ops_.resize(num_ops_ + num_hidden); num_hidden_ = num_hidden; }
64
65public:
66 // Constructor
67 user(type *ty, unsigned num_ops, const std::string &name = "")
68 : value(ty, name), ops_(num_ops), num_ops_(num_ops), num_hidden_(0){
69 }
70 virtual ~user() { }
71
72 // Operands
73 const ops_t& ops() { return ops_; }
74 const ops_t& ops() const { return ops_; }
75 op_iterator op_begin() { return ops_.begin(); }
76 op_iterator op_end() { return ops_.end(); }
77 void set_operand(unsigned i, value *x);
78 value *get_operand(unsigned i) const;
79 unsigned get_num_operands() const ;
80 unsigned get_num_hidden() const;
81
82 // Utils
83 value::users_t::iterator replace_uses_of_with(value *before, value *after);
84
85
86private:
87 ops_t ops_;
88 unsigned num_ops_;
89 unsigned num_hidden_;
90};
91
92}
93}
94
95#endif
96