17#include "llvm/Config/llvm-config.h"
29 if (Inst->
getOpcode() == Instruction::Add &&
36#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
39 dbgs() <<
"PHITransAddr: null\n";
42 dbgs() <<
"PHITransAddr: " << *Addr <<
"\n";
43 for (
unsigned i = 0, e = InstInputs.size(); i != e; ++i)
44 dbgs() <<
" Input #" << i <<
" is " << *InstInputs[i] <<
"\n";
56 if (
auto Entry =
find(InstInputs,
I); Entry != InstInputs.
end()) {
57 InstInputs.
erase(Entry);
64 errs() <<
"Instruction in PHITransAddr is not phi-translatable:\n";
67 "canPHITrans is wrong.");
72 [&](
Value *
Op) { return verifySubExpr(Op, InstInputs); });
79 if (!Addr)
return true;
87 errs() <<
"PHITransAddr contains extra instructions:\n";
88 for (
unsigned i = 0, e = InstInputs.size(); i != e; ++i)
89 errs() <<
" InstInput #" << i <<
" is " << *InstInputs[i] <<
"\n";
113 if (
auto Entry =
find(InstInputs,
I); Entry != InstInputs.
end()) {
114 InstInputs.
erase(Entry);
149 InstInputs.erase(
find(InstInputs, Inst));
153 Value *Incoming = PN->getIncomingValueForBlock(PredBB);
160 if (
SI->getCondition() ==
Cond)
161 return addAsInput(CondVal ?
SI->getTrueValue()
162 :
SI->getFalseValue());
163 return addAsInput(Incoming);
183 translateSubExpr(Cast->getOperand(0), CurBB, PredBB, DT,
Cond, CondVal);
184 if (!PHIIn)
return nullptr;
185 if (PHIIn == Cast->getOperand(0))
192 {DL, TLI, DT, AC})) {
194 return addAsInput(V);
203 for (User *U : PHIIn->
users()) {
205 if (CastI->getOpcode() == Cast->getOpcode() &&
206 CastI->getType() == Cast->getType() &&
207 (!DT || DT->
dominates(CastI->getParent(), PredBB)))
216 SmallVector<Value*, 8> GEPOps;
217 bool AnyChanged =
false;
219 Value *GEPOp = translateSubExpr(
Op, CurBB, PredBB, DT,
Cond, CondVal);
220 if (!GEPOp)
return nullptr;
222 AnyChanged |= GEPOp !=
Op;
232 GEP->getNoWrapFlags(), {DL, TLI, DT, AC})) {
236 return addAsInput(V);
240 Value *APHIOp = GEPOps[0];
244 for (User *U : APHIOp->
users()) {
246 if (GEPI->getType() ==
GEP->getType() &&
247 GEPI->getSourceElementType() ==
GEP->getSourceElementType() &&
248 GEPI->getNumOperands() == GEPOps.
size() &&
249 GEPI->getParent()->getParent() == CurBB->
getParent() &&
250 (!DT || DT->
dominates(GEPI->getParent(), PredBB))) {
251 if (std::equal(GEPOps.
begin(), GEPOps.
end(), GEPI->op_begin()))
259 if (Inst->
getOpcode() == Instruction::Add &&
267 translateSubExpr(Inst->
getOperand(0), CurBB, PredBB, DT,
Cond, CondVal);
268 if (!
LHS)
return nullptr;
272 if (BOp->getOpcode() == Instruction::Add)
274 LHS = BOp->getOperand(0);
276 isNSW = isNUW =
false;
290 return addAsInput(Res);
300 if (BO->getOpcode() == Instruction::Add &&
301 BO->getOperand(0) ==
LHS && BO->getOperand(1) ==
RHS &&
302 BO->getParent()->getParent() == CurBB->
getParent() &&
303 (!DT || DT->
dominates(BO->getParent(), PredBB)))
320 assert(DT || !MustDominate);
323 Addr = translateSubExpr(Addr, CurBB, PredBB, DT);
341 assert(
Cond &&
"expected a non-null select condition");
345 return {
nullptr,
nullptr};
347 auto TranslateSide = [&](
bool CondVal) ->
Value * {
351 return Tmp.translateSubExpr(Tmp.Addr, CurBB, PredBB, DT,
Cond, CondVal);
354 return {TranslateSide(
true), TranslateSide(
false)};
375 unsigned NISize = NewInsts.
size();
378 Addr = insertTranslatedSubExpr(Addr, CurBB, PredBB, DT, NewInsts);
381 if (Addr)
return Addr;
384 while (NewInsts.
size() != NISize)
394Value *PHITransAddr::insertTranslatedSubExpr(
401 Tmp.translateValue(CurBB, PredBB, &DT,
true))
411 Value *OpVal = insertTranslatedSubExpr(Cast->getOperand(0), CurBB, PredBB,
413 if (!OpVal)
return nullptr;
417 InVal->
getName() +
".phi.trans.insert",
429 Value *OpVal = insertTranslatedSubExpr(
Op, CurBB, PredBB, DT, NewInsts);
430 if (!OpVal)
return nullptr;
435 GEP->getSourceElementType(), GEPOps[0],
ArrayRef(GEPOps).slice(1),
436 InVal->
getName() +
".phi.trans.insert",
439 Result->setNoWrapFlags(
GEP->getNoWrapFlags());
445 if (Inst->
getOpcode() == Instruction::Add &&
454 Value *OpVal = insertTranslatedSubExpr(Inst->
getOperand(0), CurBB, PredBB,
456 if (OpVal ==
nullptr)
459 BinaryOperator *Res = BinaryOperator::CreateAdd(
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool hasNoSignedWrap(BinaryOperator &I)
static bool hasNoUnsignedWrap(BinaryOperator &I)
static bool isInput(const ArrayRef< StringRef > &Prefixes, StringRef Arg)
static void RemoveInstInputs(Value *V, SmallVectorImpl< Instruction * > &InstInputs)
static bool canPHITrans(Instruction *Inst)
static bool verifySubExpr(Value *Expr, SmallVectorImpl< Instruction * > &InstInputs)
SmallVector< MachineOperand, 4 > Cond
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
This is the base class for all instructions that perform data casts.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static LLVM_ABI Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
PHITransAddr - An address value which tracks and handles phi translation.
LLVM_ABI Value * translateValue(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree *DT, bool MustDominate)
translateValue - PHI translate the current address up the CFG from CurBB to Pred, updating our state ...
LLVM_ABI void dump() const
PHITransAddr(Value *Addr, const DataLayout &DL, AssumptionCache *AC)
LLVM_ABI bool isPotentiallyPHITranslatable() const
isPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
LLVM_ABI bool verify() const
verify - Check internal consistency of this data structure.
LLVM_ABI Value * translateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT, SmallVectorImpl< Instruction * > &NewInsts)
translateWithInsertion - PHI translate this value into the specified predecessor block,...
LLVM_ABI SelectInst * getSelect() const
If the address expression depends on a select instruction (possibly through casts or GEPs),...
std::pair< Value *, Value * > SelectAddrs
This class represents the LLVM 'select' instruction.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< user_iterator > users()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Value * simplifyGEPInst(Type *SrcTy, Value *Ptr, ArrayRef< Value * > Indices, GEPNoWrapFlags NW, const SimplifyQuery &Q)
Given operands for a GetElementPtrInst, fold the result or return null.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI Value * simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
const AnalysisOptions & getAnalysisOptions(const LLVMContext &C)
LLVM_ABI Value * simplifyAddInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for an Add, fold the result or return null.
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.