Skip to content

Commit

Permalink
[llvm] Migrate llvm::make_unique to std::make_unique
Browse files Browse the repository at this point in the history
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369013 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
JDevlieghere committed Aug 15, 2019
1 parent a714337 commit 114087c
Show file tree
Hide file tree
Showing 430 changed files with 1,472 additions and 1,472 deletions.
16 changes: 8 additions & 8 deletions docs/ORCv2.rst
Expand Up @@ -174,7 +174,7 @@ checking omitted for brevity) as:

ExecutionSession ES;
RTDyldObjectLinkingLayer ObjLinkingLayer(
ES, []() { return llvm::make_unique<SectionMemoryManager>(); });
ES, []() { return std::make_unique<SectionMemoryManager>(); });
CXXCompileLayer CXXLayer(ES, ObjLinkingLayer);

// Create JITDylib "A" and add code to it using the CXX layer.
Expand Down Expand Up @@ -453,7 +453,7 @@ std::unique_ptr<LLVMContext>:

.. code-block:: c++

ThreadSafeContext TSCtx(llvm::make_unique<LLVMContext>());
ThreadSafeContext TSCtx(std::make_unique<LLVMContext>());

ThreadSafeModules can be constructed from a pair of a std::unique_ptr<Module>
and a ThreadSafeContext value. ThreadSafeContext values may be shared between
Expand All @@ -462,10 +462,10 @@ multiple ThreadSafeModules:
.. code-block:: c++

ThreadSafeModule TSM1(
llvm::make_unique<Module>("M1", *TSCtx.getContext()), TSCtx);
std::make_unique<Module>("M1", *TSCtx.getContext()), TSCtx);
ThreadSafeModule TSM2(
llvm::make_unique<Module>("M2", *TSCtx.getContext()), TSCtx);
std::make_unique<Module>("M2", *TSCtx.getContext()), TSCtx);
Before using a ThreadSafeContext, clients should ensure that either the context
is only accessible on the current thread, or that the context is locked. In the
Expand All @@ -476,7 +476,7 @@ or creating any Modules attached to it. E.g.

.. code-block:: c++

ThreadSafeContext TSCtx(llvm::make_unique<LLVMContext>());
ThreadSafeContext TSCtx(std::make_unique<LLVMContext>());

ThreadPool TP(NumThreads);
JITStack J;
Expand Down Expand Up @@ -519,8 +519,8 @@ constructs a new ThreadSafeContext value from a std::unique_ptr<LLVMContext>:
// Maximize concurrency opportunities by loading every module on a
// separate context.
for (const auto &IRPath : IRPaths) {
auto Ctx = llvm::make_unique<LLVMContext>();
auto M = llvm::make_unique<LLVMContext>("M", *Ctx);
auto Ctx = std::make_unique<LLVMContext>();
auto M = std::make_unique<LLVMContext>("M", *Ctx);
CompileLayer.add(ES.getMainJITDylib(),
ThreadSafeModule(std::move(M), std::move(Ctx)));
}
Expand All @@ -531,7 +531,7 @@ all modules on the same context:
.. code-block:: c++

// Save memory by using one context for all Modules:
ThreadSafeContext TSCtx(llvm::make_unique<LLVMContext>());
ThreadSafeContext TSCtx(std::make_unique<LLVMContext>());
for (const auto &IRPath : IRPaths) {
ThreadSafeModule TSM(parsePath(IRPath, *TSCtx.getContext()), TSCtx);
CompileLayer.add(ES.getMainJITDylib(), ThreadSafeModule(std::move(TSM));
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorial/BuildingAJIT1.rst
Expand Up @@ -138,10 +138,10 @@ usual include guards and #includes [2]_, we get to the definition of our class:
public:
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
: ObjectLayer(ES,
[]() { return llvm::make_unique<SectionMemoryManager>(); }),
[]() { return std::make_unique<SectionMemoryManager>(); }),
CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))),
DL(std::move(DL)), Mangle(ES, this->DL),
Ctx(llvm::make_unique<LLVMContext>()) {
Ctx(std::make_unique<LLVMContext>()) {
ES.getMainJITDylib().setGenerator(
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(DL)));
}
Expand Down Expand Up @@ -195,7 +195,7 @@ REPL process as well. We do this by attaching a
if (!DL)
return DL.takeError();

return llvm::make_unique<KaleidoscopeJIT>(std::move(*JTMB), std::move(*DL));
return std::make_unique<KaleidoscopeJIT>(std::move(*JTMB), std::move(*DL));
}
const DataLayout &getDataLayout() const { return DL; }
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorial/BuildingAJIT2.rst
Expand Up @@ -71,11 +71,11 @@ apply to each Module that is added via addModule:

KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
: ObjectLayer(ES,
[]() { return llvm::make_unique<SectionMemoryManager>(); }),
[]() { return std::make_unique<SectionMemoryManager>(); }),
CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))),
TransformLayer(ES, CompileLayer, optimizeModule),
DL(std::move(DL)), Mangle(ES, this->DL),
Ctx(llvm::make_unique<LLVMContext>()) {
Ctx(std::make_unique<LLVMContext>()) {
ES.getMainJITDylib().setGenerator(
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(DL)));
}
Expand All @@ -102,7 +102,7 @@ Next we need to update our addModule method to replace the call to
static Expected<ThreadSafeModule>
optimizeModule(ThreadSafeModule M, const MaterializationResponsibility &R) {
// Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
auto FPM = std::make_unique<legacy::FunctionPassManager>(M.get());

// Add some optimizations.
FPM->add(createInstructionCombiningPass());
Expand Down Expand Up @@ -213,7 +213,7 @@ class:
.. code-block:: c++

Error IRLayer::add(JITDylib &JD, ThreadSafeModule TSM, VModuleKey K) {
return JD.define(llvm::make_unique<BasicIRLayerMaterializationUnit>(
return JD.define(std::make_unique<BasicIRLayerMaterializationUnit>(
*this, std::move(K), std::move(TSM)));
}
Expand Down
22 changes: 11 additions & 11 deletions docs/tutorial/MyFirstLanguageFrontend/LangImpl02.rst
Expand Up @@ -155,8 +155,8 @@ be generated with calls like this:

.. code-block:: c++

auto LHS = llvm::make_unique<VariableExprAST>("x");
auto RHS = llvm::make_unique<VariableExprAST>("y");
auto LHS = std::make_unique<VariableExprAST>("x");
auto RHS = std::make_unique<VariableExprAST>("y");
auto Result = std::make_unique<BinaryExprAST>('+', std::move(LHS),
std::move(RHS));

Expand Down Expand Up @@ -210,7 +210,7 @@ which parses that production. For numeric literals, we have:

/// numberexpr ::= number
static std::unique_ptr<ExprAST> ParseNumberExpr() {
auto Result = llvm::make_unique<NumberExprAST>(NumVal);
auto Result = std::make_unique<NumberExprAST>(NumVal);
getNextToken(); // consume the number
return std::move(Result);
}
Expand Down Expand Up @@ -276,7 +276,7 @@ function calls:
getNextToken(); // eat identifier.

if (CurTok != '(') // Simple variable ref.
return llvm::make_unique<VariableExprAST>(IdName);
return std::make_unique<VariableExprAST>(IdName);

// Call.
getNextToken(); // eat (
Expand All @@ -300,7 +300,7 @@ function calls:
// Eat the ')'.
getNextToken();

return llvm::make_unique<CallExprAST>(IdName, std::move(Args));
return std::make_unique<CallExprAST>(IdName, std::move(Args));
}

This routine follows the same style as the other routines. (It expects
Expand Down Expand Up @@ -503,7 +503,7 @@ then continue parsing:
}

// Merge LHS/RHS.
LHS = llvm::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
LHS = std::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
std::move(RHS));
} // loop around to the top of the while loop.
}
Expand Down Expand Up @@ -533,7 +533,7 @@ above two blocks duplicated for context):
return nullptr;
}
// Merge LHS/RHS.
LHS = llvm::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
LHS = std::make_unique<BinaryExprAST>(BinOp, std::move(LHS),
std::move(RHS));
} // loop around to the top of the while loop.
}
Expand Down Expand Up @@ -593,7 +593,7 @@ expressions):
// success.
getNextToken(); // eat ')'.

return llvm::make_unique<PrototypeAST>(FnName, std::move(ArgNames));
return std::make_unique<PrototypeAST>(FnName, std::move(ArgNames));
}

Given this, a function definition is very simple, just a prototype plus
Expand All @@ -608,7 +608,7 @@ an expression to implement the body:
if (!Proto) return nullptr;

if (auto E = ParseExpression())
return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E));
return std::make_unique<FunctionAST>(std::move(Proto), std::move(E));
return nullptr;
}

Expand All @@ -634,8 +634,8 @@ nullary (zero argument) functions for them:
static std::unique_ptr<FunctionAST> ParseTopLevelExpr() {
if (auto E = ParseExpression()) {
// Make an anonymous proto.
auto Proto = llvm::make_unique<PrototypeAST>("", std::vector<std::string>());
return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E));
auto Proto = std::make_unique<PrototypeAST>("", std::vector<std::string>());
return std::make_unique<FunctionAST>(std::move(Proto), std::move(E));
}
return nullptr;
}
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial/MyFirstLanguageFrontend/LangImpl04.rst
Expand Up @@ -141,10 +141,10 @@ for us:

void InitializeModuleAndPassManager(void) {
// Open a new module.
TheModule = llvm::make_unique<Module>("my cool jit", TheContext);
TheModule = std::make_unique<Module>("my cool jit", TheContext);

// Create a new pass manager attached to it.
TheFPM = llvm::make_unique<FunctionPassManager>(TheModule.get());
TheFPM = std::make_unique<FunctionPassManager>(TheModule.get());

// Do simple "peephole" optimizations and bit-twiddling optzns.
TheFPM->add(createInstructionCombiningPass());
Expand Down Expand Up @@ -259,7 +259,7 @@ adding a global variable ``TheJIT``, and initializing it in
fprintf(stderr, "ready> ");
getNextToken();

TheJIT = llvm::make_unique<KaleidoscopeJIT>();
TheJIT = std::make_unique<KaleidoscopeJIT>();

// Run the main "interpreter loop" now.
MainLoop();
Expand All @@ -273,11 +273,11 @@ We also need to setup the data layout for the JIT:

void InitializeModuleAndPassManager(void) {
// Open a new module.
TheModule = llvm::make_unique<Module>("my cool jit", TheContext);
TheModule = std::make_unique<Module>("my cool jit", TheContext);
TheModule->setDataLayout(TheJIT->getTargetMachine().createDataLayout());

// Create a new pass manager attached to it.
TheFPM = llvm::make_unique<FunctionPassManager>(TheModule.get());
TheFPM = std::make_unique<FunctionPassManager>(TheModule.get());
...

The KaleidoscopeJIT class is a simple JIT built specifically for these
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/MyFirstLanguageFrontend/LangImpl05.rst
Expand Up @@ -146,7 +146,7 @@ First we define a new parsing function:
if (!Else)
return nullptr;

return llvm::make_unique<IfExprAST>(std::move(Cond), std::move(Then),
return std::make_unique<IfExprAST>(std::move(Cond), std::move(Then),
std::move(Else));
}

Expand Down Expand Up @@ -560,7 +560,7 @@ value to null in the AST node:
if (!Body)
return nullptr;

return llvm::make_unique<ForExprAST>(IdName, std::move(Start),
return std::make_unique<ForExprAST>(IdName, std::move(Start),
std::move(End), std::move(Step),
std::move(Body));
}
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/MyFirstLanguageFrontend/LangImpl06.rst
Expand Up @@ -220,7 +220,7 @@ user-defined operator, we need to parse it:
if (Kind && ArgNames.size() != Kind)
return LogErrorP("Invalid number of operands for operator");

return llvm::make_unique<PrototypeAST>(FnName, std::move(ArgNames), Kind != 0,
return std::make_unique<PrototypeAST>(FnName, std::move(ArgNames), Kind != 0,
BinaryPrecedence);
}

Expand Down Expand Up @@ -348,7 +348,7 @@ simple: we'll add a new function to do it:
int Opc = CurTok;
getNextToken();
if (auto Operand = ParseUnary())
return llvm::make_unique<UnaryExprAST>(Opc, std::move(Operand));
return std::make_unique<UnaryExprAST>(Opc, std::move(Operand));
return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/MyFirstLanguageFrontend/LangImpl07.rst
Expand Up @@ -780,7 +780,7 @@ AST node:
if (!Body)
return nullptr;

return llvm::make_unique<VarExprAST>(std::move(VarNames),
return std::make_unique<VarExprAST>(std::move(VarNames),
std::move(Body));
}

Expand Down
6 changes: 3 additions & 3 deletions docs/tutorial/MyFirstLanguageFrontend/LangImpl09.rst
Expand Up @@ -77,8 +77,8 @@ statement be our "main":

.. code-block:: udiff
- auto Proto = llvm::make_unique<PrototypeAST>("", std::vector<std::string>());
+ auto Proto = llvm::make_unique<PrototypeAST>("main", std::vector<std::string>());
- auto Proto = std::make_unique<PrototypeAST>("", std::vector<std::string>());
+ auto Proto = std::make_unique<PrototypeAST>("main", std::vector<std::string>());
just with the simple change of giving it a name.

Expand Down Expand Up @@ -325,7 +325,7 @@ that we pass down through when we create a new expression:

.. code-block:: c++

LHS = llvm::make_unique<BinaryExprAST>(BinLoc, BinOp, std::move(LHS),
LHS = std::make_unique<BinaryExprAST>(BinLoc, BinOp, std::move(LHS),
std::move(RHS));

giving us locations for each of our expressions and variables.
Expand Down
2 changes: 1 addition & 1 deletion examples/ExceptionDemo/ExceptionDemo.cpp
Expand Up @@ -1904,7 +1904,7 @@ int main(int argc, char *argv[]) {

// Make the module, which holds all the code.
std::unique_ptr<llvm::Module> Owner =
llvm::make_unique<llvm::Module>("my cool jit", Context);
std::make_unique<llvm::Module>("my cool jit", Context);
llvm::Module *module = Owner.get();

std::unique_ptr<llvm::RTDyldMemoryManager> MemMgr(new llvm::SectionMemoryManager());
Expand Down
2 changes: 1 addition & 1 deletion examples/HowToUseJIT/HowToUseJIT.cpp
Expand Up @@ -63,7 +63,7 @@ int main() {
LLVMContext Context;

// Create some module to put our function into it.
std::unique_ptr<Module> Owner = make_unique<Module>("test", Context);
std::unique_ptr<Module> Owner = std::make_unique<Module>("test", Context);
Module *M = Owner.get();

// Create the add1 function entry and insert this entry into module M. The
Expand Down
4 changes: 2 additions & 2 deletions examples/HowToUseLLJIT/HowToUseLLJIT.cpp
Expand Up @@ -20,8 +20,8 @@ using namespace llvm::orc;
ExitOnError ExitOnErr;

ThreadSafeModule createDemoModule() {
auto Context = llvm::make_unique<LLVMContext>();
auto M = make_unique<Module>("test", *Context);
auto Context = std::make_unique<LLVMContext>();
auto M = std::make_unique<Module>("test", *Context);

// Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int".
Expand Down
6 changes: 3 additions & 3 deletions examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
Expand Up @@ -42,10 +42,10 @@ class KaleidoscopeJIT {
public:
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
: ObjectLayer(ES,
[]() { return llvm::make_unique<SectionMemoryManager>(); }),
[]() { return std::make_unique<SectionMemoryManager>(); }),
CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))),
DL(std::move(DL)), Mangle(ES, this->DL),
Ctx(llvm::make_unique<LLVMContext>()) {
Ctx(std::make_unique<LLVMContext>()) {
ES.getMainJITDylib().addGenerator(
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
DL.getGlobalPrefix())));
Expand All @@ -61,7 +61,7 @@ class KaleidoscopeJIT {
if (!DL)
return DL.takeError();

return llvm::make_unique<KaleidoscopeJIT>(std::move(*JTMB), std::move(*DL));
return std::make_unique<KaleidoscopeJIT>(std::move(*JTMB), std::move(*DL));
}

const DataLayout &getDataLayout() const { return DL; }
Expand Down

0 comments on commit 114087c

Please sign in to comment.