Skip to content

Commit

Permalink
Replace OwningPtr<T> with std::unique_ptr<T>.
Browse files Browse the repository at this point in the history
This compiles with no changes to clang/lld/lldb with MSVC and includes
overloads to various functions which are used by those projects and llvm
which have OwningPtr's as parameters. This should allow out of tree
projects some time to move. There are also no changes to libs/Target,
which should help out of tree targets have time to move, if necessary.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203083 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ahmedcharles committed Mar 6, 2014
1 parent ca8b562 commit f4ccd11
Show file tree
Hide file tree
Showing 167 changed files with 556 additions and 654 deletions.
2 changes: 1 addition & 1 deletion examples/Fibonacci/fibonacci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int main(int argc, char **argv) {
LLVMContext Context;

// Create some module to put our function into it.
OwningPtr<Module> M(new Module("test", Context));
std::unique_ptr<Module> M(new Module("test", Context));

// We are about to create the "fib" function:
Function *FibF = CreateFibFunction(M.get(), Context);
Expand Down
2 changes: 1 addition & 1 deletion examples/Kaleidoscope/MCJIT/cached/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ class MCJITObjectCache : public ObjectCache {
// This file isn't in our cache
return NULL;
}
OwningPtr<MemoryBuffer> IRObjectBuffer;
std::unique_ptr<MemoryBuffer> IRObjectBuffer;
MemoryBuffer::getFile(IRCacheFile.c_str(), IRObjectBuffer, -1, false);
// MCJIT will want to write into this buffer, and we don't want that
// because the file has probably just been mmapped. Instead we make
Expand Down
2 changes: 1 addition & 1 deletion examples/Kaleidoscope/MCJIT/complete/toy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class MCJITObjectCache : public ObjectCache {
// This file isn't in our cache
return NULL;
}
OwningPtr<MemoryBuffer> IRObjectBuffer;
std::unique_ptr<MemoryBuffer> IRObjectBuffer;
MemoryBuffer::getFile(IRCacheFile.c_str(), IRObjectBuffer, -1, false);
// MCJIT will want to write into this buffer, and we don't want that
// because the file has probably just been mmapped. Instead we make
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/Analysis/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#define LLVM_ANALYSIS_CALLGRAPH_H

#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Function.h"
Expand Down Expand Up @@ -314,7 +313,7 @@ class CallGraphAnalysis {
/// call graph interface is entirelly a wrapper around a \c CallGraph object
/// which is stored internally for each module.
class CallGraphWrapperPass : public ModulePass {
OwningPtr<CallGraph> G;
std::unique_ptr<CallGraph> G;

public:
static char ID; // Class identification, replacement for typeinfo
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/Analysis/MemoryDependenceAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#define LLVM_ANALYSIS_MEMORYDEPENDENCEANALYSIS_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/AliasAnalysis.h"
Expand Down Expand Up @@ -325,7 +324,8 @@ namespace llvm {
AliasAnalysis *AA;
const DataLayout *DL;
DominatorTree *DT;
OwningPtr<PredIteratorCache> PredCache;
std::unique_ptr<PredIteratorCache> PredCache;

public:
MemoryDependenceAnalysis();
~MemoryDependenceAnalysis();
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/Bitcode/BitstreamReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef LLVM_BITCODE_BITSTREAMREADER_H
#define LLVM_BITCODE_BITSTREAMREADER_H

#include "llvm/ADT/OwningPtr.h"
#include "llvm/Bitcode/BitCodes.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/StreamableMemoryObject.h"
Expand Down Expand Up @@ -44,7 +43,7 @@ class BitstreamReader {
std::vector<std::pair<unsigned, std::string> > RecordNames;
};
private:
OwningPtr<StreamableMemoryObject> BitcodeBytes;
std::unique_ptr<StreamableMemoryObject> BitcodeBytes;

std::vector<BlockInfo> BlockInfoRecords;

Expand Down
6 changes: 3 additions & 3 deletions include/llvm/CodeGen/RegAllocPBQP.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace llvm {
class MachineBlockFrequencyInfo;
class MachineFunction;
class TargetRegisterInfo;
template<class T> class OwningPtr;

typedef PBQP::RegAlloc::Graph PBQPRAGraph;

Expand Down Expand Up @@ -158,8 +157,9 @@ namespace llvm {
PBQP::PBQPNum benefit);
};

FunctionPass* createPBQPRegisterAllocator(OwningPtr<PBQPBuilder> &builder,
char *customPassID=0);
FunctionPass *
createPBQPRegisterAllocator(std::unique_ptr<PBQPBuilder> &builder,
char *customPassID = 0);
}

#endif /* LLVM_CODEGEN_REGALLOCPBQP_H */
3 changes: 1 addition & 2 deletions include/llvm/ExecutionEngine/ObjectBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef LLVM_EXECUTIONENGINE_OBJECTBUFFER_H
#define LLVM_EXECUTIONENGINE_OBJECTBUFFER_H

#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -49,7 +48,7 @@ class ObjectBuffer {

protected:
// The memory contained in an ObjectBuffer
OwningPtr<MemoryBuffer> Buffer;
std::unique_ptr<MemoryBuffer> Buffer;
};

/// ObjectBufferStream - This class encapsulates the SmallVector and
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/ExecutionEngine/ObjectImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ObjectImage {
virtual void anchor();

protected:
OwningPtr<ObjectBuffer> Buffer;
std::unique_ptr<ObjectBuffer> Buffer;

public:
ObjectImage(ObjectBuffer *Input) : Buffer(Input) {}
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/IR/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef LLVM_IR_MODULE_H
#define LLVM_IR_MODULE_H

#include "llvm/ADT/OwningPtr.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
Expand Down Expand Up @@ -197,7 +196,8 @@ class Module {
NamedMDListType NamedMDList; ///< The named metadata in the module
std::string GlobalScopeAsm; ///< Inline Asm at global scope.
ValueSymbolTable *ValSymTab; ///< Symbol table for values
OwningPtr<GVMaterializer> Materializer; ///< Used to materialize GlobalValues
std::unique_ptr<GVMaterializer>
Materializer; ///< Used to materialize GlobalValues
std::string ModuleID; ///< Human readable identifier for the module
std::string TargetTriple; ///< Platform target triple Module compiled on
void *NamedMDSymTab; ///< NamedMDNode names.
Expand Down
5 changes: 2 additions & 3 deletions include/llvm/LTO/LTOModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#define LTO_MODULE_H

#include "llvm-c/lto.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
Expand Down Expand Up @@ -48,8 +47,8 @@ struct LTOModule {
const llvm::GlobalValue *symbol;
};

llvm::OwningPtr<llvm::Module> _module;
llvm::OwningPtr<llvm::TargetMachine> _target;
std::unique_ptr<llvm::Module> _module;
std::unique_ptr<llvm::TargetMachine> _target;
llvm::MCObjectFileInfo ObjFileInfo;
StringSet _linkeropt_strings;
std::vector<const char *> _deplibs;
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/LineEditor/LineEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class LineEditor {
private:
std::string Prompt;
std::string HistoryPath;
OwningPtr<InternalData> Data;
std::unique_ptr<InternalData> Data;

struct CompleterConcept {
virtual ~CompleterConcept();
Expand Down Expand Up @@ -145,7 +145,7 @@ class LineEditor {
T Value;
};

llvm::OwningPtr<const CompleterConcept> Completer;
std::unique_ptr<const CompleterConcept> Completer;
};

}
Expand Down
11 changes: 5 additions & 6 deletions include/llvm/MC/MCDisassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ class MCDisassembler {
};

/// Constructor - Performs initial setup for the disassembler.
MCDisassembler(const MCSubtargetInfo &STI) : GetOpInfo(0), SymbolLookUp(0),
DisInfo(0), Ctx(0),
STI(STI), Symbolizer(0),
CommentStream(0) {}
MCDisassembler(const MCSubtargetInfo &STI)
: GetOpInfo(0), SymbolLookUp(0), DisInfo(0), Ctx(0), STI(STI),
Symbolizer(), CommentStream(0) {}

virtual ~MCDisassembler();

Expand Down Expand Up @@ -102,7 +101,7 @@ class MCDisassembler {
protected:
// Subtarget information, for instruction decoding predicates if required.
const MCSubtargetInfo &STI;
OwningPtr<MCSymbolizer> Symbolizer;
std::unique_ptr<MCSymbolizer> Symbolizer;

public:
// Helpers around MCSymbolizer
Expand All @@ -115,7 +114,7 @@ class MCDisassembler {

/// Set \p Symzer as the current symbolizer.
/// This takes ownership of \p Symzer, and deletes the previously set one.
void setSymbolizer(OwningPtr<MCSymbolizer> &Symzer);
void setSymbolizer(std::unique_ptr<MCSymbolizer> &Symzer);

/// Sets up an external symbolizer that uses the C API callbacks.
void setupForSymbolicDisassembly(LLVMOpInfoCallback GetOpInfo,
Expand Down
10 changes: 5 additions & 5 deletions include/llvm/MC/MCExternalSymbolizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "llvm-c/Disassembler.h"
#include "llvm/MC/MCSymbolizer.h"
#include <memory>

namespace llvm {

Expand All @@ -38,12 +39,11 @@ class MCExternalSymbolizer : public MCSymbolizer {

public:
MCExternalSymbolizer(MCContext &Ctx,
OwningPtr<MCRelocationInfo> &RelInfo,
std::unique_ptr<MCRelocationInfo> &RelInfo,
LLVMOpInfoCallback getOpInfo,
LLVMSymbolLookupCallback symbolLookUp,
void *disInfo)
: MCSymbolizer(Ctx, RelInfo),
GetOpInfo(getOpInfo), SymbolLookUp(symbolLookUp), DisInfo(disInfo) {}
LLVMSymbolLookupCallback symbolLookUp, void *disInfo)
: MCSymbolizer(Ctx, RelInfo), GetOpInfo(getOpInfo),
SymbolLookUp(symbolLookUp), DisInfo(disInfo) {}

bool tryAddingSymbolicOperand(MCInst &MI, raw_ostream &CommentStream,
int64_t Value,
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/MC/MCMachObjectWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define LLVM_MC_MCMACHOBJECTWRITER_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCObjectWriter.h"
Expand Down Expand Up @@ -92,7 +91,7 @@ class MachObjectWriter : public MCObjectWriter {
};

/// The target specific Mach-O writer instance.
llvm::OwningPtr<MCMachObjectTargetWriter> TargetObjectWriter;
std::unique_ptr<MCMachObjectTargetWriter> TargetObjectWriter;

/// @name Relocation Data
/// @{
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/MC/MCModuleYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#ifndef LLVM_MC_MCMODULEYAML_H
#define LLVM_MC_MCMODULEYAML_H

#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/MC/MCModule.h"
#include "llvm/Support/raw_ostream.h"
Expand All @@ -33,7 +32,7 @@ StringRef mcmodule2yaml(raw_ostream &OS, const MCModule &MCM,

/// \brief Creates a new module and returns it in \p MCM.
/// \returns The empty string on success, an error message on failure.
StringRef yaml2mcmodule(OwningPtr<MCModule> &MCM, StringRef YamlContent,
StringRef yaml2mcmodule(std::unique_ptr<MCModule> &MCM, StringRef YamlContent,
const MCInstrInfo &MII, const MCRegisterInfo &MRI);

} // end namespace llvm
Expand Down
5 changes: 2 additions & 3 deletions include/llvm/MC/MCObjectDisassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define LLVM_MC_MCOBJECTDISASSEMBLER_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/MemoryObject.h"
Expand Down Expand Up @@ -67,7 +66,7 @@ class MCObjectDisassembler {
/// \brief Set the region on which to fallback if disassembly was requested
/// somewhere not accessible in the object file.
/// This is used for dynamic disassembly (see RawMemoryObject).
void setFallbackRegion(OwningPtr<MemoryObject> &Region) {
void setFallbackRegion(std::unique_ptr<MemoryObject> &Region) {
FallbackRegion.reset(Region.release());
}

Expand Down Expand Up @@ -113,7 +112,7 @@ class MCObjectDisassembler {
MCObjectSymbolizer *MOS;

/// \brief The fallback memory region, outside the object file.
OwningPtr<MemoryObject> FallbackRegion;
std::unique_ptr<MemoryObject> FallbackRegion;

/// \brief Return a memory region suitable for reading starting at \p Addr.
/// In most cases, this returns a StringRefMemoryObject backed by the
Expand Down
7 changes: 4 additions & 3 deletions include/llvm/MC/MCObjectSymbolizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MCObjectSymbolizer : public MCSymbolizer {
const object::RelocationRef *findRelocationAt(uint64_t Addr);
const object::SectionRef *findSectionContaining(uint64_t Addr);

MCObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
MCObjectSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &RelInfo,
const object::ObjectFile *Obj);

public:
Expand All @@ -63,8 +63,9 @@ class MCObjectSymbolizer : public MCSymbolizer {

/// \brief Create an object symbolizer for \p Obj.
static MCObjectSymbolizer *
createObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
const object::ObjectFile *Obj);
createObjectSymbolizer(MCContext &Ctx,
std::unique_ptr<MCRelocationInfo> &RelInfo,
const object::ObjectFile *Obj);

private:
typedef DenseMap<uint64_t, object::RelocationRef> AddrToRelocMap;
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ARMTargetStreamer : public MCTargetStreamer {
void emitCurrentConstantPool();

private:
OwningPtr<AssemblerConstantPools> ConstantPools;
std::unique_ptr<AssemblerConstantPools> ConstantPools;
};

/// MCStreamer - Streaming machine code generation interface. This interface
Expand All @@ -144,7 +144,7 @@ class ARMTargetStreamer : public MCTargetStreamer {
///
class MCStreamer {
MCContext &Context;
OwningPtr<MCTargetStreamer> TargetStreamer;
std::unique_ptr<MCTargetStreamer> TargetStreamer;

MCStreamer(const MCStreamer &) LLVM_DELETED_FUNCTION;
MCStreamer &operator=(const MCStreamer &) LLVM_DELETED_FUNCTION;
Expand Down
6 changes: 3 additions & 3 deletions include/llvm/MC/MCSymbolizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#ifndef LLVM_MC_MCSYMBOLIZER_H
#define LLVM_MC_MCSYMBOLIZER_H

#include "llvm/ADT/OwningPtr.h"
#include "llvm/MC/MCRelocationInfo.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
#include <memory>

namespace llvm {

Expand All @@ -42,11 +42,11 @@ class MCSymbolizer {

protected:
MCContext &Ctx;
OwningPtr<MCRelocationInfo> RelInfo;
std::unique_ptr<MCRelocationInfo> RelInfo;

public:
/// \brief Construct an MCSymbolizer, taking ownership of \p RelInfo.
MCSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo);
MCSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &RelInfo);
virtual ~MCSymbolizer();

/// \brief Try to add a symbolic operand instead of \p Value to the MCInst.
Expand Down
5 changes: 3 additions & 2 deletions include/llvm/Object/IRObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class GlobalValue;

namespace object {
class IRObjectFile : public SymbolicFile {
OwningPtr<Module> M;
OwningPtr<Mangler> Mang;
std::unique_ptr<Module> M;
std::unique_ptr<Mangler> Mang;

public:
IRObjectFile(MemoryBuffer *Object, error_code &EC, LLVMContext &Context,
bool BufferOwned);
Expand Down
5 changes: 2 additions & 3 deletions include/llvm/Object/MachOUniversal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifndef LLVM_OBJECT_MACHOUNIVERSAL_H
#define LLVM_OBJECT_MACHOUNIVERSAL_H

#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Object/Binary.h"
Expand Down Expand Up @@ -53,7 +52,7 @@ class MachOUniversalBinary : public Binary {
ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
uint32_t getCPUType() const { return Header.cputype; }

error_code getAsObjectFile(OwningPtr<ObjectFile> &Result) const;
error_code getAsObjectFile(std::unique_ptr<ObjectFile> &Result) const;
};

class object_iterator {
Expand Down Expand Up @@ -95,7 +94,7 @@ class MachOUniversalBinary : public Binary {
}

error_code getObjectForArch(Triple::ArchType Arch,
OwningPtr<ObjectFile> &Result) const;
std::unique_ptr<ObjectFile> &Result) const;
};

}
Expand Down
Loading

0 comments on commit f4ccd11

Please sign in to comment.