2010-03-21 22:17:34 +01:00
|
|
|
//===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===//
|
2009-06-30 02:48:55 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-30 19:06:46 +02:00
|
|
|
//
|
|
|
|
// This file declares LLVMContextImpl, the opaque implementation
|
|
|
|
// of LLVMContext.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-30 02:48:55 +02:00
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
|
|
|
|
#define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
|
2009-06-30 02:48:55 +02:00
|
|
|
|
2012-12-20 02:36:59 +01:00
|
|
|
#include "AttributeImpl.h"
|
2009-08-05 00:41:48 +02:00
|
|
|
#include "ConstantsContext.h"
|
2009-08-19 19:07:46 +02:00
|
|
|
#include "LeaksContext.h"
|
2009-07-16 21:05:41 +02:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
2009-07-16 20:04:31 +02:00
|
|
|
#include "llvm/ADT/APInt.h"
|
2011-06-22 10:50:06 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2009-07-16 20:04:31 +02:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2014-11-18 00:28:21 +01:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2009-07-17 01:44:30 +02:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2012-12-04 08:12:27 +01:00
|
|
|
#include "llvm/ADT/Hashing.h"
|
2009-12-17 20:55:06 +01:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2009-07-17 00:11:26 +02:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Metadata.h"
|
2014-03-04 12:17:44 +01:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2009-07-24 01:25:33 +02:00
|
|
|
#include <vector>
|
2009-07-21 22:13:12 +02:00
|
|
|
|
2009-06-30 02:48:55 +02:00
|
|
|
namespace llvm {
|
2009-07-25 01:12:02 +02:00
|
|
|
|
2009-07-16 20:04:31 +02:00
|
|
|
class ConstantInt;
|
2009-07-16 21:05:41 +02:00
|
|
|
class ConstantFP;
|
2014-05-22 16:19:46 +02:00
|
|
|
class DiagnosticInfoOptimizationRemark;
|
|
|
|
class DiagnosticInfoOptimizationRemarkMissed;
|
|
|
|
class DiagnosticInfoOptimizationRemarkAnalysis;
|
2009-08-11 19:45:13 +02:00
|
|
|
class LLVMContext;
|
2009-07-16 20:04:31 +02:00
|
|
|
class Type;
|
2009-07-17 01:44:30 +02:00
|
|
|
class Value;
|
2009-07-16 20:04:31 +02:00
|
|
|
|
2013-09-11 20:05:11 +02:00
|
|
|
struct DenseMapAPIntKeyInfo {
|
2014-12-06 14:12:56 +01:00
|
|
|
static inline APInt getEmptyKey() {
|
|
|
|
APInt V(nullptr, 0);
|
|
|
|
V.VAL = 0;
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
static inline APInt getTombstoneKey() {
|
|
|
|
APInt V(nullptr, 0);
|
|
|
|
V.VAL = 1;
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
static unsigned getHashValue(const APInt &Key) {
|
2012-03-04 13:02:57 +01:00
|
|
|
return static_cast<unsigned>(hash_value(Key));
|
2009-07-16 20:04:31 +02:00
|
|
|
}
|
2014-12-06 14:12:56 +01:00
|
|
|
static bool isEqual(const APInt &LHS, const APInt &RHS) {
|
|
|
|
return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
|
|
|
|
}
|
2009-07-16 20:04:31 +02:00
|
|
|
};
|
|
|
|
|
2013-09-11 20:05:11 +02:00
|
|
|
struct DenseMapAPFloatKeyInfo {
|
2014-12-06 14:12:56 +01:00
|
|
|
static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus, 1); }
|
|
|
|
static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus, 2); }
|
|
|
|
static unsigned getHashValue(const APFloat &Key) {
|
2012-03-04 13:02:57 +01:00
|
|
|
return static_cast<unsigned>(hash_value(Key));
|
2009-07-16 21:05:41 +02:00
|
|
|
}
|
2014-12-06 14:12:56 +01:00
|
|
|
static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
|
|
|
|
return LHS.bitwiseIsEqual(RHS);
|
|
|
|
}
|
2009-07-16 21:05:41 +02:00
|
|
|
};
|
|
|
|
|
2013-09-11 20:05:11 +02:00
|
|
|
struct AnonStructTypeKeyInfo {
|
2012-02-23 10:17:40 +01:00
|
|
|
struct KeyTy {
|
|
|
|
ArrayRef<Type*> ETypes;
|
|
|
|
bool isPacked;
|
|
|
|
KeyTy(const ArrayRef<Type*>& E, bool P) :
|
|
|
|
ETypes(E), isPacked(P) {}
|
2014-11-21 19:53:05 +01:00
|
|
|
KeyTy(const StructType *ST)
|
|
|
|
: ETypes(ST->elements()), isPacked(ST->isPacked()) {}
|
2012-02-23 10:17:40 +01:00
|
|
|
bool operator==(const KeyTy& that) const {
|
|
|
|
if (isPacked != that.isPacked)
|
|
|
|
return false;
|
|
|
|
if (ETypes != that.ETypes)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool operator!=(const KeyTy& that) const {
|
|
|
|
return !this->operator==(that);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static inline StructType* getEmptyKey() {
|
|
|
|
return DenseMapInfo<StructType*>::getEmptyKey();
|
|
|
|
}
|
|
|
|
static inline StructType* getTombstoneKey() {
|
|
|
|
return DenseMapInfo<StructType*>::getTombstoneKey();
|
|
|
|
}
|
|
|
|
static unsigned getHashValue(const KeyTy& Key) {
|
Rewrite LLVM's generalized support library for hashing to follow the API
of the proposed standard hashing interfaces (N3333), and to use
a modified and tuned version of the CityHash algorithm.
Some of the highlights of this change:
-- Significantly higher quality hashing algorithm with very well
distributed results, and extremely few collisions. Should be close to
a checksum for up to 64-bit keys. Very little clustering or clumping of
hash codes, to better distribute load on probed hash tables.
-- Built-in support for reserved values.
-- Simplified API that composes cleanly with other C++ idioms and APIs.
-- Better scaling performance as keys grow. This is the fastest
algorithm I've found and measured for moderately sized keys (such as
show up in some of the uniquing and folding use cases)
-- Support for enabling per-execution seeds to prevent table ordering
or other artifacts of hashing algorithms to impact the output of
LLVM. The seeding would make each run different and highlight these
problems during bootstrap.
This implementation was tested extensively using the SMHasher test
suite, and pased with flying colors, doing better than the original
CityHash algorithm even.
I've included a unittest, although it is somewhat minimal at the moment.
I've also added (or refactored into the proper location) type traits
necessary to implement this, and converted users of GeneralHash over.
My only immediate concerns with this implementation is the performance
of hashing small keys. I've already started working to improve this, and
will continue to do so. Currently, the only algorithms faster produce
lower quality results, but it is likely there is a better compromise
than the current one.
Many thanks to Jeffrey Yasskin who did most of the work on the N3333
paper, pair-programmed some of this code, and reviewed much of it. Many
thanks also go to Geoff Pike Pike and Jyrki Alakuijala, the original
authors of CityHash on which this is heavily based, and Austin Appleby
who created MurmurHash and the SMHasher test suite.
Also thanks to Nadav, Tobias, Howard, Jay, Nick, Ahmed, and Duncan for
all of the review comments! If there are further comments or concerns,
please let me know and I'll jump on 'em.
llvm-svn: 151822
2012-03-01 19:55:25 +01:00
|
|
|
return hash_combine(hash_combine_range(Key.ETypes.begin(),
|
|
|
|
Key.ETypes.end()),
|
|
|
|
Key.isPacked);
|
2012-02-23 10:17:40 +01:00
|
|
|
}
|
|
|
|
static unsigned getHashValue(const StructType *ST) {
|
|
|
|
return getHashValue(KeyTy(ST));
|
|
|
|
}
|
|
|
|
static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
|
|
|
|
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
|
|
|
return false;
|
|
|
|
return LHS == KeyTy(RHS);
|
|
|
|
}
|
|
|
|
static bool isEqual(const StructType *LHS, const StructType *RHS) {
|
|
|
|
return LHS == RHS;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-11 20:05:11 +02:00
|
|
|
struct FunctionTypeKeyInfo {
|
2012-02-23 10:17:40 +01:00
|
|
|
struct KeyTy {
|
|
|
|
const Type *ReturnType;
|
|
|
|
ArrayRef<Type*> Params;
|
|
|
|
bool isVarArg;
|
|
|
|
KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
|
|
|
|
ReturnType(R), Params(P), isVarArg(V) {}
|
2014-11-21 20:03:35 +01:00
|
|
|
KeyTy(const FunctionType *FT)
|
|
|
|
: ReturnType(FT->getReturnType()), Params(FT->params()),
|
|
|
|
isVarArg(FT->isVarArg()) {}
|
2012-02-23 10:17:40 +01:00
|
|
|
bool operator==(const KeyTy& that) const {
|
|
|
|
if (ReturnType != that.ReturnType)
|
|
|
|
return false;
|
|
|
|
if (isVarArg != that.isVarArg)
|
|
|
|
return false;
|
|
|
|
if (Params != that.Params)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool operator!=(const KeyTy& that) const {
|
|
|
|
return !this->operator==(that);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static inline FunctionType* getEmptyKey() {
|
|
|
|
return DenseMapInfo<FunctionType*>::getEmptyKey();
|
|
|
|
}
|
|
|
|
static inline FunctionType* getTombstoneKey() {
|
|
|
|
return DenseMapInfo<FunctionType*>::getTombstoneKey();
|
|
|
|
}
|
|
|
|
static unsigned getHashValue(const KeyTy& Key) {
|
Rewrite LLVM's generalized support library for hashing to follow the API
of the proposed standard hashing interfaces (N3333), and to use
a modified and tuned version of the CityHash algorithm.
Some of the highlights of this change:
-- Significantly higher quality hashing algorithm with very well
distributed results, and extremely few collisions. Should be close to
a checksum for up to 64-bit keys. Very little clustering or clumping of
hash codes, to better distribute load on probed hash tables.
-- Built-in support for reserved values.
-- Simplified API that composes cleanly with other C++ idioms and APIs.
-- Better scaling performance as keys grow. This is the fastest
algorithm I've found and measured for moderately sized keys (such as
show up in some of the uniquing and folding use cases)
-- Support for enabling per-execution seeds to prevent table ordering
or other artifacts of hashing algorithms to impact the output of
LLVM. The seeding would make each run different and highlight these
problems during bootstrap.
This implementation was tested extensively using the SMHasher test
suite, and pased with flying colors, doing better than the original
CityHash algorithm even.
I've included a unittest, although it is somewhat minimal at the moment.
I've also added (or refactored into the proper location) type traits
necessary to implement this, and converted users of GeneralHash over.
My only immediate concerns with this implementation is the performance
of hashing small keys. I've already started working to improve this, and
will continue to do so. Currently, the only algorithms faster produce
lower quality results, but it is likely there is a better compromise
than the current one.
Many thanks to Jeffrey Yasskin who did most of the work on the N3333
paper, pair-programmed some of this code, and reviewed much of it. Many
thanks also go to Geoff Pike Pike and Jyrki Alakuijala, the original
authors of CityHash on which this is heavily based, and Austin Appleby
who created MurmurHash and the SMHasher test suite.
Also thanks to Nadav, Tobias, Howard, Jay, Nick, Ahmed, and Duncan for
all of the review comments! If there are further comments or concerns,
please let me know and I'll jump on 'em.
llvm-svn: 151822
2012-03-01 19:55:25 +01:00
|
|
|
return hash_combine(Key.ReturnType,
|
|
|
|
hash_combine_range(Key.Params.begin(),
|
|
|
|
Key.Params.end()),
|
|
|
|
Key.isVarArg);
|
2012-02-23 10:17:40 +01:00
|
|
|
}
|
|
|
|
static unsigned getHashValue(const FunctionType *FT) {
|
|
|
|
return getHashValue(KeyTy(FT));
|
|
|
|
}
|
|
|
|
static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
|
|
|
|
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
|
|
|
return false;
|
|
|
|
return LHS == KeyTy(RHS);
|
|
|
|
}
|
|
|
|
static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
|
|
|
|
return LHS == RHS;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-11-18 01:37:17 +01:00
|
|
|
/// \brief DenseMapInfo for GenericMDNode.
|
2014-11-18 00:28:21 +01:00
|
|
|
///
|
|
|
|
/// Note that we don't need the is-function-local bit, since that's implicit in
|
|
|
|
/// the operands.
|
|
|
|
struct GenericMDNodeInfo {
|
|
|
|
struct KeyTy {
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 19:38:53 +01:00
|
|
|
ArrayRef<Metadata *> RawOps;
|
|
|
|
ArrayRef<MDOperand> Ops;
|
2014-11-18 00:28:21 +01:00
|
|
|
unsigned Hash;
|
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 19:38:53 +01:00
|
|
|
KeyTy(ArrayRef<Metadata *> Ops)
|
|
|
|
: RawOps(Ops), Hash(hash_combine_range(Ops.begin(), Ops.end())) {}
|
2014-11-18 00:28:21 +01:00
|
|
|
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 19:38:53 +01:00
|
|
|
KeyTy(GenericMDNode *N)
|
|
|
|
: Ops(N->op_begin(), N->op_end()), Hash(N->getHash()) {}
|
2012-04-11 16:06:54 +02:00
|
|
|
|
2014-11-18 01:37:17 +01:00
|
|
|
bool operator==(const GenericMDNode *RHS) const {
|
2014-11-18 00:28:21 +01:00
|
|
|
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
|
|
|
return false;
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 19:38:53 +01:00
|
|
|
if (Hash != RHS->getHash())
|
2014-11-18 00:28:21 +01:00
|
|
|
return false;
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 19:38:53 +01:00
|
|
|
assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
|
|
|
|
return RawOps.empty() ? compareOps(Ops, RHS) : compareOps(RawOps, RHS);
|
|
|
|
}
|
|
|
|
template <class T>
|
|
|
|
static bool compareOps(ArrayRef<T> Ops, const GenericMDNode *RHS) {
|
|
|
|
if (Ops.size() != RHS->getNumOperands())
|
|
|
|
return false;
|
|
|
|
return std::equal(Ops.begin(), Ops.end(), RHS->op_begin());
|
2014-11-18 00:28:21 +01:00
|
|
|
}
|
|
|
|
};
|
2014-11-18 01:37:17 +01:00
|
|
|
static inline GenericMDNode *getEmptyKey() {
|
|
|
|
return DenseMapInfo<GenericMDNode *>::getEmptyKey();
|
2014-11-18 00:28:21 +01:00
|
|
|
}
|
2014-11-18 01:37:17 +01:00
|
|
|
static inline GenericMDNode *getTombstoneKey() {
|
|
|
|
return DenseMapInfo<GenericMDNode *>::getTombstoneKey();
|
2014-11-18 00:28:21 +01:00
|
|
|
}
|
|
|
|
static unsigned getHashValue(const KeyTy &Key) { return Key.Hash; }
|
2014-11-18 01:37:17 +01:00
|
|
|
static unsigned getHashValue(const GenericMDNode *U) {
|
2014-11-18 00:28:21 +01:00
|
|
|
return U->getHash();
|
2012-04-11 16:06:54 +02:00
|
|
|
}
|
2014-11-18 01:37:17 +01:00
|
|
|
static bool isEqual(const KeyTy &LHS, const GenericMDNode *RHS) {
|
2014-11-18 00:28:21 +01:00
|
|
|
return LHS == RHS;
|
|
|
|
}
|
2014-11-18 01:37:17 +01:00
|
|
|
static bool isEqual(const GenericMDNode *LHS, const GenericMDNode *RHS) {
|
2014-11-18 00:28:21 +01:00
|
|
|
return LHS == RHS;
|
2012-04-11 16:06:54 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-11 20:05:11 +02:00
|
|
|
class LLVMContextImpl {
|
2009-08-11 19:45:13 +02:00
|
|
|
public:
|
2010-09-08 20:03:32 +02:00
|
|
|
/// OwnedModules - The set of modules instantiated in this context, and which
|
|
|
|
/// will be automatically deleted if this context is deleted.
|
|
|
|
SmallPtrSet<Module*, 4> OwnedModules;
|
|
|
|
|
2013-02-11 06:37:07 +01:00
|
|
|
LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
|
|
|
|
void *InlineAsmDiagContext;
|
2013-12-17 18:47:22 +01:00
|
|
|
|
|
|
|
LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
|
|
|
|
void *DiagnosticContext;
|
2014-10-01 20:36:03 +02:00
|
|
|
bool RespectDiagnosticFilters;
|
2013-12-17 18:47:22 +01:00
|
|
|
|
2014-05-16 04:33:15 +02:00
|
|
|
LLVMContext::YieldCallbackTy YieldCallback;
|
|
|
|
void *YieldOpaqueHandle;
|
|
|
|
|
2014-12-06 14:12:56 +01:00
|
|
|
typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy;
|
2009-07-16 20:04:31 +02:00
|
|
|
IntMapTy IntConstants;
|
2014-12-06 06:57:06 +01:00
|
|
|
|
2014-12-06 14:12:56 +01:00
|
|
|
typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy;
|
2009-07-16 21:05:41 +02:00
|
|
|
FPMapTy FPConstants;
|
2012-09-26 23:07:29 +02:00
|
|
|
|
2012-12-20 02:36:59 +01:00
|
|
|
FoldingSet<AttributeImpl> AttrsSet;
|
2012-12-19 23:42:22 +01:00
|
|
|
FoldingSet<AttributeSetImpl> AttrsLists;
|
2013-01-24 01:06:56 +01:00
|
|
|
FoldingSet<AttributeSetNode> AttrsSetNodes;
|
2012-11-20 06:09:20 +01:00
|
|
|
|
2014-11-14 02:17:09 +01:00
|
|
|
StringMap<MDString> MDStringCache;
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 19:38:53 +01:00
|
|
|
DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
|
|
|
|
DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
|
2012-09-26 23:07:29 +02:00
|
|
|
|
2014-11-18 01:37:17 +01:00
|
|
|
DenseSet<GenericMDNode *, GenericMDNodeInfo> MDNodeSet;
|
2012-09-26 23:07:29 +02:00
|
|
|
|
2010-03-13 02:26:15 +01:00
|
|
|
// MDNodes may be uniqued or not uniqued. When they're not uniqued, they
|
|
|
|
// aren't in the MDNodeSet, but they're still shared between objects, so no
|
|
|
|
// one object can destroy them. This set allows us to at least destroy them
|
|
|
|
// on Context destruction.
|
2014-11-18 01:37:17 +01:00
|
|
|
SmallPtrSet<GenericMDNode *, 1> NonUniquedMDNodes;
|
|
|
|
|
2014-11-25 03:26:22 +01:00
|
|
|
DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
|
2009-08-10 20:16:08 +02:00
|
|
|
|
2014-08-19 18:39:58 +02:00
|
|
|
typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
|
2009-07-25 01:12:02 +02:00
|
|
|
ArrayConstantsTy ArrayConstants;
|
2009-07-21 22:13:12 +02:00
|
|
|
|
2014-08-19 18:39:58 +02:00
|
|
|
typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
|
2009-07-25 01:12:02 +02:00
|
|
|
StructConstantsTy StructConstants;
|
2009-07-24 01:25:33 +02:00
|
|
|
|
2014-08-19 18:39:58 +02:00
|
|
|
typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
|
2009-07-25 01:12:02 +02:00
|
|
|
VectorConstantsTy VectorConstants;
|
2009-07-24 02:36:24 +02:00
|
|
|
|
2012-01-23 16:20:12 +01:00
|
|
|
DenseMap<PointerType*, ConstantPointerNull*> CPNConstants;
|
|
|
|
|
|
|
|
DenseMap<Type*, UndefValue*> UVConstants;
|
2009-08-01 00:45:43 +02:00
|
|
|
|
2012-01-23 23:57:10 +01:00
|
|
|
StringMap<ConstantDataSequential*> CDSConstants;
|
|
|
|
|
2014-01-19 03:13:50 +01:00
|
|
|
DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
|
|
|
|
BlockAddresses;
|
2014-08-19 18:39:58 +02:00
|
|
|
ConstantUniqueMap<ConstantExpr> ExprConstants;
|
|
|
|
|
|
|
|
ConstantUniqueMap<InlineAsm> InlineAsms;
|
2014-08-19 03:02:18 +02:00
|
|
|
|
2009-07-21 04:47:59 +02:00
|
|
|
ConstantInt *TheTrueVal;
|
|
|
|
ConstantInt *TheFalseVal;
|
|
|
|
|
2009-08-19 19:07:46 +02:00
|
|
|
LeakDetectorImpl<Value> LLVMObjects;
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 19:38:53 +01:00
|
|
|
LeakDetectorImpl<Metadata> LLVMMDObjects;
|
|
|
|
|
2009-08-25 18:00:35 +02:00
|
|
|
// Basic type instances.
|
2011-12-17 01:04:22 +01:00
|
|
|
Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy;
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-09 19:41:24 +02:00
|
|
|
Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
|
|
|
|
IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty;
|
2010-02-11 07:41:30 +01:00
|
|
|
|
2011-07-15 07:49:15 +02:00
|
|
|
|
|
|
|
/// TypeAllocator - All dynamically allocated types are allocated from this.
|
|
|
|
/// They live forever until the context is torn down.
|
|
|
|
BumpPtrAllocator TypeAllocator;
|
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-09 19:41:24 +02:00
|
|
|
DenseMap<unsigned, IntegerType*> IntegerTypes;
|
2014-12-06 20:22:54 +01:00
|
|
|
|
|
|
|
typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
|
|
|
|
FunctionTypeSet FunctionTypes;
|
|
|
|
typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
|
|
|
|
StructTypeSet AnonStructTypes;
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
llvm-svn: 134829
2011-07-09 19:41:24 +02:00
|
|
|
StringMap<StructType*> NamedStructTypes;
|
|
|
|
unsigned NamedStructTypesUniqueID;
|
|
|
|
|
|
|
|
DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
|
|
|
|
DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
|
|
|
|
DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
|
|
|
|
DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
|
2010-02-11 07:41:30 +01:00
|
|
|
|
2009-12-17 20:55:06 +01:00
|
|
|
|
2009-08-18 20:28:58 +02:00
|
|
|
/// ValueHandles - This map keeps track of all of the value handles that are
|
|
|
|
/// watching a Value*. The Value::HasValueHandle bit is used to know
|
2013-03-01 19:48:54 +01:00
|
|
|
/// whether or not a value has an entry in this map.
|
2009-08-18 20:28:58 +02:00
|
|
|
typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
|
|
|
|
ValueHandlesTy ValueHandles;
|
|
|
|
|
2009-12-29 10:01:33 +01:00
|
|
|
/// CustomMDKindNames - Map to hold the metadata string to ID mapping.
|
|
|
|
StringMap<unsigned> CustomMDKindNames;
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 19:38:53 +01:00
|
|
|
|
|
|
|
typedef std::pair<unsigned, TrackingMDNodeRef> MDPairTy;
|
2009-12-29 10:01:33 +01:00
|
|
|
typedef SmallVector<MDPairTy, 2> MDMapTy;
|
|
|
|
|
|
|
|
/// MetadataStore - Collection of per-instruction metadata used in this
|
|
|
|
/// context.
|
|
|
|
DenseMap<const Instruction *, MDMapTy> MetadataStore;
|
|
|
|
|
2014-03-03 21:06:11 +01:00
|
|
|
/// DiscriminatorTable - This table maps file:line locations to an
|
|
|
|
/// integer representing the next DWARF path discriminator to assign to
|
|
|
|
/// instructions in different blocks at the same location.
|
|
|
|
DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
|
|
|
|
|
2013-03-01 19:48:54 +01:00
|
|
|
/// IntrinsicIDCache - Cache of intrinsic name (string) to numeric ID mappings
|
|
|
|
/// requested in this context
|
|
|
|
typedef DenseMap<const Function*, unsigned> IntrinsicIDCacheTy;
|
|
|
|
IntrinsicIDCacheTy IntrinsicIDCache;
|
|
|
|
|
2013-09-16 03:08:15 +02:00
|
|
|
/// \brief Mapping from a function to its prefix data, which is stored as the
|
|
|
|
/// operand of an unparented ReturnInst so that the prefix data has a Use.
|
|
|
|
typedef DenseMap<const Function *, ReturnInst *> PrefixDataMapTy;
|
|
|
|
PrefixDataMapTy PrefixDataMap;
|
|
|
|
|
2014-12-03 03:08:38 +01:00
|
|
|
/// \brief Mapping from a function to its prologue data, which is stored as
|
|
|
|
/// the operand of an unparented ReturnInst so that the prologue data has a
|
|
|
|
/// Use.
|
|
|
|
typedef DenseMap<const Function *, ReturnInst *> PrologueDataMapTy;
|
|
|
|
PrologueDataMapTy PrologueDataMap;
|
|
|
|
|
2010-04-01 02:37:44 +02:00
|
|
|
int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
|
|
|
|
int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
|
2014-05-15 19:49:20 +02:00
|
|
|
|
2010-03-21 22:17:34 +01:00
|
|
|
LLVMContextImpl(LLVMContext &C);
|
|
|
|
~LLVMContextImpl();
|
2009-06-30 02:48:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-06-30 19:06:46 +02:00
|
|
|
#endif
|