LLVM: include/llvm/Transforms/Scalar/GVNExpression.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
17#define LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
18
30#include
31#include
32#include
33#include
34
35namespace llvm {
36
39
41
59
61private:
63 unsigned Opcode;
65
66public:
68 : EType(ET), Opcode(O) {}
72
75
79 return false;
81 return true;
82
83
86 return false;
87
89 }
90
92
93
94
95 if (static_cast<unsigned>(HashVal) == 0)
97 return HashVal;
98 }
99
101
102
103
107
108 unsigned getOpcode() const { return Opcode; }
109 void setOpcode(unsigned opcode) { Opcode = opcode; }
111
112
114
115
117 if (PrintEType)
119 OS << "opcode = " << getOpcode() << ", ";
120 }
121
123 OS << "{ ";
125 OS << "}";
126 }
127
129};
130
132 E.print(OS);
133 return OS;
134}
135
137private:
139 using RecyclerCapacity = RecyclerType::Capacity;
140
141 Value **Operands = nullptr;
142 unsigned MaxOperands;
143 unsigned NumOperands = 0;
144 Type *ValueType = nullptr;
145
146public:
155
160
161
162
166
168 assert(Operands && "Operands not allocated");
169 assert(N < NumOperands && "Operand out of range");
170 return Operands[N];
171 }
172
174 assert(Operands && "Operands not allocated before setting");
175 assert(N < NumOperands && "Operand out of range");
176 Operands[N] = V;
177 }
178
180
183
194
196 assert(NumOperands < MaxOperands && "Tried to add too many operands");
197 assert(Operands && "Operandss not allocated before pushing");
198 Operands[NumOperands++] = Arg;
199 }
201
203 assert(!Operands && "Operands already allocated");
205 }
209
212
215 return false;
216
218 return getType() == OE.getType() && NumOperands == OE.NumOperands &&
220 }
221
226
227
229 if (PrintEType)
230 OS << "ExpressionTypeBasic, ";
231
233 OS << "operands = {";
234 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
235 OS << "[" << i << "] = ";
236 Operands[i]->printAsOperand(OS);
237 OS << " ";
238 }
239 OS << "} ";
240 }
241};
242
244private:
246
247 Container *BE;
248
249public:
255
258
260 BE->op_push_back(val);
261 return *this;
262 }
266};
267
269private:
271
272public:
279
284
288
291 return false;
293
294 return MemoryLeader == OtherMCE.MemoryLeader;
295 }
296
299};
300
302private:
304
305public:
313
317
323
324
326 if (PrintEType)
327 OS << "ExpressionTypeCall, ";
329 OS << " represents call at ";
330 Call->printAsOperand(OS);
331 }
332};
333
335private:
337
338public:
342
346
351
355
358
364
365
367 if (PrintEType)
368 OS << "ExpressionTypeLoad, ";
370 OS << " represents Load at ";
371 Load->printAsOperand(OS);
373 }
374};
375
377private:
379 Value *StoredValue;
380
381public:
385 StoredValue(StoredValue) {}
390
394
397
399
404
405
407 if (PrintEType)
408 OS << "ExpressionTypeStore, ";
410 OS << " represents Store " << *Store;
411 OS << " with StoredValue ";
412 StoredValue->printAsOperand(OS);
414 }
415};
416
418private:
419 unsigned MaxIntOperands;
420 unsigned NumIntOperands = 0;
421 unsigned *IntOperands = nullptr;
422
423public:
426 MaxIntOperands(NumIntOperands) {}
432
436
439
444 return IntOperands + NumIntOperands;
445 }
446 unsigned int_op_size() const { return NumIntOperands; }
447 bool int_op_empty() const { return NumIntOperands == 0; }
449 assert(NumIntOperands < MaxIntOperands &&
450 "Tried to add too many int operands");
451 assert(IntOperands && "Operands not allocated before pushing");
452 IntOperands[NumIntOperands++] = IntOperand;
453 }
454
456 assert(!IntOperands && "Operands already allocated");
457 IntOperands = Allocator.Allocate<unsigned>(MaxIntOperands);
458 }
459
462 return false;
464 return NumIntOperands == OE.NumIntOperands &&
466 }
467
472
473
475 if (PrintEType)
476 OS << "ExpressionTypeAggregateValue, ";
478 OS << ", intoperands = {";
479 for (unsigned i = 0, e = int_op_size(); i != e; ++i) {
480 OS << "[" << i << "] = " << IntOperands[i] << " ";
481 }
482 OS << "}";
483 }
484};
485
487private:
489
490 Container *AVE;
491
492public:
498
501
503 AVE->int_op_push_back(val);
504 return *this;
505 }
509};
510
512private:
514
515public:
522
526
529 return false;
531 return BB == OE.BB;
532 }
533
537
538
540 if (PrintEType)
541 OS << "ExpressionTypePhi, ";
543 OS << "bb = " << BB;
544 }
545};
546
548public:
552
554 return E->getExpressionType() == ET_Dead;
555 }
556};
557
559private:
560 Value *VariableValue;
561
562public:
567
571
574
577 return VariableValue == OC.VariableValue;
578 }
579
582 VariableValue->getType(), VariableValue);
583 }
584
585
587 if (PrintEType)
588 OS << "ExpressionTypeVariable, ";
590 OS << " variable = " << *VariableValue;
591 }
592};
593
595private:
596 Constant *ConstantValue = nullptr;
597
598public:
604
608
611
614 return ConstantValue == OC.ConstantValue;
615 }
616
619 ConstantValue->getType(), ConstantValue);
620 }
621
622
624 if (PrintEType)
625 OS << "ExpressionTypeConstant, ";
627 OS << " constant = " << *ConstantValue;
628 }
629};
630
632private:
634
635public:
640
644
647
650 return Inst == OU.Inst;
651 }
652
656
657
659 if (PrintEType)
660 OS << "ExpressionTypeUnknown, ";
662 OS << " inst = " << *Inst;
663 }
664};
665
666}
667
668}
669
670#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
static Capacity get(size_t N)
Recycle small arrays allocated from a BumpPtrAllocator.
LLVM Basic Block Representation.
This class represents a function call, abstracting a target machine's calling convention.
This is an important base class in LLVM.
Definition GVNExpression.h:417
unsigned * int_arg_iterator
Definition GVNExpression.h:437
int_arg_iterator int_op_begin()
Definition GVNExpression.h:440
~AggregateValueExpression() override
AggregateValueExpression()=delete
unsigned int_op_size() const
Definition GVNExpression.h:446
static bool classof(const Expression *EB)
Definition GVNExpression.h:433
AggregateValueExpression(const AggregateValueExpression &)=delete
bool equals(const Expression &Other) const override
Definition GVNExpression.h:460
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:474
bool int_op_empty() const
Definition GVNExpression.h:447
AggregateValueExpression(unsigned NumOperands, unsigned NumIntOperands)
Definition GVNExpression.h:424
void allocateIntOperands(BumpPtrAllocator &Allocator)
Definition GVNExpression.h:455
void int_op_push_back(unsigned IntOperand)
Definition GVNExpression.h:448
const unsigned * const_int_arg_iterator
Definition GVNExpression.h:438
const_int_arg_iterator int_op_begin() const
Definition GVNExpression.h:442
hash_code getHashValue() const override
Definition GVNExpression.h:468
int_arg_iterator int_op_end()
Definition GVNExpression.h:441
AggregateValueExpression & operator=(const AggregateValueExpression &)=delete
const_int_arg_iterator int_op_end() const
Definition GVNExpression.h:443
Definition GVNExpression.h:136
BasicExpression(unsigned NumOperands)
Definition GVNExpression.h:147
op_iterator op_begin()
Definition GVNExpression.h:184
void allocateOperands(RecyclerType &Recycler, BumpPtrAllocator &Allocator)
Definition GVNExpression.h:202
bool op_empty() const
Definition GVNExpression.h:200
iterator_range< const_op_iterator > operands() const
Definition GVNExpression.h:191
const_op_iterator op_begin() const
Definition GVNExpression.h:186
Value *const * const_op_iterator
Definition GVNExpression.h:182
bool equals(const Expression &Other) const override
Definition GVNExpression.h:213
const_op_iterator op_end() const
Definition GVNExpression.h:187
void op_push_back(Value *Arg)
Definition GVNExpression.h:195
BasicExpression(unsigned NumOperands, ExpressionType ET)
Definition GVNExpression.h:149
BasicExpression & operator=(const BasicExpression &)=delete
op_iterator op_end()
Definition GVNExpression.h:185
Value ** op_iterator
Definition GVNExpression.h:181
hash_code getHashValue() const override
Definition GVNExpression.h:222
void deallocateOperands(RecyclerType &Recycler)
Definition GVNExpression.h:206
iterator_range< op_iterator > operands()
Definition GVNExpression.h:188
void setType(Type *T)
Definition GVNExpression.h:210
void setOperand(unsigned N, Value *V)
Definition GVNExpression.h:173
void swapOperands(unsigned First, unsigned Second)
Swap two operands.
Definition GVNExpression.h:163
Type * getType() const
Definition GVNExpression.h:211
BasicExpression(const BasicExpression &)=delete
static bool classof(const Expression *EB)
Definition GVNExpression.h:156
Value * getOperand(unsigned N) const
Definition GVNExpression.h:167
unsigned getNumOperands() const
Definition GVNExpression.h:179
~BasicExpression() override
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:228
CallExpression(const CallExpression &)=delete
bool equals(const Expression &Other) const override
CallExpression & operator=(const CallExpression &)=delete
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:325
~CallExpression() override
static bool classof(const Expression *EB)
Definition GVNExpression.h:314
CallExpression(unsigned NumOperands, CallInst *C, const MemoryAccess *MemoryLeader)
Definition GVNExpression.h:306
bool exactlyEquals(const Expression &Other) const override
Definition GVNExpression.h:319
hash_code getHashValue() const override
Definition GVNExpression.h:617
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:623
static bool classof(const Expression *EB)
Definition GVNExpression.h:605
ConstantExpression & operator=(const ConstantExpression &)=delete
ConstantExpression(const ConstantExpression &)=delete
void setConstantValue(Constant *V)
Definition GVNExpression.h:610
ConstantExpression()
Definition GVNExpression.h:599
Constant * getConstantValue() const
Definition GVNExpression.h:609
bool equals(const Expression &Other) const override
Definition GVNExpression.h:612
ConstantExpression(Constant *constantValue)
Definition GVNExpression.h:600
static bool classof(const Expression *E)
Definition GVNExpression.h:553
DeadExpression(const DeadExpression &)=delete
DeadExpression & operator=(const DeadExpression &)=delete
DeadExpression()
Definition GVNExpression.h:549
Definition GVNExpression.h:60
bool operator==(const Expression &Other) const
Definition GVNExpression.h:77
virtual hash_code getHashValue() const
Definition GVNExpression.h:113
Expression & operator=(const Expression &)=delete
virtual bool exactlyEquals(const Expression &Other) const
Definition GVNExpression.h:104
static unsigned getEmptyKey()
Definition GVNExpression.h:73
Expression(const Expression &)=delete
Expression(ExpressionType ET=ET_Base, unsigned O=~2U)
Definition GVNExpression.h:67
bool operator!=(const Expression &Other) const
Definition GVNExpression.h:76
unsigned getOpcode() const
Definition GVNExpression.h:108
ExpressionType getExpressionType() const
Definition GVNExpression.h:110
static unsigned getTombstoneKey()
Definition GVNExpression.h:74
virtual void printInternal(raw_ostream &OS, bool PrintEType) const
Definition GVNExpression.h:116
hash_code getComputedHash() const
Definition GVNExpression.h:91
LLVM_DUMP_METHOD void dump() const
virtual bool equals(const Expression &Other) const
Definition GVNExpression.h:100
void setOpcode(unsigned opcode)
Definition GVNExpression.h:109
void print(raw_ostream &OS) const
Definition GVNExpression.h:122
LoadExpression(const LoadExpression &)=delete
LoadExpression(enum ExpressionType EType, unsigned NumOperands, LoadInst *L, const MemoryAccess *MemoryLeader)
Definition GVNExpression.h:343
static bool classof(const Expression *EB)
Definition GVNExpression.h:352
void setLoadInst(LoadInst *L)
Definition GVNExpression.h:357
bool equals(const Expression &Other) const override
LoadInst * getLoadInst() const
Definition GVNExpression.h:356
~LoadExpression() override
LoadExpression & operator=(const LoadExpression &)=delete
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:366
bool exactlyEquals(const Expression &Other) const override
Definition GVNExpression.h:360
LoadExpression(unsigned NumOperands, LoadInst *L, const MemoryAccess *MemoryLeader)
Definition GVNExpression.h:339
void setMemoryLeader(const MemoryAccess *ML)
Definition GVNExpression.h:298
static bool classof(const Expression *EB)
Definition GVNExpression.h:280
MemoryExpression()=delete
hash_code getHashValue() const override
Definition GVNExpression.h:285
MemoryExpression & operator=(const MemoryExpression &)=delete
MemoryExpression(const MemoryExpression &)=delete
MemoryExpression(unsigned NumOperands, enum ExpressionType EType, const MemoryAccess *MemoryLeader)
Definition GVNExpression.h:273
bool equals(const Expression &Other) const override
Definition GVNExpression.h:289
const MemoryAccess * getMemoryLeader() const
Definition GVNExpression.h:297
PHIExpression(const PHIExpression &)=delete
bool equals(const Expression &Other) const override
Definition GVNExpression.h:527
PHIExpression & operator=(const PHIExpression &)=delete
PHIExpression(unsigned NumOperands, BasicBlock *B)
Definition GVNExpression.h:516
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:539
hash_code getHashValue() const override
Definition GVNExpression.h:534
~PHIExpression() override
static bool classof(const Expression *EB)
Definition GVNExpression.h:523
StoreExpression(unsigned NumOperands, StoreInst *S, Value *StoredValue, const MemoryAccess *MemoryLeader)
Definition GVNExpression.h:382
StoreExpression(const StoreExpression &)=delete
bool exactlyEquals(const Expression &Other) const override
Definition GVNExpression.h:400
bool equals(const Expression &Other) const override
StoreExpression & operator=(const StoreExpression &)=delete
static bool classof(const Expression *EB)
Definition GVNExpression.h:391
~StoreExpression() override
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:406
StoreInst * getStoreInst() const
Definition GVNExpression.h:395
Value * getStoredValue() const
Definition GVNExpression.h:396
hash_code getHashValue() const override
Definition GVNExpression.h:653
UnknownExpression(const UnknownExpression &)=delete
bool equals(const Expression &Other) const override
Definition GVNExpression.h:648
void setInstruction(Instruction *I)
Definition GVNExpression.h:646
static bool classof(const Expression *EB)
Definition GVNExpression.h:641
UnknownExpression & operator=(const UnknownExpression &)=delete
UnknownExpression(Instruction *I)
Definition GVNExpression.h:636
UnknownExpression()=delete
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:658
Instruction * getInstruction() const
Definition GVNExpression.h:645
VariableExpression & operator=(const VariableExpression &)=delete
bool equals(const Expression &Other) const override
Definition GVNExpression.h:575
static bool classof(const Expression *EB)
Definition GVNExpression.h:568
void setVariableValue(Value *V)
Definition GVNExpression.h:573
VariableExpression(const VariableExpression &)=delete
Value * getVariableValue() const
Definition GVNExpression.h:572
VariableExpression(Value *V)
Definition GVNExpression.h:563
VariableExpression()=delete
void printInternal(raw_ostream &OS, bool PrintEType) const override
Definition GVNExpression.h:586
hash_code getHashValue() const override
Definition GVNExpression.h:580
int_op_inserter & operator=(unsigned int val)
Definition GVNExpression.h:502
int_op_inserter & operator++(int)
Definition GVNExpression.h:508
void reference
Definition GVNExpression.h:497
void difference_type
Definition GVNExpression.h:495
std::output_iterator_tag iterator_category
Definition GVNExpression.h:493
int_op_inserter(AggregateValueExpression &E)
Definition GVNExpression.h:499
int_op_inserter & operator++()
Definition GVNExpression.h:507
void pointer
Definition GVNExpression.h:496
int_op_inserter(AggregateValueExpression *E)
Definition GVNExpression.h:500
void value_type
Definition GVNExpression.h:494
int_op_inserter & operator*()
Definition GVNExpression.h:506
op_inserter(BasicExpression &E)
Definition GVNExpression.h:256
void difference_type
Definition GVNExpression.h:252
op_inserter & operator++()
Definition GVNExpression.h:264
op_inserter(BasicExpression *E)
Definition GVNExpression.h:257
std::output_iterator_tag iterator_category
Definition GVNExpression.h:250
op_inserter & operator=(Value *val)
Definition GVNExpression.h:259
void reference
Definition GVNExpression.h:254
void value_type
Definition GVNExpression.h:251
void pointer
Definition GVNExpression.h:253
op_inserter & operator++(int)
Definition GVNExpression.h:265
op_inserter & operator*()
Definition GVNExpression.h:263
An instruction for reading from memory.
Recycler - This class manages a linked-list of deallocated nodes and facilitates reusing deallocated ...
An instruction for storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
An opaque object representing a hash code.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
Definition GVNExpression.h:40
ExpressionType
Definition GVNExpression.h:42
@ ET_MemoryStart
Definition GVNExpression.h:52
@ ET_BasicEnd
Definition GVNExpression.h:57
@ ET_Unknown
Definition GVNExpression.h:47
@ ET_Store
Definition GVNExpression.h:55
@ ET_Base
Definition GVNExpression.h:43
@ ET_MemoryEnd
Definition GVNExpression.h:56
@ ET_AggregateValue
Definition GVNExpression.h:50
@ ET_BasicStart
Definition GVNExpression.h:48
@ ET_Phi
Definition GVNExpression.h:51
@ ET_Dead
Definition GVNExpression.h:46
@ ET_Load
Definition GVNExpression.h:54
@ ET_Basic
Definition GVNExpression.h:49
@ ET_Variable
Definition GVNExpression.h:45
@ ET_Call
Definition GVNExpression.h:53
@ ET_Constant
Definition GVNExpression.h:44
raw_ostream & operator<<(raw_ostream &OS, const Expression &E)
Definition GVNExpression.h:131
This is an optimization pass for GlobalISel generic memory operations.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.