Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions llvm/include/llvm/SandboxIR/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Verifier.h"
#include "llvm/SandboxIR/Function.h"
#include "llvm/SandboxIR/Instruction.h"
#include <optional>

Expand Down Expand Up @@ -122,6 +124,13 @@ class Utils {
const std::optional<MemoryLocation> &OptLoc) {
return BatchAA.getModRefInfo(cast<llvm::Instruction>(I->Val), OptLoc);
}

/// Equivalent to llvm::verifyFunction().
/// \Returns true if the IR is broken.
static bool verifyFunction(const Function *F, raw_ostream &OS) {
const auto &LLVMF = *cast<llvm::Function>(F->Val);
return llvm::verifyFunction(LLVMF, &OS);
}
};

} // namespace llvm::sandboxir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ static cl::opt<bool>
AllowNonPow2("sbvec-allow-non-pow2", cl::init(false), cl::Hidden,
cl::desc("Allow non-power-of-2 vectorization."));

#ifndef NDEBUG
static cl::opt<bool>
AlwaysVerify("sbvec-always-verify", cl::init(false), cl::Hidden,
cl::desc("Helps find bugs by verifying the IR whenever we "
"emit new instructions (*very* expensive)."));
#endif // NDEBUG

namespace sandboxir {

BottomUpVec::BottomUpVec(StringRef Pipeline)
Expand Down Expand Up @@ -365,6 +372,17 @@ Value *BottomUpVec::vectorizeRec(ArrayRef<Value *> Bndl,
break;
}
}
#ifndef NDEBUG
if (AlwaysVerify) {
// This helps find broken IR by constantly verifying the function. Note that
// this is very expensive and should only be used for debugging.
Instruction *I0 = isa<Instruction>(Bndl[0])
? cast<Instruction>(Bndl[0])
: cast<Instruction>(UserBndl[0]);
assert(!Utils::verifyFunction(I0->getParent()->getParent(), dbgs()) &&
"Broken function!");
}
#endif
return NewVec;
}

Expand Down
Loading