//===----------------------------------------------------------------------===//
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
+#include "llvm/Analysis/AssumptionCache.h"
+#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/LoopInfo.h"
-#include "llvm/Constants.h"
-#include "llvm/GlobalVariable.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Module.h"
-#include "llvm/PassManager.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "gtest/gtest.h"
namespace llvm {
// deleting the PassManager.
class ScalarEvolutionsTest : public testing::Test {
protected:
- ScalarEvolutionsTest() : M("", Context), SE(*new ScalarEvolution) {}
- ~ScalarEvolutionsTest() {
- // Manually clean up, since we allocated new SCEV objects after the
- // pass was finished.
- SE.releaseMemory();
- }
LLVMContext Context;
Module M;
- PassManager PM;
- ScalarEvolution &SE;
+ TargetLibraryInfoImpl TLII;
+ TargetLibraryInfo TLI;
+
+ std::unique_ptr<AssumptionCache> AC;
+ std::unique_ptr<DominatorTree> DT;
+ std::unique_ptr<LoopInfo> LI;
+
+ ScalarEvolutionsTest() : M("", Context), TLII(), TLI(TLII) {}
+
+ ScalarEvolution buildSE(Function &F) {
+ AC.reset(new AssumptionCache(F));
+ DT.reset(new DominatorTree(F));
+ LI.reset(new LoopInfo(*DT));
+ return ScalarEvolution(F, TLI, *AC, *DT, *LI);
+ }
};
TEST_F(ScalarEvolutionsTest, SCEVUnknownRAUW) {
std::vector<Type *>(), false);
Function *F = cast<Function>(M.getOrInsertFunction("f", FTy));
BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
- ReturnInst::Create(Context, 0, BB);
+ ReturnInst::Create(Context, nullptr, BB);
Type *Ty = Type::getInt1Ty(Context);
Constant *Init = Constant::getNullValue(Ty);
Value *V1 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V1");
Value *V2 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V2");
- // Create a ScalarEvolution and "run" it so that it gets initialized.
- PM.add(&SE);
- PM.run(M);
+ ScalarEvolution SE = buildSE(*F);
const SCEV *S0 = SE.getSCEV(V0);
const SCEV *S1 = SE.getSCEV(V1);
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), Types, false);
Function *F = cast<Function>(M.getOrInsertFunction("f", FTy));
BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
- ReturnInst::Create(Context, 0, BB);
+ ReturnInst::Create(Context, nullptr, BB);
- // Create a ScalarEvolution and "run" it so that it gets initialized.
- PM.add(&SE);
- PM.run(M);
+ ScalarEvolution SE = buildSE(*F);
// It's possible to produce an empty loop through the default constructor,
// but you can't add any blocks to it without a LoopInfo pass.