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-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"
|
2015-02-03 02:53:21 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#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"
|
2016-04-17 10:30:20 +08:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
Output optimization remarks in YAML
(Re-committed after moving the template specialization under the yaml
namespace. GCC was complaining about this.)
This allows various presentation of this data using an external tool.
This was first recommended here[1].
As an example, consider this module:
1 int foo();
2 int bar();
3
4 int baz() {
5 return foo() + bar();
6 }
The inliner generates these missed-optimization remarks today (the
hotness information is pulled from PGO):
remark: /tmp/s.c:5:10: foo will not be inlined into baz (hotness: 30)
remark: /tmp/s.c:5:18: bar will not be inlined into baz (hotness: 30)
Now with -pass-remarks-output=<yaml-file>, we generate this YAML file:
--- !Missed
Pass: inline
Name: NotInlined
DebugLoc: { File: /tmp/s.c, Line: 5, Column: 10 }
Function: baz
Hotness: 30
Args:
- Callee: foo
- String: will not be inlined into
- Caller: baz
...
--- !Missed
Pass: inline
Name: NotInlined
DebugLoc: { File: /tmp/s.c, Line: 5, Column: 18 }
Function: baz
Hotness: 30
Args:
- Callee: bar
- String: will not be inlined into
- Caller: baz
...
This is a summary of the high-level decisions:
* There is a new streaming interface to emit optimization remarks.
E.g. for the inliner remark above:
ORE.emit(DiagnosticInfoOptimizationRemarkMissed(
DEBUG_TYPE, "NotInlined", &I)
<< NV("Callee", Callee) << " will not be inlined into "
<< NV("Caller", CS.getCaller()) << setIsVerbose());
NV stands for named value and allows the YAML client to process a remark
using its name (NotInlined) and the named arguments (Callee and Caller)
without parsing the text of the message.
Subsequent patches will update ORE users to use the new streaming API.
* I am using YAML I/O for writing the YAML file. YAML I/O requires you
to specify reading and writing at once but reading is highly non-trivial
for some of the more complex LLVM types. Since it's not clear that we
(ever) want to use LLVM to parse this YAML file, the code supports and
asserts that we're writing only.
On the other hand, I did experiment that the class hierarchy starting at
DiagnosticInfoOptimizationBase can be mapped back from YAML generated
here (see D24479).
* The YAML stream is stored in the LLVM context.
* In the example, we can probably further specify the IR value used,
i.e. print "Function" rather than "Value".
* As before hotness is computed in the analysis pass instead of
DiganosticInfo. This avoids the layering problem since BFI is in
Analysis while DiagnosticInfo is in IR.
[1] https://reviews.llvm.org/D19678#419445
Differential Revision: https://reviews.llvm.org/D24587
llvm-svn: 282539
2016-09-28 04:55:07 +08:00
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
2016-04-20 07:59:13 +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>
|
2015-02-05 06:08:30 +08:00
|
|
|
MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
|
2015-01-20 08:01:43 +08:00
|
|
|
: Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
|
2015-01-20 06:53:18 +08:00
|
|
|
|
2015-01-20 08:01:43 +08:00
|
|
|
template <class NodeTy>
|
|
|
|
bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
|
2015-01-20 06:53:18 +08:00
|
|
|
if (getHash() != RHS->getHash())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
|
2015-01-20 08:01:43 +08:00
|
|
|
return RawOps.empty() ? compareOps(Ops, RHS, Offset)
|
|
|
|
: compareOps(RawOps, RHS, Offset);
|
2015-01-20 06:53:18 +08:00
|
|
|
}
|
|
|
|
|
2015-01-20 08:01:43 +08:00
|
|
|
static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
|
2015-01-20 06:53:18 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
template <class T>
|
2015-01-20 08:01:43 +08:00
|
|
|
static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
|
|
|
|
if (Ops.size() != RHS->getNumOperands() - Offset)
|
2015-01-20 06:53:18 +08:00
|
|
|
return false;
|
2015-01-20 08:01:43 +08:00
|
|
|
return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
|
2015-01-20 06:53:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned calculateHash(ArrayRef<Metadata *> Ops);
|
|
|
|
|
|
|
|
public:
|
|
|
|
unsigned getHash() const { return Hash; }
|
|
|
|
};
|
|
|
|
|
2015-02-05 06:08:30 +08:00
|
|
|
template <class NodeTy> struct MDNodeKeyImpl;
|
|
|
|
template <class NodeTy> struct MDNodeInfo;
|
|
|
|
|
2016-04-17 07:42:04 +08:00
|
|
|
/// Configuration point for MDNodeInfo::isEqual().
|
|
|
|
template <class NodeTy> struct MDNodeSubsetEqualImpl {
|
|
|
|
typedef MDNodeKeyImpl<NodeTy> KeyTy;
|
|
|
|
static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-02-05 06:08:30 +08:00
|
|
|
template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
|
|
|
|
MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
|
|
|
|
MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
|
2012-04-11 22:06:54 +08:00
|
|
|
|
2015-02-05 08:51:35 +08:00
|
|
|
bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
|
2015-01-20 06:53:18 +08:00
|
|
|
|
2015-02-05 06:08:30 +08:00
|
|
|
unsigned getHashValue() const { return getHash(); }
|
|
|
|
|
|
|
|
static unsigned calculateHash(MDTuple *N) {
|
|
|
|
return MDNodeOpsKey::calculateHash(N);
|
2012-04-11 22:06:54 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
/// \brief DenseMapInfo for DILocation.
|
|
|
|
template <> struct MDNodeKeyImpl<DILocation> {
|
2015-02-05 06:08:30 +08:00
|
|
|
unsigned Line;
|
|
|
|
unsigned Column;
|
|
|
|
Metadata *Scope;
|
|
|
|
Metadata *InlinedAt;
|
2015-01-14 04:44:56 +08:00
|
|
|
|
2015-02-05 06:08:30 +08:00
|
|
|
MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
|
|
|
|
Metadata *InlinedAt)
|
|
|
|
: Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
|
2015-01-14 04:44:56 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DILocation *L)
|
2015-03-27 06:05:04 +08:00
|
|
|
: Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
|
|
|
|
InlinedAt(L->getRawInlinedAt()) {}
|
2015-01-14 04:44:56 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DILocation *RHS) const {
|
2015-02-05 06:08:30 +08:00
|
|
|
return Line == RHS->getLine() && Column == RHS->getColumn() &&
|
2015-03-27 06:05:04 +08:00
|
|
|
Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
|
2015-01-14 04:44:56 +08:00
|
|
|
}
|
2015-02-05 06:08:30 +08:00
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Line, Column, Scope, InlinedAt);
|
2015-01-14 04:44:56 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
/// \brief DenseMapInfo for GenericDINode.
|
|
|
|
template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
|
2015-02-05 06:08:30 +08:00
|
|
|
unsigned Tag;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Header;
|
|
|
|
MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
|
2015-02-05 06:08:30 +08:00
|
|
|
: MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const GenericDINode *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
|
2015-01-20 08:01:43 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const GenericDINode *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
|
2015-02-05 06:08:30 +08:00
|
|
|
compareOps(RHS, 1);
|
2015-01-20 08:01:43 +08:00
|
|
|
}
|
2015-02-05 06:08:30 +08:00
|
|
|
|
|
|
|
unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
static unsigned calculateHash(GenericDINode *N) {
|
2015-02-05 06:08:30 +08:00
|
|
|
return MDNodeOpsKey::calculateHash(N, 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DISubrange> {
|
2015-02-10 08:52:32 +08:00
|
|
|
int64_t Count;
|
2015-04-07 08:39:59 +08:00
|
|
|
int64_t LowerBound;
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-07 08:39:59 +08:00
|
|
|
MDNodeKeyImpl(int64_t Count, int64_t LowerBound)
|
|
|
|
: Count(Count), LowerBound(LowerBound) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DISubrange *N)
|
2015-04-07 08:39:59 +08:00
|
|
|
: Count(N->getCount()), LowerBound(N->getLowerBound()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DISubrange *RHS) const {
|
2015-04-07 08:39:59 +08:00
|
|
|
return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
2015-04-07 08:39:59 +08:00
|
|
|
unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
|
2015-02-10 08:52:32 +08:00
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIEnumerator> {
|
2015-02-10 08:52:32 +08:00
|
|
|
int64_t Value;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(int64_t Value, MDString *Name) : Value(Value), Name(Name) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DIEnumerator *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Value(N->getValue()), Name(N->getRawName()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DIEnumerator *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Value == RHS->getValue() && Name == RHS->getRawName();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const { return hash_combine(Value, Name); }
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIBasicType> {
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Tag;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-20 07:56:07 +08:00
|
|
|
uint64_t SizeInBits;
|
|
|
|
uint64_t AlignInBits;
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Encoding;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
|
2015-02-20 07:56:07 +08:00
|
|
|
uint64_t AlignInBits, unsigned Encoding)
|
2015-02-10 08:52:32 +08:00
|
|
|
: Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
|
|
|
|
Encoding(Encoding) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DIBasicType *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
|
2015-02-10 08:52:32 +08:00
|
|
|
AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DIBasicType *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Tag == RHS->getTag() && Name == RHS->getRawName() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
SizeInBits == RHS->getSizeInBits() &&
|
|
|
|
AlignInBits == RHS->getAlignInBits() &&
|
|
|
|
Encoding == RHS->getEncoding();
|
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIDerivedType> {
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Tag;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File;
|
|
|
|
unsigned Line;
|
|
|
|
Metadata *Scope;
|
|
|
|
Metadata *BaseType;
|
2015-02-20 07:56:07 +08:00
|
|
|
uint64_t SizeInBits;
|
|
|
|
uint64_t AlignInBits;
|
|
|
|
uint64_t OffsetInBits;
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Flags;
|
|
|
|
Metadata *ExtraData;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
|
2015-02-20 07:56:07 +08:00
|
|
|
Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *ExtraData)
|
|
|
|
: Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
|
|
|
|
BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
|
|
|
|
OffsetInBits(OffsetInBits), Flags(Flags), ExtraData(ExtraData) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DIDerivedType *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
|
2015-03-28 07:05:04 +08:00
|
|
|
Line(N->getLine()), Scope(N->getRawScope()),
|
|
|
|
BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
|
|
|
|
AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
|
|
|
|
Flags(N->getFlags()), ExtraData(N->getRawExtraData()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DIDerivedType *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Tag == RHS->getTag() && Name == RHS->getRawName() &&
|
2015-03-28 07:05:04 +08:00
|
|
|
File == RHS->getRawFile() && Line == RHS->getLine() &&
|
|
|
|
Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
SizeInBits == RHS->getSizeInBits() &&
|
|
|
|
AlignInBits == RHS->getAlignInBits() &&
|
|
|
|
OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
|
2015-03-28 07:05:04 +08:00
|
|
|
ExtraData == RHS->getRawExtraData();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
2016-04-17 10:30:20 +08:00
|
|
|
// If this is a member inside an ODR type, only hash the type and the name.
|
|
|
|
// Otherwise the hash will be stronger than
|
|
|
|
// MDNodeSubsetEqualImpl::isODRMember().
|
2016-04-24 05:08:00 +08:00
|
|
|
if (Tag == dwarf::DW_TAG_member && Name)
|
|
|
|
if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
|
|
|
|
if (CT->getRawIdentifier())
|
|
|
|
return hash_combine(Name, Scope);
|
2016-04-17 10:30:20 +08:00
|
|
|
|
2016-03-19 09:06:24 +08:00
|
|
|
// Intentionally computes the hash on a subset of the operands for
|
|
|
|
// performance reason. The subset has to be significant enough to avoid
|
|
|
|
// collision "most of the time". There is no correctness issue in case of
|
|
|
|
// collision because of the full check above.
|
2016-03-19 08:59:26 +08:00
|
|
|
return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-17 10:30:20 +08:00
|
|
|
template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
|
|
|
|
typedef MDNodeKeyImpl<DIDerivedType> KeyTy;
|
|
|
|
static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
|
|
|
|
return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
|
|
|
|
}
|
|
|
|
static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
|
|
|
|
return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
|
|
|
|
RHS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Subprograms compare equal if they declare the same function in an ODR
|
|
|
|
/// type.
|
|
|
|
static bool isODRMember(unsigned Tag, const Metadata *Scope,
|
|
|
|
const MDString *Name, const DIDerivedType *RHS) {
|
|
|
|
// Check whether the LHS is eligible.
|
2016-04-24 05:08:00 +08:00
|
|
|
if (Tag != dwarf::DW_TAG_member || !Name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
|
|
|
|
if (!CT || !CT->getRawIdentifier())
|
2016-04-17 10:30:20 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Compare to the RHS.
|
|
|
|
return Tag == RHS->getTag() && Name == RHS->getRawName() &&
|
|
|
|
Scope == RHS->getRawScope();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DICompositeType> {
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Tag;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File;
|
|
|
|
unsigned Line;
|
|
|
|
Metadata *Scope;
|
|
|
|
Metadata *BaseType;
|
2015-02-20 07:56:07 +08:00
|
|
|
uint64_t SizeInBits;
|
|
|
|
uint64_t AlignInBits;
|
|
|
|
uint64_t OffsetInBits;
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Flags;
|
|
|
|
Metadata *Elements;
|
|
|
|
unsigned RuntimeLang;
|
|
|
|
Metadata *VTableHolder;
|
|
|
|
Metadata *TemplateParams;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Identifier;
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
|
2015-02-20 07:56:07 +08:00
|
|
|
Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Elements, unsigned RuntimeLang,
|
|
|
|
Metadata *VTableHolder, Metadata *TemplateParams,
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Identifier)
|
2015-02-10 08:52:32 +08:00
|
|
|
: Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
|
|
|
|
BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
|
|
|
|
OffsetInBits(OffsetInBits), Flags(Flags), Elements(Elements),
|
|
|
|
RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
|
|
|
|
TemplateParams(TemplateParams), Identifier(Identifier) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DICompositeType *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
|
2015-03-28 07:05:04 +08:00
|
|
|
Line(N->getLine()), Scope(N->getRawScope()),
|
|
|
|
BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
|
|
|
|
AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
|
|
|
|
Flags(N->getFlags()), Elements(N->getRawElements()),
|
|
|
|
RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
|
|
|
|
TemplateParams(N->getRawTemplateParams()),
|
2016-03-19 09:02:34 +08:00
|
|
|
Identifier(N->getRawIdentifier()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DICompositeType *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Tag == RHS->getTag() && Name == RHS->getRawName() &&
|
2015-03-28 07:05:04 +08:00
|
|
|
File == RHS->getRawFile() && Line == RHS->getLine() &&
|
|
|
|
Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
SizeInBits == RHS->getSizeInBits() &&
|
|
|
|
AlignInBits == RHS->getAlignInBits() &&
|
|
|
|
OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
|
2015-03-28 07:05:04 +08:00
|
|
|
Elements == RHS->getRawElements() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
RuntimeLang == RHS->getRuntimeLang() &&
|
2015-03-28 07:05:04 +08:00
|
|
|
VTableHolder == RHS->getRawVTableHolder() &&
|
|
|
|
TemplateParams == RHS->getRawTemplateParams() &&
|
2016-03-19 09:02:34 +08:00
|
|
|
Identifier == RHS->getRawIdentifier();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
2016-03-19 09:06:24 +08:00
|
|
|
// Intentionally computes the hash on a subset of the operands for
|
|
|
|
// performance reason. The subset has to be significant enough to avoid
|
|
|
|
// collision "most of the time". There is no correctness issue in case of
|
|
|
|
// collision because of the full check above.
|
2016-03-19 08:59:26 +08:00
|
|
|
return hash_combine(Name, File, Line, BaseType, Scope, Elements,
|
|
|
|
TemplateParams);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DISubroutineType> {
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Flags;
|
2016-06-09 04:34:29 +08:00
|
|
|
uint8_t CC;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *TypeArray;
|
|
|
|
|
2016-06-09 04:34:29 +08:00
|
|
|
MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
|
|
|
|
: Flags(Flags), CC(CC), TypeArray(TypeArray) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DISubroutineType *N)
|
2016-06-09 04:34:29 +08:00
|
|
|
: Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DISubroutineType *RHS) const {
|
2016-06-09 04:34:29 +08:00
|
|
|
return Flags == RHS->getFlags() && CC == RHS->getCC() &&
|
|
|
|
TypeArray == RHS->getRawTypeArray();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
2016-06-09 04:34:29 +08:00
|
|
|
unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
|
2015-02-10 08:52:32 +08:00
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIFile> {
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Filename;
|
|
|
|
MDString *Directory;
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(MDString *Filename, MDString *Directory)
|
2015-02-10 08:52:32 +08:00
|
|
|
: Filename(Filename), Directory(Directory) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DIFile *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Filename(N->getRawFilename()), Directory(N->getRawDirectory()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DIFile *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Filename == RHS->getRawFilename() &&
|
|
|
|
Directory == RHS->getRawDirectory();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const { return hash_combine(Filename, Directory); }
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DISubprogram> {
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Scope;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
|
|
|
MDString *LinkageName;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File;
|
|
|
|
unsigned Line;
|
|
|
|
Metadata *Type;
|
|
|
|
bool IsLocalToUnit;
|
|
|
|
bool IsDefinition;
|
|
|
|
unsigned ScopeLine;
|
|
|
|
Metadata *ContainingType;
|
|
|
|
unsigned Virtuality;
|
|
|
|
unsigned VirtualIndex;
|
2016-07-01 10:41:21 +08:00
|
|
|
int ThisAdjustment;
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Flags;
|
|
|
|
bool IsOptimized;
|
2016-04-15 23:57:41 +08:00
|
|
|
Metadata *Unit;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *TemplateParams;
|
|
|
|
Metadata *Declaration;
|
|
|
|
Metadata *Variables;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File, unsigned Line, Metadata *Type,
|
|
|
|
bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
|
|
|
|
Metadata *ContainingType, unsigned Virtuality,
|
2016-07-01 10:41:21 +08:00
|
|
|
unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
|
|
|
|
bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
|
|
|
|
Metadata *Declaration, Metadata *Variables)
|
2015-02-10 08:52:32 +08:00
|
|
|
: Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
|
|
|
|
Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
|
|
|
|
IsDefinition(IsDefinition), ScopeLine(ScopeLine),
|
|
|
|
ContainingType(ContainingType), Virtuality(Virtuality),
|
2016-07-01 10:41:21 +08:00
|
|
|
VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
|
|
|
|
Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
|
|
|
|
TemplateParams(TemplateParams), Declaration(Declaration),
|
2015-11-06 06:03:56 +08:00
|
|
|
Variables(Variables) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DISubprogram *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Scope(N->getRawScope()), Name(N->getRawName()),
|
|
|
|
LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
|
2015-03-31 00:19:15 +08:00
|
|
|
Line(N->getLine()), Type(N->getRawType()),
|
2015-02-10 08:52:32 +08:00
|
|
|
IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
|
2015-03-31 00:19:15 +08:00
|
|
|
ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
|
2015-02-10 08:52:32 +08:00
|
|
|
Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
|
2016-07-01 10:41:21 +08:00
|
|
|
ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
|
|
|
|
IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
|
|
|
|
TemplateParams(N->getRawTemplateParams()),
|
2015-03-31 00:19:15 +08:00
|
|
|
Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DISubprogram *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
|
|
|
|
LinkageName == RHS->getRawLinkageName() &&
|
|
|
|
File == RHS->getRawFile() && Line == RHS->getLine() &&
|
|
|
|
Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
IsDefinition == RHS->isDefinition() &&
|
|
|
|
ScopeLine == RHS->getScopeLine() &&
|
2015-03-31 00:19:15 +08:00
|
|
|
ContainingType == RHS->getRawContainingType() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
Virtuality == RHS->getVirtuality() &&
|
2016-07-01 10:41:21 +08:00
|
|
|
VirtualIndex == RHS->getVirtualIndex() &&
|
|
|
|
ThisAdjustment == RHS->getThisAdjustment() &&
|
|
|
|
Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
|
|
|
|
Unit == RHS->getUnit() &&
|
2015-03-31 00:19:15 +08:00
|
|
|
TemplateParams == RHS->getRawTemplateParams() &&
|
|
|
|
Declaration == RHS->getRawDeclaration() &&
|
|
|
|
Variables == RHS->getRawVariables();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
2016-04-17 10:30:20 +08:00
|
|
|
// If this is a declaration inside an ODR type, only hash the type and the
|
|
|
|
// name. Otherwise the hash will be stronger than
|
|
|
|
// MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
|
2016-04-24 05:08:00 +08:00
|
|
|
if (!IsDefinition && LinkageName)
|
|
|
|
if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
|
|
|
|
if (CT->getRawIdentifier())
|
|
|
|
return hash_combine(LinkageName, Scope);
|
2016-04-17 10:30:20 +08:00
|
|
|
|
2016-03-19 09:06:24 +08:00
|
|
|
// Intentionally computes the hash on a subset of the operands for
|
|
|
|
// performance reason. The subset has to be significant enough to avoid
|
|
|
|
// collision "most of the time". There is no correctness issue in case of
|
|
|
|
// collision because of the full check above.
|
2016-03-19 08:59:26 +08:00
|
|
|
return hash_combine(Name, Scope, File, Type, Line);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-17 10:30:20 +08:00
|
|
|
template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
|
|
|
|
typedef MDNodeKeyImpl<DISubprogram> KeyTy;
|
|
|
|
static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
|
|
|
|
return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
|
|
|
|
LHS.LinkageName, RHS);
|
|
|
|
}
|
|
|
|
static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
|
|
|
|
return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
|
|
|
|
LHS->getRawLinkageName(), RHS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Subprograms compare equal if they declare the same function in an ODR
|
|
|
|
/// type.
|
|
|
|
static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
|
|
|
|
const MDString *LinkageName,
|
|
|
|
const DISubprogram *RHS) {
|
|
|
|
// Check whether the LHS is eligible.
|
2016-04-24 05:08:00 +08:00
|
|
|
if (IsDefinition || !Scope || !LinkageName)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
|
|
|
|
if (!CT || !CT->getRawIdentifier())
|
2016-04-17 10:30:20 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Compare to the RHS.
|
|
|
|
return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
|
|
|
|
LinkageName == RHS->getRawLinkageName();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DILexicalBlock> {
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Scope;
|
|
|
|
Metadata *File;
|
|
|
|
unsigned Line;
|
|
|
|
unsigned Column;
|
|
|
|
|
|
|
|
MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
|
|
|
|
: Scope(Scope), File(File), Line(Line), Column(Column) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DILexicalBlock *N)
|
2015-03-31 00:37:48 +08:00
|
|
|
: Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
|
2015-02-10 08:52:32 +08:00
|
|
|
Column(N->getColumn()) {}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DILexicalBlock *RHS) const {
|
2015-03-31 00:37:48 +08:00
|
|
|
return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
Line == RHS->getLine() && Column == RHS->getColumn();
|
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Scope, File, Line, Column);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Scope;
|
|
|
|
Metadata *File;
|
|
|
|
unsigned Discriminator;
|
|
|
|
|
|
|
|
MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
|
|
|
|
: Scope(Scope), File(File), Discriminator(Discriminator) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DILexicalBlockFile *N)
|
2015-03-31 00:37:48 +08:00
|
|
|
: Scope(N->getRawScope()), File(N->getRawFile()),
|
2015-02-10 08:52:32 +08:00
|
|
|
Discriminator(N->getDiscriminator()) {}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DILexicalBlockFile *RHS) const {
|
2015-03-31 00:37:48 +08:00
|
|
|
return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
Discriminator == RHS->getDiscriminator();
|
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Scope, File, Discriminator);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DINamespace> {
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Scope;
|
|
|
|
Metadata *File;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Line;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(Metadata *Scope, Metadata *File, MDString *Name, unsigned Line)
|
2015-02-10 08:52:32 +08:00
|
|
|
: Scope(Scope), File(File), Name(Name), Line(Line) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DINamespace *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getRawName()),
|
2015-02-10 08:52:32 +08:00
|
|
|
Line(N->getLine()) {}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DINamespace *RHS) const {
|
2015-03-31 01:21:38 +08:00
|
|
|
return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
|
2016-03-19 09:02:34 +08:00
|
|
|
Name == RHS->getRawName() && Line == RHS->getLine();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Scope, File, Name, Line);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-30 07:03:47 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIModule> {
|
|
|
|
Metadata *Scope;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
|
|
|
MDString *ConfigurationMacros;
|
|
|
|
MDString *IncludePath;
|
|
|
|
MDString *ISysRoot;
|
|
|
|
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
|
|
|
|
MDString *IncludePath, MDString *ISysRoot)
|
|
|
|
: Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
|
|
|
|
IncludePath(IncludePath), ISysRoot(ISysRoot) {}
|
2015-06-30 07:03:47 +08:00
|
|
|
MDNodeKeyImpl(const DIModule *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Scope(N->getRawScope()), Name(N->getRawName()),
|
|
|
|
ConfigurationMacros(N->getRawConfigurationMacros()),
|
|
|
|
IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
|
2015-06-30 07:03:47 +08:00
|
|
|
|
|
|
|
bool isKeyOf(const DIModule *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
|
|
|
|
ConfigurationMacros == RHS->getRawConfigurationMacros() &&
|
|
|
|
IncludePath == RHS->getRawIncludePath() &&
|
|
|
|
ISysRoot == RHS->getRawISysRoot();
|
2015-06-30 07:03:47 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Scope, Name,
|
|
|
|
ConfigurationMacros, IncludePath, ISysRoot);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Type;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DITemplateTypeParameter *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Name(N->getRawName()), Type(N->getRawType()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DITemplateTypeParameter *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Name == RHS->getRawName() && Type == RHS->getRawType();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
2015-02-19 08:37:21 +08:00
|
|
|
unsigned getHashValue() const { return hash_combine(Name, Type); }
|
2015-02-10 08:52:32 +08:00
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Tag;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Type;
|
|
|
|
Metadata *Value;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
|
2015-02-19 08:37:21 +08:00
|
|
|
: Tag(Tag), Name(Name), Type(Type), Value(Value) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DITemplateValueParameter *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
|
2015-02-19 08:37:21 +08:00
|
|
|
Value(N->getValue()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DITemplateValueParameter *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Tag == RHS->getTag() && Name == RHS->getRawName() &&
|
2015-04-07 03:03:45 +08:00
|
|
|
Type == RHS->getRawType() && Value == RHS->getValue();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
2015-02-19 08:37:21 +08:00
|
|
|
unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
|
2015-02-10 08:52:32 +08:00
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIGlobalVariable> {
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Scope;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
|
|
|
MDString *LinkageName;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File;
|
|
|
|
unsigned Line;
|
|
|
|
Metadata *Type;
|
|
|
|
bool IsLocalToUnit;
|
|
|
|
bool IsDefinition;
|
2016-09-13 09:12:59 +08:00
|
|
|
Metadata *Expr;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *StaticDataMemberDeclaration;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File, unsigned Line, Metadata *Type,
|
2016-09-13 09:12:59 +08:00
|
|
|
bool IsLocalToUnit, bool IsDefinition, Metadata *Expr,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *StaticDataMemberDeclaration)
|
|
|
|
: Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
|
|
|
|
Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
|
2016-09-13 09:12:59 +08:00
|
|
|
IsDefinition(IsDefinition), Expr(Expr),
|
2015-02-10 08:52:32 +08:00
|
|
|
StaticDataMemberDeclaration(StaticDataMemberDeclaration) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DIGlobalVariable *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Scope(N->getRawScope()), Name(N->getRawName()),
|
|
|
|
LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
|
2015-03-28 01:29:58 +08:00
|
|
|
Line(N->getLine()), Type(N->getRawType()),
|
2015-02-10 08:52:32 +08:00
|
|
|
IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
|
2016-09-13 09:12:59 +08:00
|
|
|
Expr(N->getRawExpr()),
|
2015-03-28 01:29:58 +08:00
|
|
|
StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DIGlobalVariable *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
|
|
|
|
LinkageName == RHS->getRawLinkageName() &&
|
|
|
|
File == RHS->getRawFile() && Line == RHS->getLine() &&
|
|
|
|
Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
|
2015-02-10 08:52:32 +08:00
|
|
|
IsDefinition == RHS->isDefinition() &&
|
2016-09-13 09:12:59 +08:00
|
|
|
Expr == RHS->getRawExpr() &&
|
2015-03-28 01:29:58 +08:00
|
|
|
StaticDataMemberDeclaration ==
|
|
|
|
RHS->getRawStaticDataMemberDeclaration();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Scope, Name, LinkageName, File, Line, Type,
|
2016-09-13 09:12:59 +08:00
|
|
|
IsLocalToUnit, IsDefinition, Expr,
|
2015-02-10 08:52:32 +08:00
|
|
|
StaticDataMemberDeclaration);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DILocalVariable> {
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Scope;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File;
|
|
|
|
unsigned Line;
|
|
|
|
Metadata *Type;
|
|
|
|
unsigned Arg;
|
|
|
|
unsigned Flags;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
|
2015-08-01 02:58:39 +08:00
|
|
|
Metadata *Type, unsigned Arg, unsigned Flags)
|
|
|
|
: Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
|
|
|
|
Flags(Flags) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DILocalVariable *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
|
2015-08-01 02:58:39 +08:00
|
|
|
Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
|
|
|
|
Flags(N->getFlags()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DILocalVariable *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
|
2015-08-01 02:58:39 +08:00
|
|
|
File == RHS->getRawFile() && Line == RHS->getLine() &&
|
|
|
|
Type == RHS->getRawType() && Arg == RHS->getArg() &&
|
|
|
|
Flags == RHS->getFlags();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
2015-08-01 02:58:39 +08:00
|
|
|
return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIExpression> {
|
2015-02-10 08:52:32 +08:00
|
|
|
ArrayRef<uint64_t> Elements;
|
|
|
|
|
|
|
|
MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DIExpression *RHS) const {
|
2015-02-10 08:52:32 +08:00
|
|
|
return Elements == RHS->getElements();
|
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine_range(Elements.begin(), Elements.end());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIObjCProperty> {
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *File;
|
|
|
|
unsigned Line;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *GetterName;
|
|
|
|
MDString *SetterName;
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Attributes;
|
|
|
|
Metadata *Type;
|
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
|
|
|
|
MDString *GetterName, MDString *SetterName, unsigned Attributes,
|
2015-02-10 08:52:32 +08:00
|
|
|
Metadata *Type)
|
|
|
|
: Name(Name), File(File), Line(Line), GetterName(GetterName),
|
|
|
|
SetterName(SetterName), Attributes(Attributes), Type(Type) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DIObjCProperty *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
|
|
|
|
GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
|
2015-03-31 01:21:38 +08:00
|
|
|
Attributes(N->getAttributes()), Type(N->getRawType()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DIObjCProperty *RHS) const {
|
2016-03-19 09:02:34 +08:00
|
|
|
return Name == RHS->getRawName() && File == RHS->getRawFile() &&
|
|
|
|
Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
|
|
|
|
SetterName == RHS->getRawSetterName() &&
|
2015-03-31 01:21:38 +08:00
|
|
|
Attributes == RHS->getAttributes() && Type == RHS->getRawType();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
|
|
|
|
Type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIImportedEntity> {
|
2015-02-10 08:52:32 +08:00
|
|
|
unsigned Tag;
|
|
|
|
Metadata *Scope;
|
|
|
|
Metadata *Entity;
|
|
|
|
unsigned Line;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
2015-02-10 08:52:32 +08:00
|
|
|
|
|
|
|
MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line,
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name)
|
2015-02-10 08:52:32 +08:00
|
|
|
: Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
|
2015-04-30 00:38:44 +08:00
|
|
|
MDNodeKeyImpl(const DIImportedEntity *N)
|
2015-03-31 01:21:38 +08:00
|
|
|
: Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
|
2016-03-19 09:02:34 +08:00
|
|
|
Line(N->getLine()), Name(N->getRawName()) {}
|
2015-02-10 08:52:32 +08:00
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool isKeyOf(const DIImportedEntity *RHS) const {
|
2015-03-31 01:21:38 +08:00
|
|
|
return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
|
|
|
|
Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
|
2016-03-19 09:02:34 +08:00
|
|
|
Name == RHS->getRawName();
|
2015-02-10 08:52:32 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(Tag, Scope, Entity, Line, Name);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-10 20:56:35 +08:00
|
|
|
template <> struct MDNodeKeyImpl<DIMacro> {
|
|
|
|
unsigned MIType;
|
|
|
|
unsigned Line;
|
2016-03-19 09:02:34 +08:00
|
|
|
MDString *Name;
|
|
|
|
MDString *Value;
|
2015-12-10 20:56:35 +08:00
|
|
|
|
2016-03-19 09:02:34 +08:00
|
|
|
MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
|
2015-12-10 20:56:35 +08:00
|
|
|
: MIType(MIType), Line(Line), Name(Name), Value(Value) {}
|
|
|
|
MDNodeKeyImpl(const DIMacro *N)
|
2016-03-19 09:02:34 +08:00
|
|
|
: MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
|
|
|
|
Value(N->getRawValue()) {}
|
2015-12-10 20:56:35 +08:00
|
|
|
|
|
|
|
bool isKeyOf(const DIMacro *RHS) const {
|
|
|
|
return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
|
2016-03-19 09:02:34 +08:00
|
|
|
Name == RHS->getRawName() && Value == RHS->getRawValue();
|
2015-12-10 20:56:35 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(MIType, Line, Name, Value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct MDNodeKeyImpl<DIMacroFile> {
|
|
|
|
unsigned MIType;
|
|
|
|
unsigned Line;
|
|
|
|
Metadata *File;
|
|
|
|
Metadata *Elements;
|
|
|
|
|
|
|
|
MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
|
|
|
|
Metadata *Elements)
|
|
|
|
: MIType(MIType), Line(Line), File(File), Elements(Elements) {}
|
|
|
|
MDNodeKeyImpl(const DIMacroFile *N)
|
|
|
|
: MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
|
|
|
|
Elements(N->getRawElements()) {}
|
|
|
|
|
|
|
|
bool isKeyOf(const DIMacroFile *RHS) const {
|
|
|
|
return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
|
2016-07-31 22:41:50 +08:00
|
|
|
File == RHS->getRawFile() && Elements == RHS->getRawElements();
|
2015-12-10 20:56:35 +08:00
|
|
|
}
|
|
|
|
unsigned getHashValue() const {
|
|
|
|
return hash_combine(MIType, Line, File, Elements);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-05 06:08:30 +08:00
|
|
|
/// \brief DenseMapInfo for MDNode subclasses.
|
|
|
|
template <class NodeTy> struct MDNodeInfo {
|
|
|
|
typedef MDNodeKeyImpl<NodeTy> KeyTy;
|
2016-04-17 07:42:04 +08:00
|
|
|
typedef MDNodeSubsetEqualImpl<NodeTy> SubsetEqualTy;
|
2015-02-05 06:08:30 +08:00
|
|
|
static inline NodeTy *getEmptyKey() {
|
|
|
|
return DenseMapInfo<NodeTy *>::getEmptyKey();
|
2015-01-20 08:01:43 +08:00
|
|
|
}
|
2015-02-05 06:08:30 +08:00
|
|
|
static inline NodeTy *getTombstoneKey() {
|
|
|
|
return DenseMapInfo<NodeTy *>::getTombstoneKey();
|
2015-01-20 08:01:43 +08:00
|
|
|
}
|
2015-02-05 06:08:30 +08:00
|
|
|
static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
|
|
|
|
static unsigned getHashValue(const NodeTy *N) {
|
|
|
|
return KeyTy(N).getHashValue();
|
2015-01-20 08:01:43 +08:00
|
|
|
}
|
2015-02-05 06:08:30 +08:00
|
|
|
static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
|
|
|
|
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
|
|
|
return false;
|
2016-04-17 07:42:04 +08:00
|
|
|
return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
|
2015-01-20 08:01:43 +08:00
|
|
|
}
|
2015-02-05 06:08:30 +08:00
|
|
|
static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
|
2016-04-17 07:42:04 +08:00
|
|
|
if (LHS == RHS)
|
|
|
|
return true;
|
|
|
|
if (RHS == getEmptyKey() || RHS == getTombstoneKey())
|
|
|
|
return false;
|
|
|
|
return SubsetEqualTy::isSubsetEqual(LHS, RHS);
|
2015-01-20 08:01:43 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-05 06:08:30 +08:00
|
|
|
#define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info;
|
|
|
|
#include "llvm/IR/Metadata.def"
|
|
|
|
|
2015-04-25 04:36:25 +08:00
|
|
|
/// \brief Map-like storage for metadata attachments.
|
|
|
|
class MDAttachmentMap {
|
|
|
|
SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool empty() const { return Attachments.empty(); }
|
|
|
|
size_t size() const { return Attachments.size(); }
|
|
|
|
|
|
|
|
/// \brief Get a particular attachment (if any).
|
|
|
|
MDNode *lookup(unsigned ID) const;
|
|
|
|
|
|
|
|
/// \brief Set an attachment to a particular node.
|
|
|
|
///
|
|
|
|
/// Set the \c ID attachment to \c MD, replacing the current attachment at \c
|
|
|
|
/// ID (if anyway).
|
|
|
|
void set(unsigned ID, MDNode &MD);
|
|
|
|
|
|
|
|
/// \brief Remove an attachment.
|
|
|
|
///
|
|
|
|
/// Remove the attachment at \c ID, if any.
|
|
|
|
void erase(unsigned ID);
|
|
|
|
|
|
|
|
/// \brief Copy out all the attachments.
|
|
|
|
///
|
|
|
|
/// Copies all the current attachments into \c Result, sorting by attachment
|
|
|
|
/// ID. This function does \em not clear \c Result.
|
|
|
|
void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
|
|
|
|
|
|
|
|
/// \brief Erase matching attachments.
|
|
|
|
///
|
|
|
|
/// Erases all attachments matching the \c shouldRemove predicate.
|
|
|
|
template <class PredTy> void remove_if(PredTy shouldRemove) {
|
2016-08-12 12:32:42 +08:00
|
|
|
Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
|
|
|
|
Attachments.end());
|
2015-04-25 04:36:25 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-01 09:17:57 +08:00
|
|
|
/// Multimap-like storage for metadata attachments for globals. This differs
|
|
|
|
/// from MDAttachmentMap in that it allows multiple attachments per metadata
|
|
|
|
/// kind.
|
|
|
|
class MDGlobalAttachmentMap {
|
|
|
|
struct Attachment {
|
|
|
|
unsigned MDKind;
|
|
|
|
TrackingMDNodeRef Node;
|
|
|
|
};
|
|
|
|
SmallVector<Attachment, 1> Attachments;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool empty() const { return Attachments.empty(); }
|
|
|
|
|
|
|
|
/// Appends all attachments with the given ID to \c Result in insertion order.
|
|
|
|
/// If the global has no attachments with the given ID, or if ID is invalid,
|
|
|
|
/// leaves Result unchanged.
|
|
|
|
void get(unsigned ID, SmallVectorImpl<MDNode *> &Result);
|
|
|
|
|
|
|
|
void insert(unsigned ID, MDNode &MD);
|
|
|
|
void erase(unsigned ID);
|
|
|
|
|
|
|
|
/// Appends all attachments for the global to \c Result, sorting by attachment
|
|
|
|
/// ID. Attachments with the same ID appear in insertion order. This function
|
|
|
|
/// does \em not clear \c Result.
|
|
|
|
void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
|
|
|
|
};
|
|
|
|
|
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;
|
2016-07-16 01:23:20 +08:00
|
|
|
bool DiagnosticHotnessRequested;
|
Output optimization remarks in YAML
(Re-committed after moving the template specialization under the yaml
namespace. GCC was complaining about this.)
This allows various presentation of this data using an external tool.
This was first recommended here[1].
As an example, consider this module:
1 int foo();
2 int bar();
3
4 int baz() {
5 return foo() + bar();
6 }
The inliner generates these missed-optimization remarks today (the
hotness information is pulled from PGO):
remark: /tmp/s.c:5:10: foo will not be inlined into baz (hotness: 30)
remark: /tmp/s.c:5:18: bar will not be inlined into baz (hotness: 30)
Now with -pass-remarks-output=<yaml-file>, we generate this YAML file:
--- !Missed
Pass: inline
Name: NotInlined
DebugLoc: { File: /tmp/s.c, Line: 5, Column: 10 }
Function: baz
Hotness: 30
Args:
- Callee: foo
- String: will not be inlined into
- Caller: baz
...
--- !Missed
Pass: inline
Name: NotInlined
DebugLoc: { File: /tmp/s.c, Line: 5, Column: 18 }
Function: baz
Hotness: 30
Args:
- Callee: bar
- String: will not be inlined into
- Caller: baz
...
This is a summary of the high-level decisions:
* There is a new streaming interface to emit optimization remarks.
E.g. for the inliner remark above:
ORE.emit(DiagnosticInfoOptimizationRemarkMissed(
DEBUG_TYPE, "NotInlined", &I)
<< NV("Callee", Callee) << " will not be inlined into "
<< NV("Caller", CS.getCaller()) << setIsVerbose());
NV stands for named value and allows the YAML client to process a remark
using its name (NotInlined) and the named arguments (Callee and Caller)
without parsing the text of the message.
Subsequent patches will update ORE users to use the new streaming API.
* I am using YAML I/O for writing the YAML file. YAML I/O requires you
to specify reading and writing at once but reading is highly non-trivial
for some of the more complex LLVM types. Since it's not clear that we
(ever) want to use LLVM to parse this YAML file, the code supports and
asserts that we're writing only.
On the other hand, I did experiment that the class hierarchy starting at
DiagnosticInfoOptimizationBase can be mapped back from YAML generated
here (see D24479).
* The YAML stream is stored in the LLVM context.
* In the example, we can probably further specify the IR value used,
i.e. print "Function" rather than "Value".
* As before hotness is computed in the analysis pass instead of
DiganosticInfo. This avoids the layering problem since BFI is in
Analysis while DiagnosticInfo is in IR.
[1] https://reviews.llvm.org/D19678#419445
Differential Revision: https://reviews.llvm.org/D24587
llvm-svn: 282539
2016-09-28 04:55:07 +08:00
|
|
|
std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
|
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
|
|
|
|
2016-04-06 14:41:54 +08:00
|
|
|
StringMap<MDString, BumpPtrAllocator> 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-06-02 06:24:01 +08:00
|
|
|
DenseMap<const Value*, ValueName*> ValueNames;
|
|
|
|
|
2015-08-04 01:26:41 +08:00
|
|
|
#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
|
|
|
|
DenseSet<CLASS *, CLASS##Info> CLASS##s;
|
2015-02-05 05:46:12 +08:00
|
|
|
#include "llvm/IR/Metadata.def"
|
2012-09-27 05:07:29 +08:00
|
|
|
|
2016-04-17 11:58:21 +08:00
|
|
|
// Optional map for looking up composite types by identifier.
|
2016-04-20 00:06:50 +08:00
|
|
|
Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
|
2016-04-17 11:58:21 +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
|
2016-04-20 07:59:13 +08:00
|
|
|
// one object can destroy them. Keep track of them here so we can delete
|
|
|
|
// them on context teardown.
|
|
|
|
std::vector<MDNode *> 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;
|
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-11-17 04:55:57 +08:00
|
|
|
std::unique_ptr<ConstantTokenNone> TheNoneToken;
|
2015-11-12 05:57:16 +08:00
|
|
|
|
2009-08-26 00:00:35 +08:00
|
|
|
// Basic type instances.
|
2015-08-14 13:09:07 +08:00
|
|
|
Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
|
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;
|
2015-04-17 23:32:15 +08:00
|
|
|
IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
|
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
|
|
|
|
2015-04-25 04:16:42 +08:00
|
|
|
/// Collection of per-instruction metadata used in this context.
|
2015-04-25 04:36:25 +08:00
|
|
|
DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
|
2015-04-25 04:16:42 +08:00
|
|
|
|
2016-06-01 07:01:54 +08:00
|
|
|
/// Collection of per-GlobalObject metadata used in this context.
|
2016-06-01 09:17:57 +08:00
|
|
|
DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
|
2015-04-25 05:51:02 +08:00
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2015-09-25 03:14:18 +08:00
|
|
|
/// \brief A set of interned tags for operand bundles. The StringMap maps
|
|
|
|
/// bundle tags to their IDs.
|
|
|
|
///
|
|
|
|
/// \see LLVMContext::getOperandBundleTagID
|
|
|
|
StringMap<uint32_t> BundleTagCache;
|
|
|
|
|
|
|
|
StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
|
|
|
|
void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
|
|
|
|
uint32_t getOperandBundleTagID(StringRef Tag) const;
|
|
|
|
|
2016-01-08 10:28:20 +08:00
|
|
|
/// Maintain the GC name for each function.
|
|
|
|
///
|
|
|
|
/// This saves allocating an additional word in Function for programs which
|
|
|
|
/// do not use GC (i.e., most programs) at the cost of increased overhead for
|
|
|
|
/// clients which do use GC.
|
|
|
|
DenseMap<const Function*, std::string> GCNames;
|
|
|
|
|
Add a flag to the LLVMContext to disable name for Value other than GlobalValue
Summary:
This is intended to be a performance flag, on the same level as clang
cc1 option "--disable-free". LLVM will never initialize it by default,
it will be up to the client creating the LLVMContext to request this
behavior. Clang will do it by default in Release build (just like
--disable-free).
"opt" and "llc" can opt-in using -disable-named-value command line
option.
When performing LTO on llvm-tblgen, the initial merging of IR peaks
at 92MB without this patch, and 86MB after this patch,setNameImpl()
drops from 6.5MB to 0.5MB.
The total link time goes from ~29.5s to ~27.8s.
Compared to a compile-time flag (like the IRBuilder one), it performs
very close. I profiled on SROA and obtain these results:
420ms with IRBuilder that preserve name
372ms with IRBuilder that strip name
375ms with IRBuilder that preserve name, and a runtime flag to strip
Reviewers: chandlerc, dexonsmith, bogner
Subscribers: joker.eph, llvm-commits
Differential Revision: http://reviews.llvm.org/D17946
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 263086
2016-03-10 09:28:54 +08:00
|
|
|
/// Flag to indicate if Value (other than GlobalValue) retains their name or
|
|
|
|
/// not.
|
|
|
|
bool DiscardValueNames = false;
|
|
|
|
|
2010-03-22 05:17:34 +08:00
|
|
|
LLVMContextImpl(LLVMContext &C);
|
|
|
|
~LLVMContextImpl();
|
2015-01-21 03:24:59 +08:00
|
|
|
|
|
|
|
/// Destroy the ConstantArrays if they are not used.
|
|
|
|
void dropTriviallyDeadConstantArrays();
|
2016-04-23 06:06:11 +08:00
|
|
|
|
|
|
|
/// \brief Access the object which manages optimization bisection for failure
|
|
|
|
/// analysis.
|
|
|
|
OptBisect &getOptBisect();
|
2009-06-30 08:48:55 +08:00
|
|
|
};
|
|
|
|
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2009-06-30 08:48:55 +08:00
|
|
|
|
2009-07-01 01:06:46 +08:00
|
|
|
#endif
|