494 changes: 251 additions & 243 deletions llvm/unittests/Analysis/LazyCallGraphTest.cpp

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions llvm/unittests/Analysis/LoopPassManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,39 +99,39 @@ class TestLoopInvalidatingPass {
static StringRef name() { return "TestLoopInvalidatingPass"; }
};

std::unique_ptr<Module> parseIR(const char *IR) {
LLVMContext &C = getGlobalContext();
std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
SMDiagnostic Err;
return parseAssemblyString(IR, Err, C);
}

class LoopPassManagerTest : public ::testing::Test {
protected:
LLVMContext Context;
std::unique_ptr<Module> M;

public:
LoopPassManagerTest()
: M(parseIR("define void @f() {\n"
"entry:\n"
" br label %loop.0\n"
"loop.0:\n"
" br i1 undef, label %loop.0.0, label %end\n"
"loop.0.0:\n"
" br i1 undef, label %loop.0.0, label %loop.0.1\n"
"loop.0.1:\n"
" br i1 undef, label %loop.0.1, label %loop.0\n"
"end:\n"
" ret void\n"
"}\n"
"\n"
"define void @g() {\n"
"entry:\n"
" br label %loop.g.0\n"
"loop.g.0:\n"
" br i1 undef, label %loop.g.0, label %end\n"
"end:\n"
" ret void\n"
"}\n")) {}
: M(parseIR(Context, "define void @f() {\n"
"entry:\n"
" br label %loop.0\n"
"loop.0:\n"
" br i1 undef, label %loop.0.0, label %end\n"
"loop.0.0:\n"
" br i1 undef, label %loop.0.0, label %loop.0.1\n"
"loop.0.1:\n"
" br i1 undef, label %loop.0.1, label %loop.0\n"
"end:\n"
" ret void\n"
"}\n"
"\n"
"define void @g() {\n"
"entry:\n"
" br label %loop.g.0\n"
"loop.g.0:\n"
" br i1 undef, label %loop.g.0, label %end\n"
"end:\n"
" ret void\n"
"}\n")) {}
};

#define EXPECT_N_ELEMENTS_EQ(N, EXPECTED, ACTUAL) \
Expand Down
21 changes: 13 additions & 8 deletions llvm/unittests/Analysis/UnrollAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ struct UnrollAnalyzerTest : public FunctionPass {

char UnrollAnalyzerTest::ID = 0;

std::unique_ptr<Module> makeLLVMModule(UnrollAnalyzerTest *P,
std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context,
UnrollAnalyzerTest *P,
const char *ModuleStr) {
LLVMContext &C = getGlobalContext();
SMDiagnostic Err;
return parseAssemblyString(ModuleStr, Err, C);
return parseAssemblyString(ModuleStr, Err, Context);
}

TEST(UnrollAnalyzerTest, BasicSimplifications) {
Expand All @@ -86,7 +86,8 @@ TEST(UnrollAnalyzerTest, BasicSimplifications) {
" ret i64 %x.lcssa\n"
"}\n";
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
LLVMContext Context;
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
legacy::PassManager Passes;
Passes.add(P);
Passes.run(*M);
Expand Down Expand Up @@ -148,7 +149,8 @@ TEST(UnrollAnalyzerTest, OuterLoopSimplification) {
"}\n";

UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
LLVMContext Context;
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
legacy::PassManager Passes;
Passes.add(P);
Passes.run(*M);
Expand Down Expand Up @@ -188,7 +190,8 @@ TEST(UnrollAnalyzerTest, CmpSimplifications) {
" ret void\n"
"}\n";
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
LLVMContext Context;
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
legacy::PassManager Passes;
Passes.add(P);
Passes.run(*M);
Expand Down Expand Up @@ -234,7 +237,8 @@ TEST(UnrollAnalyzerTest, PtrCmpSimplifications) {
" ret void\n"
"}\n";
UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
LLVMContext Context;
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
legacy::PassManager Passes;
Passes.add(P);
Passes.run(*M);
Expand Down Expand Up @@ -279,7 +283,8 @@ TEST(UnrollAnalyzerTest, CastSimplifications) {
"}\n";

UnrollAnalyzerTest *P = new UnrollAnalyzerTest();
std::unique_ptr<Module> M = makeLLVMModule(P, ModuleStr);
LLVMContext Context;
std::unique_ptr<Module> M = makeLLVMModule(Context, P, ModuleStr);
legacy::PassManager Passes;
Passes.add(P);
Passes.run(*M);
Expand Down
3 changes: 2 additions & 1 deletion llvm/unittests/Analysis/ValueTrackingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MatchSelectPatternTest : public testing::Test {
protected:
void parseAssembly(const char *Assembly) {
SMDiagnostic Error;
M = parseAssemblyString(Assembly, Error, getGlobalContext());
M = parseAssemblyString(Assembly, Error, Context);

std::string errMsg;
raw_string_ostream os(errMsg);
Expand Down Expand Up @@ -59,6 +59,7 @@ class MatchSelectPatternTest : public testing::Test {
EXPECT_EQ(P.Ordered, R.Ordered);
}

LLVMContext Context;
std::unique_ptr<Module> M;
Instruction *A, *B;
};
Expand Down
14 changes: 7 additions & 7 deletions llvm/unittests/AsmParser/AsmParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace llvm;
namespace {

TEST(AsmParserTest, NullTerminatedInput) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
StringRef Source = "; Empty module \n";
SMDiagnostic Error;
auto Mod = parseAssemblyString(Source, Error, Ctx);
Expand All @@ -34,7 +34,7 @@ TEST(AsmParserTest, NullTerminatedInput) {
#ifndef NDEBUG

TEST(AsmParserTest, NonNullTerminatedInput) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
StringRef Source = "; Empty module \n\1\2";
SMDiagnostic Error;
std::unique_ptr<Module> Mod;
Expand All @@ -47,7 +47,7 @@ TEST(AsmParserTest, NonNullTerminatedInput) {
#endif

TEST(AsmParserTest, SlotMappingTest) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
StringRef Source = "@0 = global i32 0\n !0 = !{}\n !42 = !{i32 42}";
SMDiagnostic Error;
SlotMapping Mapping;
Expand All @@ -66,7 +66,7 @@ TEST(AsmParserTest, SlotMappingTest) {
}

TEST(AsmParserTest, TypeAndConstantValueParsing) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
SMDiagnostic Error;
StringRef Source = "define void @test() {\n entry:\n ret void\n}";
auto Mod = parseAssemblyString(Source, Error, Ctx);
Expand Down Expand Up @@ -117,7 +117,7 @@ TEST(AsmParserTest, TypeAndConstantValueParsing) {
}

TEST(AsmParserTest, TypeAndConstantValueWithSlotMappingParsing) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
SMDiagnostic Error;
StringRef Source =
"%st = type { i32, i32 }\n"
Expand Down Expand Up @@ -153,7 +153,7 @@ TEST(AsmParserTest, TypeAndConstantValueWithSlotMappingParsing) {
}

TEST(AsmParserTest, TypeWithSlotMappingParsing) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
SMDiagnostic Error;
StringRef Source =
"%st = type { i32, i32 }\n"
Expand Down Expand Up @@ -277,7 +277,7 @@ TEST(AsmParserTest, TypeWithSlotMappingParsing) {
}

TEST(AsmParserTest, TypeAtBeginningWithSlotMappingParsing) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
SMDiagnostic Error;
StringRef Source =
"%st = type { i32, i32 }\n"
Expand Down
10 changes: 5 additions & 5 deletions llvm/unittests/Bitcode/BitReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ using namespace llvm;

namespace {

std::unique_ptr<Module> parseAssembly(const char *Assembly) {
std::unique_ptr<Module> parseAssembly(LLVMContext &Context,
const char *Assembly) {
SMDiagnostic Error;
std::unique_ptr<Module> M =
parseAssemblyString(Assembly, Error, getGlobalContext());
std::unique_ptr<Module> M = parseAssemblyString(Assembly, Error, Context);

std::string ErrMsg;
raw_string_ostream OS(ErrMsg);
Expand All @@ -54,7 +54,7 @@ static void writeModuleToBuffer(std::unique_ptr<Module> Mod,
static std::unique_ptr<Module> getLazyModuleFromAssembly(LLVMContext &Context,
SmallString<1024> &Mem,
const char *Assembly) {
writeModuleToBuffer(parseAssembly(Assembly), Mem);
writeModuleToBuffer(parseAssembly(Context, Assembly), Mem);
std::unique_ptr<MemoryBuffer> Buffer =
MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
Expand Down Expand Up @@ -82,7 +82,7 @@ class BufferDataStreamer : public DataStreamer {
static std::unique_ptr<Module>
getStreamedModuleFromAssembly(LLVMContext &Context, SmallString<1024> &Mem,
const char *Assembly) {
writeModuleToBuffer(parseAssembly(Assembly), Mem);
writeModuleToBuffer(parseAssembly(Context, Assembly), Mem);
std::unique_ptr<MemoryBuffer> Buffer =
MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
auto Streamer = llvm::make_unique<BufferDataStreamer>(std::move(Buffer));
Expand Down
24 changes: 9 additions & 15 deletions llvm/unittests/ExecutionEngine/ExecutionEngineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ExecutionEngineTest : public testing::Test {

protected:
ExecutionEngineTest() {
auto Owner = make_unique<Module>("<main>", getGlobalContext());
auto Owner = make_unique<Module>("<main>", Context);
M = Owner.get();
Engine.reset(EngineBuilder(std::move(Owner)).setErrorStr(&Error).create());
}
Expand All @@ -44,13 +44,13 @@ class ExecutionEngineTest : public testing::Test {
}

std::string Error;
LLVMContext Context;
Module *M; // Owned by ExecutionEngine.
std::unique_ptr<ExecutionEngine> Engine;
};

TEST_F(ExecutionEngineTest, ForwardGlobalMapping) {
GlobalVariable *G1 =
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
GlobalVariable *G1 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");
int32_t Mem1 = 3;
Engine->addGlobalMapping(G1, &Mem1);
EXPECT_EQ(&Mem1, Engine->getPointerToGlobalIfAvailable(G1));
Expand All @@ -63,8 +63,7 @@ TEST_F(ExecutionEngineTest, ForwardGlobalMapping) {
Engine->updateGlobalMapping(G1, &Mem2);
EXPECT_EQ(&Mem2, Engine->getPointerToGlobalIfAvailable(G1));

GlobalVariable *G2 =
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
GlobalVariable *G2 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");
EXPECT_EQ(nullptr, Engine->getPointerToGlobalIfAvailable(G2))
<< "The NULL return shouldn't depend on having called"
<< " updateGlobalMapping(..., NULL)";
Expand All @@ -76,8 +75,7 @@ TEST_F(ExecutionEngineTest, ForwardGlobalMapping) {
}

TEST_F(ExecutionEngineTest, ReverseGlobalMapping) {
GlobalVariable *G1 =
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
GlobalVariable *G1 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");

int32_t Mem1 = 3;
Engine->addGlobalMapping(G1, &Mem1);
Expand All @@ -87,8 +85,7 @@ TEST_F(ExecutionEngineTest, ReverseGlobalMapping) {
EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1));
EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2));

GlobalVariable *G2 =
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global2");
GlobalVariable *G2 = NewExtGlobal(Type::getInt32Ty(Context), "Global2");
Engine->updateGlobalMapping(G2, &Mem1);
EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem1));
EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2));
Expand All @@ -104,8 +101,7 @@ TEST_F(ExecutionEngineTest, ReverseGlobalMapping) {
}

TEST_F(ExecutionEngineTest, ClearModuleMappings) {
GlobalVariable *G1 =
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
GlobalVariable *G1 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");

int32_t Mem1 = 3;
Engine->addGlobalMapping(G1, &Mem1);
Expand All @@ -115,17 +111,15 @@ TEST_F(ExecutionEngineTest, ClearModuleMappings) {

EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1));

GlobalVariable *G2 =
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global2");
GlobalVariable *G2 = NewExtGlobal(Type::getInt32Ty(Context), "Global2");
// After clearing the module mappings, we can assign a new GV to the
// same address.
Engine->addGlobalMapping(G2, &Mem1);
EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem1));
}

TEST_F(ExecutionEngineTest, DestructionRemovesGlobalMapping) {
GlobalVariable *G1 =
NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1");
GlobalVariable *G1 = NewExtGlobal(Type::getInt32Ty(Context), "Global1");
int32_t Mem1 = 3;
Engine->addGlobalMapping(G1, &Mem1);
// Make sure the reverse mapping is enabled.
Expand Down
3 changes: 2 additions & 1 deletion llvm/unittests/ExecutionEngine/Orc/IndirectionUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ using namespace llvm;
namespace {

TEST(IndirectionUtilsTest, MakeStub) {
ModuleBuilder MB(getGlobalContext(), "x86_64-apple-macosx10.10", "");
LLVMContext Context;
ModuleBuilder MB(Context, "x86_64-apple-macosx10.10", "");
Function *F = MB.createFunctionDecl<void(DummyStruct, DummyStruct)>("");
SmallVector<AttributeSet, 4> Attrs;
Attrs.push_back(
Expand Down
32 changes: 15 additions & 17 deletions llvm/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace {

class ObjectLinkingLayerExecutionTest : public testing::Test,
public OrcExecutionTest {

};

class SectionMemoryManagerWrapper : public SectionMemoryManager {
Expand Down Expand Up @@ -64,9 +65,10 @@ TEST(ObjectLinkingLayerTest, TestSetProcessAllSections) {

ObjectLinkingLayer<> ObjLayer;

auto M = llvm::make_unique<Module>("", getGlobalContext());
LLVMContext Context;
auto M = llvm::make_unique<Module>("", Context);
M->setTargetTriple("x86_64-unknown-linux-gnu");
Type *Int32Ty = IntegerType::get(getGlobalContext(), 32);
Type *Int32Ty = IntegerType::get(Context, 32);
GlobalVariable *GV =
new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
ConstantInt::get(Int32Ty, 42), "foo");
Expand Down Expand Up @@ -131,14 +133,13 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
// instance (for Module 1) which is unsafe, as it will prevent relocation of
// Module 2.

ModuleBuilder MB1(getGlobalContext(), "", "dummy");
ModuleBuilder MB1(Context, "", "dummy");
{
MB1.getModule()->setDataLayout(TM->createDataLayout());
Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("bar");
BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
BarImpl);
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
IRBuilder<> Builder(BarEntry);
IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
IntegerType *Int32Ty = IntegerType::get(Context, 32);
Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
Builder.CreateRet(FourtyTwo);
}
Expand All @@ -147,13 +148,12 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
std::vector<object::ObjectFile*> Obj1Set;
Obj1Set.push_back(Obj1.getBinary());

ModuleBuilder MB2(getGlobalContext(), "", "dummy");
ModuleBuilder MB2(Context, "", "dummy");
{
MB2.getModule()->setDataLayout(TM->createDataLayout());
Function *BarDecl = MB2.createFunctionDecl<int32_t(void)>("bar");
Function *FooImpl = MB2.createFunctionDecl<int32_t(void)>("foo");
BasicBlock *FooEntry = BasicBlock::Create(getGlobalContext(), "entry",
FooImpl);
BasicBlock *FooEntry = BasicBlock::Create(Context, "entry", FooImpl);
IRBuilder<> Builder(FooEntry);
Builder.CreateRet(Builder.CreateCall(BarDecl));
}
Expand Down Expand Up @@ -203,14 +203,13 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
// RuntimeDyld::MemoryManager::needsToReserveAllocationSpace hook, which is
// called once per object before any sections are allocated.

ModuleBuilder MB1(getGlobalContext(), "", "dummy");
ModuleBuilder MB1(Context, "", "dummy");
{
MB1.getModule()->setDataLayout(TM->createDataLayout());
Function *BarImpl = MB1.createFunctionDecl<int32_t(void)>("foo");
BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
BarImpl);
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
IRBuilder<> Builder(BarEntry);
IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
IntegerType *Int32Ty = IntegerType::get(Context, 32);
Value *FourtyTwo = ConstantInt::getSigned(Int32Ty, 42);
Builder.CreateRet(FourtyTwo);
}
Expand All @@ -219,14 +218,13 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
std::vector<object::ObjectFile*> Obj1Set;
Obj1Set.push_back(Obj1.getBinary());

ModuleBuilder MB2(getGlobalContext(), "", "dummy");
ModuleBuilder MB2(Context, "", "dummy");
{
MB2.getModule()->setDataLayout(TM->createDataLayout());
Function *BarImpl = MB2.createFunctionDecl<int32_t(void)>("bar");
BasicBlock *BarEntry = BasicBlock::Create(getGlobalContext(), "entry",
BarImpl);
BasicBlock *BarEntry = BasicBlock::Create(Context, "entry", BarImpl);
IRBuilder<> Builder(BarEntry);
IntegerType *Int32Ty = IntegerType::get(getGlobalContext(), 32);
IntegerType *Int32Ty = IntegerType::get(Context, 32);
Value *Seven = ConstantInt::getSigned(Int32Ty, 7);
Builder.CreateRet(Seven);
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
class OrcCAPIExecutionTest : public testing::Test, public OrcExecutionTest {
protected:
std::unique_ptr<Module> createTestModule(const Triple &TT) {
ModuleBuilder MB(getGlobalContext(), TT.str(), "");
ModuleBuilder MB(Context, TT.str(), "");
Function *TestFunc = MB.createFunctionDecl<int()>("testFunc");
Function *Main = MB.createFunctionDecl<int(int, char*[])>("main");

Main->getBasicBlockList().push_back(BasicBlock::Create(getGlobalContext()));
Main->getBasicBlockList().push_back(BasicBlock::Create(Context));
IRBuilder<> B(&Main->back());
Value* Result = B.CreateCall(TestFunc);
B.CreateRet(Result);
Expand Down
1 change: 1 addition & 0 deletions llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class OrcExecutionTest {
};

protected:
LLVMContext Context;
std::unique_ptr<TargetMachine> TM;
private:
static bool NativeTargetInitialized;
Expand Down
36 changes: 20 additions & 16 deletions llvm/unittests/IR/ConstantsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace llvm {
namespace {

TEST(ConstantsTest, Integer_i1) {
IntegerType* Int1 = IntegerType::get(getGlobalContext(), 1);
LLVMContext Context;
IntegerType *Int1 = IntegerType::get(Context, 1);
Constant* One = ConstantInt::get(Int1, 1, true);
Constant* Zero = ConstantInt::get(Int1, 0);
Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true);
Expand Down Expand Up @@ -103,7 +104,8 @@ TEST(ConstantsTest, Integer_i1) {
}

TEST(ConstantsTest, IntSigns) {
IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext());
LLVMContext Context;
IntegerType *Int8Ty = Type::getInt8Ty(Context);
EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue());
EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue());
EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue());
Expand All @@ -116,16 +118,17 @@ TEST(ConstantsTest, IntSigns) {
}

TEST(ConstantsTest, FP128Test) {
Type *FP128Ty = Type::getFP128Ty(getGlobalContext());
LLVMContext Context;
Type *FP128Ty = Type::getFP128Ty(Context);

IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128);
IntegerType *Int128Ty = Type::getIntNTy(Context, 128);
Constant *Zero128 = Constant::getNullValue(Int128Ty);
Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty);
EXPECT_TRUE(isa<ConstantFP>(X));
}

TEST(ConstantsTest, PointerCast) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Type *Int8PtrTy = Type::getInt8PtrTy(C);
Type *Int32PtrTy = Type::getInt32PtrTy(C);
Type *Int64Ty = Type::getInt64Ty(C);
Expand Down Expand Up @@ -165,14 +168,15 @@ TEST(ConstantsTest, PointerCast) {
}

TEST(ConstantsTest, AsInstructionsTest) {
std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext()));
LLVMContext Context;
std::unique_ptr<Module> M(new Module("MyModule", Context));

Type *Int64Ty = Type::getInt64Ty(getGlobalContext());
Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
Type *Int16Ty = Type::getInt16Ty(getGlobalContext());
Type *Int1Ty = Type::getInt1Ty(getGlobalContext());
Type *FloatTy = Type::getFloatTy(getGlobalContext());
Type *DoubleTy = Type::getDoubleTy(getGlobalContext());
Type *Int64Ty = Type::getInt64Ty(Context);
Type *Int32Ty = Type::getInt32Ty(Context);
Type *Int16Ty = Type::getInt16Ty(Context);
Type *Int1Ty = Type::getInt1Ty(Context);
Type *FloatTy = Type::getFloatTy(Context);
Type *DoubleTy = Type::getDoubleTy(Context);

Constant *Global = M->getOrInsertGlobal("dummy",
PointerType::getUnqual(Int32Ty));
Expand All @@ -189,8 +193,7 @@ TEST(ConstantsTest, AsInstructionsTest) {

Constant *One = ConstantInt::get(Int32Ty, 1);
Constant *Two = ConstantInt::get(Int64Ty, 2);
Constant *Big = ConstantInt::get(getGlobalContext(),
APInt{256, uint64_t(-1), true});
Constant *Big = ConstantInt::get(Context, APInt{256, uint64_t(-1), true});
Constant *Elt = ConstantInt::get(Int16Ty, 2015);
Constant *Undef16 = UndefValue::get(Int16Ty);
Constant *Undef64 = UndefValue::get(Int64Ty);
Expand Down Expand Up @@ -278,9 +281,10 @@ TEST(ConstantsTest, AsInstructionsTest) {
#ifdef GTEST_HAS_DEATH_TEST
#ifndef NDEBUG
TEST(ConstantsTest, ReplaceWithConstantTest) {
std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext()));
LLVMContext Context;
std::unique_ptr<Module> M(new Module("MyModule", Context));

Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
Type *Int32Ty = Type::getInt32Ty(Context);
Constant *One = ConstantInt::get(Int32Ty, 1);

Constant *Global =
Expand Down
8 changes: 4 additions & 4 deletions llvm/unittests/IR/DominatorTreeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace llvm {
};
char DPass::ID = 0;

std::unique_ptr<Module> makeLLVMModule(DPass *P) {
std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context, DPass *P) {
const char *ModuleStrig =
"declare i32 @g()\n" \
"define void @f(i32 %x) personality i32 ()* @g {\n" \
Expand All @@ -239,14 +239,14 @@ namespace llvm {
" %y9 = phi i32 [0, %bb2], [%y4, %bb1]\n"
" ret void\n" \
"}\n";
LLVMContext &C = getGlobalContext();
SMDiagnostic Err;
return parseAssemblyString(ModuleStrig, Err, C);
return parseAssemblyString(ModuleStrig, Err, Context);
}

TEST(DominatorTree, Unreachable) {
DPass *P = new DPass();
std::unique_ptr<Module> M = makeLLVMModule(P);
LLVMContext Context;
std::unique_ptr<Module> M = makeLLVMModule(Context, P);
legacy::PassManager Passes;
Passes.add(P);
Passes.run(*M);
Expand Down
26 changes: 15 additions & 11 deletions llvm/unittests/IR/InstructionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace llvm {
namespace {

TEST(InstructionsTest, ReturnInst) {
LLVMContext &C(getGlobalContext());
LLVMContext C;

// test for PR6589
const ReturnInst* r0 = ReturnInst::Create(C);
Expand Down Expand Up @@ -103,7 +103,7 @@ TEST_F(ModuleWithFunctionTest, InvokeInst) {
}

TEST(InstructionsTest, BranchInst) {
LLVMContext &C(getGlobalContext());
LLVMContext C;

// Make a BasicBlocks
BasicBlock* bb0 = BasicBlock::Create(C);
Expand Down Expand Up @@ -169,7 +169,7 @@ TEST(InstructionsTest, BranchInst) {
}

TEST(InstructionsTest, CastInst) {
LLVMContext &C(getGlobalContext());
LLVMContext C;

Type *Int8Ty = Type::getInt8Ty(C);
Type *Int16Ty = Type::getInt16Ty(C);
Expand Down Expand Up @@ -281,14 +281,18 @@ TEST(InstructionsTest, CastInst) {
// First form
BasicBlock *BB = BasicBlock::Create(C);
Constant *NullV2I32Ptr = Constant::getNullValue(V2Int32PtrTy);
CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty, "foo", BB);
auto Inst1 = CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty, "foo", BB);

// Second form
CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty);
auto Inst2 = CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty);

delete Inst2;
Inst1->eraseFromParent();
delete BB;
}

TEST(InstructionsTest, VectorGep) {
LLVMContext &C(getGlobalContext());
LLVMContext C;

// Type Definitions
Type *I8Ty = IntegerType::get(C, 8);
Expand Down Expand Up @@ -391,7 +395,7 @@ TEST(InstructionsTest, VectorGep) {
}

TEST(InstructionsTest, FPMathOperator) {
LLVMContext &Context = getGlobalContext();
LLVMContext Context;
IRBuilder<> Builder(Context);
MDBuilder MDHelper(Context);
Instruction *I = Builder.CreatePHI(Builder.getDoubleTy(), 0);
Expand All @@ -406,7 +410,7 @@ TEST(InstructionsTest, FPMathOperator) {


TEST(InstructionsTest, isEliminableCastPair) {
LLVMContext &C(getGlobalContext());
LLVMContext C;

Type* Int16Ty = Type::getInt16Ty(C);
Type* Int32Ty = Type::getInt32Ty(C);
Expand Down Expand Up @@ -486,7 +490,7 @@ TEST(InstructionsTest, isEliminableCastPair) {
}

TEST(InstructionsTest, CloneCall) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Type *Int32Ty = Type::getInt32Ty(C);
Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty};
Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false);
Expand Down Expand Up @@ -519,7 +523,7 @@ TEST(InstructionsTest, CloneCall) {
}

TEST(InstructionsTest, AlterCallBundles) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Type *Int32Ty = Type::getInt32Ty(C);
Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false);
Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
Expand All @@ -546,7 +550,7 @@ TEST(InstructionsTest, AlterCallBundles) {
}

TEST(InstructionsTest, AlterInvokeBundles) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Type *Int32Ty = Type::getInt32Ty(C);
Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false);
Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
Expand Down
73 changes: 40 additions & 33 deletions llvm/unittests/IR/LegacyPassManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ namespace llvm {
char OnTheFlyTest::ID=0;

TEST(PassManager, RunOnce) {
Module M("test-once", getGlobalContext());
LLVMContext Context;
Module M("test-once", Context);
struct ModuleNDNM *mNDNM = new ModuleNDNM();
struct ModuleDNM *mDNM = new ModuleDNM();
struct ModuleNDM *mNDM = new ModuleNDM();
Expand All @@ -311,7 +312,8 @@ namespace llvm {
}

TEST(PassManager, ReRun) {
Module M("test-rerun", getGlobalContext());
LLVMContext Context;
Module M("test-rerun", Context);
struct ModuleNDNM *mNDNM = new ModuleNDNM();
struct ModuleDNM *mDNM = new ModuleDNM();
struct ModuleNDM *mNDM = new ModuleNDM();
Expand All @@ -334,11 +336,12 @@ namespace llvm {
EXPECT_EQ(1, mDNM->run);
}

Module* makeLLVMModule();
Module *makeLLVMModule(LLVMContext &Context);

template<typename T>
void MemoryTestHelper(int run) {
std::unique_ptr<Module> M(makeLLVMModule());
LLVMContext Context;
std::unique_ptr<Module> M(makeLLVMModule(Context));
T *P = new T();
legacy::PassManager Passes;
Passes.add(P);
Expand All @@ -348,7 +351,8 @@ namespace llvm {

template<typename T>
void MemoryTestHelper(int run, int N) {
Module *M = makeLLVMModule();
LLVMContext Context;
Module *M = makeLLVMModule(Context);
T *P = new T();
legacy::PassManager Passes;
Passes.add(P);
Expand Down Expand Up @@ -383,7 +387,8 @@ namespace llvm {
}

TEST(PassManager, MemoryOnTheFly) {
Module *M = makeLLVMModule();
LLVMContext Context;
Module *M = makeLLVMModule(Context);
{
SCOPED_TRACE("Running OnTheFlyTest");
struct OnTheFlyTest *O = new OnTheFlyTest();
Expand All @@ -396,28 +401,27 @@ namespace llvm {
delete M;
}

Module* makeLLVMModule() {
Module *makeLLVMModule(LLVMContext &Context) {
// Module Construction
Module* mod = new Module("test-mem", getGlobalContext());
Module *mod = new Module("test-mem", Context);
mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
"i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
"a:0:64-s:64:64-f80:128:128");
mod->setTargetTriple("x86_64-unknown-linux-gnu");

// Type Definitions
std::vector<Type*>FuncTy_0_args;
FunctionType* FuncTy_0 = FunctionType::get(
/*Result=*/IntegerType::get(getGlobalContext(), 32),
/*Params=*/FuncTy_0_args,
/*isVarArg=*/false);
FunctionType *FuncTy_0 = FunctionType::get(
/*Result=*/IntegerType::get(Context, 32),
/*Params=*/FuncTy_0_args,
/*isVarArg=*/false);

std::vector<Type*>FuncTy_2_args;
FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1));
FunctionType* FuncTy_2 = FunctionType::get(
/*Result=*/Type::getVoidTy(getGlobalContext()),
/*Params=*/FuncTy_2_args,
/*isVarArg=*/false);

FuncTy_2_args.push_back(IntegerType::get(Context, 1));
FunctionType *FuncTy_2 = FunctionType::get(
/*Result=*/Type::getVoidTy(Context),
/*Params=*/FuncTy_2_args,
/*isVarArg=*/false);

// Function Declarations

Expand Down Expand Up @@ -465,46 +469,46 @@ namespace llvm {
// Function: test1 (func_test1)
{

BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,nullptr);
BasicBlock *label_entry =
BasicBlock::Create(Context, "entry", func_test1, nullptr);

// Block entry (label_entry)
CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
int32_3->setCallingConv(CallingConv::C);
int32_3->setTailCall(false);AttributeSet int32_3_PAL;
int32_3->setAttributes(int32_3_PAL);

ReturnInst::Create(getGlobalContext(), int32_3, label_entry);

ReturnInst::Create(Context, int32_3, label_entry);
}

// Function: test2 (func_test2)
{

BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,nullptr);
BasicBlock *label_entry_5 =
BasicBlock::Create(Context, "entry", func_test2, nullptr);

// Block entry (label_entry_5)
CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
int32_6->setCallingConv(CallingConv::C);
int32_6->setTailCall(false);AttributeSet int32_6_PAL;
int32_6->setAttributes(int32_6_PAL);

ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5);

ReturnInst::Create(Context, int32_6, label_entry_5);
}

// Function: test3 (func_test3)
{

BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,nullptr);
BasicBlock *label_entry_8 =
BasicBlock::Create(Context, "entry", func_test3, nullptr);

// Block entry (label_entry_8)
CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
int32_9->setCallingConv(CallingConv::C);
int32_9->setTailCall(false);AttributeSet int32_9_PAL;
int32_9->setAttributes(int32_9_PAL);

ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8);

ReturnInst::Create(Context, int32_9, label_entry_8);
}

// Function: test4 (func_test4)
Expand All @@ -513,10 +517,14 @@ namespace llvm {
Value *int1_f = &*args++;
int1_f->setName("f");

BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,nullptr);
BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,nullptr);
BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,nullptr);
BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,nullptr);
BasicBlock *label_entry_11 =
BasicBlock::Create(Context, "entry", func_test4, nullptr);
BasicBlock *label_bb =
BasicBlock::Create(Context, "bb", func_test4, nullptr);
BasicBlock *label_bb1 =
BasicBlock::Create(Context, "bb1", func_test4, nullptr);
BasicBlock *label_return =
BasicBlock::Create(Context, "return", func_test4, nullptr);

// Block entry (label_entry_11)
BranchInst::Create(label_bb, label_entry_11);
Expand All @@ -528,8 +536,7 @@ namespace llvm {
BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);

// Block return (label_return)
ReturnInst::Create(getGlobalContext(), label_return);

ReturnInst::Create(Context, label_return);
}
return mod;
}
Expand Down
16 changes: 8 additions & 8 deletions llvm/unittests/IR/MetadataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ TEST_F(MDNodeTest, Simple) {

MDString *s1 = MDString::get(Context, StringRef(&x[0], 3));
MDString *s2 = MDString::get(Context, StringRef(&y[0], 3));
ConstantAsMetadata *CI = ConstantAsMetadata::get(
ConstantInt::get(getGlobalContext(), APInt(8, 0)));
ConstantAsMetadata *CI =
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0)));

std::vector<Metadata *> V;
V.push_back(s1);
Expand Down Expand Up @@ -206,8 +206,8 @@ TEST_F(MDNodeTest, Simple) {
}

TEST_F(MDNodeTest, Delete) {
Constant *C = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 1);
Instruction *I = new BitCastInst(C, Type::getInt32Ty(getGlobalContext()));
Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 1);
Instruction *I = new BitCastInst(C, Type::getInt32Ty(Context));

Metadata *const V = LocalAsMetadata::get(I);
MDNode *n = MDNode::get(Context, V);
Expand Down Expand Up @@ -2062,8 +2062,8 @@ TEST_F(ValueAsMetadataTest, UpdatesOnRAUW) {

TEST_F(ValueAsMetadataTest, TempTempReplacement) {
// Create a constant.
ConstantAsMetadata *CI = ConstantAsMetadata::get(
ConstantInt::get(getGlobalContext(), APInt(8, 0)));
ConstantAsMetadata *CI =
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0)));

auto Temp1 = MDTuple::getTemporary(Context, None);
auto Temp2 = MDTuple::getTemporary(Context, {CI});
Expand All @@ -2079,8 +2079,8 @@ TEST_F(ValueAsMetadataTest, TempTempReplacement) {

TEST_F(ValueAsMetadataTest, CollidingDoubleUpdates) {
// Create a constant.
ConstantAsMetadata *CI = ConstantAsMetadata::get(
ConstantInt::get(getGlobalContext(), APInt(8, 0)));
ConstantAsMetadata *CI =
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(8, 0)));

// Create a temporary to prevent nodes from resolving.
auto Temp = MDTuple::getTemporary(Context, None);
Expand Down
30 changes: 15 additions & 15 deletions llvm/unittests/IR/PassManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,30 @@ struct TestInvalidationFunctionPass
StringRef Name;
};

std::unique_ptr<Module> parseIR(const char *IR) {
LLVMContext &C = getGlobalContext();
std::unique_ptr<Module> parseIR(LLVMContext &Context, const char *IR) {
SMDiagnostic Err;
return parseAssemblyString(IR, Err, C);
return parseAssemblyString(IR, Err, Context);
}

class PassManagerTest : public ::testing::Test {
protected:
LLVMContext Context;
std::unique_ptr<Module> M;

public:
PassManagerTest()
: M(parseIR("define void @f() {\n"
"entry:\n"
" call void @g()\n"
" call void @h()\n"
" ret void\n"
"}\n"
"define void @g() {\n"
" ret void\n"
"}\n"
"define void @h() {\n"
" ret void\n"
"}\n")) {}
: M(parseIR(Context, "define void @f() {\n"
"entry:\n"
" call void @g()\n"
" call void @h()\n"
" ret void\n"
"}\n"
"define void @g() {\n"
" ret void\n"
"}\n"
"define void @h() {\n"
" ret void\n"
"}\n")) {}
};

TEST_F(PassManagerTest, BasicPreservedAnalyses) {
Expand Down
302 changes: 168 additions & 134 deletions llvm/unittests/IR/TypeBuilderTest.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions llvm/unittests/IR/UserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ TEST(UserTest, ValueOpIteration) {
}

TEST(UserTest, PersonalityUser) {
Module M("", getGlobalContext());
FunctionType *RetVoidTy =
FunctionType::get(Type::getVoidTy(getGlobalContext()), false);
LLVMContext Context;
Module M("", Context);
FunctionType *RetVoidTy = FunctionType::get(Type::getVoidTy(Context), false);
Function *PersonalityF = Function::Create(
RetVoidTy, GlobalValue::ExternalLinkage, "PersonalityFn", &M);
Function *TestF =
Expand Down
44 changes: 23 additions & 21 deletions llvm/unittests/IR/ValueHandleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace {

class ValueHandle : public testing::Test {
protected:
LLVMContext Context;
Constant *ConstantV;
std::unique_ptr<BitCastInst> BitcastV;

ValueHandle() :
ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)),
BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))) {
}
ValueHandle()
: ConstantV(ConstantInt::get(Type::getInt32Ty(Context), 0)),
BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(Context))) {}
};

class ConcreteCallbackVH final : public CallbackVH {
Expand All @@ -42,8 +42,8 @@ TEST_F(ValueHandle, WeakVH_BasicOperation) {

// Make sure I can call a method on the underlying Value. It
// doesn't matter which method.
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), WVH->getType());
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*WVH).getType());
EXPECT_EQ(Type::getInt32Ty(Context), WVH->getType());
EXPECT_EQ(Type::getInt32Ty(Context), (*WVH).getType());
}

TEST_F(ValueHandle, WeakVH_Comparisons) {
Expand Down Expand Up @@ -197,8 +197,8 @@ TEST_F(ValueHandle, CallbackVH_BasicOperation) {

// Make sure I can call a method on the underlying Value. It
// doesn't matter which method.
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), CVH->getType());
EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*CVH).getType());
EXPECT_EQ(Type::getInt32Ty(Context), CVH->getType());
EXPECT_EQ(Type::getInt32Ty(Context), (*CVH).getType());
}

TEST_F(ValueHandle, CallbackVH_Comparisons) {
Expand Down Expand Up @@ -297,15 +297,17 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
Value *AURWArgument;
LLVMContext *Context;

RecoveringVH() : DeletedCalls(0), AURWArgument(nullptr),
Context(&getGlobalContext()) {}
RecoveringVH(Value *V)
: CallbackVH(V), DeletedCalls(0), AURWArgument(nullptr),
Context(&getGlobalContext()) {}
RecoveringVH(LLVMContext &TheContext)
: DeletedCalls(0), AURWArgument(nullptr), Context(&TheContext) {}

RecoveringVH(LLVMContext &TheContext, Value *V)
: CallbackVH(V), DeletedCalls(0), AURWArgument(nullptr),
Context(&TheContext) {}

private:
void deleted() override {
getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())));
getValPtr()->replaceAllUsesWith(
Constant::getNullValue(Type::getInt32Ty(*Context)));
setValPtr(nullptr);
}
void allUsesReplacedWith(Value *new_value) override {
Expand All @@ -318,15 +320,15 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {

// Normally, if a value has uses, deleting it will crash. However, we can use
// a CallbackVH to remove the uses before the check for no uses.
RecoveringVH RVH;
RVH = BitcastV.get();
std::unique_ptr<BinaryOperator> BitcastUser(
BinaryOperator::CreateAdd(RVH,
Constant::getNullValue(Type::getInt32Ty(getGlobalContext()))));
RecoveringVH RVH(Context);
RVH = RecoveringVH(Context, BitcastV.get());
std::unique_ptr<BinaryOperator> BitcastUser(BinaryOperator::CreateAdd(
RVH, Constant::getNullValue(Type::getInt32Ty(Context))));
EXPECT_EQ(BitcastV.get(), BitcastUser->getOperand(0));
BitcastV.reset(); // Would crash without the ValueHandler.
EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), RVH.AURWArgument);
EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())),
EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(Context)),
RVH.AURWArgument);
EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(Context)),
BitcastUser->getOperand(0));
}

Expand Down
10 changes: 5 additions & 5 deletions llvm/unittests/IR/ValueMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ namespace {
template<typename T>
class ValueMapTest : public testing::Test {
protected:
LLVMContext Context;
Constant *ConstantV;
std::unique_ptr<BitCastInst> BitcastV;
std::unique_ptr<BinaryOperator> AddV;

ValueMapTest() :
ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)),
BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))),
AddV(BinaryOperator::CreateAdd(ConstantV, ConstantV)) {
}
ValueMapTest()
: ConstantV(ConstantInt::get(Type::getInt32Ty(Context), 0)),
BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(Context))),
AddV(BinaryOperator::CreateAdd(ConstantV, ConstantV)) {}
};

// Run everything on Value*, a subtype to make sure that casting works as
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/IR/ValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST(ValueTest, UsedInBasicBlock) {
}

TEST(GlobalTest, CreateAddressSpace) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
std::unique_ptr<Module> M(new Module("TestModule", Ctx));
Type *Int8Ty = Type::getInt8Ty(Ctx);
Type *Int32Ty = Type::getInt32Ty(Ctx);
Expand Down Expand Up @@ -92,7 +92,7 @@ TEST(GlobalTest, CreateAddressSpace) {
#ifdef GTEST_HAS_DEATH_TEST
#ifndef NDEBUG
TEST(GlobalTest, AlignDeath) {
LLVMContext &Ctx = getGlobalContext();
LLVMContext Ctx;
std::unique_ptr<Module> M(new Module("TestModule", Ctx));
Type *Int32Ty = Type::getInt32Ty(Ctx);
GlobalVariable *Var =
Expand Down
8 changes: 4 additions & 4 deletions llvm/unittests/IR/VerifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace llvm {
namespace {

TEST(VerifierTest, Branch_i1) {
LLVMContext &C = getGlobalContext();
LLVMContext C;
Module M("M", C);
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy));
Expand All @@ -46,7 +46,7 @@ TEST(VerifierTest, Branch_i1) {
}

TEST(VerifierTest, InvalidRetAttribute) {
LLVMContext &C = getGlobalContext();
LLVMContext C;
Module M("M", C);
FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false);
Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy));
Expand All @@ -62,7 +62,7 @@ TEST(VerifierTest, InvalidRetAttribute) {
}

TEST(VerifierTest, CrossModuleRef) {
LLVMContext &C = getGlobalContext();
LLVMContext C;
Module M1("M1", C);
Module M2("M2", C);
Module M3("M3", C);
Expand Down Expand Up @@ -121,7 +121,7 @@ TEST(VerifierTest, CrossModuleRef) {
}

TEST(VerifierTest, CrossModuleMetadataRef) {
LLVMContext &C = getGlobalContext();
LLVMContext C;
Module M1("M1", C);
Module M2("M2", C);
GlobalVariable *newGV =
Expand Down
12 changes: 5 additions & 7 deletions llvm/unittests/IR/WaymarkTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
namespace llvm {
namespace {

Constant *char2constant(char c) {
return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c);
}


TEST(WaymarkTest, NativeArray) {
LLVMContext Context;
static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
Value * values[22];
std::transform(tail, tail + 22, values, char2constant);
FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true);
std::transform(tail, tail + 22, values, [&](char c) {
return ConstantInt::get(Type::getInt8Ty(Context), c);
});
FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), true);
std::unique_ptr<Function> F(
Function::Create(FT, GlobalValue::ExternalLinkage));
const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
Expand Down
5 changes: 3 additions & 2 deletions llvm/unittests/ProfileData/InstrProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ TEST_F(InstrProfTest, get_profile_summary) {
VerifySummary(PS);

// Test that conversion of summary to and from Metadata works.
Metadata *MD = PS.getMD(getGlobalContext());
LLVMContext Context;
Metadata *MD = PS.getMD(Context);
ASSERT_TRUE(MD);
ProfileSummary *PSFromMD = ProfileSummary::getFromMD(MD);
ASSERT_TRUE(PSFromMD);
Expand All @@ -190,7 +191,7 @@ TEST_F(InstrProfTest, get_profile_summary) {
delete IPS;

// Test that summary can be attached to and read back from module.
Module M("my_module", getGlobalContext());
Module M("my_module", Context);
M.setProfileSummary(MD);
MD = M.getProfileSummary();
ASSERT_TRUE(MD);
Expand Down
7 changes: 4 additions & 3 deletions llvm/unittests/ProfileData/SampleProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace {

struct SampleProfTest : ::testing::Test {
std::string Data;
LLVMContext Context;
std::unique_ptr<raw_ostream> OS;
std::unique_ptr<SampleProfileWriter> Writer;
std::unique_ptr<SampleProfileReader> Reader;
Expand All @@ -43,7 +44,7 @@ struct SampleProfTest : ::testing::Test {
}

void readProfile(std::unique_ptr<MemoryBuffer> &Profile) {
auto ReaderOrErr = SampleProfileReader::create(Profile, getGlobalContext());
auto ReaderOrErr = SampleProfileReader::create(Profile, Context);
ASSERT_TRUE(NoError(ReaderOrErr.getError()));
Reader = std::move(ReaderOrErr.get());
}
Expand Down Expand Up @@ -127,7 +128,7 @@ struct SampleProfTest : ::testing::Test {
VerifySummary(Summary);

// Test that conversion of summary to and from Metadata works.
Metadata *MD = Summary.getMD(getGlobalContext());
Metadata *MD = Summary.getMD(Context);
ASSERT_TRUE(MD);
ProfileSummary *PS = ProfileSummary::getFromMD(MD);
ASSERT_TRUE(PS);
Expand All @@ -137,7 +138,7 @@ struct SampleProfTest : ::testing::Test {
delete SPS;

// Test that summary can be attached to and read back from module.
Module M("my_module", getGlobalContext());
Module M("my_module", Context);
M.setProfileSummary(MD);
MD = M.getProfileSummary();
ASSERT_TRUE(MD);
Expand Down
16 changes: 8 additions & 8 deletions llvm/unittests/Transforms/Utils/IntegerDivision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace {


TEST(IntegerDivision, SDiv) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Module M("test division", C);
IRBuilder<> Builder(C);

Expand Down Expand Up @@ -51,7 +51,7 @@ TEST(IntegerDivision, SDiv) {
}

TEST(IntegerDivision, UDiv) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Module M("test division", C);
IRBuilder<> Builder(C);

Expand Down Expand Up @@ -81,7 +81,7 @@ TEST(IntegerDivision, UDiv) {
}

TEST(IntegerDivision, SRem) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Module M("test remainder", C);
IRBuilder<> Builder(C);

Expand Down Expand Up @@ -111,7 +111,7 @@ TEST(IntegerDivision, SRem) {
}

TEST(IntegerDivision, URem) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Module M("test remainder", C);
IRBuilder<> Builder(C);

Expand Down Expand Up @@ -142,7 +142,7 @@ TEST(IntegerDivision, URem) {


TEST(IntegerDivision, SDiv64) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Module M("test division", C);
IRBuilder<> Builder(C);

Expand Down Expand Up @@ -172,7 +172,7 @@ TEST(IntegerDivision, SDiv64) {
}

TEST(IntegerDivision, UDiv64) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Module M("test division", C);
IRBuilder<> Builder(C);

Expand Down Expand Up @@ -202,7 +202,7 @@ TEST(IntegerDivision, UDiv64) {
}

TEST(IntegerDivision, SRem64) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Module M("test remainder", C);
IRBuilder<> Builder(C);

Expand Down Expand Up @@ -232,7 +232,7 @@ TEST(IntegerDivision, SRem64) {
}

TEST(IntegerDivision, URem64) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
Module M("test remainder", C);
IRBuilder<> Builder(C);

Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using namespace llvm;

TEST(Local, RecursivelyDeleteDeadPHINodes) {
LLVMContext &C(getGlobalContext());
LLVMContext C;

IRBuilder<> builder(C);

Expand Down Expand Up @@ -60,7 +60,7 @@ TEST(Local, RecursivelyDeleteDeadPHINodes) {
}

TEST(Local, RemoveDuplicatePHINodes) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
IRBuilder<> B(C);

std::unique_ptr<Function> F(
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Transforms/Utils/MemorySSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using namespace llvm;

TEST(MemorySSA, RemoveMemoryAccess) {
LLVMContext &C(getGlobalContext());
LLVMContext C;
std::unique_ptr<Module> M(new Module("Remove memory access", C));
IRBuilder<> B(C);
DataLayout DL("e-i64:64-f80:128-n8:16:32:64-S128");
Expand Down