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
11namespace triton{
12namespace ir{
13
14class type;
15class context;
16
17/* Constant */
18class constant: public user{
19protected:
20 using user::user;
21
22public:
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 */
29class undef_value: public constant{
30private:
31 undef_value(type *ty);
32
33public:
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 */
41class constant_int: public constant{
42protected:
43 constant_int(type *ty, uint64_t value);
44
45public:
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
51protected:
52 uint64_t value_;
53};
54
55/* Constant fp */
56class constant_fp: public constant{
57 constant_fp(type *ty, double value);
58
59public:
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
68private:
69 double value_;
70};
71
72
73/* Global Value */
74class global_value: public constant {
75public:
76 enum linkage_types_t {
77 external
78 };
79
80public:
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
86private:
87 linkage_types_t linkage_;
88};
89
90/* global object */
91class global_object: public global_value {
92public:
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 */
100class alloc_const: public global_object {
101public:
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