IR: Return unique_ptr from MDNode::getTemporary()

Change `MDTuple::getTemporary()` and `MDLocation::getTemporary()` to
return (effectively) `std::unique_ptr<T, MDNode::deleteTemporary>`, and
clean up call sites.  (For now, `DIBuilder` call sites just call
`release()` immediately.)

There's an accompanying change in each of clang and polly to use the new
API.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226504 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-01-19 21:30:18 +00:00
parent a23cc6a1ea
commit f9eaea701d
10 changed files with 77 additions and 81 deletions

View File

@@ -651,6 +651,15 @@ public:
}
};
template <class T>
struct TempMDNodeDeleter {
inline void operator()(T *Node) const;
};
#define HANDLE_UNIQUABLE_LEAF(CLASS) \
typedef std::unique_ptr<CLASS, TempMDNodeDeleter<CLASS>> Temp##CLASS;
#include "llvm/IR/Metadata.def"
//===----------------------------------------------------------------------===//
/// \brief Tuple of metadata.
class MDNode : public Metadata {
@@ -697,8 +706,8 @@ public:
ArrayRef<Metadata *> MDs);
static inline MDTuple *getDistinct(LLVMContext &Context,
ArrayRef<Metadata *> MDs);
static inline MDTuple *getTemporary(LLVMContext &Context,
ArrayRef<Metadata *> MDs);
static inline TempMDTuple getTemporary(LLVMContext &Context,
ArrayRef<Metadata *> MDs);
/// \brief Deallocate a node created by getTemporary.
///
@@ -884,8 +893,9 @@ public:
/// For use in constructing cyclic MDNode structures. A temporary MDNode is
/// not uniqued, may be RAUW'd, and must be manually deleted with
/// deleteTemporary.
static MDTuple *getTemporary(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
return getImpl(Context, MDs, Temporary);
static TempMDTuple getTemporary(LLVMContext &Context,
ArrayRef<Metadata *> MDs) {
return TempMDTuple(getImpl(Context, MDs, Temporary));
}
static bool classof(const Metadata *MD) {
@@ -906,9 +916,14 @@ MDTuple *MDNode::getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
MDTuple *MDNode::getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
return MDTuple::getDistinct(Context, MDs);
}
MDTuple *MDNode::getTemporary(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
TempMDTuple MDNode::getTemporary(LLVMContext &Context,
ArrayRef<Metadata *> MDs) {
return MDTuple::getTemporary(Context, MDs);
}
template <class T>
void TempMDNodeDeleter<T>::operator()(T *Node) const {
MDNode::deleteTemporary(Node);
}
/// \brief Debug location.
///
@@ -945,10 +960,11 @@ public:
Metadata *InlinedAt = nullptr) {
return getImpl(Context, Line, Column, Scope, InlinedAt, Distinct);
}
static MDLocation *getTemporary(LLVMContext &Context, unsigned Line,
unsigned Column, Metadata *Scope,
Metadata *InlinedAt = nullptr) {
return getImpl(Context, Line, Column, Scope, InlinedAt, Temporary);
static TempMDLocation getTemporary(LLVMContext &Context, unsigned Line,
unsigned Column, Metadata *Scope,
Metadata *InlinedAt = nullptr) {
return TempMDLocation(
getImpl(Context, Line, Column, Scope, InlinedAt, Temporary));
}
unsigned getLine() const { return MDNodeSubclassData; }