0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 //===-- ConstantsContext.h - Constants-related Context Interals -----------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 // This file defines various helper methods and classes used by
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 // LLVMContextImpl for creating and managing constants.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14
|
77
|
15 #ifndef LLVM_LIB_IR_CONSTANTSCONTEXT_H
|
|
16 #define LLVM_LIB_IR_CONSTANTSCONTEXT_H
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 #include "llvm/ADT/DenseMap.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 #include "llvm/ADT/Hashing.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 #include "llvm/IR/InlineAsm.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 #include "llvm/IR/Instructions.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 #include "llvm/IR/Operator.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 #include "llvm/Support/Debug.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 #include "llvm/Support/ErrorHandling.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 #include "llvm/Support/raw_ostream.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 #include <map>
|
77
|
27 #include <tuple>
|
|
28
|
|
29 #define DEBUG_TYPE "ir"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 namespace llvm {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 /// UnaryConstantExpr - This class is private to Constants.cpp, and is used
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 /// behind the scenes to implement unary constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 class UnaryConstantExpr : public ConstantExpr {
|
77
|
36 void anchor() override;
|
83
|
37 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 // allocate space for exactly one operand
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 return User::operator new(s, 1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 UnaryConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 : ConstantExpr(Ty, Opcode, &Op<0>(), 1) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 Op<0>() = C;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 /// BinaryConstantExpr - This class is private to Constants.cpp, and is used
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 /// behind the scenes to implement binary constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 class BinaryConstantExpr : public ConstantExpr {
|
77
|
53 void anchor() override;
|
83
|
54 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 // allocate space for exactly two operands
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 return User::operator new(s, 2);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 unsigned Flags)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 : ConstantExpr(C1->getType(), Opcode, &Op<0>(), 2) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 Op<0>() = C1;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 Op<1>() = C2;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 SubclassOptionalData = Flags;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 /// SelectConstantExpr - This class is private to Constants.cpp, and is used
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 /// behind the scenes to implement select constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 class SelectConstantExpr : public ConstantExpr {
|
77
|
74 void anchor() override;
|
83
|
75 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 // allocate space for exactly three operands
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 return User::operator new(s, 3);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 : ConstantExpr(C2->getType(), Instruction::Select, &Op<0>(), 3) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 Op<0>() = C1;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 Op<1>() = C2;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 Op<2>() = C3;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 /// ExtractElementConstantExpr - This class is private to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 /// Constants.cpp, and is used behind the scenes to implement
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 /// extractelement constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 class ExtractElementConstantExpr : public ConstantExpr {
|
77
|
95 void anchor() override;
|
83
|
96 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 // allocate space for exactly two operands
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 return User::operator new(s, 2);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 ExtractElementConstantExpr(Constant *C1, Constant *C2)
|
95
|
103 : ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 Instruction::ExtractElement, &Op<0>(), 2) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 Op<0>() = C1;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 Op<1>() = C2;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 /// InsertElementConstantExpr - This class is private to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 /// Constants.cpp, and is used behind the scenes to implement
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 /// insertelement constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 class InsertElementConstantExpr : public ConstantExpr {
|
77
|
116 void anchor() override;
|
83
|
117 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 // allocate space for exactly three operands
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 return User::operator new(s, 3);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
|
95
|
124 : ConstantExpr(C1->getType(), Instruction::InsertElement,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 &Op<0>(), 3) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 Op<0>() = C1;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 Op<1>() = C2;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 Op<2>() = C3;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134 /// ShuffleVectorConstantExpr - This class is private to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 /// Constants.cpp, and is used behind the scenes to implement
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 /// shufflevector constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137 class ShuffleVectorConstantExpr : public ConstantExpr {
|
77
|
138 void anchor() override;
|
83
|
139 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 // allocate space for exactly three operands
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 return User::operator new(s, 3);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 : ConstantExpr(VectorType::get(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 cast<VectorType>(C1->getType())->getElementType(),
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 cast<VectorType>(C3->getType())->getNumElements()),
|
95
|
149 Instruction::ShuffleVector,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 &Op<0>(), 3) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 Op<0>() = C1;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152 Op<1>() = C2;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 Op<2>() = C3;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 /// ExtractValueConstantExpr - This class is private to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 /// Constants.cpp, and is used behind the scenes to implement
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 /// extractvalue constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 class ExtractValueConstantExpr : public ConstantExpr {
|
77
|
163 void anchor() override;
|
83
|
164 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 // allocate space for exactly one operand
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 return User::operator new(s, 1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 }
|
77
|
170 ExtractValueConstantExpr(Constant *Agg, ArrayRef<unsigned> IdxList,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 Type *DestTy)
|
77
|
172 : ConstantExpr(DestTy, Instruction::ExtractValue, &Op<0>(), 1),
|
|
173 Indices(IdxList.begin(), IdxList.end()) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174 Op<0>() = Agg;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177 /// Indices - These identify which value to extract.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 const SmallVector<unsigned, 4> Indices;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
100
|
182
|
|
183 static bool classof(const ConstantExpr *CE) {
|
|
184 return CE->getOpcode() == Instruction::ExtractValue;
|
|
185 }
|
|
186 static bool classof(const Value *V) {
|
|
187 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
|
|
188 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 /// InsertValueConstantExpr - This class is private to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 /// Constants.cpp, and is used behind the scenes to implement
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 /// insertvalue constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 class InsertValueConstantExpr : public ConstantExpr {
|
77
|
195 void anchor() override;
|
83
|
196 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 // allocate space for exactly one operand
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 return User::operator new(s, 2);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
201 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
202 InsertValueConstantExpr(Constant *Agg, Constant *Val,
|
77
|
203 ArrayRef<unsigned> IdxList, Type *DestTy)
|
|
204 : ConstantExpr(DestTy, Instruction::InsertValue, &Op<0>(), 2),
|
|
205 Indices(IdxList.begin(), IdxList.end()) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 Op<0>() = Agg;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 Op<1>() = Val;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 /// Indices - These identify the position for the insertion.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211 const SmallVector<unsigned, 4> Indices;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
100
|
215
|
|
216 static bool classof(const ConstantExpr *CE) {
|
|
217 return CE->getOpcode() == Instruction::InsertValue;
|
|
218 }
|
|
219 static bool classof(const Value *V) {
|
|
220 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
|
|
221 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224 /// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225 /// used behind the scenes to implement getelementpr constant exprs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
226 class GetElementPtrConstantExpr : public ConstantExpr {
|
95
|
227 Type *SrcElementTy;
|
100
|
228 Type *ResElementTy;
|
77
|
229 void anchor() override;
|
95
|
230 GetElementPtrConstantExpr(Type *SrcElementTy, Constant *C,
|
|
231 ArrayRef<Constant *> IdxList, Type *DestTy);
|
|
232
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
233 public:
|
95
|
234 static GetElementPtrConstantExpr *Create(Type *SrcElementTy, Constant *C,
|
|
235 ArrayRef<Constant *> IdxList,
|
|
236 Type *DestTy, unsigned Flags) {
|
|
237 GetElementPtrConstantExpr *Result = new (IdxList.size() + 1)
|
|
238 GetElementPtrConstantExpr(SrcElementTy, C, IdxList, DestTy);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239 Result->SubclassOptionalData = Flags;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
240 return Result;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 }
|
95
|
242 Type *getSourceElementType() const;
|
100
|
243 Type *getResultElementType() const;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
244 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
245 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
100
|
246
|
|
247 static bool classof(const ConstantExpr *CE) {
|
|
248 return CE->getOpcode() == Instruction::GetElementPtr;
|
|
249 }
|
|
250 static bool classof(const Value *V) {
|
|
251 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
|
|
252 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
255 // CompareConstantExpr - This class is private to Constants.cpp, and is used
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256 // behind the scenes to implement ICmp and FCmp constant expressions. This is
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257 // needed in order to store the predicate value for these instructions.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258 class CompareConstantExpr : public ConstantExpr {
|
77
|
259 void anchor() override;
|
83
|
260 void *operator new(size_t, unsigned) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 // allocate space for exactly two operands
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 void *operator new(size_t s) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 return User::operator new(s, 2);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 unsigned short predicate;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
267 CompareConstantExpr(Type *ty, Instruction::OtherOps opc,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268 unsigned short pred, Constant* LHS, Constant* RHS)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 : ConstantExpr(ty, opc, &Op<0>(), 2), predicate(pred) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270 Op<0>() = LHS;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 Op<1>() = RHS;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 /// Transparently provide more efficient getOperand methods.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
100
|
275
|
|
276 static bool classof(const ConstantExpr *CE) {
|
|
277 return CE->getOpcode() == Instruction::ICmp ||
|
|
278 CE->getOpcode() == Instruction::FCmp;
|
|
279 }
|
|
280 static bool classof(const Value *V) {
|
|
281 return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V));
|
|
282 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
283 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285 template <>
|
95
|
286 struct OperandTraits<UnaryConstantExpr>
|
|
287 : public FixedNumOperandTraits<UnaryConstantExpr, 1> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
288 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
289
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 template <>
|
95
|
291 struct OperandTraits<BinaryConstantExpr>
|
|
292 : public FixedNumOperandTraits<BinaryConstantExpr, 2> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295 template <>
|
95
|
296 struct OperandTraits<SelectConstantExpr>
|
|
297 : public FixedNumOperandTraits<SelectConstantExpr, 3> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
298 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
299
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
300 template <>
|
95
|
301 struct OperandTraits<ExtractElementConstantExpr>
|
|
302 : public FixedNumOperandTraits<ExtractElementConstantExpr, 2> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
303 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
304
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
305 template <>
|
95
|
306 struct OperandTraits<InsertElementConstantExpr>
|
|
307 : public FixedNumOperandTraits<InsertElementConstantExpr, 3> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
308 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
309
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
310 template <>
|
95
|
311 struct OperandTraits<ShuffleVectorConstantExpr>
|
|
312 : public FixedNumOperandTraits<ShuffleVectorConstantExpr, 3> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
313 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
314
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
315 template <>
|
95
|
316 struct OperandTraits<ExtractValueConstantExpr>
|
|
317 : public FixedNumOperandTraits<ExtractValueConstantExpr, 1> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
318 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractValueConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
319
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
320 template <>
|
95
|
321 struct OperandTraits<InsertValueConstantExpr>
|
|
322 : public FixedNumOperandTraits<InsertValueConstantExpr, 2> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
323 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
324
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
325 template <>
|
95
|
326 struct OperandTraits<GetElementPtrConstantExpr>
|
|
327 : public VariadicOperandTraits<GetElementPtrConstantExpr, 1> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
328
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
329 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
330
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
331 template <>
|
95
|
332 struct OperandTraits<CompareConstantExpr>
|
|
333 : public FixedNumOperandTraits<CompareConstantExpr, 2> {};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
334 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CompareConstantExpr, Value)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
335
|
77
|
336 template <class ConstantClass> struct ConstantAggrKeyType;
|
|
337 struct InlineAsmKeyType;
|
|
338 struct ConstantExprKeyType;
|
|
339
|
|
340 template <class ConstantClass> struct ConstantInfo;
|
|
341 template <> struct ConstantInfo<ConstantExpr> {
|
|
342 typedef ConstantExprKeyType ValType;
|
|
343 typedef Type TypeClass;
|
|
344 };
|
|
345 template <> struct ConstantInfo<InlineAsm> {
|
|
346 typedef InlineAsmKeyType ValType;
|
|
347 typedef PointerType TypeClass;
|
|
348 };
|
|
349 template <> struct ConstantInfo<ConstantArray> {
|
|
350 typedef ConstantAggrKeyType<ConstantArray> ValType;
|
|
351 typedef ArrayType TypeClass;
|
|
352 };
|
|
353 template <> struct ConstantInfo<ConstantStruct> {
|
|
354 typedef ConstantAggrKeyType<ConstantStruct> ValType;
|
|
355 typedef StructType TypeClass;
|
|
356 };
|
|
357 template <> struct ConstantInfo<ConstantVector> {
|
|
358 typedef ConstantAggrKeyType<ConstantVector> ValType;
|
|
359 typedef VectorType TypeClass;
|
|
360 };
|
|
361
|
|
362 template <class ConstantClass> struct ConstantAggrKeyType {
|
|
363 ArrayRef<Constant *> Operands;
|
|
364 ConstantAggrKeyType(ArrayRef<Constant *> Operands) : Operands(Operands) {}
|
|
365 ConstantAggrKeyType(ArrayRef<Constant *> Operands, const ConstantClass *)
|
|
366 : Operands(Operands) {}
|
|
367 ConstantAggrKeyType(const ConstantClass *C,
|
|
368 SmallVectorImpl<Constant *> &Storage) {
|
|
369 assert(Storage.empty() && "Expected empty storage");
|
|
370 for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I)
|
|
371 Storage.push_back(C->getOperand(I));
|
|
372 Operands = Storage;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
373 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
374
|
77
|
375 bool operator==(const ConstantAggrKeyType &X) const {
|
|
376 return Operands == X.Operands;
|
|
377 }
|
|
378 bool operator==(const ConstantClass *C) const {
|
|
379 if (Operands.size() != C->getNumOperands())
|
|
380 return false;
|
|
381 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
|
|
382 if (Operands[I] != C->getOperand(I))
|
|
383 return false;
|
|
384 return true;
|
|
385 }
|
|
386 unsigned getHash() const {
|
|
387 return hash_combine_range(Operands.begin(), Operands.end());
|
|
388 }
|
|
389
|
|
390 typedef typename ConstantInfo<ConstantClass>::TypeClass TypeClass;
|
|
391 ConstantClass *create(TypeClass *Ty) const {
|
|
392 return new (Operands.size()) ConstantClass(Ty, Operands);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
393 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
394 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
395
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
396 struct InlineAsmKeyType {
|
77
|
397 StringRef AsmString;
|
|
398 StringRef Constraints;
|
95
|
399 FunctionType *FTy;
|
77
|
400 bool HasSideEffects;
|
|
401 bool IsAlignStack;
|
|
402 InlineAsm::AsmDialect AsmDialect;
|
|
403
|
|
404 InlineAsmKeyType(StringRef AsmString, StringRef Constraints,
|
95
|
405 FunctionType *FTy, bool HasSideEffects, bool IsAlignStack,
|
77
|
406 InlineAsm::AsmDialect AsmDialect)
|
95
|
407 : AsmString(AsmString), Constraints(Constraints), FTy(FTy),
|
77
|
408 HasSideEffects(HasSideEffects), IsAlignStack(IsAlignStack),
|
|
409 AsmDialect(AsmDialect) {}
|
|
410 InlineAsmKeyType(const InlineAsm *Asm, SmallVectorImpl<Constant *> &)
|
|
411 : AsmString(Asm->getAsmString()), Constraints(Asm->getConstraintString()),
|
95
|
412 FTy(Asm->getFunctionType()), HasSideEffects(Asm->hasSideEffects()),
|
77
|
413 IsAlignStack(Asm->isAlignStack()), AsmDialect(Asm->getDialect()) {}
|
|
414
|
|
415 bool operator==(const InlineAsmKeyType &X) const {
|
|
416 return HasSideEffects == X.HasSideEffects &&
|
|
417 IsAlignStack == X.IsAlignStack && AsmDialect == X.AsmDialect &&
|
95
|
418 AsmString == X.AsmString && Constraints == X.Constraints &&
|
|
419 FTy == X.FTy;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
420 }
|
77
|
421 bool operator==(const InlineAsm *Asm) const {
|
|
422 return HasSideEffects == Asm->hasSideEffects() &&
|
|
423 IsAlignStack == Asm->isAlignStack() &&
|
|
424 AsmDialect == Asm->getDialect() &&
|
|
425 AsmString == Asm->getAsmString() &&
|
95
|
426 Constraints == Asm->getConstraintString() &&
|
|
427 FTy == Asm->getFunctionType();
|
77
|
428 }
|
|
429 unsigned getHash() const {
|
|
430 return hash_combine(AsmString, Constraints, HasSideEffects, IsAlignStack,
|
95
|
431 AsmDialect, FTy);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
432 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433
|
77
|
434 typedef ConstantInfo<InlineAsm>::TypeClass TypeClass;
|
|
435 InlineAsm *create(TypeClass *Ty) const {
|
95
|
436 assert(PointerType::getUnqual(FTy) == Ty);
|
|
437 return new InlineAsm(FTy, AsmString, Constraints, HasSideEffects,
|
77
|
438 IsAlignStack, AsmDialect);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
439 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
440 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
441
|
77
|
442 struct ConstantExprKeyType {
|
|
443 uint8_t Opcode;
|
|
444 uint8_t SubclassOptionalData;
|
|
445 uint16_t SubclassData;
|
|
446 ArrayRef<Constant *> Ops;
|
|
447 ArrayRef<unsigned> Indexes;
|
95
|
448 Type *ExplicitTy;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449
|
77
|
450 ConstantExprKeyType(unsigned Opcode, ArrayRef<Constant *> Ops,
|
|
451 unsigned short SubclassData = 0,
|
|
452 unsigned short SubclassOptionalData = 0,
|
95
|
453 ArrayRef<unsigned> Indexes = None,
|
|
454 Type *ExplicitTy = nullptr)
|
77
|
455 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData),
|
95
|
456 SubclassData(SubclassData), Ops(Ops), Indexes(Indexes),
|
|
457 ExplicitTy(ExplicitTy) {}
|
77
|
458 ConstantExprKeyType(ArrayRef<Constant *> Operands, const ConstantExpr *CE)
|
|
459 : Opcode(CE->getOpcode()),
|
|
460 SubclassOptionalData(CE->getRawSubclassOptionalData()),
|
|
461 SubclassData(CE->isCompare() ? CE->getPredicate() : 0), Ops(Operands),
|
|
462 Indexes(CE->hasIndices() ? CE->getIndices() : ArrayRef<unsigned>()) {}
|
|
463 ConstantExprKeyType(const ConstantExpr *CE,
|
|
464 SmallVectorImpl<Constant *> &Storage)
|
|
465 : Opcode(CE->getOpcode()),
|
|
466 SubclassOptionalData(CE->getRawSubclassOptionalData()),
|
|
467 SubclassData(CE->isCompare() ? CE->getPredicate() : 0),
|
|
468 Indexes(CE->hasIndices() ? CE->getIndices() : ArrayRef<unsigned>()) {
|
|
469 assert(Storage.empty() && "Expected empty storage");
|
|
470 for (unsigned I = 0, E = CE->getNumOperands(); I != E; ++I)
|
|
471 Storage.push_back(CE->getOperand(I));
|
|
472 Ops = Storage;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
473 }
|
77
|
474
|
|
475 bool operator==(const ConstantExprKeyType &X) const {
|
|
476 return Opcode == X.Opcode && SubclassData == X.SubclassData &&
|
|
477 SubclassOptionalData == X.SubclassOptionalData && Ops == X.Ops &&
|
|
478 Indexes == X.Indexes;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
479 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
480
|
77
|
481 bool operator==(const ConstantExpr *CE) const {
|
|
482 if (Opcode != CE->getOpcode())
|
|
483 return false;
|
|
484 if (SubclassOptionalData != CE->getRawSubclassOptionalData())
|
|
485 return false;
|
|
486 if (Ops.size() != CE->getNumOperands())
|
|
487 return false;
|
|
488 if (SubclassData != (CE->isCompare() ? CE->getPredicate() : 0))
|
|
489 return false;
|
|
490 for (unsigned I = 0, E = Ops.size(); I != E; ++I)
|
|
491 if (Ops[I] != CE->getOperand(I))
|
|
492 return false;
|
|
493 if (Indexes != (CE->hasIndices() ? CE->getIndices() : ArrayRef<unsigned>()))
|
|
494 return false;
|
|
495 return true;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
496 }
|
77
|
497
|
|
498 unsigned getHash() const {
|
|
499 return hash_combine(Opcode, SubclassOptionalData, SubclassData,
|
|
500 hash_combine_range(Ops.begin(), Ops.end()),
|
|
501 hash_combine_range(Indexes.begin(), Indexes.end()));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
502 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
503
|
77
|
504 typedef ConstantInfo<ConstantExpr>::TypeClass TypeClass;
|
|
505 ConstantExpr *create(TypeClass *Ty) const {
|
|
506 switch (Opcode) {
|
|
507 default:
|
|
508 if (Instruction::isCast(Opcode))
|
|
509 return new UnaryConstantExpr(Opcode, Ops[0], Ty);
|
|
510 if ((Opcode >= Instruction::BinaryOpsBegin &&
|
|
511 Opcode < Instruction::BinaryOpsEnd))
|
|
512 return new BinaryConstantExpr(Opcode, Ops[0], Ops[1],
|
|
513 SubclassOptionalData);
|
|
514 llvm_unreachable("Invalid ConstantExpr!");
|
|
515 case Instruction::Select:
|
|
516 return new SelectConstantExpr(Ops[0], Ops[1], Ops[2]);
|
|
517 case Instruction::ExtractElement:
|
|
518 return new ExtractElementConstantExpr(Ops[0], Ops[1]);
|
|
519 case Instruction::InsertElement:
|
|
520 return new InsertElementConstantExpr(Ops[0], Ops[1], Ops[2]);
|
|
521 case Instruction::ShuffleVector:
|
|
522 return new ShuffleVectorConstantExpr(Ops[0], Ops[1], Ops[2]);
|
|
523 case Instruction::InsertValue:
|
|
524 return new InsertValueConstantExpr(Ops[0], Ops[1], Indexes, Ty);
|
|
525 case Instruction::ExtractValue:
|
|
526 return new ExtractValueConstantExpr(Ops[0], Indexes, Ty);
|
|
527 case Instruction::GetElementPtr:
|
95
|
528 return GetElementPtrConstantExpr::Create(
|
|
529 ExplicitTy ? ExplicitTy
|
|
530 : cast<PointerType>(Ops[0]->getType()->getScalarType())
|
|
531 ->getElementType(),
|
|
532 Ops[0], Ops.slice(1), Ty, SubclassOptionalData);
|
77
|
533 case Instruction::ICmp:
|
|
534 return new CompareConstantExpr(Ty, Instruction::ICmp, SubclassData,
|
|
535 Ops[0], Ops[1]);
|
|
536 case Instruction::FCmp:
|
|
537 return new CompareConstantExpr(Ty, Instruction::FCmp, SubclassData,
|
|
538 Ops[0], Ops[1]);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
539 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
540 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
541 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
542
|
77
|
543 template <class ConstantClass> class ConstantUniqueMap {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
544 public:
|
77
|
545 typedef typename ConstantInfo<ConstantClass>::ValType ValType;
|
|
546 typedef typename ConstantInfo<ConstantClass>::TypeClass TypeClass;
|
|
547 typedef std::pair<TypeClass *, ValType> LookupKey;
|
|
548
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
549 private:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
550 struct MapInfo {
|
77
|
551 typedef DenseMapInfo<ConstantClass *> ConstantClassInfo;
|
|
552 static inline ConstantClass *getEmptyKey() {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
553 return ConstantClassInfo::getEmptyKey();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
554 }
|
77
|
555 static inline ConstantClass *getTombstoneKey() {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
556 return ConstantClassInfo::getTombstoneKey();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
557 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
558 static unsigned getHashValue(const ConstantClass *CP) {
|
77
|
559 SmallVector<Constant *, 8> Storage;
|
|
560 return getHashValue(LookupKey(CP->getType(), ValType(CP, Storage)));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
561 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
562 static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
563 return LHS == RHS;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
564 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
565 static unsigned getHashValue(const LookupKey &Val) {
|
77
|
566 return hash_combine(Val.first, Val.second.getHash());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
567 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
568 static bool isEqual(const LookupKey &LHS, const ConstantClass *RHS) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
569 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
570 return false;
|
77
|
571 if (LHS.first != RHS->getType())
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
572 return false;
|
77
|
573 return LHS.second == RHS;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
574 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
575 };
|
77
|
576
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
577 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
578 typedef DenseMap<ConstantClass *, char, MapInfo> MapTy;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
579
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
580 private:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
581 MapTy Map;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
582
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
583 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
584 typename MapTy::iterator map_begin() { return Map.begin(); }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
585 typename MapTy::iterator map_end() { return Map.end(); }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
586
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
587 void freeConstants() {
|
77
|
588 for (auto &I : Map)
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
589 // Asserts that use_empty().
|
77
|
590 delete I.first;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
591 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
592
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
593 private:
|
77
|
594 ConstantClass *create(TypeClass *Ty, ValType V) {
|
|
595 ConstantClass *Result = V.create(Ty);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
596
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
597 assert(Result->getType() == Ty && "Type specified is not correct!");
|
77
|
598 insert(Result);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
599
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
600 return Result;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
601 }
|
77
|
602
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
603 public:
|
77
|
604 /// Return the specified constant from the map, creating it if necessary.
|
|
605 ConstantClass *getOrCreate(TypeClass *Ty, ValType V) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
606 LookupKey Lookup(Ty, V);
|
77
|
607 ConstantClass *Result = nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
608
|
77
|
609 auto I = find(Lookup);
|
|
610 if (I == Map.end())
|
|
611 Result = create(Ty, V);
|
|
612 else
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
613 Result = I->first;
|
77
|
614 assert(Result && "Unexpected nullptr");
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
615
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
616 return Result;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
617 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
618
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
619 /// Find the constant by lookup key.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
620 typename MapTy::iterator find(LookupKey Lookup) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
621 return Map.find_as(Lookup);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
622 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
623
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
624 /// Insert the constant into its proper slot.
|
77
|
625 void insert(ConstantClass *CP) { Map[CP] = '\0'; }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
626
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
627 /// Remove this constant from the map
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
628 void remove(ConstantClass *CP) {
|
77
|
629 typename MapTy::iterator I = Map.find(CP);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
630 assert(I != Map.end() && "Constant not found in constant table!");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
631 assert(I->first == CP && "Didn't find correct element?");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
632 Map.erase(I);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
633 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
634
|
77
|
635 ConstantClass *replaceOperandsInPlace(ArrayRef<Constant *> Operands,
|
|
636 ConstantClass *CP, Value *From,
|
|
637 Constant *To, unsigned NumUpdated = 0,
|
|
638 unsigned OperandNo = ~0u) {
|
|
639 LookupKey Lookup(CP->getType(), ValType(Operands, CP));
|
|
640 auto I = find(Lookup);
|
|
641 if (I != Map.end())
|
|
642 return I->first;
|
|
643
|
|
644 // Update to the new value. Optimize for the case when we have a single
|
|
645 // operand that we're changing, but handle bulk updates efficiently.
|
|
646 remove(CP);
|
|
647 if (NumUpdated == 1) {
|
|
648 assert(OperandNo < CP->getNumOperands() && "Invalid index");
|
|
649 assert(CP->getOperand(OperandNo) != To && "I didn't contain From!");
|
|
650 CP->setOperand(OperandNo, To);
|
|
651 } else {
|
|
652 for (unsigned I = 0, E = CP->getNumOperands(); I != E; ++I)
|
|
653 if (CP->getOperand(I) == From)
|
|
654 CP->setOperand(I, To);
|
|
655 }
|
|
656 insert(CP);
|
|
657 return nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
658 }
|
77
|
659
|
|
660 void dump() const { DEBUG(dbgs() << "Constant.cpp: ConstantUniqueMap\n"); }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
661 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
662
|
77
|
663 } // end namespace llvm
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
664
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
665 #endif
|