[llvm] r256531 - [ptr-traits] Merge the MetadataTracking helpers into the Metadata

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 28 18:14:51 PST 2015


Author: chandlerc
Date: Mon Dec 28 20:14:50 2015
New Revision: 256531

URL: http://llvm.org/viewvc/llvm-project?rev=256531&view=rev
Log:
[ptr-traits] Merge the MetadataTracking helpers into the Metadata
header.

This is part of a series of patches to allow LLVM to check for complete
pointee types when computing its pointer traits. This is absolutely
necessary to get correct (or reproducible) results for things like how
many low bits are guaranteed to be zero.

The MetadataTracking helpers aren't actually independent. They rely on
constructing a PointerUnion between Metadata and MetadataAsValue
pointers, which requires know the alignment of pointers to those types
which requires them to be complete.

The .cpp file even defined a method declared in Metadata.h! These really
don't seem like something that is separable, and there is no real
layering problem with just placing them together.

Removed:
    llvm/trunk/include/llvm/IR/MetadataTracking.h
    llvm/trunk/lib/IR/MetadataTracking.cpp
Modified:
    llvm/trunk/include/llvm/IR/Metadata.h
    llvm/trunk/include/llvm/IR/TrackingMDRef.h
    llvm/trunk/lib/IR/CMakeLists.txt
    llvm/trunk/lib/IR/Metadata.cpp

Modified: llvm/trunk/include/llvm/IR/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=256531&r1=256530&r2=256531&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Metadata.h (original)
+++ llvm/trunk/include/llvm/IR/Metadata.h Mon Dec 28 20:14:50 2015
@@ -18,10 +18,11 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/ilist_node.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/IR/Constant.h"
-#include "llvm/IR/MetadataTracking.h"
+#include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Support/ErrorHandling.h"
 #include <type_traits>
@@ -196,6 +197,77 @@ private:
   void untrack();
 };
 
+/// \brief API for tracking metadata references through RAUW and deletion.
+///
+/// Shared API for updating \a Metadata pointers in subclasses that support
+/// RAUW.
+///
+/// This API is not meant to be used directly.  See \a TrackingMDRef for a
+/// user-friendly tracking reference.
+class MetadataTracking {
+public:
+  /// \brief Track the reference to metadata.
+  ///
+  /// Register \c MD with \c *MD, if the subclass supports tracking.  If \c *MD
+  /// gets RAUW'ed, \c MD will be updated to the new address.  If \c *MD gets
+  /// deleted, \c MD will be set to \c nullptr.
+  ///
+  /// If tracking isn't supported, \c *MD will not change.
+  ///
+  /// \return true iff tracking is supported by \c MD.
+  static bool track(Metadata *&MD) {
+    return track(&MD, *MD, static_cast<Metadata *>(nullptr));
+  }
+
+  /// \brief Track the reference to metadata for \a Metadata.
+  ///
+  /// As \a track(Metadata*&), but with support for calling back to \c Owner to
+  /// tell it that its operand changed.  This could trigger \c Owner being
+  /// re-uniqued.
+  static bool track(void *Ref, Metadata &MD, Metadata &Owner) {
+    return track(Ref, MD, &Owner);
+  }
+
+  /// \brief Track the reference to metadata for \a MetadataAsValue.
+  ///
+  /// As \a track(Metadata*&), but with support for calling back to \c Owner to
+  /// tell it that its operand changed.  This could trigger \c Owner being
+  /// re-uniqued.
+  static bool track(void *Ref, Metadata &MD, MetadataAsValue &Owner) {
+    return track(Ref, MD, &Owner);
+  }
+
+  /// \brief Stop tracking a reference to metadata.
+  ///
+  /// Stops \c *MD from tracking \c MD.
+  static void untrack(Metadata *&MD) { untrack(&MD, *MD); }
+  static void untrack(void *Ref, Metadata &MD);
+
+  /// \brief Move tracking from one reference to another.
+  ///
+  /// Semantically equivalent to \c untrack(MD) followed by \c track(New),
+  /// except that ownership callbacks are maintained.
+  ///
+  /// Note: it is an error if \c *MD does not equal \c New.
+  ///
+  /// \return true iff tracking is supported by \c MD.
+  static bool retrack(Metadata *&MD, Metadata *&New) {
+    return retrack(&MD, *MD, &New);
+  }
+  static bool retrack(void *Ref, Metadata &MD, void *New);
+
+  /// \brief Check whether metadata is replaceable.
+  static bool isReplaceable(const Metadata &MD);
+
+  typedef PointerUnion<MetadataAsValue *, Metadata *> OwnerTy;
+
+private:
+  /// \brief Track a reference to metadata for an owner.
+  ///
+  /// Generalized version of tracking.
+  static bool track(void *Ref, Metadata &MD, OwnerTy Owner);
+};
+
 /// \brief Shared implementation of use-lists for replaceable metadata.
 ///
 /// Most metadata cannot be RAUW'ed.  This is a shared implementation of

Removed: llvm/trunk/include/llvm/IR/MetadataTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/MetadataTracking.h?rev=256530&view=auto
==============================================================================
--- llvm/trunk/include/llvm/IR/MetadataTracking.h (original)
+++ llvm/trunk/include/llvm/IR/MetadataTracking.h (removed)
@@ -1,99 +0,0 @@
-//===- llvm/IR/MetadataTracking.h - Metadata tracking ---------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Low-level functions to enable tracking of metadata that could RAUW.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_IR_METADATATRACKING_H
-#define LLVM_IR_METADATATRACKING_H
-
-#include "llvm/ADT/PointerUnion.h"
-#include "llvm/Support/Casting.h"
-#include <type_traits>
-
-namespace llvm {
-
-class Metadata;
-class MetadataAsValue;
-
-/// \brief API for tracking metadata references through RAUW and deletion.
-///
-/// Shared API for updating \a Metadata pointers in subclasses that support
-/// RAUW.
-///
-/// This API is not meant to be used directly.  See \a TrackingMDRef for a
-/// user-friendly tracking reference.
-class MetadataTracking {
-public:
-  /// \brief Track the reference to metadata.
-  ///
-  /// Register \c MD with \c *MD, if the subclass supports tracking.  If \c *MD
-  /// gets RAUW'ed, \c MD will be updated to the new address.  If \c *MD gets
-  /// deleted, \c MD will be set to \c nullptr.
-  ///
-  /// If tracking isn't supported, \c *MD will not change.
-  ///
-  /// \return true iff tracking is supported by \c MD.
-  static bool track(Metadata *&MD) {
-    return track(&MD, *MD, static_cast<Metadata *>(nullptr));
-  }
-
-  /// \brief Track the reference to metadata for \a Metadata.
-  ///
-  /// As \a track(Metadata*&), but with support for calling back to \c Owner to
-  /// tell it that its operand changed.  This could trigger \c Owner being
-  /// re-uniqued.
-  static bool track(void *Ref, Metadata &MD, Metadata &Owner) {
-    return track(Ref, MD, &Owner);
-  }
-
-  /// \brief Track the reference to metadata for \a MetadataAsValue.
-  ///
-  /// As \a track(Metadata*&), but with support for calling back to \c Owner to
-  /// tell it that its operand changed.  This could trigger \c Owner being
-  /// re-uniqued.
-  static bool track(void *Ref, Metadata &MD, MetadataAsValue &Owner) {
-    return track(Ref, MD, &Owner);
-  }
-
-  /// \brief Stop tracking a reference to metadata.
-  ///
-  /// Stops \c *MD from tracking \c MD.
-  static void untrack(Metadata *&MD) { untrack(&MD, *MD); }
-  static void untrack(void *Ref, Metadata &MD);
-
-  /// \brief Move tracking from one reference to another.
-  ///
-  /// Semantically equivalent to \c untrack(MD) followed by \c track(New),
-  /// except that ownership callbacks are maintained.
-  ///
-  /// Note: it is an error if \c *MD does not equal \c New.
-  ///
-  /// \return true iff tracking is supported by \c MD.
-  static bool retrack(Metadata *&MD, Metadata *&New) {
-    return retrack(&MD, *MD, &New);
-  }
-  static bool retrack(void *Ref, Metadata &MD, void *New);
-
-  /// \brief Check whether metadata is replaceable.
-  static bool isReplaceable(const Metadata &MD);
-
-  typedef PointerUnion<MetadataAsValue *, Metadata *> OwnerTy;
-
-private:
-  /// \brief Track a reference to metadata for an owner.
-  ///
-  /// Generalized version of tracking.
-  static bool track(void *Ref, Metadata &MD, OwnerTy Owner);
-};
-
-} // end namespace llvm
-
-#endif

Modified: llvm/trunk/include/llvm/IR/TrackingMDRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/TrackingMDRef.h?rev=256531&r1=256530&r2=256531&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/TrackingMDRef.h (original)
+++ llvm/trunk/include/llvm/IR/TrackingMDRef.h Mon Dec 28 20:14:50 2015
@@ -14,15 +14,11 @@
 #ifndef LLVM_IR_TRACKINGMDREF_H
 #define LLVM_IR_TRACKINGMDREF_H
 
-#include "llvm/IR/MetadataTracking.h"
+#include "llvm/IR/Metadata.h"
 #include "llvm/Support/Casting.h"
 
 namespace llvm {
 
-class Metadata;
-class MDNode;
-class ValueAsMetadata;
-
 /// \brief Tracking metadata reference.
 ///
 /// This class behaves like \a TrackingVH, but for metadata.

Modified: llvm/trunk/lib/IR/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/CMakeLists.txt?rev=256531&r1=256530&r2=256531&view=diff
==============================================================================
--- llvm/trunk/lib/IR/CMakeLists.txt (original)
+++ llvm/trunk/lib/IR/CMakeLists.txt Mon Dec 28 20:14:50 2015
@@ -36,7 +36,6 @@ add_llvm_library(LLVMCore
   MDBuilder.cpp
   Mangler.cpp
   Metadata.cpp
-  MetadataTracking.cpp
   Module.cpp
   Operator.cpp
   Pass.cpp

Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=256531&r1=256530&r2=256531&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Mon Dec 28 20:14:50 2015
@@ -120,6 +120,38 @@ void MetadataAsValue::untrack() {
     MetadataTracking::untrack(MD);
 }
 
+bool MetadataTracking::track(void *Ref, Metadata &MD, OwnerTy Owner) {
+  assert(Ref && "Expected live reference");
+  assert((Owner || *static_cast<Metadata **>(Ref) == &MD) &&
+         "Reference without owner must be direct");
+  if (auto *R = ReplaceableMetadataImpl::get(MD)) {
+    R->addRef(Ref, Owner);
+    return true;
+  }
+  return false;
+}
+
+void MetadataTracking::untrack(void *Ref, Metadata &MD) {
+  assert(Ref && "Expected live reference");
+  if (auto *R = ReplaceableMetadataImpl::get(MD))
+    R->dropRef(Ref);
+}
+
+bool MetadataTracking::retrack(void *Ref, Metadata &MD, void *New) {
+  assert(Ref && "Expected live reference");
+  assert(New && "Expected live reference");
+  assert(Ref != New && "Expected change");
+  if (auto *R = ReplaceableMetadataImpl::get(MD)) {
+    R->moveRef(Ref, New, MD);
+    return true;
+  }
+  return false;
+}
+
+bool MetadataTracking::isReplaceable(const Metadata &MD) {
+  return ReplaceableMetadataImpl::get(const_cast<Metadata &>(MD));
+}
+
 void ReplaceableMetadataImpl::addRef(void *Ref, OwnerTy Owner) {
   bool WasInserted =
       UseMap.insert(std::make_pair(Ref, std::make_pair(Owner, NextIndex)))
@@ -239,6 +271,12 @@ void ReplaceableMetadataImpl::resolveAll
   }
 }
 
+ReplaceableMetadataImpl *ReplaceableMetadataImpl::get(Metadata &MD) {
+  if (auto *N = dyn_cast<MDNode>(&MD))
+    return N->Context.getReplaceableUses();
+  return dyn_cast<ValueAsMetadata>(&MD);
+}
+
 static Function *getLocalFunction(Value *V) {
   assert(V && "Expected value");
   if (auto *A = dyn_cast<Argument>(V))

Removed: llvm/trunk/lib/IR/MetadataTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/MetadataTracking.cpp?rev=256530&view=auto
==============================================================================
--- llvm/trunk/lib/IR/MetadataTracking.cpp (original)
+++ llvm/trunk/lib/IR/MetadataTracking.cpp (removed)
@@ -1,55 +0,0 @@
-//===- MetadataTracking.cpp - Implement metadata tracking -----------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements Metadata tracking.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/IR/MetadataTracking.h"
-#include "llvm/IR/Metadata.h"
-
-using namespace llvm;
-
-ReplaceableMetadataImpl *ReplaceableMetadataImpl::get(Metadata &MD) {
-  if (auto *N = dyn_cast<MDNode>(&MD))
-    return N->Context.getReplaceableUses();
-  return dyn_cast<ValueAsMetadata>(&MD);
-}
-
-bool MetadataTracking::track(void *Ref, Metadata &MD, OwnerTy Owner) {
-  assert(Ref && "Expected live reference");
-  assert((Owner || *static_cast<Metadata **>(Ref) == &MD) &&
-         "Reference without owner must be direct");
-  if (auto *R = ReplaceableMetadataImpl::get(MD)) {
-    R->addRef(Ref, Owner);
-    return true;
-  }
-  return false;
-}
-
-void MetadataTracking::untrack(void *Ref, Metadata &MD) {
-  assert(Ref && "Expected live reference");
-  if (auto *R = ReplaceableMetadataImpl::get(MD))
-    R->dropRef(Ref);
-}
-
-bool MetadataTracking::retrack(void *Ref, Metadata &MD, void *New) {
-  assert(Ref && "Expected live reference");
-  assert(New && "Expected live reference");
-  assert(Ref != New && "Expected change");
-  if (auto *R = ReplaceableMetadataImpl::get(MD)) {
-    R->moveRef(Ref, New, MD);
-    return true;
-  }
-  return false;
-}
-
-bool MetadataTracking::isReplaceable(const Metadata &MD) {
-  return ReplaceableMetadataImpl::get(const_cast<Metadata &>(MD));
-}




More information about the llvm-commits mailing list