16 #ifndef LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
17 #define LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
37 namespace GVNExpression {
65 : EType(ET), Opcode(O), HashVal(0) {}
90 if (static_cast<unsigned>(HashVal) == 0)
115 OS <<
"opcode = " <<
getOpcode() <<
", ";
137 unsigned MaxOperands;
138 unsigned NumOperands;
145 :
Expression(ET), Operands(nullptr), MaxOperands(NumOperands),
160 std::swap(Operands[First], Operands[Second]);
164 assert(Operands &&
"Operands not allocated");
165 assert(N < NumOperands &&
"Operand out of range");
170 assert(Operands &&
"Operands not allocated before setting");
171 assert(N < NumOperands &&
"Operand out of range");
191 assert(NumOperands < MaxOperands &&
"Tried to add too many operands");
192 assert(Operands &&
"Operandss not allocated before pushing");
193 Operands[NumOperands++] = Arg;
198 assert(!Operands &&
"Operands already allocated");
212 const auto &OE = cast<BasicExpression>(Other);
213 return getType() == OE.getType() && NumOperands == OE.NumOperands &&
227 OS <<
"ExpressionTypeBasic, ";
230 OS <<
"operands = {";
232 OS <<
"[" << i <<
"] = ";
241 :
public std::iterator<std::output_iterator_tag, void, void, void, void> {
284 return MemoryLeader == OtherMCE.MemoryLeader;
313 OS <<
"ExpressionTypeCall, ";
315 OS <<
" represents call at ";
360 OS <<
"ExpressionTypeLoad, ";
362 OS <<
" represents Load at ";
377 StoredValue(StoredValue) {}
400 OS <<
"ExpressionTypeStore, ";
402 OS <<
" represents Store " << *Store;
403 OS <<
" with StoredValue ";
411 unsigned MaxIntOperands;
412 unsigned NumIntOperands;
413 unsigned *IntOperands;
418 MaxIntOperands(NumIntOperands), NumIntOperands(0),
419 IntOperands(nullptr) {}
437 return IntOperands + NumIntOperands;
442 assert(NumIntOperands < MaxIntOperands &&
443 "Tried to add too many int operands");
444 assert(IntOperands &&
"Operands not allocated before pushing");
445 IntOperands[NumIntOperands++] = IntOperand;
449 assert(!IntOperands &&
"Operands already allocated");
450 IntOperands = Allocator.
Allocate<
unsigned>(MaxIntOperands);
457 return NumIntOperands == OE.NumIntOperands &&
471 OS <<
"ExpressionTypeAggregateValue, ";
473 OS <<
", intoperands = {";
474 for (
unsigned i = 0, e =
int_op_size(); i != e; ++i) {
475 OS <<
"[" << i <<
"] = " << IntOperands[i] <<
" ";
482 :
public std::iterator<std::output_iterator_tag, void, void, void, void> {
532 OS <<
"ExpressionTypePhi, ";
551 Value *VariableValue;
568 return VariableValue == OC.VariableValue;
573 VariableValue->
getType(), VariableValue);
581 OS <<
"ExpressionTypeVariable, ";
583 OS <<
" variable = " << *VariableValue;
607 return ConstantValue == OC.ConstantValue;
612 ConstantValue->
getType(), ConstantValue);
620 OS <<
"ExpressionTypeConstant, ";
622 OS <<
" constant = " << *ConstantValue;
644 const auto &OU = cast<UnknownExpression>(Other);
645 return Inst == OU.Inst;
657 OS <<
"ExpressionTypeUnknown, ";
659 OS <<
" inst = " << *Inst;
667 #endif // LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
Value *const * const_op_iterator
bool equals(const Expression &Other) const override
~BasicExpression() override
void printInternal(raw_ostream &OS, bool PrintEType) const override
UnknownExpression(Instruction *I)
hash_code getHashValue() const override
int_op_inserter & operator++(int)
op_inserter & operator=(Value *val)
PHIExpression(unsigned NumOperands, BasicBlock *B)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
T * allocate(Capacity Cap, AllocatorType &Allocator)
Allocate an array of at least the requested capacity.
int_op_inserter & operator=(unsigned int val)
StoreExpression & operator=(const StoreExpression &)=delete
static bool classof(const Expression *E)
bool equals(const Expression &Other) const override
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
This class represents a function call, abstracting a target machine's calling convention.
BasicExpression(unsigned NumOperands, ExpressionType ET)
UnknownExpression & operator=(const UnknownExpression &)=delete
hash_code getHashValue() const override
void setConstantValue(Constant *V)
bool exactlyEquals(const Expression &Other) const override
Recycle small arrays allocated from a BumpPtrAllocator.
bool equals(const Expression &Other) const override
op_inserter & operator++()
An instruction for reading from memory.
LLVM_DUMP_METHOD void dump() const
hash_code getComputedHash() const
virtual hash_code getHashValue() const
AggregateValueExpression(unsigned NumOperands, unsigned NumIntOperands)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
bool operator!=(const Expression &Other) const
unsigned getOpcode() const
MemoryExpression(unsigned NumOperands, enum ExpressionType EType, const MemoryAccess *MemoryLeader)
bool equals(const Expression &Other) const override
The size of an allocated array is represented by a Capacity instance.
~AggregateValueExpression() override
bool equals(const Expression &Other) const override
int_arg_iterator int_op_begin()
void printInternal(raw_ostream &OS, bool PrintEType) const override
AggregateValueExpression()=delete
StoreInst * getStoreInst() const
ExpressionType getExpressionType() const
raw_ostream & operator<<(raw_ostream &OS, const Expression &E)
void printInternal(raw_ostream &OS, bool PrintEType) const override
int_arg_iterator int_op_end()
Expression & operator=(const Expression &)=delete
virtual bool exactlyEquals(const Expression &Other) const
bool equals(const Expression &Other) const override
int_op_inserter(AggregateValueExpression *E)
void swapOperands(unsigned First, unsigned Second)
Swap two operands.
AggregateValueExpression & operator=(const AggregateValueExpression &)=delete
void printInternal(raw_ostream &OS, bool PrintEType) const override
DeadExpression & operator=(const DeadExpression &)=delete
const_int_arg_iterator int_op_begin() const
static unsigned getEmptyKey()
op_inserter & operator++(int)
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
iterator_range< const_op_iterator > operands() const
const_op_iterator op_begin() const
void setMemoryLeader(const MemoryAccess *ML)
An instruction for storing to memory.
const MemoryAccess * getMemoryLeader() const
void print(raw_ostream &OS) const
StoreExpression(unsigned NumOperands, StoreInst *S, Value *StoredValue, const MemoryAccess *MemoryLeader)
void printInternal(raw_ostream &OS, bool PrintEType) const override
const_int_arg_iterator int_op_end() const
int_op_inserter(AggregateValueExpression &E)
ConstantExpression & operator=(const ConstantExpression &)=delete
static bool classof(const Expression *EB)
LoadExpression(unsigned NumOperands, LoadInst *L, const MemoryAccess *MemoryLeader)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
const_op_iterator op_end() const
Allocate memory in an ever growing pool, as if by bump-pointer.
unsigned int_op_size() const
This is an important base class in LLVM.
unsigned * int_arg_iterator
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
UnknownExpression()=delete
Instruction * getInstruction() const
bool operator==(const Expression &Other) const
static unsigned getTombstoneKey()
CallExpression(unsigned NumOperands, CallInst *C, const MemoryAccess *MemoryLeader)
Constant * getConstantValue() const
hash_code getHashValue() const override
CallExpression & operator=(const CallExpression &)=delete
void printInternal(raw_ostream &OS, bool PrintEType) const override
op_inserter(BasicExpression *E)
static bool classof(const Expression *EB)
hash_code getHashValue() const override
Value * getStoredValue() const
void setOperand(unsigned N, Value *V)
void setOpcode(unsigned opcode)
static bool classof(const Expression *EB)
Recycler - This class manages a linked-list of deallocated nodes and facilitates reusing deallocated ...
static Capacity get(size_t N)
Get the capacity of an array that can hold at least N elements.
Type * getType() const
All values are typed, get the type of this value.
void int_op_push_back(unsigned IntOperand)
Expression(ExpressionType ET=ET_Base, unsigned O=~2U)
virtual bool equals(const Expression &Other) const
int_op_inserter & operator++()
static bool classof(const Expression *EB)
unsigned getAlignment() const
bool exactlyEquals(const Expression &Other) const override
LoadInst * getLoadInst() const
void printInternal(raw_ostream &OS, bool PrintEType) const override
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A range adaptor for a pair of iterators.
void setInstruction(Instruction *I)
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static bool classof(const Expression *EB)
unsigned getNumOperands() const
ConstantExpression(Constant *constantValue)
MemoryExpression & operator=(const MemoryExpression &)=delete
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
An opaque object representing a hash code.
VariableExpression(Value *V)
const unsigned * const_int_arg_iterator
LoadExpression(enum ExpressionType EType, unsigned NumOperands, LoadInst *L, const MemoryAccess *MemoryLeader)
static bool classof(const Expression *EB)
hash_code getHashValue() const override
bool equals(const Expression &Other) const override
op_inserter(BasicExpression &E)
static bool classof(const Expression *EB)
VariableExpression()=delete
bool int_op_empty() const
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Value * getVariableValue() const
void printInternal(raw_ostream &OS, bool PrintEType) const override
static bool classof(const Expression *EB)
Value * getOperand(unsigned N) const
~LoadExpression() override
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
~CallExpression() override
bool equals(const Expression &Other) const override
op_inserter & operator*()
PHIExpression & operator=(const PHIExpression &)=delete
BasicExpression(unsigned NumOperands)
~StoreExpression() override
iterator_range< op_iterator > operands()
void setVariableValue(Value *V)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool classof(const Expression *EB)
bool equals(const Expression &Other) const override
LLVM Value Representation.
int_op_inserter & operator*()
~PHIExpression() override
static bool classof(const Expression *EB)
void printInternal(raw_ostream &OS, bool PrintEType) const override
VariableExpression & operator=(const VariableExpression &)=delete
virtual void printInternal(raw_ostream &OS, bool PrintEType) const
This class implements an extremely fast bulk output stream that can only output to a stream...
virtual void allocateIntOperands(BumpPtrAllocator &Allocator)
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
void deallocate(Capacity Cap, T *Ptr)
Deallocate an array with the specified Capacity.
MemoryExpression()=delete
LoadExpression & operator=(const LoadExpression &)=delete
hash_code getHashValue() const override
hash_code getHashValue() const override
void setLoadInst(LoadInst *L)
void op_push_back(Value *Arg)
void deallocateOperands(RecyclerType &Recycler)
BasicExpression & operator=(const BasicExpression &)=delete
void allocateOperands(RecyclerType &Recycler, BumpPtrAllocator &Allocator)
void setAlignment(unsigned Align)