|
@@ -51,8 +51,10 @@ Value *RandomIRBuilder::newSource(BasicBlock &BB, ArrayRef<Instruction *> Insts,
|
|
if (Ptr) {
|
|
if (Ptr) {
|
|
// Create load from the chosen pointer
|
|
// Create load from the chosen pointer
|
|
auto IP = BB.getFirstInsertionPt();
|
|
auto IP = BB.getFirstInsertionPt();
|
|
- if (auto *I = dyn_cast<Instruction>(Ptr))
|
|
|
|
|
|
+ if (auto *I = dyn_cast<Instruction>(Ptr)) {
|
|
IP = ++I->getIterator();
|
|
IP = ++I->getIterator();
|
|
|
|
+ assert(IP != BB.end() && "guaranteed by the findPointer");
|
|
|
|
+ }
|
|
auto *NewLoad = new LoadInst(Ptr, "L", &*IP);
|
|
auto *NewLoad = new LoadInst(Ptr, "L", &*IP);
|
|
|
|
|
|
// Only sample this load if it really matches the descriptor
|
|
// Only sample this load if it really matches the descriptor
|
|
@@ -133,6 +135,11 @@ Value *RandomIRBuilder::findPointer(BasicBlock &BB,
|
|
ArrayRef<Instruction *> Insts,
|
|
ArrayRef<Instruction *> Insts,
|
|
ArrayRef<Value *> Srcs, SourcePred Pred) {
|
|
ArrayRef<Value *> Srcs, SourcePred Pred) {
|
|
auto IsMatchingPtr = [&Srcs, &Pred](Instruction *Inst) {
|
|
auto IsMatchingPtr = [&Srcs, &Pred](Instruction *Inst) {
|
|
|
|
+ // Invoke instructions sometimes produce valid pointers but currently
|
|
|
|
+ // we can't insert loads or stores from them
|
|
|
|
+ if (isa<TerminatorInst>(Inst))
|
|
|
|
+ return false;
|
|
|
|
+
|
|
if (auto PtrTy = dyn_cast<PointerType>(Inst->getType()))
|
|
if (auto PtrTy = dyn_cast<PointerType>(Inst->getType()))
|
|
// TODO: Check if this is horribly expensive.
|
|
// TODO: Check if this is horribly expensive.
|
|
return Pred.matches(Srcs, UndefValue::get(PtrTy->getElementType()));
|
|
return Pred.matches(Srcs, UndefValue::get(PtrTy->getElementType()));
|