2009-07-28 21:49:47 +00:00
|
|
|
//===-- llvm/Metadata.h - Metadata definitions ------------------*- C++ -*-===//
|
2009-05-10 20:57:05 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// @file
|
2009-07-28 21:49:47 +00:00
|
|
|
/// This file contains the declarations for metadata subclasses.
|
|
|
|
/// They represent the different flavors of metadata that live in LLVM.
|
2009-05-10 20:57:05 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_IR_METADATA_H
|
|
|
|
#define LLVM_IR_METADATA_H
|
2009-05-10 20:57:05 +00:00
|
|
|
|
2011-03-04 01:20:33 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2014-07-24 12:16:19 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2009-09-03 01:39:20 +00:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2009-07-29 17:16:17 +00:00
|
|
|
#include "llvm/ADT/ilist_node.h"
|
2014-03-06 01:12:56 +00:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Value.h"
|
2009-05-10 20:57:05 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2009-12-28 08:30:43 +00:00
|
|
|
class Module;
|
2009-12-31 01:22:29 +00:00
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
|
|
|
class SymbolTableListTraits;
|
2013-01-10 22:14:33 +00:00
|
|
|
|
|
|
|
|
2014-03-02 03:20:38 +00:00
|
|
|
enum LLVMConstants : uint32_t {
|
2014-10-03 20:01:09 +00:00
|
|
|
DEBUG_METADATA_VERSION = 2 // Current debug info version number.
|
2013-12-02 20:09:52 +00:00
|
|
|
};
|
|
|
|
|
2014-11-13 13:17:47 +00:00
|
|
|
/// \brief Root of the metadata hierarchy.
|
|
|
|
///
|
|
|
|
/// This is a root class for typeless data in the IR.
|
|
|
|
///
|
|
|
|
/// TODO: Detach from the Value hierarchy.
|
|
|
|
class Metadata : public Value {
|
|
|
|
protected:
|
2014-11-14 18:42:09 +00:00
|
|
|
Metadata(LLVMContext &Context, unsigned ID);
|
2014-11-13 13:17:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return V->getValueID() == MDNodeVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-22 17:43:22 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief A single uniqued string.
|
|
|
|
///
|
2009-07-22 17:43:22 +00:00
|
|
|
/// These are used to efficiently contain a byte sequence for metadata.
|
2011-06-01 23:32:40 +00:00
|
|
|
/// MDString is always unnamed.
|
2014-11-13 13:17:47 +00:00
|
|
|
///
|
|
|
|
/// TODO: Inherit from Metadata.
|
2010-01-22 22:52:10 +00:00
|
|
|
class MDString : public Value {
|
2014-11-14 01:17:09 +00:00
|
|
|
friend class StringMapEntry<MDString>;
|
|
|
|
|
2011-12-20 02:50:00 +00:00
|
|
|
virtual void anchor();
|
2012-09-17 07:16:40 +00:00
|
|
|
MDString(const MDString &) LLVM_DELETED_FUNCTION;
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2012-04-10 20:12:16 +00:00
|
|
|
explicit MDString(LLVMContext &C);
|
2014-11-13 23:59:16 +00:00
|
|
|
|
|
|
|
/// \brief Shadow Value::getName() to prevent its use.
|
2014-11-14 01:17:09 +00:00
|
|
|
StringRef getName() const LLVM_DELETED_FUNCTION;
|
2014-11-13 23:59:16 +00:00
|
|
|
|
2009-07-23 01:19:53 +00:00
|
|
|
public:
|
2009-10-22 00:10:15 +00:00
|
|
|
static MDString *get(LLVMContext &Context, StringRef Str);
|
2010-03-10 16:04:20 +00:00
|
|
|
static MDString *get(LLVMContext &Context, const char *Str) {
|
|
|
|
return get(Context, Str ? StringRef(Str) : StringRef());
|
|
|
|
}
|
|
|
|
|
2014-11-14 01:17:09 +00:00
|
|
|
StringRef getString() const;
|
2009-07-25 23:55:21 +00:00
|
|
|
|
2014-11-14 01:17:09 +00:00
|
|
|
unsigned getLength() const { return (unsigned)getString().size(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2009-10-19 07:10:59 +00:00
|
|
|
typedef StringRef::iterator iterator;
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Pointer to the first byte of the string.
|
2014-11-14 01:17:09 +00:00
|
|
|
iterator begin() const { return getString().begin(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Pointer to one byte past the end of the string.
|
2014-11-14 01:17:09 +00:00
|
|
|
iterator end() const { return getString().end(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast.
|
2009-07-22 17:43:22 +00:00
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return V->getValueID() == MDStringVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief A collection of metadata nodes that might be associated with a
|
2014-07-24 12:16:19 +00:00
|
|
|
/// memory access used by the alias-analysis infrastructure.
|
|
|
|
struct AAMDNodes {
|
2014-10-04 22:44:29 +00:00
|
|
|
explicit AAMDNodes(MDNode *T = nullptr, MDNode *S = nullptr,
|
|
|
|
MDNode *N = nullptr)
|
|
|
|
: TBAA(T), Scope(S), NoAlias(N) {}
|
2014-07-24 12:16:19 +00:00
|
|
|
|
2014-10-04 22:44:29 +00:00
|
|
|
bool operator==(const AAMDNodes &A) const {
|
|
|
|
return TBAA == A.TBAA && Scope == A.Scope && NoAlias == A.NoAlias;
|
2014-07-24 12:16:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-04 22:44:29 +00:00
|
|
|
bool operator!=(const AAMDNodes &A) const { return !(*this == A); }
|
2014-07-24 12:16:19 +00:00
|
|
|
|
2014-10-04 22:44:29 +00:00
|
|
|
LLVM_EXPLICIT operator bool() const { return TBAA || Scope || NoAlias; }
|
2014-07-24 12:16:19 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief The tag for type-based alias analysis.
|
2014-07-24 12:16:19 +00:00
|
|
|
MDNode *TBAA;
|
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief The tag for alias scope specification (used with noalias).
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
MDNode *Scope;
|
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief The tag specifying the noalias scope.
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
MDNode *NoAlias;
|
2014-07-24 12:16:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Specialize DenseMapInfo for AAMDNodes.
|
|
|
|
template<>
|
|
|
|
struct DenseMapInfo<AAMDNodes> {
|
|
|
|
static inline AAMDNodes getEmptyKey() {
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
return AAMDNodes(DenseMapInfo<MDNode *>::getEmptyKey(), 0, 0);
|
2014-07-24 12:16:19 +00:00
|
|
|
}
|
|
|
|
static inline AAMDNodes getTombstoneKey() {
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
return AAMDNodes(DenseMapInfo<MDNode *>::getTombstoneKey(), 0, 0);
|
2014-07-24 12:16:19 +00:00
|
|
|
}
|
|
|
|
static unsigned getHashValue(const AAMDNodes &Val) {
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
return DenseMapInfo<MDNode *>::getHashValue(Val.TBAA) ^
|
|
|
|
DenseMapInfo<MDNode *>::getHashValue(Val.Scope) ^
|
|
|
|
DenseMapInfo<MDNode *>::getHashValue(Val.NoAlias);
|
2014-07-24 12:16:19 +00:00
|
|
|
}
|
|
|
|
static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS) {
|
|
|
|
return LHS == RHS;
|
|
|
|
}
|
|
|
|
};
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2009-12-31 01:22:29 +00:00
|
|
|
class MDNodeOperand;
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2014-11-13 13:17:47 +00:00
|
|
|
/// \brief Generic tuple of metadata.
|
|
|
|
class MDNode : public Metadata, public FoldingSetNode {
|
2012-09-17 07:16:40 +00:00
|
|
|
MDNode(const MDNode &) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const MDNode &) LLVM_DELETED_FUNCTION;
|
2009-12-31 01:22:29 +00:00
|
|
|
friend class MDNodeOperand;
|
2010-02-18 20:53:16 +00:00
|
|
|
friend class LLVMContextImpl;
|
2012-04-11 14:06:54 +00:00
|
|
|
friend struct FoldingSetTrait<MDNode>;
|
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief If the MDNode is uniqued cache the hash to speed up lookup.
|
2012-04-11 14:06:54 +00:00
|
|
|
unsigned Hash;
|
2009-12-28 09:07:21 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Subclass data enums.
|
2009-12-28 09:07:21 +00:00
|
|
|
enum {
|
2009-12-30 21:42:11 +00:00
|
|
|
/// FunctionLocalBit - This bit is set if this MDNode is function local.
|
|
|
|
/// This is true when it (potentially transitively) contains a reference to
|
|
|
|
/// something in a function, like an argument, basicblock, or instruction.
|
|
|
|
FunctionLocalBit = 1 << 0,
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2009-12-30 21:42:11 +00:00
|
|
|
/// NotUniquedBit - This is set on MDNodes that are not uniqued because they
|
2010-04-29 12:32:45 +00:00
|
|
|
/// have a null operand.
|
2009-12-31 01:05:46 +00:00
|
|
|
NotUniquedBit = 1 << 1,
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2009-12-31 01:05:46 +00:00
|
|
|
/// DestroyFlag - This bit is set by destroy() so the destructor can assert
|
|
|
|
/// that the node isn't being destroyed with a plain 'delete'.
|
|
|
|
DestroyFlag = 1 << 2
|
2009-12-28 09:07:21 +00:00
|
|
|
};
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief FunctionLocal enums.
|
2010-01-10 07:14:18 +00:00
|
|
|
enum FunctionLocalness {
|
|
|
|
FL_Unknown = -1,
|
|
|
|
FL_No = 0,
|
|
|
|
FL_Yes = 1
|
|
|
|
};
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Replace each instance of the given operand with a new value.
|
2009-12-31 01:22:29 +00:00
|
|
|
void replaceOperand(MDNodeOperand *Op, Value *NewVal);
|
2009-12-31 01:05:46 +00:00
|
|
|
~MDNode();
|
2009-09-03 01:39:20 +00:00
|
|
|
|
2011-04-21 19:59:31 +00:00
|
|
|
MDNode(LLVMContext &C, ArrayRef<Value*> Vals, bool isFunctionLocal);
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2011-04-21 19:59:31 +00:00
|
|
|
static MDNode *getMDNode(LLVMContext &C, ArrayRef<Value*> Vals,
|
2010-01-26 02:36:35 +00:00
|
|
|
FunctionLocalness FL, bool Insert = true);
|
2009-05-10 20:57:05 +00:00
|
|
|
public:
|
2011-04-21 19:59:31 +00:00
|
|
|
static MDNode *get(LLVMContext &Context, ArrayRef<Value*> Vals);
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Construct MDNode with an explicit function-localness.
|
|
|
|
///
|
|
|
|
/// Don't analyze Vals; trust isFunctionLocal.
|
2011-04-21 19:59:31 +00:00
|
|
|
static MDNode *getWhenValsUnresolved(LLVMContext &Context,
|
|
|
|
ArrayRef<Value*> Vals,
|
|
|
|
bool isFunctionLocal);
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2011-04-21 19:59:31 +00:00
|
|
|
static MDNode *getIfExists(LLVMContext &Context, ArrayRef<Value*> Vals);
|
2010-08-20 22:02:26 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Return a temporary MDNode
|
|
|
|
///
|
|
|
|
/// For use in constructing cyclic MDNode structures. A temporary MDNode is
|
|
|
|
/// not uniqued, may be RAUW'd, and must be manually deleted with
|
|
|
|
/// deleteTemporary.
|
2011-04-21 19:59:31 +00:00
|
|
|
static MDNode *getTemporary(LLVMContext &Context, ArrayRef<Value*> Vals);
|
2010-08-20 22:02:26 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Deallocate a node created by getTemporary.
|
|
|
|
///
|
|
|
|
/// The node must not have any users.
|
2010-08-20 22:02:26 +00:00
|
|
|
static void deleteTemporary(MDNode *N);
|
2012-02-15 09:09:29 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Replace a specific operand.
|
2012-02-15 09:09:29 +00:00
|
|
|
void replaceOperandWith(unsigned i, Value *NewVal);
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Return specified operand.
|
2013-07-12 12:05:13 +00:00
|
|
|
Value *getOperand(unsigned i) const LLVM_READONLY;
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Return number of MDNode operands.
|
2009-12-31 01:22:29 +00:00
|
|
|
unsigned getNumOperands() const { return NumOperands; }
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Return whether MDNode is local to a function.
|
2009-12-29 02:14:09 +00:00
|
|
|
bool isFunctionLocal() const {
|
|
|
|
return (getSubclassDataFromValue() & FunctionLocalBit) != 0;
|
|
|
|
}
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Return the first function-local operand's function.
|
|
|
|
///
|
|
|
|
/// If this metadata is function-local and recursively has a function-local
|
|
|
|
/// operand, return the first such operand's parent function. Otherwise,
|
|
|
|
/// return null. getFunction() should not be used for performance- critical
|
|
|
|
/// code because it recursively visits all the MDNode's operands.
|
2010-01-20 04:45:57 +00:00
|
|
|
const Function *getFunction() const;
|
2009-12-18 20:09:14 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Calculate a unique identifier for this MDNode.
|
2009-09-03 01:39:20 +00:00
|
|
|
void Profile(FoldingSetNodeID &ID) const;
|
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-05-10 20:57:05 +00:00
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return V->getValueID() == MDNodeVal;
|
|
|
|
}
|
2012-06-16 20:33:37 +00:00
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Check whether MDNode is a vtable access.
|
2013-09-06 22:47:05 +00:00
|
|
|
bool isTBAAVtableAccess() const;
|
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Methods for metadata merging.
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
static MDNode *concatenate(MDNode *A, MDNode *B);
|
|
|
|
static MDNode *intersect(MDNode *A, MDNode *B);
|
2012-06-16 20:33:37 +00:00
|
|
|
static MDNode *getMostGenericTBAA(MDNode *A, MDNode *B);
|
2014-07-24 12:16:19 +00:00
|
|
|
static AAMDNodes getMostGenericAA(const AAMDNodes &A, const AAMDNodes &B);
|
2012-06-16 20:33:37 +00:00
|
|
|
static MDNode *getMostGenericFPMath(MDNode *A, MDNode *B);
|
|
|
|
static MDNode *getMostGenericRange(MDNode *A, MDNode *B);
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Delete this node. Only when there are no uses.
|
2010-07-21 18:54:18 +00:00
|
|
|
void destroy();
|
|
|
|
|
2013-01-10 22:14:33 +00:00
|
|
|
bool isNotUniqued() const {
|
2009-12-30 21:42:11 +00:00
|
|
|
return (getSubclassDataFromValue() & NotUniquedBit) != 0;
|
|
|
|
}
|
2010-03-13 01:26:15 +00:00
|
|
|
void setIsNotUniqued();
|
2013-01-10 22:14:33 +00:00
|
|
|
|
2009-12-29 02:14:09 +00:00
|
|
|
// Shadow Value::setValueSubclassData with a private forwarding method so that
|
|
|
|
// any future subclasses cannot accidentally use it.
|
|
|
|
void setValueSubclassData(unsigned short D) {
|
|
|
|
Value::setValueSubclassData(D);
|
|
|
|
}
|
2009-05-10 20:57:05 +00:00
|
|
|
};
|
|
|
|
|
2009-07-29 00:33:07 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2014-11-11 21:30:22 +00:00
|
|
|
/// \brief A tuple of MDNodes.
|
2014-10-15 20:28:31 +00:00
|
|
|
///
|
|
|
|
/// Despite its name, a NamedMDNode isn't itself an MDNode. NamedMDNodes belong
|
2014-11-11 21:30:22 +00:00
|
|
|
/// to modules, have names, and contain lists of MDNodes.
|
2014-11-13 13:17:47 +00:00
|
|
|
///
|
|
|
|
/// TODO: Inherit from Metadata.
|
2010-07-21 23:38:33 +00:00
|
|
|
class NamedMDNode : public ilist_node<NamedMDNode> {
|
2009-07-29 17:16:17 +00:00
|
|
|
friend class SymbolTableListTraits<NamedMDNode, Module>;
|
2010-01-12 22:00:04 +00:00
|
|
|
friend struct ilist_traits<NamedMDNode>;
|
2009-08-11 17:45:13 +00:00
|
|
|
friend class LLVMContextImpl;
|
2010-07-21 23:38:33 +00:00
|
|
|
friend class Module;
|
2012-09-17 07:16:40 +00:00
|
|
|
NamedMDNode(const NamedMDNode &) LLVM_DELETED_FUNCTION;
|
2009-08-03 22:51:10 +00:00
|
|
|
|
2010-01-07 19:39:36 +00:00
|
|
|
std::string Name;
|
2009-07-29 00:33:07 +00:00
|
|
|
Module *Parent;
|
2014-11-11 21:30:22 +00:00
|
|
|
void *Operands; // SmallVector<TrackingVH<MDNode>, 4>
|
2009-07-29 00:33:07 +00:00
|
|
|
|
2009-10-21 17:33:41 +00:00
|
|
|
void setParent(Module *M) { Parent = M; }
|
2009-07-29 00:33:07 +00:00
|
|
|
|
2010-07-21 23:38:33 +00:00
|
|
|
explicit NamedMDNode(const Twine &N);
|
2009-08-11 18:01:24 +00:00
|
|
|
|
2014-03-06 01:51:01 +00:00
|
|
|
template<class T1, class T2>
|
|
|
|
class op_iterator_impl :
|
2014-03-06 02:02:43 +00:00
|
|
|
public std::iterator<std::bidirectional_iterator_tag, T2> {
|
2014-03-06 01:12:56 +00:00
|
|
|
const NamedMDNode *Node;
|
|
|
|
unsigned Idx;
|
|
|
|
op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) { }
|
|
|
|
|
|
|
|
friend class NamedMDNode;
|
|
|
|
|
|
|
|
public:
|
2014-04-09 06:08:46 +00:00
|
|
|
op_iterator_impl() : Node(nullptr), Idx(0) { }
|
2014-03-06 01:12:56 +00:00
|
|
|
|
2014-03-06 01:51:01 +00:00
|
|
|
bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; }
|
|
|
|
bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
|
2014-03-06 01:12:56 +00:00
|
|
|
op_iterator_impl &operator++() {
|
2014-03-06 01:51:01 +00:00
|
|
|
++Idx;
|
|
|
|
return *this;
|
2014-03-06 01:12:56 +00:00
|
|
|
}
|
|
|
|
op_iterator_impl operator++(int) {
|
|
|
|
op_iterator_impl tmp(*this);
|
|
|
|
operator++();
|
|
|
|
return tmp;
|
|
|
|
}
|
2014-03-06 02:02:43 +00:00
|
|
|
op_iterator_impl &operator--() {
|
|
|
|
--Idx;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
op_iterator_impl operator--(int) {
|
|
|
|
op_iterator_impl tmp(*this);
|
|
|
|
operator--();
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:51:01 +00:00
|
|
|
T1 operator*() const { return Node->getOperand(Idx); }
|
2014-03-06 01:12:56 +00:00
|
|
|
};
|
|
|
|
|
2010-07-21 23:38:33 +00:00
|
|
|
public:
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Drop all references and remove the node from parent module.
|
2009-08-03 06:19:01 +00:00
|
|
|
void eraseFromParent();
|
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Remove all uses and clear node vector.
|
2009-08-03 06:19:01 +00:00
|
|
|
void dropAllReferences();
|
|
|
|
|
|
|
|
~NamedMDNode();
|
|
|
|
|
2014-10-15 20:28:31 +00:00
|
|
|
/// \brief Get the module that holds this named metadata collection.
|
2009-07-29 00:33:07 +00:00
|
|
|
inline Module *getParent() { return Parent; }
|
|
|
|
inline const Module *getParent() const { return Parent; }
|
|
|
|
|
2014-11-11 21:30:22 +00:00
|
|
|
MDNode *getOperand(unsigned i) const;
|
2009-12-31 01:22:29 +00:00
|
|
|
unsigned getNumOperands() const;
|
2014-11-11 21:30:22 +00:00
|
|
|
void addOperand(MDNode *M);
|
2010-01-07 19:39:36 +00:00
|
|
|
StringRef getName() const;
|
2014-04-23 12:23:05 +00:00
|
|
|
void print(raw_ostream &ROS) const;
|
2011-12-09 23:18:34 +00:00
|
|
|
void dump() const;
|
2014-03-06 01:12:56 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Operand Iterator interface...
|
|
|
|
//
|
2014-11-11 21:30:22 +00:00
|
|
|
typedef op_iterator_impl<MDNode *, MDNode> op_iterator;
|
2014-03-06 01:12:56 +00:00
|
|
|
op_iterator op_begin() { return op_iterator(this, 0); }
|
|
|
|
op_iterator op_end() { return op_iterator(this, getNumOperands()); }
|
|
|
|
|
2014-11-11 21:30:22 +00:00
|
|
|
typedef op_iterator_impl<const MDNode *, MDNode> const_op_iterator;
|
2014-03-06 01:12:56 +00:00
|
|
|
const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
|
|
|
|
const_op_iterator op_end() const { return const_op_iterator(this, getNumOperands()); }
|
|
|
|
|
|
|
|
inline iterator_range<op_iterator> operands() {
|
|
|
|
return iterator_range<op_iterator>(op_begin(), op_end());
|
|
|
|
}
|
|
|
|
inline iterator_range<const_op_iterator> operands() const {
|
|
|
|
return iterator_range<const_op_iterator>(op_begin(), op_end());
|
|
|
|
}
|
2009-07-29 00:33:07 +00:00
|
|
|
};
|
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
#endif
|