Go to the documentation of this file.
16 #include "llvm/Config/llvm-config.h"
25 if (isa<PHINode>(Inst) ||
26 isa<GetElementPtrInst>(Inst))
29 if (isa<CastInst>(Inst) &&
43 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
46 dbgs() <<
"PHITransAddr: null\n";
49 dbgs() <<
"PHITransAddr: " << *Addr <<
"\n";
50 for (
unsigned i = 0,
e = InstInputs.size();
i !=
e; ++
i)
51 dbgs() <<
" Input #" <<
i <<
" is " << *InstInputs[
i] <<
"\n";
65 if (Entry != InstInputs.end()) {
66 InstInputs.
erase(Entry);
73 errs() <<
"Instruction in PHITransAddr is not phi-translatable:\n";
76 "CanPHITrans is wrong.");
80 for (
unsigned i = 0,
e =
I->getNumOperands();
i !=
e; ++
i)
91 if (!Addr)
return true;
99 errs() <<
"PHITransAddr contains extra instructions:\n";
100 for (
unsigned i = 0,
e = InstInputs.size();
i !=
e; ++
i)
101 errs() <<
" InstInput #" <<
i <<
" is " << *InstInputs[
i] <<
"\n";
128 if (Entry != InstInputs.end()) {
129 InstInputs.
erase(Entry);
133 assert(!isa<PHINode>(
I) &&
"Error, removing something that isn't an input");
136 for (
unsigned i = 0,
e =
I->getNumOperands();
i !=
e; ++
i) {
164 InstInputs.erase(
find(InstInputs, Inst));
167 if (
PHINode *PN = dyn_cast<PHINode>(Inst))
168 return AddAsInput(PN->getIncomingValueForBlock(PredBB));
179 InstInputs.push_back(
Op);
186 if (
CastInst *Cast = dyn_cast<CastInst>(Inst)) {
188 Value *PHIIn = PHITranslateSubExpr(Cast->getOperand(0), CurBB, PredBB, DT);
189 if (!PHIIn)
return nullptr;
190 if (PHIIn == Cast->getOperand(0))
196 if (
Constant *
C = dyn_cast<Constant>(PHIIn))
198 C, Cast->getType()));
203 if (
CastInst *CastI = dyn_cast<CastInst>(U))
204 if (CastI->getOpcode() == Cast->getOpcode() &&
205 CastI->getType() == Cast->getType() &&
206 (!DT || DT->
dominates(CastI->getParent(), PredBB)))
215 bool AnyChanged =
false;
216 for (
unsigned i = 0,
e =
GEP->getNumOperands();
i !=
e; ++
i) {
217 Value *GEPOp = PHITranslateSubExpr(
GEP->getOperand(
i), CurBB, PredBB, DT);
218 if (!GEPOp)
return nullptr;
220 AnyChanged |= GEPOp !=
GEP->getOperand(
i);
221 GEPOps.push_back(GEPOp);
230 GEP->isInBounds(), {DL, TLI, DT, AC})) {
231 for (
unsigned i = 0,
e = GEPOps.size();
i !=
e; ++
i)
234 return AddAsInput(V);
238 Value *APHIOp = GEPOps[0];
241 if (GEPI->getType() ==
GEP->getType() &&
242 GEPI->getSourceElementType() ==
GEP->getSourceElementType() &&
243 GEPI->getNumOperands() == GEPOps.size() &&
244 GEPI->getParent()->getParent() == CurBB->
getParent() &&
245 (!DT || DT->
dominates(GEPI->getParent(), PredBB))) {
246 if (
std::equal(GEPOps.begin(), GEPOps.end(), GEPI->op_begin()))
258 bool isNSW = cast<BinaryOperator>(Inst)->hasNoSignedWrap();
259 bool isNUW = cast<BinaryOperator>(Inst)->hasNoUnsignedWrap();
262 if (!
LHS)
return nullptr;
267 if (
ConstantInt *CI = dyn_cast<ConstantInt>(BOp->getOperand(1))) {
268 LHS = BOp->getOperand(0);
270 isNSW = isNUW =
false;
284 return AddAsInput(Res);
295 BO->getOperand(0) ==
LHS && BO->getOperand(1) ==
RHS &&
296 BO->getParent()->getParent() == CurBB->
getParent() &&
297 (!DT || DT->
dominates(BO->getParent(), PredBB)))
316 assert(DT || !MustDominate);
320 PHITranslateSubExpr(Addr, CurBB, PredBB, MustDominate ? DT :
nullptr);
327 if (
Instruction *Inst = dyn_cast_or_null<Instruction>(Addr))
328 if (!DT->dominates(Inst->
getParent(), PredBB))
331 return Addr ==
nullptr;
345 unsigned NISize = NewInsts.size();
348 Addr = InsertPHITranslatedSubExpr(Addr, CurBB, PredBB, DT, NewInsts);
351 if (Addr)
return Addr;
354 while (NewInsts.size() != NISize)
365 Value *PHITransAddr::
372 if (!Tmp.PHITranslateValue(CurBB, PredBB, &DT,
true))
373 return Tmp.getAddr();
376 auto *Inst = dyn_cast<Instruction>(InVal);
381 if (
CastInst *Cast = dyn_cast<CastInst>(Inst)) {
383 Value *OpVal = InsertPHITranslatedSubExpr(Cast->getOperand(0),
384 CurBB, PredBB, DT, NewInsts);
385 if (!OpVal)
return nullptr;
389 InVal->
getName() +
".phi.trans.insert",
392 NewInsts.push_back(New);
400 for (
unsigned i = 0,
e =
GEP->getNumOperands();
i !=
e; ++
i) {
401 Value *OpVal = InsertPHITranslatedSubExpr(
GEP->getOperand(
i),
402 CurBB, PredBB, DT, NewInsts);
403 if (!OpVal)
return nullptr;
404 GEPOps.push_back(OpVal);
411 Result->setIsInBounds(
GEP->isInBounds());
412 NewInsts.push_back(Result);
426 CurBB, PredBB, DT, NewInsts);
427 if (OpVal == 0)
return 0;
430 InVal->
getName()+
".phi.trans.insert",
434 NewInsts.push_back(Res);
static void RemoveInstInputs(Value *V, SmallVectorImpl< Instruction * > &InstInputs)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This is an optimization pass for GlobalISel generic memory operations.
iterator erase(const_iterator CI)
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
PHITransAddr - An address value which tracks and handles phi translation.
const Function * getParent() const
Return the enclosing method, or null if none.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Value * PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT, SmallVectorImpl< Instruction * > &NewInsts)
PHITranslateWithInsertion - PHI translate this value into the specified predecessor block,...
static bool CanPHITrans(Instruction *Inst)
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
bool IsPotentiallyPHITranslatable() const
IsPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
Value * SimplifyGEPInst(Type *SrcTy, Value *Ptr, ArrayRef< Value * > Indices, bool InBounds, const SimplifyQuery &Q)
Given operands for a GetElementPtrInst, fold the result or return null.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_NODISCARD T pop_back_val()
LLVM Basic Block Representation.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
This is the shared class of boolean and integer constants.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static bool hasNoUnsignedWrap(BinaryOperator &I)
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
(vector float) vec_cmpeq(*A, *B) C
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
This is an important base class in LLVM.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
static bool VerifySubExpr(Value *Expr, SmallVectorImpl< Instruction * > &InstInputs)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree *DT, bool MustDominate)
PHITranslateValue - PHI translate the current address up the CFG from CurBB to Pred,...
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Type * getType() const
All values are typed, get the type of this value.
bool Verify() const
Verify - Check internal consistency of this data structure.
This is the base class for all instructions that perform data casts.
StringRef getName() const
Return a constant reference to the value's name.
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static bool isInput(const StringSet<> &Prefixes, StringRef Arg)
static bool hasNoSignedWrap(BinaryOperator &I)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
unsigned getNumOperands() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
const BasicBlock * getParent() const
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
Value * getOperand(unsigned i) const
Value * SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for an Add, fold the result or return null.
LLVM Value Representation.
iterator_range< user_iterator > users()