File tree 2 files changed +27
-0
lines changed
lib/Transforms/Vectorize/SandboxVectorizer/Passes
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 17
17
#include " llvm/Analysis/MemoryLocation.h"
18
18
#include " llvm/Analysis/ScalarEvolution.h"
19
19
#include " llvm/Analysis/ValueTracking.h"
20
+ #include " llvm/IR/Verifier.h"
21
+ #include " llvm/SandboxIR/Function.h"
20
22
#include " llvm/SandboxIR/Instruction.h"
21
23
#include < optional>
22
24
@@ -122,6 +124,13 @@ class Utils {
122
124
const std::optional<MemoryLocation> &OptLoc) {
123
125
return BatchAA.getModRefInfo (cast<llvm::Instruction>(I->Val ), OptLoc);
124
126
}
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
+ }
125
134
};
126
135
127
136
} // namespace llvm::sandboxir
Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ static cl::opt<bool>
27
27
AllowNonPow2 (" sbvec-allow-non-pow2" , cl::init(false ), cl::Hidden,
28
28
cl::desc (" Allow non-power-of-2 vectorization." ));
29
29
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
+
30
37
namespace sandboxir {
31
38
32
39
BottomUpVec::BottomUpVec (StringRef Pipeline)
@@ -365,6 +372,17 @@ Value *BottomUpVec::vectorizeRec(ArrayRef<Value *> Bndl,
365
372
break ;
366
373
}
367
374
}
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
368
386
return NewVec;
369
387
}
370
388
You can’t perform that action at this time.
0 commit comments