2010-03-22 05:17:34 +08:00
|
|
|
//===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===//
|
2009-06-30 08:48:55 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-07-01 01:06:46 +08:00
|
|
|
//
|
|
|
|
// This file declares LLVMContextImpl, the opaque implementation
|
|
|
|
// of LLVMContext.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-30 08:48:55 +08:00
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
|
|
|
|
#define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
|
2009-06-30 08:48:55 +08:00
|
|
|
|
2012-12-20 09:36:59 +08:00
|
|
|
#include "AttributeImpl.h"
|
2009-08-05 06:41:48 +08:00
|
|
|
#include "ConstantsContext.h"
|
2009-08-20 01:07:46 +08:00
|
|
|
#include "LeaksContext.h"
|
2009-07-17 03:05:41 +08:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
2009-07-17 02:04:31 +08:00
|
|
|
#include "llvm/ADT/APInt.h"
|
2011-06-22 16:50:06 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2009-07-17 02:04:31 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2014-11-18 07:28:21 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2009-07-17 07:44:30 +08:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2012-12-04 15:12:27 +08:00
|
|
|
#include "llvm/ADT/Hashing.h"
|
2009-12-18 03:55:06 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2009-07-17 06:11:26 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Metadata.h"
|
2014-03-04 19:17:44 +08:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2009-07-24 07:25:33 +08:00
|
|
|
#include <vector>
|
2009-07-22 04:13:12 +08:00
|
|
|
|
2009-06-30 08:48:55 +08:00
|
|
|
namespace llvm {
|
2009-07-25 07:12:02 +08:00
|
|
|
|
2009-07-17 02:04:31 +08:00
|
|
|
class ConstantInt;
|
2009-07-17 03:05:41 +08:00
|
|
|
class ConstantFP;
|
2014-05-22 22:19:46 +08:00
|
|
|
class DiagnosticInfoOptimizationRemark;
|
|
|
|
class DiagnosticInfoOptimizationRemarkMissed;
|
|
|
|
class DiagnosticInfoOptimizationRemarkAnalysis;
|
2015-01-17 04:07:33 +08:00
|
|
|
class GCStrategy;
|
2009-08-12 01:45:13 +08:00
|
|
|
class LLVMContext;
|
2009-07-17 02:04:31 +08:00
|
|
|
class Type;
|
2009-07-17 07:44:30 +08:00
|
|
|
class Value;
|
2009-07-17 02:04:31 +08:00
|
|
|
|
2013-09-12 02:05:11 +08:00
|
|
|
struct DenseMapAPIntKeyInfo {
|
2014-12-06 21:12:56 +08: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 20:02:57 +08:00
|
|
|
return static_cast<unsigned>(hash_value(Key));
|
2009-07-17 02:04:31 +08:00
|
|
|
}
|
2014-12-06 21:12:56 +08:00
|
|
|
static bool isEqual(const APInt &LHS, const APInt &RHS) {
|
|
|
|
return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
|
|
|
|
}
|
2009-07-17 02:04:31 +08:00
|
|
|
};
|
|
|
|
|
2013-09-12 02:05:11 +08:00
|
|
|
struct DenseMapAPFloatKeyInfo {
|
2014-12-06 21:12:56 +08: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 20:02:57 +08:00
|
|
|
return static_cast<unsigned>(hash_value(Key));
|
2009-07-17 03:05:41 +08:00
|
|
|
}
|
2014-12-06 21:12:56 +08:00
|
|
|
static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
|
|
|
|
return LHS.bitwiseIsEqual(RHS);
|
|
|
|
}
|
2009-07-17 03:05:41 +08:00
|
|
|
};
|
|
|
|
|
2013-09-12 02:05:11 +08:00
|
|
|
struct AnonStructTypeKeyInfo {
|
2012-02-23 17:17:40 +08:00
|
|
|
struct KeyTy {
|
|
|
|
ArrayRef<Type*> ETypes;
|
|
|
|
bool isPacked;
|
|
|
|
KeyTy(const ArrayRef<Type*>& E, bool P) :
|
|
|
|
ETypes(E), isPacked(P) {}
|
2014-11-22 02:53:05 +08:00
|
|
|
KeyTy(const StructType *ST)
|
|
|
|
: ETypes(ST->elements()), isPacked(ST->isPacked()) {}
|
2012-02-23 17:17:40 +08: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-02 02:55:25 +08:00
|
|
|
return hash_combine(hash_combine_range(Key.ETypes.begin(),
|
|
|
|
Key.ETypes.end()),
|
|
|
|
Key.isPacked);
|
2012-02-23 17:17:40 +08: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-12 02:05:11 +08:00
|
|
|
struct FunctionTypeKeyInfo {
|
2012-02-23 17:17:40 +08: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-22 03:03:35 +08:00
|
|
|
KeyTy(const FunctionType *FT)
|
|
|
|
: ReturnType(FT->getReturnType()), Params(FT->params()),
|
|
|
|
isVarArg(FT->isVarArg()) {}
|
2012-02-23 17:17:40 +08: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-02 02:55:25 +08:00
|
|
|
return hash_combine(Key.ReturnType,
|
|
|
|
hash_combine_range(Key.Params.begin(),
|
|
|
|
Key.Params.end()),
|
|
|
|
Key.isVarArg);
|
2012-02-23 17:17:40 +08: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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-20 06:53:18 +08:00
|
|
|
/// \brief Structure for hashing arbitrary MDNode operands.
|
|
|
|
class MDNodeOpsKey {
|
|
|
|
ArrayRef<Metadata *> RawOps;
|
|
|
|
ArrayRef<MDOperand> Ops;
|
|
|
|
|
|
|
|
unsigned Hash;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MDNodeOpsKey(ArrayRef<Metadata *> Ops)
|
|
|
|
: RawOps(Ops), Hash(calculateHash(Ops)) {}
|
|
|
|
|
|
|
|
template <class NodeTy>
|
|
|
|
MDNodeOpsKey(NodeTy *N)
|
|
|
|
: Ops(N->op_begin(), N->op_end()), Hash(N->getHash()) {}
|
|
|
|
|
|
|
|
template <class NodeTy> bool compareOps(const NodeTy *RHS) const {
|
|
|
|
if (getHash() != RHS->getHash())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
|
|
|
|
return RawOps.empty() ? compareOps(Ops, RHS) : compareOps(RawOps, RHS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned calculateHash(MDNode *N);
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <class T>
|
|
|
|
static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS) {
|
|
|
|
if (Ops.size() != RHS->getNumOperands())
|
|
|
|
return false;
|
|
|
|
return std::equal(Ops.begin(), Ops.end(), RHS->op_begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned calculateHash(ArrayRef<Metadata *> Ops);
|
|
|
|
|
|
|
|
public:
|
|
|
|
unsigned getHash() const { return Hash; }
|
|
|
|
};
|
|
|
|
|
2015-01-13 04:09:34 +08:00
|
|
|
/// \brief DenseMapInfo for MDTuple.
|
2014-11-18 07:28:21 +08:00
|
|
|
///
|
|
|
|
/// Note that we don't need the is-function-local bit, since that's implicit in
|
|
|
|
/// the operands.
|
2015-01-13 04:09:34 +08:00
|
|
|
struct MDTupleInfo {
|
2015-01-20 06:53:18 +08:00
|
|
|
struct KeyTy : MDNodeOpsKey {
|
|
|
|
KeyTy(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
|
|
|
|
KeyTy(MDTuple *N) : MDNodeOpsKey(N) {}
|
2012-04-11 22:06:54 +08:00
|
|
|
|
2015-01-13 04:09:34 +08:00
|
|
|
bool operator==(const MDTuple *RHS) const {
|
2014-11-18 07:28:21 +08:00
|
|
|
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
|
|
|
return false;
|
2015-01-20 06:53:18 +08:00
|
|
|
return compareOps(RHS);
|
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-10 02:38:53 +08:00
|
|
|
}
|
2015-01-20 06:53:18 +08:00
|
|
|
|
|
|
|
static unsigned calculateHash(MDTuple *N) {
|
|
|
|
return MDNodeOpsKey::calculateHash(N);
|
2014-11-18 07:28:21 +08:00
|
|
|
}
|
|
|
|
};
|
2015-01-13 04:09:34 +08:00
|
|
|
static inline MDTuple *getEmptyKey() {
|
|
|
|
return DenseMapInfo<MDTuple *>::getEmptyKey();
|
2014-11-18 07:28:21 +08:00
|
|
|
}
|
2015-01-13 04:09:34 +08:00
|
|
|
static inline MDTuple *getTombstoneKey() {
|
|
|
|
return DenseMapInfo<MDTuple *>::getTombstoneKey();
|
2014-11-18 07:28:21 +08:00
|
|
|
}
|
2015-01-20 06:53:18 +08:00
|
|
|
static unsigned getHashValue(const KeyTy &Key) { return Key.getHash(); }
|
|
|
|
static unsigned getHashValue(const MDTuple *U) { return U->getHash(); }
|
2015-01-13 04:09:34 +08:00
|
|
|
static bool isEqual(const KeyTy &LHS, const MDTuple *RHS) {
|
2014-11-18 07:28:21 +08:00
|
|
|
return LHS == RHS;
|
|
|
|
}
|
2015-01-13 04:09:34 +08:00
|
|
|
static bool isEqual(const MDTuple *LHS, const MDTuple *RHS) {
|
2014-11-18 07:28:21 +08:00
|
|
|
return LHS == RHS;
|
2012-04-11 22:06:54 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-14 04:44:56 +08:00
|
|
|
/// \brief DenseMapInfo for MDLocation.
|
|
|
|
struct MDLocationInfo {
|
|
|
|
struct KeyTy {
|
|
|
|
unsigned Line;
|
|
|
|
unsigned Column;
|
|
|
|
Metadata *Scope;
|
|
|
|
Metadata *InlinedAt;
|
|
|
|
|
|
|
|
KeyTy(unsigned Line, unsigned Column, Metadata *Scope, Metadata *InlinedAt)
|
|
|
|
: Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
|
|
|
|
|
|
|
|
KeyTy(const MDLocation *L)
|
|
|
|
: Line(L->getLine()), Column(L->getColumn()), Scope(L->getScope()),
|
|
|
|
InlinedAt(L->getInlinedAt()) {}
|
|
|
|
|
|
|
|
bool operator==(const MDLocation *RHS) const {
|
|
|
|
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
|
|
|
return false;
|
|
|
|
return Line == RHS->getLine() && Column == RHS->getColumn() &&
|
|
|
|
Scope == RHS->getScope() && InlinedAt == RHS->getInlinedAt();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static inline MDLocation *getEmptyKey() {
|
|
|
|
return DenseMapInfo<MDLocation *>::getEmptyKey();
|
|
|
|
}
|
|
|
|
static inline MDLocation *getTombstoneKey() {
|
|
|
|
return DenseMapInfo<MDLocation *>::getTombstoneKey();
|
|
|
|
}
|
|
|
|
static unsigned getHashValue(const KeyTy &Key) {
|
|
|
|
return hash_combine(Key.Line, Key.Column, Key.Scope, Key.InlinedAt);
|
|
|
|
}
|
|
|
|
static unsigned getHashValue(const MDLocation *U) {
|
|
|
|
return getHashValue(KeyTy(U));
|
|
|
|
}
|
|
|
|
static bool isEqual(const KeyTy &LHS, const MDLocation *RHS) {
|
|
|
|
return LHS == RHS;
|
|
|
|
}
|
|
|
|
static bool isEqual(const MDLocation *LHS, const MDLocation *RHS) {
|
|
|
|
return LHS == RHS;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-12 02:05:11 +08:00
|
|
|
class LLVMContextImpl {
|
2009-08-12 01:45:13 +08:00
|
|
|
public:
|
2010-09-09 02:03:32 +08: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 13:37:07 +08:00
|
|
|
LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
|
|
|
|
void *InlineAsmDiagContext;
|
2013-12-18 01:47:22 +08:00
|
|
|
|
|
|
|
LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
|
|
|
|
void *DiagnosticContext;
|
2014-10-02 02:36:03 +08:00
|
|
|
bool RespectDiagnosticFilters;
|
2013-12-18 01:47:22 +08:00
|
|
|
|
2014-05-16 10:33:15 +08:00
|
|
|
LLVMContext::YieldCallbackTy YieldCallback;
|
|
|
|
void *YieldOpaqueHandle;
|
|
|
|
|
2014-12-06 21:12:56 +08:00
|
|
|
typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy;
|
2009-07-17 02:04:31 +08:00
|
|
|
IntMapTy IntConstants;
|
2014-12-06 13:57:06 +08:00
|
|
|
|
2014-12-06 21:12:56 +08:00
|
|
|
typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy;
|
2009-07-17 03:05:41 +08:00
|
|
|
FPMapTy FPConstants;
|
2012-09-27 05:07:29 +08:00
|
|
|
|
2012-12-20 09:36:59 +08:00
|
|
|
FoldingSet<AttributeImpl> AttrsSet;
|
2012-12-20 06:42:22 +08:00
|
|
|
FoldingSet<AttributeSetImpl> AttrsLists;
|
2013-01-24 08:06:56 +08:00
|
|
|
FoldingSet<AttributeSetNode> AttrsSetNodes;
|
2012-11-20 13:09:20 +08:00
|
|
|
|
2014-11-14 09:17:09 +08: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-10 02:38:53 +08:00
|
|
|
DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
|
|
|
|
DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
|
2012-09-27 05:07:29 +08:00
|
|
|
|
2015-01-13 04:09:34 +08:00
|
|
|
DenseSet<MDTuple *, MDTupleInfo> MDTuples;
|
2015-01-14 04:44:56 +08:00
|
|
|
DenseSet<MDLocation *, MDLocationInfo> MDLocations;
|
2012-09-27 05:07:29 +08:00
|
|
|
|
2010-03-13 09:26:15 +08: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.
|
2015-01-13 04:09:34 +08:00
|
|
|
SmallPtrSet<UniquableMDNode *, 1> DistinctMDNodes;
|
2014-11-18 08:37:17 +08:00
|
|
|
|
2014-11-25 10:26:22 +08:00
|
|
|
DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
|
2009-08-11 02:16:08 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
|
2009-07-25 07:12:02 +08:00
|
|
|
ArrayConstantsTy ArrayConstants;
|
2009-07-22 04:13:12 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
|
2009-07-25 07:12:02 +08:00
|
|
|
StructConstantsTy StructConstants;
|
2009-07-24 07:25:33 +08:00
|
|
|
|
2014-08-20 00:39:58 +08:00
|
|
|
typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
|
2009-07-25 07:12:02 +08:00
|
|
|
VectorConstantsTy VectorConstants;
|
2009-07-24 08:36:24 +08:00
|
|
|
|
2012-01-23 23:20:12 +08:00
|
|
|
DenseMap<PointerType*, ConstantPointerNull*> CPNConstants;
|
|
|
|
|
|
|
|
DenseMap<Type*, UndefValue*> UVConstants;
|
2009-08-01 06:45:43 +08:00
|
|
|
|
2012-01-24 06:57:10 +08:00
|
|
|
StringMap<ConstantDataSequential*> CDSConstants;
|
|
|
|
|
2014-01-19 10:13:50 +08:00
|
|
|
DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
|
|
|
|
BlockAddresses;
|
2014-08-20 00:39:58 +08:00
|
|
|
ConstantUniqueMap<ConstantExpr> ExprConstants;
|
|
|
|
|
|
|
|
ConstantUniqueMap<InlineAsm> InlineAsms;
|
2014-08-19 09:02:18 +08:00
|
|
|
|
2009-07-21 10:47:59 +08:00
|
|
|
ConstantInt *TheTrueVal;
|
|
|
|
ConstantInt *TheFalseVal;
|
|
|
|
|
2009-08-20 01:07:46 +08: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-10 02:38:53 +08:00
|
|
|
LeakDetectorImpl<Metadata> LLVMMDObjects;
|
|
|
|
|
2009-08-26 00:00:35 +08:00
|
|
|
// Basic type instances.
|
2011-12-17 08:04:22 +08: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-10 01:41:24 +08:00
|
|
|
Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
|
|
|
|
IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty;
|
2010-02-11 14:41:30 +08:00
|
|
|
|
2011-07-15 13:49:15 +08: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-10 01:41:24 +08:00
|
|
|
DenseMap<unsigned, IntegerType*> IntegerTypes;
|
2014-12-07 03:22:54 +08: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-10 01:41:24 +08: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 14:41:30 +08:00
|
|
|
|
2009-12-18 03:55:06 +08:00
|
|
|
|
2009-08-19 02:28:58 +08: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-02 02:48:54 +08:00
|
|
|
/// whether or not a value has an entry in this map.
|
2009-08-19 02:28:58 +08:00
|
|
|
typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
|
|
|
|
ValueHandlesTy ValueHandles;
|
|
|
|
|
2009-12-29 17:01:33 +08: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-10 02:38:53 +08:00
|
|
|
|
|
|
|
typedef std::pair<unsigned, TrackingMDNodeRef> MDPairTy;
|
2009-12-29 17:01:33 +08:00
|
|
|
typedef SmallVector<MDPairTy, 2> MDMapTy;
|
|
|
|
|
|
|
|
/// MetadataStore - Collection of per-instruction metadata used in this
|
|
|
|
/// context.
|
|
|
|
DenseMap<const Instruction *, MDMapTy> MetadataStore;
|
|
|
|
|
2014-03-04 04:06:11 +08: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-02 02:48:54 +08: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 09:08:15 +08: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 10:08:38 +08: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 08:37:44 +08:00
|
|
|
int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
|
|
|
|
int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
|
2015-01-17 04:07:33 +08:00
|
|
|
|
|
|
|
/// An owning list of all GCStrategies which have been created
|
|
|
|
SmallVector<std::unique_ptr<GCStrategy>, 1> GCStrategyList;
|
|
|
|
/// A helper map to speedup lookups into the above list
|
|
|
|
StringMap<GCStrategy*> GCStrategyMap;
|
|
|
|
|
|
|
|
/// Lookup the GCStrategy object associated with the given gc name. If one
|
|
|
|
/// can't be found, returns nullptr. The lifetime of the returned objects
|
|
|
|
/// is dictated by the lifetime of the associated context. No caller should
|
|
|
|
/// attempt to delete the returned objects.
|
|
|
|
GCStrategy *getGCStrategy(const StringRef Name);
|
2014-05-16 01:49:20 +08:00
|
|
|
|
2010-03-22 05:17:34 +08:00
|
|
|
LLVMContextImpl(LLVMContext &C);
|
|
|
|
~LLVMContextImpl();
|
2009-06-30 08:48:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-07-01 01:06:46 +08:00
|
|
|
#endif
|