<div dir="ltr"><div>For anyone following along at home, this commit through some strange interaction is causing LTO (but only LTO!) to infloop. Trying to track down why, but it's... really hard....</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 28, 2015 at 6:18 PM Chandler Carruth via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: chandlerc<br>
Date: Mon Dec 28 20:14:50 2015<br>
New Revision: 256531<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=256531&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=256531&view=rev</a><br>
Log:<br>
[ptr-traits] Merge the MetadataTracking helpers into the Metadata<br>
header.<br>
<br>
This is part of a series of patches to allow LLVM to check for complete<br>
pointee types when computing its pointer traits. This is absolutely<br>
necessary to get correct (or reproducible) results for things like how<br>
many low bits are guaranteed to be zero.<br>
<br>
The MetadataTracking helpers aren't actually independent. They rely on<br>
constructing a PointerUnion between Metadata and MetadataAsValue<br>
pointers, which requires know the alignment of pointers to those types<br>
which requires them to be complete.<br>
<br>
The .cpp file even defined a method declared in Metadata.h! These really<br>
don't seem like something that is separable, and there is no real<br>
layering problem with just placing them together.<br>
<br>
Removed:<br>
llvm/trunk/include/llvm/IR/MetadataTracking.h<br>
llvm/trunk/lib/IR/MetadataTracking.cpp<br>
Modified:<br>
llvm/trunk/include/llvm/IR/Metadata.h<br>
llvm/trunk/include/llvm/IR/TrackingMDRef.h<br>
llvm/trunk/lib/IR/CMakeLists.txt<br>
llvm/trunk/lib/IR/Metadata.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/IR/Metadata.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=256531&r1=256530&r2=256531&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=256531&r1=256530&r2=256531&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/Metadata.h (original)<br>
+++ llvm/trunk/include/llvm/IR/Metadata.h Mon Dec 28 20:14:50 2015<br>
@@ -18,10 +18,11 @@<br>
<br>
#include "llvm/ADT/ArrayRef.h"<br>
#include "llvm/ADT/DenseMap.h"<br>
+#include "llvm/ADT/PointerUnion.h"<br>
#include "llvm/ADT/ilist_node.h"<br>
#include "llvm/ADT/iterator_range.h"<br>
#include "llvm/IR/Constant.h"<br>
-#include "llvm/IR/MetadataTracking.h"<br>
+#include "llvm/IR/LLVMContext.h"<br>
#include "llvm/IR/Value.h"<br>
#include "llvm/Support/ErrorHandling.h"<br>
#include <type_traits><br>
@@ -196,6 +197,77 @@ private:<br>
void untrack();<br>
};<br>
<br>
+/// \brief API for tracking metadata references through RAUW and deletion.<br>
+///<br>
+/// Shared API for updating \a Metadata pointers in subclasses that support<br>
+/// RAUW.<br>
+///<br>
+/// This API is not meant to be used directly. See \a TrackingMDRef for a<br>
+/// user-friendly tracking reference.<br>
+class MetadataTracking {<br>
+public:<br>
+ /// \brief Track the reference to metadata.<br>
+ ///<br>
+ /// Register \c MD with \c *MD, if the subclass supports tracking. If \c *MD<br>
+ /// gets RAUW'ed, \c MD will be updated to the new address. If \c *MD gets<br>
+ /// deleted, \c MD will be set to \c nullptr.<br>
+ ///<br>
+ /// If tracking isn't supported, \c *MD will not change.<br>
+ ///<br>
+ /// \return true iff tracking is supported by \c MD.<br>
+ static bool track(Metadata *&MD) {<br>
+ return track(&MD, *MD, static_cast<Metadata *>(nullptr));<br>
+ }<br>
+<br>
+ /// \brief Track the reference to metadata for \a Metadata.<br>
+ ///<br>
+ /// As \a track(Metadata*&), but with support for calling back to \c Owner to<br>
+ /// tell it that its operand changed. This could trigger \c Owner being<br>
+ /// re-uniqued.<br>
+ static bool track(void *Ref, Metadata &MD, Metadata &Owner) {<br>
+ return track(Ref, MD, &Owner);<br>
+ }<br>
+<br>
+ /// \brief Track the reference to metadata for \a MetadataAsValue.<br>
+ ///<br>
+ /// As \a track(Metadata*&), but with support for calling back to \c Owner to<br>
+ /// tell it that its operand changed. This could trigger \c Owner being<br>
+ /// re-uniqued.<br>
+ static bool track(void *Ref, Metadata &MD, MetadataAsValue &Owner) {<br>
+ return track(Ref, MD, &Owner);<br>
+ }<br>
+<br>
+ /// \brief Stop tracking a reference to metadata.<br>
+ ///<br>
+ /// Stops \c *MD from tracking \c MD.<br>
+ static void untrack(Metadata *&MD) { untrack(&MD, *MD); }<br>
+ static void untrack(void *Ref, Metadata &MD);<br>
+<br>
+ /// \brief Move tracking from one reference to another.<br>
+ ///<br>
+ /// Semantically equivalent to \c untrack(MD) followed by \c track(New),<br>
+ /// except that ownership callbacks are maintained.<br>
+ ///<br>
+ /// Note: it is an error if \c *MD does not equal \c New.<br>
+ ///<br>
+ /// \return true iff tracking is supported by \c MD.<br>
+ static bool retrack(Metadata *&MD, Metadata *&New) {<br>
+ return retrack(&MD, *MD, &New);<br>
+ }<br>
+ static bool retrack(void *Ref, Metadata &MD, void *New);<br>
+<br>
+ /// \brief Check whether metadata is replaceable.<br>
+ static bool isReplaceable(const Metadata &MD);<br>
+<br>
+ typedef PointerUnion<MetadataAsValue *, Metadata *> OwnerTy;<br>
+<br>
+private:<br>
+ /// \brief Track a reference to metadata for an owner.<br>
+ ///<br>
+ /// Generalized version of tracking.<br>
+ static bool track(void *Ref, Metadata &MD, OwnerTy Owner);<br>
+};<br>
+<br>
/// \brief Shared implementation of use-lists for replaceable metadata.<br>
///<br>
/// Most metadata cannot be RAUW'ed. This is a shared implementation of<br>
<br>
Removed: llvm/trunk/include/llvm/IR/MetadataTracking.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/MetadataTracking.h?rev=256530&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/MetadataTracking.h?rev=256530&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/MetadataTracking.h (original)<br>
+++ llvm/trunk/include/llvm/IR/MetadataTracking.h (removed)<br>
@@ -1,99 +0,0 @@<br>
-//===- llvm/IR/MetadataTracking.h - Metadata tracking ---------------------===//<br>
-//<br>
-// The LLVM Compiler Infrastructure<br>
-//<br>
-// This file is distributed under the University of Illinois Open Source<br>
-// License. See LICENSE.TXT for details.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-//<br>
-// Low-level functions to enable tracking of metadata that could RAUW.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-<br>
-#ifndef LLVM_IR_METADATATRACKING_H<br>
-#define LLVM_IR_METADATATRACKING_H<br>
-<br>
-#include "llvm/ADT/PointerUnion.h"<br>
-#include "llvm/Support/Casting.h"<br>
-#include <type_traits><br>
-<br>
-namespace llvm {<br>
-<br>
-class Metadata;<br>
-class MetadataAsValue;<br>
-<br>
-/// \brief API for tracking metadata references through RAUW and deletion.<br>
-///<br>
-/// Shared API for updating \a Metadata pointers in subclasses that support<br>
-/// RAUW.<br>
-///<br>
-/// This API is not meant to be used directly. See \a TrackingMDRef for a<br>
-/// user-friendly tracking reference.<br>
-class MetadataTracking {<br>
-public:<br>
- /// \brief Track the reference to metadata.<br>
- ///<br>
- /// Register \c MD with \c *MD, if the subclass supports tracking. If \c *MD<br>
- /// gets RAUW'ed, \c MD will be updated to the new address. If \c *MD gets<br>
- /// deleted, \c MD will be set to \c nullptr.<br>
- ///<br>
- /// If tracking isn't supported, \c *MD will not change.<br>
- ///<br>
- /// \return true iff tracking is supported by \c MD.<br>
- static bool track(Metadata *&MD) {<br>
- return track(&MD, *MD, static_cast<Metadata *>(nullptr));<br>
- }<br>
-<br>
- /// \brief Track the reference to metadata for \a Metadata.<br>
- ///<br>
- /// As \a track(Metadata*&), but with support for calling back to \c Owner to<br>
- /// tell it that its operand changed. This could trigger \c Owner being<br>
- /// re-uniqued.<br>
- static bool track(void *Ref, Metadata &MD, Metadata &Owner) {<br>
- return track(Ref, MD, &Owner);<br>
- }<br>
-<br>
- /// \brief Track the reference to metadata for \a MetadataAsValue.<br>
- ///<br>
- /// As \a track(Metadata*&), but with support for calling back to \c Owner to<br>
- /// tell it that its operand changed. This could trigger \c Owner being<br>
- /// re-uniqued.<br>
- static bool track(void *Ref, Metadata &MD, MetadataAsValue &Owner) {<br>
- return track(Ref, MD, &Owner);<br>
- }<br>
-<br>
- /// \brief Stop tracking a reference to metadata.<br>
- ///<br>
- /// Stops \c *MD from tracking \c MD.<br>
- static void untrack(Metadata *&MD) { untrack(&MD, *MD); }<br>
- static void untrack(void *Ref, Metadata &MD);<br>
-<br>
- /// \brief Move tracking from one reference to another.<br>
- ///<br>
- /// Semantically equivalent to \c untrack(MD) followed by \c track(New),<br>
- /// except that ownership callbacks are maintained.<br>
- ///<br>
- /// Note: it is an error if \c *MD does not equal \c New.<br>
- ///<br>
- /// \return true iff tracking is supported by \c MD.<br>
- static bool retrack(Metadata *&MD, Metadata *&New) {<br>
- return retrack(&MD, *MD, &New);<br>
- }<br>
- static bool retrack(void *Ref, Metadata &MD, void *New);<br>
-<br>
- /// \brief Check whether metadata is replaceable.<br>
- static bool isReplaceable(const Metadata &MD);<br>
-<br>
- typedef PointerUnion<MetadataAsValue *, Metadata *> OwnerTy;<br>
-<br>
-private:<br>
- /// \brief Track a reference to metadata for an owner.<br>
- ///<br>
- /// Generalized version of tracking.<br>
- static bool track(void *Ref, Metadata &MD, OwnerTy Owner);<br>
-};<br>
-<br>
-} // end namespace llvm<br>
-<br>
-#endif<br>
<br>
Modified: llvm/trunk/include/llvm/IR/TrackingMDRef.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/TrackingMDRef.h?rev=256531&r1=256530&r2=256531&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/TrackingMDRef.h?rev=256531&r1=256530&r2=256531&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/TrackingMDRef.h (original)<br>
+++ llvm/trunk/include/llvm/IR/TrackingMDRef.h Mon Dec 28 20:14:50 2015<br>
@@ -14,15 +14,11 @@<br>
#ifndef LLVM_IR_TRACKINGMDREF_H<br>
#define LLVM_IR_TRACKINGMDREF_H<br>
<br>
-#include "llvm/IR/MetadataTracking.h"<br>
+#include "llvm/IR/Metadata.h"<br>
#include "llvm/Support/Casting.h"<br>
<br>
namespace llvm {<br>
<br>
-class Metadata;<br>
-class MDNode;<br>
-class ValueAsMetadata;<br>
-<br>
/// \brief Tracking metadata reference.<br>
///<br>
/// This class behaves like \a TrackingVH, but for metadata.<br>
<br>
Modified: llvm/trunk/lib/IR/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/CMakeLists.txt?rev=256531&r1=256530&r2=256531&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/CMakeLists.txt?rev=256531&r1=256530&r2=256531&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/IR/CMakeLists.txt Mon Dec 28 20:14:50 2015<br>
@@ -36,7 +36,6 @@ add_llvm_library(LLVMCore<br>
MDBuilder.cpp<br>
Mangler.cpp<br>
Metadata.cpp<br>
- MetadataTracking.cpp<br>
Module.cpp<br>
Operator.cpp<br>
Pass.cpp<br>
<br>
Modified: llvm/trunk/lib/IR/Metadata.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=256531&r1=256530&r2=256531&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=256531&r1=256530&r2=256531&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/Metadata.cpp (original)<br>
+++ llvm/trunk/lib/IR/Metadata.cpp Mon Dec 28 20:14:50 2015<br>
@@ -120,6 +120,38 @@ void MetadataAsValue::untrack() {<br>
MetadataTracking::untrack(MD);<br>
}<br>
<br>
+bool MetadataTracking::track(void *Ref, Metadata &MD, OwnerTy Owner) {<br>
+ assert(Ref && "Expected live reference");<br>
+ assert((Owner || *static_cast<Metadata **>(Ref) == &MD) &&<br>
+ "Reference without owner must be direct");<br>
+ if (auto *R = ReplaceableMetadataImpl::get(MD)) {<br>
+ R->addRef(Ref, Owner);<br>
+ return true;<br>
+ }<br>
+ return false;<br>
+}<br>
+<br>
+void MetadataTracking::untrack(void *Ref, Metadata &MD) {<br>
+ assert(Ref && "Expected live reference");<br>
+ if (auto *R = ReplaceableMetadataImpl::get(MD))<br>
+ R->dropRef(Ref);<br>
+}<br>
+<br>
+bool MetadataTracking::retrack(void *Ref, Metadata &MD, void *New) {<br>
+ assert(Ref && "Expected live reference");<br>
+ assert(New && "Expected live reference");<br>
+ assert(Ref != New && "Expected change");<br>
+ if (auto *R = ReplaceableMetadataImpl::get(MD)) {<br>
+ R->moveRef(Ref, New, MD);<br>
+ return true;<br>
+ }<br>
+ return false;<br>
+}<br>
+<br>
+bool MetadataTracking::isReplaceable(const Metadata &MD) {<br>
+ return ReplaceableMetadataImpl::get(const_cast<Metadata &>(MD));<br>
+}<br>
+<br>
void ReplaceableMetadataImpl::addRef(void *Ref, OwnerTy Owner) {<br>
bool WasInserted =<br>
UseMap.insert(std::make_pair(Ref, std::make_pair(Owner, NextIndex)))<br>
@@ -239,6 +271,12 @@ void ReplaceableMetadataImpl::resolveAll<br>
}<br>
}<br>
<br>
+ReplaceableMetadataImpl *ReplaceableMetadataImpl::get(Metadata &MD) {<br>
+ if (auto *N = dyn_cast<MDNode>(&MD))<br>
+ return N->Context.getReplaceableUses();<br>
+ return dyn_cast<ValueAsMetadata>(&MD);<br>
+}<br>
+<br>
static Function *getLocalFunction(Value *V) {<br>
assert(V && "Expected value");<br>
if (auto *A = dyn_cast<Argument>(V))<br>
<br>
Removed: llvm/trunk/lib/IR/MetadataTracking.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/MetadataTracking.cpp?rev=256530&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/MetadataTracking.cpp?rev=256530&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/MetadataTracking.cpp (original)<br>
+++ llvm/trunk/lib/IR/MetadataTracking.cpp (removed)<br>
@@ -1,55 +0,0 @@<br>
-//===- MetadataTracking.cpp - Implement metadata tracking -----------------===//<br>
-//<br>
-// The LLVM Compiler Infrastructure<br>
-//<br>
-// This file is distributed under the University of Illinois Open Source<br>
-// License. See LICENSE.TXT for details.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-//<br>
-// This file implements Metadata tracking.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-<br>
-#include "llvm/IR/MetadataTracking.h"<br>
-#include "llvm/IR/Metadata.h"<br>
-<br>
-using namespace llvm;<br>
-<br>
-ReplaceableMetadataImpl *ReplaceableMetadataImpl::get(Metadata &MD) {<br>
- if (auto *N = dyn_cast<MDNode>(&MD))<br>
- return N->Context.getReplaceableUses();<br>
- return dyn_cast<ValueAsMetadata>(&MD);<br>
-}<br>
-<br>
-bool MetadataTracking::track(void *Ref, Metadata &MD, OwnerTy Owner) {<br>
- assert(Ref && "Expected live reference");<br>
- assert((Owner || *static_cast<Metadata **>(Ref) == &MD) &&<br>
- "Reference without owner must be direct");<br>
- if (auto *R = ReplaceableMetadataImpl::get(MD)) {<br>
- R->addRef(Ref, Owner);<br>
- return true;<br>
- }<br>
- return false;<br>
-}<br>
-<br>
-void MetadataTracking::untrack(void *Ref, Metadata &MD) {<br>
- assert(Ref && "Expected live reference");<br>
- if (auto *R = ReplaceableMetadataImpl::get(MD))<br>
- R->dropRef(Ref);<br>
-}<br>
-<br>
-bool MetadataTracking::retrack(void *Ref, Metadata &MD, void *New) {<br>
- assert(Ref && "Expected live reference");<br>
- assert(New && "Expected live reference");<br>
- assert(Ref != New && "Expected change");<br>
- if (auto *R = ReplaceableMetadataImpl::get(MD)) {<br>
- R->moveRef(Ref, New, MD);<br>
- return true;<br>
- }<br>
- return false;<br>
-}<br>
-<br>
-bool MetadataTracking::isReplaceable(const Metadata &MD) {<br>
- return ReplaceableMetadataImpl::get(const_cast<Metadata &>(MD));<br>
-}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>