LLVM 24.0.0git
GVNValueTable.h
Go to the documentation of this file.
1//===- GVNValueTable.h - Value table for GVN ------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file provides a data structure for mapping values and expressions to
11/// congruence class IDs.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_SCALAR_GVNVALUETABLE_H
16#define LLVM_TRANSFORMS_SCALAR_GVNVALUETABLE_H
17
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/IR/InstrTypes.h"
20
21namespace llvm {
22
23class AAResults;
24class BasicBlock;
25class CallInst;
26class DominatorTree;
28class GVNLeaderMap;
29class Instruction;
31class MemoryAccess;
33class MemorySSA;
34class PHINode;
35class Value;
36
37/// This class holds the mapping between values and value numbers. It is used
38/// as an efficient mechanism to determine the expression-wise equivalence of
39/// two values.
41public:
42 struct Expression;
43
44private:
45 DenseMap<Value *, uint32_t> ValueNumbering;
46 DenseMap<Expression, uint32_t> ExpressionNumbering;
47
48 // Expressions is the vector of Expression. ExprIdx is the mapping from
49 // value number to the index of Expression in Expressions. We use it
50 // instead of a DenseMap because filling such mapping is faster than
51 // filling a DenseMap and the compile time is a little better.
52 uint32_t NextExprNumber = 0;
53
54 std::vector<Expression> Expressions;
55 std::vector<uint32_t> ExprIdx;
56
57 // Value number to PHINode mapping. Used for phi-translate in scalarpre.
59
60 // Value number to BasicBlock mapping. Used for phi-translate across
61 // MemoryPhis.
63
64 // Cache for phi-translate in scalarpre.
65 using PhiTranslateMap =
67 PhiTranslateMap PhiTranslateTable;
68
69 AAResults *AA = nullptr;
70 MemoryDependenceResults *MD = nullptr;
71 bool IsMDEnabled = false;
72 MemorySSA *MSSA = nullptr;
73 bool IsMSSAEnabled = false;
74 DominatorTree *DT = nullptr;
75
76 uint32_t NextValueNumber = 1;
77
78 Expression createExpr(Instruction *I);
79 Expression createCmpExpr(unsigned Opcode, CmpInst::Predicate Predicate,
80 Value *LHS, Value *RHS);
81 Expression createExtractValueExpr(ExtractValueInst *EI);
82 Expression createGEPExpr(GetElementPtrInst *GEP);
83 uint32_t lookupOrAddCall(CallInst *C);
84 uint32_t computeLoadStoreVN(Instruction *I);
85 uint32_t phiTranslateImpl(const BasicBlock *BB, const BasicBlock *PhiBlock,
86 uint32_t Num, GVNLeaderMap &LeaderTable);
87 bool areCallValsEqual(uint32_t Num, uint32_t NewNum, const BasicBlock *Pred,
88 const BasicBlock *PhiBlock, GVNLeaderMap &LeaderTable);
89 std::pair<uint32_t, bool> assignExpNewValueNum(Expression &Exp);
90 bool areAllValsInBB(uint32_t Num, const BasicBlock *BB,
91 GVNLeaderMap &LeaderTable);
92 void addMemoryStateToExp(Instruction *I, Expression &Exp);
93
94public:
100
103 LLVM_ABI uint32_t lookup(Value *V, bool Verify = true) const;
105 Value *LHS, Value *RHS);
108 const BasicBlock *PhiBlock, uint32_t Num,
109 GVNLeaderMap &LeaderTable);
111 const BasicBlock &CurrBlock);
112 LLVM_ABI bool exists(Value *V) const;
113 LLVM_ABI void add(Value *V, uint32_t Num);
114 LLVM_ABI void clear();
115 LLVM_ABI void erase(Value *V);
116 void setAliasAnalysis(AAResults *A) { AA = A; }
117 AAResults *getAliasAnalysis() const { return AA; }
118 void setMemDep(MemoryDependenceResults *M, bool MDEnabled = true) {
119 MD = M;
120 IsMDEnabled = MDEnabled;
121 }
122 void setMemorySSA(MemorySSA *M, bool MSSAEnabled = false) {
123 MSSA = M;
124 IsMSSAEnabled = MSSAEnabled;
125 }
126 void setDomTree(DominatorTree *D) { DT = D; }
127 uint32_t getNextUnusedValueNumber() { return NextValueNumber; }
128 LLVM_ABI void verifyRemoved(const Value *) const;
129};
130
131} // namespace llvm
132#endif // LLVM_TRANSFORMS_SCALAR_GVNVALUETABLE_H
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
Hexagon Common GEP
#define I(x, y, z)
Definition MD5.cpp:57
ppc ctr loops PowerPC CTR Loops Verify
Value * RHS
Value * LHS
LLVM Basic Block Representation.
Definition BasicBlock.h:62
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
This instruction extracts a struct member or array element value from an aggregate value.
A mapping from value numbers to lists of Value*'s that have that value number.
Definition GVN.h:122
LLVM_ABI uint32_t lookupOrAddCmp(unsigned Opcode, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
Returns the value number of the given comparison, assigning it a new number if it did not have one be...
Definition GVN.cpp:756
LLVM_ABI void erase(Value *V)
Remove a value from the value numbering.
Definition GVN.cpp:785
LLVM_ABI uint32_t lookup(Value *V, bool Verify=true) const
Returns the value number of the specified value.
Definition GVN.cpp:743
LLVM_ABI void add(Value *V, uint32_t Num)
add - Insert a value into the table with a specified value number.
Definition GVN.cpp:464
LLVM_ABI void eraseTranslateCacheEntry(uint32_t Num, const BasicBlock &CurrBlock)
Erase stale entry from phiTranslate cache so phiTranslate can be computed again.
Definition GVN.cpp:3061
LLVM_ABI void verifyRemoved(const Value *) const
verifyRemoved - Verify that the value is removed from all internal data structures.
Definition GVN.cpp:797
void setAliasAnalysis(AAResults *A)
LLVM_ABI uint32_t phiTranslate(const BasicBlock *BB, const BasicBlock *PhiBlock, uint32_t Num, GVNLeaderMap &LeaderTable)
Wrap phiTranslateImpl to provide caching functionality.
Definition GVN.cpp:2929
LLVM_ABI GVNValueTable(const GVNValueTable &Arg)
LLVM_ABI GVNValueTable()
AAResults * getAliasAnalysis() const
LLVM_ABI uint32_t lookupOrAdd(MemoryAccess *MA)
Definition GVN.cpp:647
void setMemDep(MemoryDependenceResults *M, bool MDEnabled=true)
LLVM_ABI void clear()
Remove all entries from the ValueTable.
Definition GVN.cpp:772
LLVM_ABI bool exists(Value *V) const
Returns true if a value number exists for the specified value.
Definition GVN.cpp:643
LLVM_ABI GVNValueTable(GVNValueTable &&Arg)
uint32_t getNextUnusedValueNumber()
LLVM_ABI GVNValueTable & operator=(const GVNValueTable &Arg)
LLVM_ABI uint32_t lookupPtrToInt(Value *Ptr, Type *Ty)
Returns the value number of ptrtoint Ptr to \Ty.
Definition GVN.cpp:764
void setDomTree(DominatorTree *D)
LLVM_ABI ~GVNValueTable()
void setMemorySSA(MemorySSA *M, bool MSSAEnabled=false)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Provides a lazy, caching interface for making common memory aliasing information queries,...
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition MemorySSA.h:702
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.