AssumptionCache AC;
AAResults AA;
BasicAAResult BAA;
- MemorySSA MSSA;
+ // We need to defer MSSA construction until AA is *entirely* set up, which
+ // requires calling addAAResult. Hence, we just use a pointer here.
+ std::unique_ptr<MemorySSA> MSSA;
MemorySSAWalker *Walker;
TestAnalyses(MemorySSATest &Test)
: DT(*Test.F), AC(*Test.F), AA(Test.TLI),
- BAA(Test.DL, Test.TLI, AC, &DT), MSSA(*Test.F, &AA, &DT) {
+ BAA(Test.DL, Test.TLI, AC, &DT) {
AA.addAAResult(BAA);
- Walker = MSSA.getWalker();
+ MSSA = make_unique<MemorySSA>(*Test.F, &AA, &DT);
+ Walker = MSSA->getWalker();
}
};
BranchInst::Create(Merge, Right);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
// Add the load
B.SetInsertPoint(Merge);
LoadInst *LoadInst = B.CreateLoad(PointerArg);
B.SetInsertPoint(Merge);
B.CreateLoad(PointerArg);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
// Move the store
SideStore->moveBefore(Entry->getTerminator());
LoadInst *LoadInst = B.CreateLoad(PointerArg);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
// Before, the load will be a use of a phi<store, liveonentry>.
MemoryUse *LoadAccess = cast<MemoryUse>(MSSA.getMemoryAccess(LoadInst));
MemoryDef *StoreAccess = cast<MemoryDef>(MSSA.getMemoryAccess(StoreInst));
LoadInst *LoadInst = B.CreateLoad(PointerArg);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
MemorySSAWalker *Walker = Analyses->Walker;
// Before, the load will be a use of a phi<store, liveonentry>. It should be
StoreInst *S3 = B.CreateStore(ConstantInt::get(Int8, 2), Alloca);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
MemorySSAWalker *Walker = Analyses->Walker;
unsigned I = 0;
Instruction *LI = B.CreateLoad(Alloca);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
MemorySSAWalker *Walker = Analyses->Walker;
MemoryAccess *LoadClobber = Walker->getClobberingMemoryAccess(LI);
StoreInst *SI = B.CreateStore(ConstantInt::get(Int8, 0), Alloca);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
MemorySSAWalker *Walker = Analyses->Walker;
MemoryAccess *StoreAccess = MSSA.getMemoryAccess(SI);
Instruction *BelowPhi = B.CreateStore(Zero, AllocA);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
MemorySSAWalker *Walker = Analyses->Walker;
// Kill `KillStore`; it exists solely so that the load after it won't be
Instruction *Load = B.CreateLoad(AllocA);
setupAnalyses();
- MemorySSA &MSSA = Analyses->MSSA;
+ MemorySSA &MSSA = *Analyses->MSSA;
MemorySSAWalker *Walker = Analyses->Walker;
auto *LoadMA = cast<MemoryUse>(MSSA.getMemoryAccess(Load));
MemoryAccess *LoadClobber = Walker->getClobberingMemoryAccess(LoadMA);
EXPECT_EQ(LoadClobber, MSSA.getLiveOnEntryDef());
}
+
+// At one point, we were building MSSA with 0 AA passes. This ensures that we
+// actually use BasicAA.
+TEST_F(MemorySSATest, AAIsPresentAtBuildTime) {
+ F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false),
+ GlobalValue::ExternalLinkage, "F", &M);
+ B.SetInsertPoint(BasicBlock::Create(C, "", F));
+
+ Type *Int8 = Type::getInt8Ty(C);
+ Constant *One = ConstantInt::get(Int8, 1);
+ Value *AllocaA = B.CreateAlloca(Int8);
+ Instruction *StoreA = B.CreateStore(One, AllocaA);
+
+ Value *AllocaB = B.CreateAlloca(Int8);
+ B.CreateStore(One, AllocaB);
+ Instruction *LoadA = B.CreateLoad(AllocaA);
+
+ setupAnalyses();
+ MemorySSA &MSSA = *Analyses->MSSA;
+ auto *MU = cast<MemoryUse>(MSSA.getMemoryAccess(LoadA));
+ EXPECT_EQ(MU->getDefiningAccess(), MSSA.getMemoryAccess(StoreA));
+}