16 #ifndef LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
17 #define LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
33 namespace GVNExpression {
58 : EType(ET), Opcode(O) {}
83 void setOpcode(
unsigned opcode) { Opcode = opcode; }
115 typedef RecyclerType::Capacity RecyclerCapacity;
117 unsigned MaxOperands;
118 unsigned NumOperands;
130 :
Expression(ET), Operands(nullptr), MaxOperands(NumOperands),
140 std::swap(Operands[First], Operands[Second]);
144 assert(Operands &&
"Operands not allocated");
145 assert(N < NumOperands &&
"Operand out of range");
150 assert(Operands &&
"Operands not allocated before setting");
151 assert(N < NumOperands &&
"Operand out of range");
171 assert(NumOperands < MaxOperands &&
"Tried to add too many operands");
172 assert(Operands &&
"Operandss not allocated before pushing");
173 Operands[NumOperands++] = Arg;
178 assert(!Operands &&
"Operands already allocated");
179 Operands = Recycler.
allocate(RecyclerCapacity::get(MaxOperands), Allocator);
182 Recycler.
deallocate(RecyclerCapacity::get(MaxOperands), Operands);
192 const auto &OE = cast<BasicExpression>(Other);
193 return getType() == OE.getType() && NumOperands == OE.NumOperands &&
207 OS <<
"ExpressionTypeBasic, ";
210 OS <<
"operands = {";
212 OS <<
"[" <<
i <<
"] = ";
220 :
public std::iterator<std::output_iterator_tag, void, void, void, void> {
258 const auto &OE = cast<CallExpression>(Other);
259 return DefiningAccess == OE.DefiningAccess;
271 OS <<
"ExpressionTypeCall, ";
273 OS <<
" represents call at " << Call;
320 OS <<
"ExpressionTypeLoad, ";
322 OS <<
" represents Load at " << Load;
323 OS <<
" with DefiningAccess " << *DefiningAccess;
359 OS <<
"ExpressionTypeStore, ";
361 OS <<
" represents Store at " << Store;
362 OS <<
" with DefiningAccess " << *DefiningAccess;
368 unsigned MaxIntOperands;
369 unsigned NumIntOperands;
370 unsigned *IntOperands;
379 MaxIntOperands(NumIntOperands), NumIntOperands(0),
380 IntOperands(nullptr) {}
394 return IntOperands + NumIntOperands;
399 assert(NumIntOperands < MaxIntOperands &&
400 "Tried to add too many int operands");
401 assert(IntOperands &&
"Operands not allocated before pushing");
402 IntOperands[NumIntOperands++] = IntOperand;
406 assert(!IntOperands &&
"Operands already allocated");
407 IntOperands = Allocator.
Allocate<
unsigned>(MaxIntOperands);
414 return NumIntOperands == OE.NumIntOperands &&
428 OS <<
"ExpressionTypeAggregateValue, ";
430 OS <<
", intoperands = {";
432 OS <<
"[" <<
i <<
"] = " << IntOperands[
i] <<
" ";
438 :
public std::iterator<std::output_iterator_tag, void, void, void, void> {
487 OS <<
"ExpressionTypePhi, ";
495 Value *VariableValue;
511 return VariableValue == OC.VariableValue;
524 OS <<
"ExpressionTypeVariable, ";
526 OS <<
" variable = " << *VariableValue;
550 return ConstantValue == OC.ConstantValue;
563 OS <<
"ExpressionTypeConstant, ";
565 OS <<
" constant = " << *ConstantValue;
586 const auto &OU = cast<UnknownExpression>(Other);
587 return Inst == OU.Inst;
597 OS <<
"ExpressionTypeUnknown, ";
599 OS <<
" inst = " << *Inst;
Value *const * const_op_iterator
void operator=(const LoadExpression &)=delete
virtual ~BasicExpression() override
UnknownExpression(Instruction *I)
int_op_inserter & operator++(int)
void operator=(const ConstantExpression &)=delete
virtual hash_code getHashValue() const override
op_inserter & operator=(Value *val)
PHIExpression(unsigned NumOperands, BasicBlock *B)
T * allocate(Capacity Cap, AllocatorType &Allocator)
Allocate an array of at least the requested capacity.
int_op_inserter & operator=(unsigned int val)
This class represents a function call, abstracting a target machine's calling convention.
BasicExpression(unsigned NumOperands, ExpressionType ET)
void setConstantValue(Constant *V)
virtual hash_code getHashValue() const override
void operator=(const CallExpression &)=delete
op_inserter & operator++()
An instruction for reading from memory.
virtual hash_code getHashValue() const
AggregateValueExpression(unsigned NumOperands, unsigned NumIntOperands)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
unsigned getOpcode() const
virtual ~AggregateValueExpression() override
int_arg_iterator int_op_begin()
AggregateValueExpression()=delete
MemoryAccess * getDefiningAccess() const
StoreInst * getStoreInst() const
ExpressionType getExpressionType() const
raw_ostream & operator<<(raw_ostream &OS, const Expression &E)
int_arg_iterator int_op_end()
virtual bool equals(const Expression &Other) const override
int_op_inserter(AggregateValueExpression *E)
void swapOperands(unsigned First, unsigned Second)
Swap two operands.
void operator=(const Expression &)=delete
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
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
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
An instruction for storing to memory.
void print(raw_ostream &OS) const
virtual hash_code getHashValue() const override
const_int_arg_iterator int_op_end() const
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
int_op_inserter(AggregateValueExpression &E)
void operator=(const BasicExpression &)=delete
MemoryAccess * getDefiningAccess() const
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
static bool classof(const Expression *EB)
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
void operator=(const VariableExpression &)=delete
Allocate memory in an ever growing pool, as if by bump-pointer.
unsigned int_op_size() const
LoadExpression(unsigned NumOperands, LoadInst *L, MemoryAccess *DA)
This is an important base class in LLVM.
void operator=(const StoreExpression &)=delete
unsigned * int_arg_iterator
virtual hash_code getHashValue() const override
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
UnknownExpression()=delete
LoadExpression(enum ExpressionType EType, unsigned NumOperands, LoadInst *L, MemoryAccess *DA)
Greedy Register Allocator
Instruction * getInstruction() const
void operator=(const AggregateValueExpression &)=delete
bool operator==(const Expression &Other) const
static unsigned getTombstoneKey()
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
virtual bool equals(const Expression &Other) const override
virtual bool equals(const Expression &Other) const override
Constant * getConstantValue() const
StoreExpression(unsigned NumOperands, StoreInst *S, MemoryAccess *DA)
op_inserter(BasicExpression *E)
static bool classof(const Expression *EB)
virtual bool equals(const Expression &Other) const override
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
void setOperand(unsigned N, Value *V)
void setOpcode(unsigned opcode)
void operator=(const UnknownExpression &)=delete
Recycler - This class manages a linked-list of deallocated nodes and facilitates reusing deallocated ...
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
void setDefiningAccess(MemoryAccess *MA)
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++()
virtual hash_code getHashValue() const override
virtual bool equals(const Expression &Other) const override
static bool classof(const Expression *EB)
unsigned getAlignment() const
LoadInst * getLoadInst() const
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
virtual hash_code getHashValue() const override
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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)
void operator=(const PHIExpression &)=delete
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)
virtual hash_code getHashValue() const override
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)
Expression(const Expression &)=delete
virtual bool equals(const Expression &Other) const override
const unsigned * const_int_arg_iterator
static bool classof(const Expression *EB)
op_inserter(BasicExpression &E)
static bool classof(const Expression *EB)
virtual bool equals(const Expression &Other) const override
VariableExpression()=delete
bool int_op_empty() const
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Value * getVariableValue() const
static bool classof(const Expression *EB)
Value * getOperand(unsigned N) const
virtual ~LoadExpression() override
virtual hash_code getHashValue() const override
virtual ~CallExpression() override
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
op_inserter & operator*()
virtual bool equals(const Expression &Other) const override
BasicExpression(unsigned NumOperands)
virtual ~StoreExpression() override
iterator_range< op_iterator > operands()
void setVariableValue(Value *V)
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
CallExpression(unsigned NumOperands, CallInst *C, MemoryAccess *DA)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool classof(const Expression *EB)
virtual bool equals(const Expression &Other) const override
virtual void printInternal(raw_ostream &OS, bool PrintEType) const override
LLVM Value Representation.
int_op_inserter & operator*()
virtual ~PHIExpression() override
static bool classof(const Expression *EB)
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)
void deallocate(Capacity Cap, T *Ptr)
Deallocate an array with the specified Capacity.
void setLoadInst(LoadInst *L)
virtual hash_code getHashValue() const override
void op_push_back(Value *Arg)
void deallocateOperands(RecyclerType &Recycler)
void allocateOperands(RecyclerType &Recycler, BumpPtrAllocator &Allocator)
void setAlignment(unsigned Align)