77 #define DEBUG_TYPE "poison-checking" 82 cl::desc(
"Check that returns are non-poison (for testing)"));
87 if (
auto *CI = dyn_cast<ConstantInt>(V))
99 Value *Accum = Ops[i++];
100 for (; i < Ops.
size(); i++)
108 assert(isa<BinaryOperator>(I));
129 case Instruction::Sub: {
142 case Instruction::Mul: {
155 case Instruction::UDiv: {
164 case Instruction::SDiv: {
173 case Instruction::AShr:
174 case Instruction::LShr:
175 case Instruction::Shl: {
196 case Instruction::ExtractElement: {
208 case Instruction::InsertElement: {
225 auto Itr = ValToPoison.
find(V);
226 if (Itr != ValToPoison.
end())
228 if (isa<Constant>(V)) {
240 if (
auto *CI = dyn_cast<ConstantInt>(Cond))
241 if (CI->isAllOnesValue())
263 for (
auto I = BB.begin(); isa<PHINode>(&*
I);
I++) {
264 auto *OldPHI = cast<PHINode>(&*
I);
266 OldPHI->getNumIncomingValues());
267 for (
unsigned i = 0; i < OldPHI->getNumIncomingValues(); i++)
269 OldPHI->getIncomingBlock(i));
270 NewPHI->insertBefore(OldPHI);
271 ValToPoison[OldPHI] = NewPHI;
276 if (isa<PHINode>(
I))
continue;
286 if (
auto *RI = dyn_cast<ReturnInst>(&
I))
287 if (RI->getNumOperands() != 0) {
294 for (
Value *V :
I.operands())
303 for (
auto I = BB.begin(); isa<PHINode>(&*
I);
I++) {
304 auto *OldPHI = cast<PHINode>(&*
I);
305 if (!ValToPoison.count(OldPHI))
307 auto *NewPHI = cast<PHINode>(ValToPoison[OldPHI]);
308 for (
unsigned i = 0; i < OldPHI->getNumIncomingValues(); i++) {
309 auto *OldVal = OldPHI->getIncomingValue(i);
310 NewPHI->setIncomingValue(i,
getPoisonFor(ValToPoison, OldVal));
319 bool Changed =
false;
const Value * getGuaranteedNonFullPoisonOp(const Instruction *I)
Return either nullptr or an operand of I such that I will trigger undefined behavior if I is executed...
static bool Check(DecodeStatus &Out, DecodeStatus In)
static ConstantInt * getFalse(LLVMContext &Context)
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
static IntegerType * getInt1Ty(LLVMContext &C)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
LLVMContext & getContext() const
All values hold a context through their type.
static void generatePoisonChecksForBinOp(Instruction &I, SmallVector< Value *, 2 > &Checks)
bool isVectorTy() const
True if this is an instance of VectorType.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
bool propagatesFullPoison(const Instruction *I)
Return true if this function can prove that I is guaranteed to yield full-poison (all bits poison) if...
Value * CreateNot(Value *V, const Twine &Name="")
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
LLVMContext & getContext() const
Get the global data context.
bool isIntegerTy() const
True if this is an instance of IntegerType.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Type * getType() const
All values are typed, get the type of this value.
BasicBlock * GetInsertBlock() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Value * getOperand(unsigned i) const
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
iterator find(const_arg_type_t< KeyT > Val)
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
LLVM Basic Block Representation.
size_t size() const
size - Get the array size.
static Type * getVoidTy(LLVMContext &C)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
static bool isConstantFalse(Value *V)
bool isExact() const
Determine whether the exact flag is set.
Value * CreateSRem(Value *LHS, Value *RHS, const Twine &Name="")
static Value * generatePoisonChecks(Instruction &I)
static Value * getPoisonFor(DenseMap< Value *, Value *> &ValToPoison, Value *V)
static cl::opt< bool > LocalCheck("poison-checking-function-local", cl::init(false), cl::desc("Check that returns are non-poison (for testing)"))
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static Value * buildOrChain(IRBuilder<> &B, ArrayRef< Value *> Ops)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Value * CreateURem(Value *LHS, Value *RHS, const Twine &Name="")
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
unsigned getVectorNumElements() const
static void CreateAssert(IRBuilder<> &B, Value *Cond)
ConstantInt * getFalse()
Get the constant value for i1 false.
unsigned greater or equal
static void CreateAssertNot(IRBuilder<> &B, Value *Cond)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
static bool rewrite(Function &F)
bool getVectorIsScalable() const
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
CallInst * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type. ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
A container for analyses that lazily runs them and caches their results.