File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
lib/Transforms/Vectorize/SandboxVectorizer/Passes Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 1717#include " llvm/Analysis/MemoryLocation.h"
1818#include " llvm/Analysis/ScalarEvolution.h"
1919#include " llvm/Analysis/ValueTracking.h"
20+ #include " llvm/IR/Verifier.h"
21+ #include " llvm/SandboxIR/Function.h"
2022#include " llvm/SandboxIR/Instruction.h"
2123#include < optional>
2224
@@ -122,6 +124,13 @@ class Utils {
122124 const std::optional<MemoryLocation> &OptLoc) {
123125 return BatchAA.getModRefInfo (cast<llvm::Instruction>(I->Val ), OptLoc);
124126 }
127+
128+ // / Equivalent to llvm::verifyFunction().
129+ // / \Returns true if the IR is broken.
130+ static bool verifyFunction (const Function *F, raw_ostream &OS) {
131+ const auto &LLVMF = *cast<llvm::Function>(F->Val );
132+ return llvm::verifyFunction (LLVMF, &OS);
133+ }
125134};
126135
127136} // namespace llvm::sandboxir
Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ static cl::opt<bool>
2727 AllowNonPow2 (" sbvec-allow-non-pow2" , cl::init(false ), cl::Hidden,
2828 cl::desc (" Allow non-power-of-2 vectorization." ));
2929
30+ #ifndef NDEBUG
31+ static cl::opt<bool >
32+ AlwaysVerify (" sbvec-always-verify" , cl::init(false ), cl::Hidden,
33+ cl::desc(" Helps find bugs by verifying the IR whenever we "
34+ " emit new instructions (*very* expensive)." ));
35+ #endif // NDEBUG
36+
3037namespace sandboxir {
3138
3239BottomUpVec::BottomUpVec (StringRef Pipeline)
@@ -365,6 +372,17 @@ Value *BottomUpVec::vectorizeRec(ArrayRef<Value *> Bndl,
365372 break ;
366373 }
367374 }
375+ #ifndef NDEBUG
376+ if (AlwaysVerify) {
377+ // This helps find broken IR by constantly verifying the function. Note that
378+ // this is very expensive and should only be used for debugging.
379+ Instruction *I0 = isa<Instruction>(Bndl[0 ])
380+ ? cast<Instruction>(Bndl[0 ])
381+ : cast<Instruction>(UserBndl[0 ]);
382+ assert (!Utils::verifyFunction (I0->getParent ()->getParent (), dbgs ()) &&
383+ " Broken function!" );
384+ }
385+ #endif
368386 return NewVec;
369387}
370388
You can’t perform that action at this time.
0 commit comments