summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-12-29 02:14:50 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-12-29 02:14:50 +0000
commita7dc087b365ea83abf80ae86303dc705349018d2 (patch)
tree648ec1260265627fde0cad76510d2dd9f7b316e2 /llvm/lib/IR
parentdc82f130800ec166bcbf009110af480854710113 (diff)
downloadbcm5719-llvm-a7dc087b365ea83abf80ae86303dc705349018d2.tar.gz
bcm5719-llvm-a7dc087b365ea83abf80ae86303dc705349018d2.zip
[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. llvm-svn: 256531
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/CMakeLists.txt1
-rw-r--r--llvm/lib/IR/Metadata.cpp38
-rw-r--r--llvm/lib/IR/MetadataTracking.cpp55
3 files changed, 38 insertions, 56 deletions
diff --git a/llvm/lib/IR/CMakeLists.txt b/llvm/lib/IR/CMakeLists.txt
index eb67c525ce2..40b4ec65e22 100644
--- a/llvm/lib/IR/CMakeLists.txt
+++ b/llvm/lib/IR/CMakeLists.txt
@@ -36,7 +36,6 @@ add_llvm_library(LLVMCore
MDBuilder.cpp
Mangler.cpp
Metadata.cpp
- MetadataTracking.cpp
Module.cpp
Operator.cpp
Pass.cpp
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index b1da0301ecf..ab1ba5e2035 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -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::resolveAllUses(bool ResolveUsers) {
}
}
+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))
diff --git a/llvm/lib/IR/MetadataTracking.cpp b/llvm/lib/IR/MetadataTracking.cpp
deleted file mode 100644
index 47f0b9366d7..00000000000
--- a/llvm/lib/IR/MetadataTracking.cpp
+++ /dev/null
@@ -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));
-}
OpenPOWER on IntegriCloud