26 if (isa<PHINode>(Inst) ||
27 isa<GetElementPtrInst>(Inst))
30 if (isa<CastInst>(Inst) &&
34 if (Inst->
getOpcode() == Instruction::Add &&
44 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
47 dbgs() <<
"PHITransAddr: null\n";
50 dbgs() <<
"PHITransAddr: " << *Addr <<
"\n";
51 for (
unsigned i = 0, e = InstInputs.size(); i != e; ++i)
52 dbgs() <<
" Input #" << i <<
" is " << *InstInputs[i] <<
"\n";
66 std::find(InstInputs.
begin(), InstInputs.
end(),
I);
67 if (Entry != InstInputs.
end()) {
68 InstInputs.
erase(Entry);
75 errs() <<
"Instruction in PHITransAddr is not phi-translatable:\n";
78 "CanPHITrans is wrong.");
93 if (!Addr)
return true;
101 errs() <<
"PHITransAddr contains extra instructions:\n";
102 for (
unsigned i = 0, e = InstInputs.size(); i != e; ++i)
103 errs() <<
" InstInput #" << i <<
" is " << *InstInputs[i] <<
"\n";
130 std::find(InstInputs.
begin(), InstInputs.
end(),
I);
131 if (Entry != InstInputs.
end()) {
132 InstInputs.
erase(Entry);
136 assert(!isa<PHINode>(I) &&
"Error, removing something that isn't an input");
154 std::find(InstInputs.begin(), InstInputs.end(), Inst) != InstInputs.end();
168 InstInputs.erase(std::find(InstInputs.begin(), InstInputs.end(), Inst));
171 if (
PHINode *PN = dyn_cast<PHINode>(Inst))
172 return AddAsInput(PN->getIncomingValueForBlock(PredBB));
183 InstInputs.push_back(Op);
190 if (
CastInst *Cast = dyn_cast<CastInst>(Inst)) {
192 Value *PHIIn = PHITranslateSubExpr(Cast->getOperand(0), CurBB, PredBB, DT);
193 if (!PHIIn)
return nullptr;
194 if (PHIIn == Cast->getOperand(0))
200 if (
Constant *
C = dyn_cast<Constant>(PHIIn))
202 C, Cast->getType()));
207 if (
CastInst *CastI = dyn_cast<CastInst>(U))
208 if (CastI->getOpcode() == Cast->getOpcode() &&
209 CastI->getType() == Cast->getType() &&
210 (!DT || DT->
dominates(CastI->getParent(), PredBB)))
219 bool AnyChanged =
false;
220 for (
unsigned i = 0, e =
GEP->getNumOperands(); i != e; ++i) {
221 Value *GEPOp = PHITranslateSubExpr(
GEP->getOperand(i), CurBB, PredBB, DT);
222 if (!GEPOp)
return nullptr;
224 AnyChanged |= GEPOp !=
GEP->getOperand(i);
233 for (
unsigned i = 0, e = GEPOps.
size(); i != e; ++i)
236 return AddAsInput(V);
240 Value *APHIOp = GEPOps[0];
243 if (GEPI->getType() ==
GEP->getType() &&
244 GEPI->getNumOperands() == GEPOps.
size() &&
245 GEPI->getParent()->getParent() == CurBB->
getParent() &&
246 (!DT || DT->
dominates(GEPI->getParent(), PredBB))) {
255 if (Inst->
getOpcode() == Instruction::Add &&
259 bool isNSW = cast<BinaryOperator>(Inst)->hasNoSignedWrap();
260 bool isNUW = cast<BinaryOperator>(Inst)->hasNoUnsignedWrap();
262 Value *LHS = PHITranslateSubExpr(Inst->
getOperand(0), CurBB, PredBB, DT);
263 if (!LHS)
return nullptr;
267 if (BOp->getOpcode() == Instruction::Add)
268 if (
ConstantInt *CI = dyn_cast<ConstantInt>(BOp->getOperand(1))) {
269 LHS = BOp->getOperand(0);
271 isNSW = isNUW =
false;
274 if (std::find(InstInputs.begin(), InstInputs.end(), BOp) !=
286 return AddAsInput(Res);
296 if (BO->getOpcode() == Instruction::Add &&
297 BO->getOperand(0) == LHS && BO->getOperand(1) == RHS &&
298 BO->getParent()->getParent() == CurBB->
getParent() &&
299 (!DT || DT->
dominates(BO->getParent(), PredBB)))
318 assert(DT || !MustDominate);
319 assert(
Verify() &&
"Invalid PHITransAddr!");
322 PHITranslateSubExpr(Addr, CurBB, PredBB, MustDominate ? DT :
nullptr);
325 assert(
Verify() &&
"Invalid PHITransAddr!");
329 if (
Instruction *Inst = dyn_cast_or_null<Instruction>(Addr))
330 if (!DT->dominates(Inst->
getParent(), PredBB))
333 return Addr ==
nullptr;
347 unsigned NISize = NewInsts.
size();
350 Addr = InsertPHITranslatedSubExpr(Addr, CurBB, PredBB, DT, NewInsts);
353 if (Addr)
return Addr;
356 while (NewInsts.
size() != NISize)
367 Value *PHITransAddr::
374 if (!Tmp.PHITranslateValue(CurBB, PredBB, &DT,
true))
375 return Tmp.getAddr();
383 if (
CastInst *Cast = dyn_cast<CastInst>(Inst)) {
385 Value *OpVal = InsertPHITranslatedSubExpr(Cast->getOperand(0),
386 CurBB, PredBB, DT, NewInsts);
387 if (!OpVal)
return nullptr;
391 InVal->
getName() +
".phi.trans.insert",
392 PredBB->getTerminator());
402 for (
unsigned i = 0, e =
GEP->getNumOperands(); i != e; ++i) {
403 Value *OpVal = InsertPHITranslatedSubExpr(
GEP->getOperand(i),
404 CurBB, PredBB, DT, NewInsts);
405 if (!OpVal)
return nullptr;
411 InVal->
getName() +
".phi.trans.insert", PredBB->getTerminator());
424 if (Inst->
getOpcode() == Instruction::Add &&
428 CurBB, PredBB, DT, NewInsts);
429 if (OpVal == 0)
return 0;
432 InVal->
getName()+
".phi.trans.insert",
433 PredBB->getTerminator());
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void push_back(const T &Elt)
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Value * PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT, SmallVectorImpl< Instruction * > &NewInsts)
PHITranslateWithInsertion - PHI translate this value into the specified predecessor block...
unsigned getNumOperands() const
const Function * getParent() const
Return the enclosing method, or null if none.
Value * SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyAddInst - Given operands for an Add, see if we can fold the result.
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 llvm::StringSet<> &Prefixes, StringRef Arg)
This is the base class for all instructions that perform data casts.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
void setIsInBounds(bool b=true)
setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
void setDebugLoc(DebugLoc Loc)
setDebugLoc - Set the debug location information for this instruction.
LLVM Basic Block Representation.
PHITransAddr - An address value which tracks and handles phi translation.
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
Value * getOperand(unsigned i) const
iterator erase(iterator I)
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
bool IsPotentiallyPHITranslatable() const
IsPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
static void RemoveInstInputs(Value *V, SmallVectorImpl< Instruction * > &InstInputs)
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
This is the shared class of boolean and integer constants.
bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree *DT, bool MustDominate)
PHITranslateValue - PHI translate the current address up the CFG from CurBB to Pred, updating our state to reflect any needed changes.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
static bool VerifySubExpr(Value *Expr, SmallVectorImpl< Instruction * > &InstInputs)
Value * SimplifyGEPInst(ArrayRef< Value * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can fold the result...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
iterator_range< user_iterator > users()
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static bool CanPHITrans(Instruction *Inst)
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 ...
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
isSafeToSpeculativelyExecute - Return true if the instruction does not have any effects besides calcu...
bool Verify() const
Verify - Check internal consistency of this data structure.
const BasicBlock * getParent() const