51 #define DEBUG_TYPE "safepoint-ir-verifier"
95 "Safepoint IR Verifier",
false,
true)
100 if (
auto *PT = dyn_cast<PointerType>(T))
104 return (1 == PT->getAddressSpace());
111 if (
VectorType *VT = dyn_cast<VectorType>(Ty))
113 if (
ArrayType *AT = dyn_cast<ArrayType>(Ty))
122 template<
typename IteratorTy>
125 while (Begin != End) {
126 OS << **Begin <<
" ";
151 bool Cleared =
false;
166 const auto &Defs = BlockMap[DTN->
getBlock()]->Contribution;
167 Result.
insert(Defs.begin(), Defs.end());
172 if (BlockMap[DTN->
getBlock()]->Cleared)
213 AvailableOut = std::move(Temp);
244 bool isExclusivelyDerivedFromNull =
true;
249 while(!Worklist.
empty()) {
251 if (!Visited.
insert(V).second)
254 if (
const auto *CI = dyn_cast<CastInst>(V)) {
255 Worklist.
push_back(CI->stripPointerCasts());
258 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(V)) {
264 if (
const auto *PN = dyn_cast<PHINode>(V)) {
265 for (
Value *InV: PN->incoming_values())
269 if (
const auto *
SI = dyn_cast<SelectInst>(V)) {
275 if (isa<Constant>(V)) {
279 isExclusivelyDerivedFromNull =
false;
298 DEBUG(
dbgs() <<
"Verifying gc pointers in function: " << F.
getName() <<
"\n");
300 dbgs() <<
"Verifying gc pointers in function: " << F.
getName() <<
"\n";
305 for (
const auto &
I : BB)
310 for (
auto &BBI : BlockMap) {
316 for (
auto &BBI : BlockMap)
317 Worklist.
insert(BBI.first);
321 while (!Worklist.
empty()) {
345 bool AnyInvalidUses =
false;
347 auto ReportInvalidUse = [&AnyInvalidUses](
const Value &V,
349 errs() <<
"Illegal use of unrelocated value found!\n";
350 errs() <<
"Def: " << V <<
"\n";
351 errs() <<
"Use: " <<
I <<
"\n";
354 AnyInvalidUses =
true;
357 auto isNotExclusivelyConstantDerived = [](
const Value *V) {
366 if (
const PHINode *PN = dyn_cast<PHINode>(&
I)) {
368 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
369 const BasicBlock *InBB = PN->getIncomingBlock(i);
370 const Value *InValue = PN->getIncomingValue(i);
372 if (isNotExclusivelyConstantDerived(InValue) &&
373 !BlockMap[InBB]->AvailableOut.count(InValue))
374 ReportInvalidUse(*InValue, *PN);
376 }
else if (isa<CmpInst>(
I) &&
378 Value *LHS =
I.getOperand(0), *RHS =
I.getOperand(1);
384 auto hasValidUnrelocatedUse = [&AvailableSet, baseTyLHS, baseTyRHS, &LHS, &RHS] () {
392 if (AvailableSet.
count(LHS) || AvailableSet.
count(RHS))
412 if (!hasValidUnrelocatedUse()) {
416 ReportInvalidUse(*LHS,
I);
418 ReportInvalidUse(*RHS,
I);
421 for (
const Value *V :
I.operands())
423 isNotExclusivelyConstantDerived(V) && !AvailableSet.
count(V))
424 ReportInvalidUse(*V,
I);
427 bool Cleared =
false;
434 dbgs() <<
"No illegal uses found by SafepointIRVerifier in: " << F.getName()
void push_back(const T &Elt)
static void PrintValueSet(raw_ostream &OS, IteratorTy Begin, IteratorTy End)
Safe Stack instrumentation pass
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents an incoming formal argument to a Function.
LLVM_NODISCARD T pop_back_val()
void initializeSafepointIRVerifierPass(PassRegistry &)
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null, or not exclusively derived from constant.
INITIALIZE_PASS_BEGIN(SafepointIRVerifier,"verify-safepoint-ir","Safepoint IR Verifier", false, true) INITIALIZE_PASS_END(SafepointIRVerifier
const Function * getParent() const
Return the enclosing method, or null if none.
DenseSet< const Value * > AvailableIn
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
static void TransferBlock(const BasicBlock *BB, BasicBlockState &BBS, bool FirstPass)
Compute the AvailableOut set for BB, based on the BasicBlockState BBS, which is the BasicBlockState f...
Class to represent struct types.
LLVM_NODISCARD bool empty() const
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
DenseSet< const Value * > AvailableOut
bool insert(const value_type &X)
Insert a new element into the SetVector.
DomTreeNodeBase * getIDom() const
Class to represent array types.
bool empty() const
Determine if the SetVector is empty or not.
Base class for the actual dominator tree node.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Interval::succ_iterator succ_end(Interval *I)
static void Verify(const Function &F, const DominatorTree &DT)
The verifier algorithm is phrased in terms of availability.
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
static void GatherDominatingDefs(const BasicBlock *BB, DenseSet< const Value * > &Result, const DominatorTree &DT, DenseMap< const BasicBlock *, BasicBlockState * > &BlockMap)
Gather all the definitions dominating the start of BB into Result.
initializer< Ty > init(const Ty &Val)
void verifySafepointIR(Function &F)
Run the safepoint verifier over a single function. Crashes on failure.
FunctionPass * createSafepointIRVerifierPass()
Create an instance of the safepoint verifier pass which can be added to a pass pipeline to check for ...
void set_intersect(S1Ty &S1, const S2Ty &S2)
set_intersect(A, B) - Compute A := A ^ B Identical to set_intersection, except that it works on set<&g...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
verify safepoint Safepoint IR static true bool isGCPointerType(Type *T)
std::pair< iterator, bool > insert(const ValueT &V)
static bool containsGCPtrType(Type *Ty)
Represent the analysis usage information of a pass.
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static const unsigned End
FunctionPass class - This class is used to implement most global optimizations.
T * Allocate(size_t num=1)
Allocate space for an array of objects without constructing them.
DenseSet< const Value * > Contribution
static void TransferInstruction(const Instruction &I, bool &Cleared, DenseSet< const Value * > &Available)
Model the effect of an instruction on the set of available values.
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
LLVM_NODISCARD T pop_back_val()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
pred_range predecessors(BasicBlock *BB)
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class to represent vector types.
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
static cl::opt< bool > PrintOnly("safepoint-ir-verifier-print-only", cl::init(false))
This option is used for writing test cases.
verify safepoint Safepoint IR Verifier
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
bool isStatepoint(ImmutableCallSite CS)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
verify safepoint Safepoint IR false
LLVM Value Representation.
A vector that has set insertion semantics.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
StringRef - Represent a constant reference to a string, i.e.
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
Statically lint checks LLVM IR
iterator_range< arg_iterator > args()