1 | #pragma once |
2 | |
3 | #ifndef _TRITON_IR_CONSTANT_H_ |
4 | #define _TRITON_IR_CONSTANT_H_ |
5 | |
6 | #include "enums.h" |
7 | #include "value.h" |
8 | #include <cassert> |
9 | #include "visitor.h" |
10 | |
11 | namespace triton{ |
12 | namespace ir{ |
13 | |
14 | class type; |
15 | class context; |
16 | |
17 | /* Constant */ |
18 | class constant: public user{ |
19 | protected: |
20 | using user::user; |
21 | |
22 | public: |
23 | static constant* get_all_ones_value(type *ty); |
24 | static constant* get_null_value(type *ty); |
25 | virtual std::string repr() const = 0; |
26 | }; |
27 | |
28 | /* Undef value */ |
29 | class undef_value: public constant{ |
30 | private: |
31 | undef_value(type *ty); |
32 | |
33 | public: |
34 | static undef_value* get(type* ty); |
35 | std::string repr() const { return "undef" ; } |
36 | void accept(visitor* vst) { vst->visit_undef_value(this); } |
37 | }; |
38 | |
39 | |
40 | /* Constant int */ |
41 | class constant_int: public constant{ |
42 | protected: |
43 | constant_int(type *ty, uint64_t value); |
44 | |
45 | public: |
46 | virtual uint64_t get_value() const { return value_; } |
47 | static constant_int *get(type *ty, uint64_t value); |
48 | std::string repr() const { return std::to_string(value_); } |
49 | void accept(visitor* vst) { vst->visit_constant_int(this); } |
50 | |
51 | protected: |
52 | uint64_t value_; |
53 | }; |
54 | |
55 | /* Constant fp */ |
56 | class constant_fp: public constant{ |
57 | constant_fp(type *ty, double value); |
58 | |
59 | public: |
60 | double get_value() { return value_; } |
61 | static constant* get_negative_zero(type *ty); |
62 | static constant* get_zero_value_for_negation(type *ty); |
63 | static constant* get(context &ctx, double v); |
64 | static constant* get(type *ty, double v); |
65 | std::string repr() const { return std::to_string(value_); } |
66 | void accept(visitor* vst) { vst->visit_constant_fp(this); } |
67 | |
68 | private: |
69 | double value_; |
70 | }; |
71 | |
72 | |
73 | /* Global Value */ |
74 | class global_value: public constant { |
75 | public: |
76 | enum linkage_types_t { |
77 | external |
78 | }; |
79 | |
80 | public: |
81 | global_value(type *ty, unsigned num_ops, |
82 | linkage_types_t linkage, const std::string &name, |
83 | unsigned addr_space); |
84 | std::string repr() const { return get_name(); } |
85 | |
86 | private: |
87 | linkage_types_t linkage_; |
88 | }; |
89 | |
90 | /* global object */ |
91 | class global_object: public global_value { |
92 | public: |
93 | global_object(type *ty, unsigned num_ops, |
94 | linkage_types_t linkage, const std::string &name, |
95 | unsigned addr_space = 0); |
96 | std::string repr() const { return get_name(); } |
97 | }; |
98 | |
99 | /* global variable */ |
100 | class alloc_const: public global_object { |
101 | public: |
102 | alloc_const(type *ty, constant_int *size, |
103 | const std::string &name = "" ); |
104 | std::string repr() const { return get_name(); } |
105 | void accept(visitor* vst) { vst->visit_alloc_const(this); } |
106 | |
107 | |
108 | }; |
109 | |
110 | } |
111 | } |
112 | |
113 | #endif |
114 | |