[IR] Fix some Clang-tidy modernize-use-using warnings; other minor fixes (NFC).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305755 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eugene Zelenko 2017-06-19 22:05:08 +00:00
parent 4b199ee307
commit f1934002e0
12 changed files with 301 additions and 168 deletions

View File

@ -622,7 +622,8 @@ public:
// AttributeList Introspection // AttributeList Introspection
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
typedef const AttributeSet *iterator; using iterator = const AttributeSet *;
iterator begin() const; iterator begin() const;
iterator end() const; iterator end() const;
@ -830,8 +831,8 @@ bool areInlineCompatible(const Function &Caller, const Function &Callee);
/// \brief Merge caller's and callee's attributes. /// \brief Merge caller's and callee's attributes.
void mergeAttributesForInlining(Function &Caller, const Function &Callee); void mergeAttributesForInlining(Function &Caller, const Function &Callee);
} // end AttributeFuncs namespace } // end namespace AttributeFuncs
} // end llvm namespace } // end namespace llvm
#endif // LLVM_IR_ATTRIBUTES_H #endif // LLVM_IR_ATTRIBUTES_H

View File

@ -1,4 +1,4 @@
//===-- llvm/BasicBlock.h - Represent a basic block in the VM ---*- C++ -*-===// //===- llvm/BasicBlock.h - Represent a basic block in the VM ----*- C++ -*-===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -18,13 +18,17 @@
#include "llvm/ADT/Twine.h" #include "llvm/ADT/Twine.h"
#include "llvm/ADT/ilist.h" #include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h" #include "llvm/ADT/ilist_node.h"
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/Instruction.h" #include "llvm/IR/Instruction.h"
#include "llvm/IR/SymbolTableListTraits.h" #include "llvm/IR/SymbolTableListTraits.h"
#include "llvm/IR/Value.h" #include "llvm/IR/Value.h"
#include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>
#include <iterator>
namespace llvm { namespace llvm {
@ -294,9 +298,9 @@ public:
return *this; return *this;
} }
}; };
typedef phi_iterator_impl<> phi_iterator; using phi_iterator = phi_iterator_impl<>;
typedef phi_iterator_impl<const PHINode, BasicBlock::const_iterator> using const_phi_iterator =
const_phi_iterator; phi_iterator_impl<const PHINode, BasicBlock::const_iterator>;
/// Returns a range that iterates over the phis in the basic block. /// Returns a range that iterates over the phis in the basic block.
/// ///

View File

@ -34,11 +34,14 @@
#include "llvm/ADT/APInt.h" #include "llvm/ADT/APInt.h"
#include "llvm/IR/InstrTypes.h" #include "llvm/IR/InstrTypes.h"
#include "llvm/Support/DataTypes.h" #include "llvm/IR/Instruction.h"
#include "llvm/Support/Compiler.h"
#include <cstdint>
namespace llvm { namespace llvm {
class MDNode; class MDNode;
class raw_ostream;
/// This class represents a range of values. /// This class represents a range of values.
class LLVM_NODISCARD ConstantRange { class LLVM_NODISCARD ConstantRange {
@ -330,6 +333,6 @@ inline raw_ostream &operator<<(raw_ostream &OS, const ConstantRange &CR) {
/// E.g. if RangeMD is !{i32 0, i32 10, i32 15, i32 20} then return [0, 20). /// E.g. if RangeMD is !{i32 0, i32 10, i32 15, i32 20} then return [0, 20).
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD); ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD);
} // End llvm namespace } // end namespace llvm
#endif #endif // LLVM_IR_CONSTANTRANGE_H

View File

@ -1,4 +1,4 @@
//===-- DerivedUser.h - Base for non-IR Users -------------------*- C++ -*-===// //===- DerivedUser.h - Base for non-IR Users --------------------*- C++ -*-===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -14,6 +14,9 @@
namespace llvm { namespace llvm {
class Type;
class Use;
/// Extension point for the Value hierarchy. All classes outside of lib/IR /// Extension point for the Value hierarchy. All classes outside of lib/IR
/// that wish to inherit from User should instead inherit from DerivedUser /// that wish to inherit from User should instead inherit from DerivedUser
/// instead. Inheriting from this class is discouraged. /// instead. Inheriting from this class is discouraged.
@ -24,10 +27,11 @@ namespace llvm {
/// its use/def list machinery. /// its use/def list machinery.
class DerivedUser : public User { class DerivedUser : public User {
protected: protected:
typedef void (*DeleteValueTy)(DerivedUser *); using DeleteValueTy = void (*)(DerivedUser *);
private: private:
friend Value; friend class Value;
DeleteValueTy DeleteValue; DeleteValueTy DeleteValue;
public: public:
@ -36,6 +40,6 @@ public:
: User(Ty, VK, U, NumOps), DeleteValue(DeleteValue) {} : User(Ty, VK, U, NumOps), DeleteValue(DeleteValue) {}
}; };
} // namespace llvm } // end namespace llvm
#endif // LLVM_IR_DERIVEDUSER_H #endif // LLVM_IR_DERIVEDUSER_H

View File

@ -45,6 +45,8 @@ namespace llvm {
class Module; class Module;
class ModuleSlotTracker; class ModuleSlotTracker;
class raw_ostream;
class Type;
enum LLVMConstants : uint32_t { enum LLVMConstants : uint32_t {
DEBUG_METADATA_VERSION = 3 // Current debug info version number. DEBUG_METADATA_VERSION = 3 // Current debug info version number.
@ -67,8 +69,8 @@ protected:
unsigned char Storage; unsigned char Storage;
// TODO: expose remaining bits to subclasses. // TODO: expose remaining bits to subclasses.
unsigned short SubclassData16; unsigned short SubclassData16 = 0;
unsigned SubclassData32; unsigned SubclassData32 = 0;
public: public:
enum MetadataKind { enum MetadataKind {
@ -78,7 +80,7 @@ public:
protected: protected:
Metadata(unsigned ID, StorageType Storage) Metadata(unsigned ID, StorageType Storage)
: SubclassID(ID), Storage(Storage), SubclassData16(0), SubclassData32(0) { : SubclassID(ID), Storage(Storage) {
static_assert(sizeof(*this) == 8, "Metadata fields poorly packed"); static_assert(sizeof(*this) == 8, "Metadata fields poorly packed");
} }
@ -183,6 +185,7 @@ public:
static MetadataAsValue *get(LLVMContext &Context, Metadata *MD); static MetadataAsValue *get(LLVMContext &Context, Metadata *MD);
static MetadataAsValue *getIfExists(LLVMContext &Context, Metadata *MD); static MetadataAsValue *getIfExists(LLVMContext &Context, Metadata *MD);
Metadata *getMetadata() const { return MD; } Metadata *getMetadata() const { return MD; }
static bool classof(const Value *V) { static bool classof(const Value *V) {
@ -257,7 +260,7 @@ public:
/// \brief Check whether metadata is replaceable. /// \brief Check whether metadata is replaceable.
static bool isReplaceable(const Metadata &MD); static bool isReplaceable(const Metadata &MD);
typedef PointerUnion<MetadataAsValue *, Metadata *> OwnerTy; using OwnerTy = PointerUnion<MetadataAsValue *, Metadata *>;
private: private:
/// \brief Track a reference to metadata for an owner. /// \brief Track a reference to metadata for an owner.
@ -275,7 +278,7 @@ class ReplaceableMetadataImpl {
friend class MetadataTracking; friend class MetadataTracking;
public: public:
typedef MetadataTracking::OwnerTy OwnerTy; using OwnerTy = MetadataTracking::OwnerTy;
private: private:
LLVMContext &Context; LLVMContext &Context;
@ -352,17 +355,21 @@ protected:
public: public:
static ValueAsMetadata *get(Value *V); static ValueAsMetadata *get(Value *V);
static ConstantAsMetadata *getConstant(Value *C) { static ConstantAsMetadata *getConstant(Value *C) {
return cast<ConstantAsMetadata>(get(C)); return cast<ConstantAsMetadata>(get(C));
} }
static LocalAsMetadata *getLocal(Value *Local) { static LocalAsMetadata *getLocal(Value *Local) {
return cast<LocalAsMetadata>(get(Local)); return cast<LocalAsMetadata>(get(Local));
} }
static ValueAsMetadata *getIfExists(Value *V); static ValueAsMetadata *getIfExists(Value *V);
static ConstantAsMetadata *getConstantIfExists(Value *C) { static ConstantAsMetadata *getConstantIfExists(Value *C) {
return cast_or_null<ConstantAsMetadata>(getIfExists(C)); return cast_or_null<ConstantAsMetadata>(getIfExists(C));
} }
static LocalAsMetadata *getLocalIfExists(Value *Local) { static LocalAsMetadata *getLocalIfExists(Value *Local) {
return cast_or_null<LocalAsMetadata>(getIfExists(Local)); return cast_or_null<LocalAsMetadata>(getIfExists(Local));
} }
@ -491,8 +498,8 @@ namespace detail {
template <class T> T &make(); template <class T> T &make();
template <class T, class Result> struct HasDereference { template <class T, class Result> struct HasDereference {
typedef char Yes[1]; using Yes = char[1];
typedef char No[2]; using No = char[2];
template <size_t N> struct SFINAE {}; template <size_t N> struct SFINAE {};
template <class U, class V> template <class U, class V>
@ -613,7 +620,7 @@ public:
unsigned getLength() const { return (unsigned)getString().size(); } unsigned getLength() const { return (unsigned)getString().size(); }
typedef StringRef::iterator iterator; using iterator = StringRef::iterator;
/// \brief Pointer to the first byte of the string. /// \brief Pointer to the first byte of the string.
iterator begin() const { return getString().begin(); } iterator begin() const { return getString().begin(); }
@ -730,12 +737,14 @@ private:
}; };
template <> struct simplify_type<MDOperand> { template <> struct simplify_type<MDOperand> {
typedef Metadata *SimpleType; using SimpleType = Metadata *;
static SimpleType getSimplifiedValue(MDOperand &MD) { return MD.get(); } static SimpleType getSimplifiedValue(MDOperand &MD) { return MD.get(); }
}; };
template <> struct simplify_type<const MDOperand> { template <> struct simplify_type<const MDOperand> {
typedef Metadata *SimpleType; using SimpleType = Metadata *;
static SimpleType getSimplifiedValue(const MDOperand &MD) { return MD.get(); } static SimpleType getSimplifiedValue(const MDOperand &MD) { return MD.get(); }
}; };
@ -817,7 +826,7 @@ struct TempMDNodeDeleter {
}; };
#define HANDLE_MDNODE_LEAF(CLASS) \ #define HANDLE_MDNODE_LEAF(CLASS) \
typedef std::unique_ptr<CLASS, TempMDNodeDeleter> Temp##CLASS; using Temp##CLASS = std::unique_ptr<CLASS, TempMDNodeDeleter>;
#define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS) #define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS)
#include "llvm/IR/Metadata.def" #include "llvm/IR/Metadata.def"
@ -847,6 +856,10 @@ class MDNode : public Metadata {
ContextAndReplaceableUses Context; ContextAndReplaceableUses Context;
protected: protected:
MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None);
~MDNode() = default;
void *operator new(size_t Size, unsigned NumOps); void *operator new(size_t Size, unsigned NumOps);
void operator delete(void *Mem); void operator delete(void *Mem);
@ -860,16 +873,13 @@ protected:
llvm_unreachable("Constructor throws?"); llvm_unreachable("Constructor throws?");
} }
MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None);
~MDNode() = default;
void dropAllReferences(); void dropAllReferences();
MDOperand *mutable_begin() { return mutable_end() - NumOperands; } MDOperand *mutable_begin() { return mutable_end() - NumOperands; }
MDOperand *mutable_end() { return reinterpret_cast<MDOperand *>(this); } MDOperand *mutable_end() { return reinterpret_cast<MDOperand *>(this); }
typedef iterator_range<MDOperand *> mutable_op_range; using mutable_op_range = iterator_range<MDOperand *>;
mutable_op_range mutable_operands() { mutable_op_range mutable_operands() {
return mutable_op_range(mutable_begin(), mutable_end()); return mutable_op_range(mutable_begin(), mutable_end());
} }
@ -1028,8 +1038,8 @@ private:
static void dispatchResetHash(NodeTy *, std::false_type) {} static void dispatchResetHash(NodeTy *, std::false_type) {}
public: public:
typedef const MDOperand *op_iterator; using op_iterator = const MDOperand *;
typedef iterator_range<op_iterator> op_range; using op_range = iterator_range<op_iterator>;
op_iterator op_begin() const { op_iterator op_begin() const {
return const_cast<MDNode *>(this)->mutable_begin(); return const_cast<MDNode *>(this)->mutable_begin();
@ -1227,13 +1237,14 @@ public:
T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); } T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); }
// FIXME: Fix callers and remove condition on N. // FIXME: Fix callers and remove condition on N.
typedef TypedMDOperandIterator<T> iterator; using iterator = TypedMDOperandIterator<T>;
iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); } iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
iterator end() const { return N ? iterator(N->op_end()) : iterator(); } iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
}; };
#define HANDLE_METADATA(CLASS) \ #define HANDLE_METADATA(CLASS) \
typedef MDTupleTypedArrayWrapper<CLASS> CLASS##Array; using CLASS##Array = MDTupleTypedArrayWrapper<CLASS>;
#include "llvm/IR/Metadata.def" #include "llvm/IR/Metadata.def"
/// Placeholder metadata for operands of distinct MDNodes. /// Placeholder metadata for operands of distinct MDNodes.
@ -1304,13 +1315,13 @@ class NamedMDNode : public ilist_node<NamedMDNode> {
template<class T1, class T2> template<class T1, class T2>
class op_iterator_impl : class op_iterator_impl :
public std::iterator<std::bidirectional_iterator_tag, T2> { public std::iterator<std::bidirectional_iterator_tag, T2> {
friend class NamedMDNode;
const NamedMDNode *Node = nullptr; const NamedMDNode *Node = nullptr;
unsigned Idx = 0; unsigned Idx = 0;
op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {} op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {}
friend class NamedMDNode;
public: public:
op_iterator_impl() = default; op_iterator_impl() = default;
@ -1371,11 +1382,13 @@ public:
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Operand Iterator interface... // Operand Iterator interface...
// //
typedef op_iterator_impl<MDNode *, MDNode> op_iterator; using op_iterator = op_iterator_impl<MDNode *, MDNode>;
op_iterator op_begin() { return op_iterator(this, 0); } op_iterator op_begin() { return op_iterator(this, 0); }
op_iterator op_end() { return op_iterator(this, getNumOperands()); } op_iterator op_end() { return op_iterator(this, getNumOperands()); }
typedef op_iterator_impl<const MDNode *, MDNode> const_op_iterator; using const_op_iterator = op_iterator_impl<const MDNode *, MDNode>;
const_op_iterator op_begin() const { return const_op_iterator(this, 0); } const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
const_op_iterator op_end() const { return const_op_iterator(this, getNumOperands()); } const_op_iterator op_end() const { return const_op_iterator(this, getNumOperands()); }

View File

@ -49,6 +49,7 @@ template<typename ValueTy> class StringMapEntry;
class StringRef; class StringRef;
class Twine; class Twine;
class Type; class Type;
class User;
using ValueName = StringMapEntry<Value *>; using ValueName = StringMapEntry<Value *>;
@ -212,7 +213,7 @@ protected:
public: public:
Value(const Value &) = delete; Value(const Value &) = delete;
void operator=(const Value &) = delete; Value &operator=(const Value &) = delete;
/// Delete a pointer to a generic Value. /// Delete a pointer to a generic Value.
void deleteValue(); void deleteValue();
@ -660,7 +661,7 @@ struct ValueDeleter { void operator()(Value *V) { V->deleteValue(); } };
/// Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>. /// Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
/// Those don't work because Value and Instruction's destructors are protected, /// Those don't work because Value and Instruction's destructors are protected,
/// aren't virtual, and won't destroy the complete object. /// aren't virtual, and won't destroy the complete object.
typedef std::unique_ptr<Value, ValueDeleter> unique_value; using unique_value = std::unique_ptr<Value, ValueDeleter>;
inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) { inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
V.print(OS); V.print(OS);

View File

@ -1,5 +1,4 @@
//===- AsmWriter.cpp - Printing LLVM as an assembly file ------------------===//
//===-- AsmWriter.cpp - Printing LLVM as an assembly file -----------------===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -15,63 +14,105 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/AssemblyAnnotationWriter.h" #include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/Attributes.h" #include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h" #include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h" #include "llvm/IR/CallingConv.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h" #include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h" #include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalIFunc.h"
#include "llvm/IR/GlobalIndirectSymbol.h"
#include "llvm/IR/GlobalObject.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/InlineAsm.h" #include "llvm/IR/InlineAsm.h"
#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h" #include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/IR/Operator.h" #include "llvm/IR/Operator.h"
#include "llvm/IR/Statepoint.h" #include "llvm/IR/Statepoint.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/TypeFinder.h" #include "llvm/IR/TypeFinder.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/UseListOrder.h" #include "llvm/IR/UseListOrder.h"
#include "llvm/IR/ValueSymbolTable.h" #include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h" #include "llvm/Support/Format.h"
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
#include <cassert>
#include <cctype> #include <cctype>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace llvm; using namespace llvm;
// Make virtual table appear in this compilation unit. // Make virtual table appear in this compilation unit.
AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {} AssemblyAnnotationWriter::~AssemblyAnnotationWriter() = default;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Helper Functions // Helper Functions
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
namespace { namespace {
struct OrderMap { struct OrderMap {
DenseMap<const Value *, std::pair<unsigned, bool>> IDs; DenseMap<const Value *, std::pair<unsigned, bool>> IDs;
unsigned size() const { return IDs.size(); } unsigned size() const { return IDs.size(); }
std::pair<unsigned, bool> &operator[](const Value *V) { return IDs[V]; } std::pair<unsigned, bool> &operator[](const Value *V) { return IDs[V]; }
std::pair<unsigned, bool> lookup(const Value *V) const { std::pair<unsigned, bool> lookup(const Value *V) const {
return IDs.lookup(V); return IDs.lookup(V);
} }
void index(const Value *V) { void index(const Value *V) {
// Explicitly sequence get-size and insert-value operations to avoid UB. // Explicitly sequence get-size and insert-value operations to avoid UB.
unsigned ID = IDs.size() + 1; unsigned ID = IDs.size() + 1;
IDs[V].first = ID; IDs[V].first = ID;
} }
}; };
}
} // end anonymous namespace
static void orderValue(const Value *V, OrderMap &OM) { static void orderValue(const Value *V, OrderMap &OM) {
if (OM.lookup(V).first) if (OM.lookup(V).first)
@ -139,7 +180,7 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F,
unsigned ID, const OrderMap &OM, unsigned ID, const OrderMap &OM,
UseListOrderStack &Stack) { UseListOrderStack &Stack) {
// Predict use-list order for this one. // Predict use-list order for this one.
typedef std::pair<const Use *, unsigned> Entry; using Entry = std::pair<const Use *, unsigned>;
SmallVector<Entry, 64> List; SmallVector<Entry, 64> List;
for (const Use &U : V->uses()) for (const Use &U : V->uses())
// Check if this user will be serialized. // Check if this user will be serialized.
@ -421,13 +462,10 @@ static void PrintLLVMName(raw_ostream &OS, const Value *V) {
isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix); isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix);
} }
namespace { namespace {
class TypePrinting {
TypePrinting(const TypePrinting &) = delete;
void operator=(const TypePrinting&) = delete;
public:
class TypePrinting {
public:
/// NamedTypes - The named types that are used by the current module. /// NamedTypes - The named types that are used by the current module.
TypeFinder NamedTypes; TypeFinder NamedTypes;
@ -435,6 +473,8 @@ public:
DenseMap<StructType*, unsigned> NumberedTypes; DenseMap<StructType*, unsigned> NumberedTypes;
TypePrinting() = default; TypePrinting() = default;
TypePrinting(const TypePrinting &) = delete;
TypePrinting &operator=(const TypePrinting &) = delete;
void incorporateTypes(const Module &M); void incorporateTypes(const Module &M);
@ -442,7 +482,8 @@ public:
void printStructBody(StructType *Ty, raw_ostream &OS); void printStructBody(StructType *Ty, raw_ostream &OS);
}; };
} // namespace
} // end anonymous namespace
void TypePrinting::incorporateTypes(const Module &M) { void TypePrinting::incorporateTypes(const Module &M) {
NamedTypes.run(M, false); NamedTypes.run(M, false);
@ -574,6 +615,7 @@ void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
} }
namespace llvm { namespace llvm {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// SlotTracker Class: Enumerate slot numbers for unnamed values // SlotTracker Class: Enumerate slot numbers for unnamed values
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -582,32 +624,33 @@ namespace llvm {
class SlotTracker { class SlotTracker {
public: public:
/// ValueMap - A mapping of Values to slot numbers. /// ValueMap - A mapping of Values to slot numbers.
typedef DenseMap<const Value*, unsigned> ValueMap; using ValueMap = DenseMap<const Value *, unsigned>;
private: private:
/// TheModule - The module for which we are holding slot numbers. /// TheModule - The module for which we are holding slot numbers.
const Module* TheModule; const Module* TheModule;
/// TheFunction - The function for which we are holding slot numbers. /// TheFunction - The function for which we are holding slot numbers.
const Function* TheFunction; const Function* TheFunction = nullptr;
bool FunctionProcessed; bool FunctionProcessed = false;
bool ShouldInitializeAllMetadata; bool ShouldInitializeAllMetadata;
/// mMap - The slot map for the module level data. /// mMap - The slot map for the module level data.
ValueMap mMap; ValueMap mMap;
unsigned mNext; unsigned mNext = 0;
/// fMap - The slot map for the function level data. /// fMap - The slot map for the function level data.
ValueMap fMap; ValueMap fMap;
unsigned fNext; unsigned fNext = 0;
/// mdnMap - Map for MDNodes. /// mdnMap - Map for MDNodes.
DenseMap<const MDNode*, unsigned> mdnMap; DenseMap<const MDNode*, unsigned> mdnMap;
unsigned mdnNext; unsigned mdnNext = 0;
/// asMap - The slot map for attribute sets. /// asMap - The slot map for attribute sets.
DenseMap<AttributeSet, unsigned> asMap; DenseMap<AttributeSet, unsigned> asMap;
unsigned asNext; unsigned asNext = 0;
public: public:
/// Construct from a module. /// Construct from a module.
/// ///
@ -616,6 +659,7 @@ public:
/// within a function (even if no functions have been initialized). /// within a function (even if no functions have been initialized).
explicit SlotTracker(const Module *M, explicit SlotTracker(const Module *M,
bool ShouldInitializeAllMetadata = false); bool ShouldInitializeAllMetadata = false);
/// Construct from a function, starting out in incorp state. /// Construct from a function, starting out in incorp state.
/// ///
/// If \c ShouldInitializeAllMetadata, initializes all metadata in all /// If \c ShouldInitializeAllMetadata, initializes all metadata in all
@ -624,6 +668,9 @@ public:
explicit SlotTracker(const Function *F, explicit SlotTracker(const Function *F,
bool ShouldInitializeAllMetadata = false); bool ShouldInitializeAllMetadata = false);
SlotTracker(const SlotTracker &) = delete;
SlotTracker &operator=(const SlotTracker &) = delete;
/// Return the slot number of the specified value in it's type /// Return the slot number of the specified value in it's type
/// plane. If something is not in the SlotTracker, return -1. /// plane. If something is not in the SlotTracker, return -1.
int getLocalSlot(const Value *V); int getLocalSlot(const Value *V);
@ -646,14 +693,16 @@ public:
void purgeFunction(); void purgeFunction();
/// MDNode map iterators. /// MDNode map iterators.
typedef DenseMap<const MDNode*, unsigned>::iterator mdn_iterator; using mdn_iterator = DenseMap<const MDNode*, unsigned>::iterator;
mdn_iterator mdn_begin() { return mdnMap.begin(); } mdn_iterator mdn_begin() { return mdnMap.begin(); }
mdn_iterator mdn_end() { return mdnMap.end(); } mdn_iterator mdn_end() { return mdnMap.end(); }
unsigned mdn_size() const { return mdnMap.size(); } unsigned mdn_size() const { return mdnMap.size(); }
bool mdn_empty() const { return mdnMap.empty(); } bool mdn_empty() const { return mdnMap.empty(); }
/// AttributeSet map iterators. /// AttributeSet map iterators.
typedef DenseMap<AttributeSet, unsigned>::iterator as_iterator; using as_iterator = DenseMap<AttributeSet, unsigned>::iterator;
as_iterator as_begin() { return asMap.begin(); } as_iterator as_begin() { return asMap.begin(); }
as_iterator as_end() { return asMap.end(); } as_iterator as_end() { return asMap.end(); }
unsigned as_size() const { return asMap.size(); } unsigned as_size() const { return asMap.size(); }
@ -691,11 +740,9 @@ private:
/// Add all of the metadata from an instruction. /// Add all of the metadata from an instruction.
void processInstructionMetadata(const Instruction &I); void processInstructionMetadata(const Instruction &I);
SlotTracker(const SlotTracker &) = delete;
void operator=(const SlotTracker &) = delete;
}; };
} // namespace llvm
} // end namespace llvm
ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M, ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M,
const Function *F) const Function *F)
@ -706,7 +753,7 @@ ModuleSlotTracker::ModuleSlotTracker(const Module *M,
: ShouldCreateStorage(M), : ShouldCreateStorage(M),
ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {} ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
ModuleSlotTracker::~ModuleSlotTracker() {} ModuleSlotTracker::~ModuleSlotTracker() = default;
SlotTracker *ModuleSlotTracker::getMachine() { SlotTracker *ModuleSlotTracker::getMachine() {
if (!ShouldCreateStorage) if (!ShouldCreateStorage)
@ -773,17 +820,13 @@ static SlotTracker *createSlotTracker(const Value *V) {
// Module level constructor. Causes the contents of the Module (sans functions) // Module level constructor. Causes the contents of the Module (sans functions)
// to be added to the slot table. // to be added to the slot table.
SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata) SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata)
: TheModule(M), TheFunction(nullptr), FunctionProcessed(false), : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), mNext(0),
fNext(0), mdnNext(0), asNext(0) {}
// Function level constructor. Causes the contents of the Module and the one // Function level constructor. Causes the contents of the Module and the one
// function provided to be added to the slot table. // function provided to be added to the slot table.
SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata) SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata)
: TheModule(F ? F->getParent() : nullptr), TheFunction(F), : TheModule(F ? F->getParent() : nullptr), TheFunction(F),
FunctionProcessed(false), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), mNext(0),
fNext(0), mdnNext(0), asNext(0) {}
inline void SlotTracker::initialize() { inline void SlotTracker::initialize() {
if (TheModule) { if (TheModule) {
@ -949,7 +992,6 @@ int SlotTracker::getMetadataSlot(const MDNode *N) {
return MI == mdnMap.end() ? -1 : (int)MI->second; return MI == mdnMap.end() ? -1 : (int)MI->second;
} }
/// getLocalSlot - Get the slot number for a value that is local to a function. /// getLocalSlot - Get the slot number for a value that is local to a function.
int SlotTracker::getLocalSlot(const Value *V) { int SlotTracker::getLocalSlot(const Value *V) {
assert(!isa<Constant>(V) && "Can't get a constant or global slot with this!"); assert(!isa<Constant>(V) && "Can't get a constant or global slot with this!");
@ -1248,7 +1290,6 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
return; return;
} }
if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) { if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) {
if (CS->getType()->isPacked()) if (CS->getType()->isPacked())
Out << '<'; Out << '<';
@ -1381,11 +1422,14 @@ static void writeMDTuple(raw_ostream &Out, const MDTuple *Node,
} }
namespace { namespace {
struct FieldSeparator { struct FieldSeparator {
bool Skip; bool Skip = true;
const char *Sep; const char *Sep;
FieldSeparator(const char *Sep = ", ") : Skip(true), Sep(Sep) {}
FieldSeparator(const char *Sep = ", ") : Sep(Sep) {}
}; };
raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) { raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) {
if (FS.Skip) { if (FS.Skip) {
FS.Skip = false; FS.Skip = false;
@ -1393,19 +1437,20 @@ raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) {
} }
return OS << FS.Sep; return OS << FS.Sep;
} }
struct MDFieldPrinter { struct MDFieldPrinter {
raw_ostream &Out; raw_ostream &Out;
FieldSeparator FS; FieldSeparator FS;
TypePrinting *TypePrinter; TypePrinting *TypePrinter = nullptr;
SlotTracker *Machine; SlotTracker *Machine = nullptr;
const Module *Context; const Module *Context = nullptr;
explicit MDFieldPrinter(raw_ostream &Out) explicit MDFieldPrinter(raw_ostream &Out) : Out(Out) {}
: Out(Out), TypePrinter(nullptr), Machine(nullptr), Context(nullptr) {}
MDFieldPrinter(raw_ostream &Out, TypePrinting *TypePrinter, MDFieldPrinter(raw_ostream &Out, TypePrinting *TypePrinter,
SlotTracker *Machine, const Module *Context) SlotTracker *Machine, const Module *Context)
: Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) { : Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) {
} }
void printTag(const DINode *N); void printTag(const DINode *N);
void printMacinfoType(const DIMacroNode *N); void printMacinfoType(const DIMacroNode *N);
void printChecksumKind(const DIFile *N); void printChecksumKind(const DIFile *N);
@ -1422,7 +1467,8 @@ struct MDFieldPrinter {
bool ShouldSkipZero = true); bool ShouldSkipZero = true);
void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK); void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK);
}; };
} // end namespace
} // end anonymous namespace
void MDFieldPrinter::printTag(const DINode *N) { void MDFieldPrinter::printTag(const DINode *N) {
Out << FS << "tag: "; Out << FS << "tag: ";
@ -1518,7 +1564,6 @@ void MDFieldPrinter::printEmissionKind(StringRef Name,
Out << FS << Name << ": " << DICompileUnit::EmissionKindString(EK); Out << FS << Name << ": " << DICompileUnit::EmissionKindString(EK);
} }
template <class IntTy, class Stringifier> template <class IntTy, class Stringifier>
void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value, void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value,
Stringifier toString, bool ShouldSkipZero) { Stringifier toString, bool ShouldSkipZero) {
@ -1923,7 +1968,6 @@ static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N,
Out << ")"; Out << ")";
} }
static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
TypePrinting *TypePrinter, TypePrinting *TypePrinter,
SlotTracker *Machine, SlotTracker *Machine,
@ -2062,6 +2106,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD,
} }
namespace { namespace {
class AssemblyWriter { class AssemblyWriter {
formatted_raw_ostream &Out; formatted_raw_ostream &Out;
const Module *TheModule; const Module *TheModule;
@ -2125,7 +2170,8 @@ private:
// intrinsic indicating base and derived pointer names. // intrinsic indicating base and derived pointer names.
void printGCRelocateComment(const GCRelocateInst &Relocate); void printGCRelocateComment(const GCRelocateInst &Relocate);
}; };
} // namespace
} // end anonymous namespace
AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac, AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const Module *M, AssemblyAnnotationWriter *AAW, const Module *M, AssemblyAnnotationWriter *AAW,
@ -2594,7 +2640,6 @@ void AssemblyWriter::printTypeIdentities() {
} }
/// printFunction - Print all aspects of a function. /// printFunction - Print all aspects of a function.
///
void AssemblyWriter::printFunction(const Function *F) { void AssemblyWriter::printFunction(const Function *F) {
// Print out the return type and name. // Print out the return type and name.
Out << '\n'; Out << '\n';
@ -2730,7 +2775,6 @@ void AssemblyWriter::printFunction(const Function *F) {
/// printArgument - This member is called for every argument that is passed into /// printArgument - This member is called for every argument that is passed into
/// the function. Simply print it out /// the function. Simply print it out
///
void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) { void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) {
// Output type... // Output type...
TypePrinter.print(Arg->getType(), Out); TypePrinter.print(Arg->getType(), Out);
@ -2747,7 +2791,6 @@ void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) {
} }
/// printBasicBlock - This member is called for each basic block in a method. /// printBasicBlock - This member is called for each basic block in a method.
///
void AssemblyWriter::printBasicBlock(const BasicBlock *BB) { void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
if (BB->hasName()) { // Print out the label if it exists... if (BB->hasName()) { // Print out the label if it exists...
Out << "\n"; Out << "\n";
@ -2813,7 +2856,6 @@ void AssemblyWriter::printGCRelocateComment(const GCRelocateInst &Relocate) {
/// printInfoComment - Print a little comment after the instruction indicating /// printInfoComment - Print a little comment after the instruction indicating
/// which slot it occupies. /// which slot it occupies.
///
void AssemblyWriter::printInfoComment(const Value &V) { void AssemblyWriter::printInfoComment(const Value &V) {
if (const auto *Relocate = dyn_cast<GCRelocateInst>(&V)) if (const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
printGCRelocateComment(*Relocate); printGCRelocateComment(*Relocate);
@ -3046,7 +3088,6 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes()); Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
writeOperandBundles(CI); writeOperandBundles(CI);
} else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) { } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
Operand = II->getCalledValue(); Operand = II->getCalledValue();
FunctionType *FTy = II->getFunctionType(); FunctionType *FTy = II->getFunctionType();
@ -3087,7 +3128,6 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
writeOperand(II->getNormalDest(), true); writeOperand(II->getNormalDest(), true);
Out << " unwind "; Out << " unwind ";
writeOperand(II->getUnwindDest(), true); writeOperand(II->getUnwindDest(), true);
} else if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) { } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
Out << ' '; Out << ' ';
if (AI->isUsedWithInAlloca()) if (AI->isUsedWithInAlloca())
@ -3113,7 +3153,6 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
if (AddrSpace != 0) { if (AddrSpace != 0) {
Out << ", addrspace(" << AddrSpace << ')'; Out << ", addrspace(" << AddrSpace << ')';
} }
} else if (isa<CastInst>(I)) { } else if (isa<CastInst>(I)) {
if (Operand) { if (Operand) {
Out << ' '; Out << ' ';

View File

@ -100,6 +100,7 @@ public:
class EnumAttributeImpl : public AttributeImpl { class EnumAttributeImpl : public AttributeImpl {
virtual void anchor(); virtual void anchor();
Attribute::AttrKind Kind; Attribute::AttrKind Kind;
protected: protected:
@ -133,6 +134,7 @@ public:
class StringAttributeImpl : public AttributeImpl { class StringAttributeImpl : public AttributeImpl {
virtual void anchor(); virtual void anchor();
std::string Kind; std::string Kind;
std::string Val; std::string Val;
@ -243,7 +245,8 @@ public:
return AvailableFunctionAttrs & ((uint64_t)1) << Kind; return AvailableFunctionAttrs & ((uint64_t)1) << Kind;
} }
typedef const AttributeSet *iterator; using iterator = const AttributeSet *;
iterator begin() const { return getTrailingObjects<AttributeSet>(); } iterator begin() const { return getTrailingObjects<AttributeSet>(); }
iterator end() const { return begin() + NumAttrSets; } iterator end() const { return begin() + NumAttrSets; }

View File

@ -1,4 +1,4 @@
//===-- ConstantRange.cpp - ConstantRange implementation ------------------===// //===- ConstantRange.cpp - ConstantRange implementation -------------------===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -21,12 +21,21 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/ADT/APInt.h"
#include "llvm/IR/ConstantRange.h" #include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/InstrTypes.h" #include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h" #include "llvm/IR/Instruction.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Operator.h" #include "llvm/IR/Operator.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
using namespace llvm; using namespace llvm;
ConstantRange::ConstantRange(uint32_t BitWidth, bool Full) ConstantRange::ConstantRange(uint32_t BitWidth, bool Full)
@ -170,7 +179,7 @@ ConstantRange
ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
const ConstantRange &Other, const ConstantRange &Other,
unsigned NoWrapKind) { unsigned NoWrapKind) {
typedef OverflowingBinaryOperator OBO; using OBO = OverflowingBinaryOperator;
// Computes the intersection of CR0 and CR1. It is different from // Computes the intersection of CR0 and CR1. It is different from
// intersectWith in that the ConstantRange returned will only contain elements // intersectWith in that the ConstantRange returned will only contain elements

View File

@ -1,4 +1,4 @@
//===-- LLVMContextImpl.cpp - Implement LLVMContextImpl -------------------===// //===- LLVMContextImpl.cpp - Implement LLVMContextImpl --------------------===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -12,18 +12,17 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "LLVMContextImpl.h" #include "LLVMContextImpl.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/OptBisect.h" #include "llvm/IR/OptBisect.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include <algorithm> #include <cassert>
#include <utility>
using namespace llvm; using namespace llvm;
LLVMContextImpl::LLVMContextImpl(LLVMContext &C) LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
: TheTrueVal(nullptr), TheFalseVal(nullptr), : VoidTy(C, Type::VoidTyID),
VoidTy(C, Type::VoidTyID),
LabelTy(C, Type::LabelTyID), LabelTy(C, Type::LabelTyID),
HalfTy(C, Type::HalfTyID), HalfTy(C, Type::HalfTyID),
FloatTy(C, Type::FloatTyID), FloatTy(C, Type::FloatTyID),
@ -39,17 +38,7 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
Int16Ty(C, 16), Int16Ty(C, 16),
Int32Ty(C, 32), Int32Ty(C, 32),
Int64Ty(C, 64), Int64Ty(C, 64),
Int128Ty(C, 128) { Int128Ty(C, 128) {}
InlineAsmDiagHandler = nullptr;
InlineAsmDiagContext = nullptr;
DiagnosticHandler = nullptr;
DiagnosticContext = nullptr;
RespectDiagnosticFilters = false;
DiagnosticHotnessRequested = false;
YieldCallback = nullptr;
YieldOpaqueHandle = nullptr;
NamedStructTypesUniqueID = 0;
}
LLVMContextImpl::~LLVMContextImpl() { LLVMContextImpl::~LLVMContextImpl() {
// NOTE: We need to delete the contents of OwnedModules, but Module's dtor // NOTE: We need to delete the contents of OwnedModules, but Module's dtor
@ -156,7 +145,6 @@ void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
C->destroyConstant(); C->destroyConstant();
} }
} }
} while (Changed); } while (Changed);
} }
@ -165,6 +153,7 @@ void Module::dropTriviallyDeadConstantArrays() {
} }
namespace llvm { namespace llvm {
/// \brief Make MDOperand transparent for hashing. /// \brief Make MDOperand transparent for hashing.
/// ///
/// This overload of an implementation detail of the hashing library makes /// This overload of an implementation detail of the hashing library makes
@ -179,7 +168,8 @@ namespace llvm {
/// does not cause MDOperand to be transparent. In particular, a bare pointer /// does not cause MDOperand to be transparent. In particular, a bare pointer
/// doesn't get hashed before it's combined, whereas \a MDOperand would. /// doesn't get hashed before it's combined, whereas \a MDOperand would.
static const Metadata *get_hashable_data(const MDOperand &X) { return X.get(); } static const Metadata *get_hashable_data(const MDOperand &X) { return X.get(); }
}
} // end namespace llvm
unsigned MDNodeOpsKey::calculateHash(MDNode *N, unsigned Offset) { unsigned MDNodeOpsKey::calculateHash(MDNode *N, unsigned Offset) {
unsigned Hash = hash_combine_range(N->op_begin() + Offset, N->op_end()); unsigned Hash = hash_combine_range(N->op_begin() + Offset, N->op_end());

View File

@ -1,4 +1,4 @@
//===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===// //===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -21,11 +21,16 @@
#include "llvm/ADT/APInt.h" #include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/Hashing.h" #include "llvm/ADT/Hashing.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSet.h"
#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/Constants.h" #include "llvm/IR/Constants.h"
@ -33,21 +38,26 @@
#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h" #include "llvm/IR/Metadata.h"
#include "llvm/IR/ValueHandle.h" #include "llvm/IR/TrackingMDRef.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/YAMLTraits.h" #include "llvm/Support/YAMLTraits.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector> #include <vector>
namespace llvm { namespace llvm {
class ConstantInt;
class ConstantFP; class ConstantFP;
class DiagnosticInfoOptimizationRemark; class ConstantInt;
class DiagnosticInfoOptimizationRemarkMissed;
class DiagnosticInfoOptimizationRemarkAnalysis;
class GCStrategy;
class LLVMContext;
class Type; class Type;
class Value; class Value;
class ValueHandleBase;
struct DenseMapAPIntKeyInfo { struct DenseMapAPIntKeyInfo {
static inline APInt getEmptyKey() { static inline APInt getEmptyKey() {
@ -55,14 +65,17 @@ struct DenseMapAPIntKeyInfo {
V.U.VAL = 0; V.U.VAL = 0;
return V; return V;
} }
static inline APInt getTombstoneKey() { static inline APInt getTombstoneKey() {
APInt V(nullptr, 0); APInt V(nullptr, 0);
V.U.VAL = 1; V.U.VAL = 1;
return V; return V;
} }
static unsigned getHashValue(const APInt &Key) { static unsigned getHashValue(const APInt &Key) {
return static_cast<unsigned>(hash_value(Key)); return static_cast<unsigned>(hash_value(Key));
} }
static bool isEqual(const APInt &LHS, const APInt &RHS) { static bool isEqual(const APInt &LHS, const APInt &RHS) {
return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS; return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
} }
@ -71,9 +84,11 @@ struct DenseMapAPIntKeyInfo {
struct DenseMapAPFloatKeyInfo { struct DenseMapAPFloatKeyInfo {
static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); } static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); } static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
static unsigned getHashValue(const APFloat &Key) { static unsigned getHashValue(const APFloat &Key) {
return static_cast<unsigned>(hash_value(Key)); return static_cast<unsigned>(hash_value(Key));
} }
static bool isEqual(const APFloat &LHS, const APFloat &RHS) { static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
return LHS.bitwiseIsEqual(RHS); return LHS.bitwiseIsEqual(RHS);
} }
@ -83,10 +98,13 @@ struct AnonStructTypeKeyInfo {
struct KeyTy { struct KeyTy {
ArrayRef<Type*> ETypes; ArrayRef<Type*> ETypes;
bool isPacked; bool isPacked;
KeyTy(const ArrayRef<Type*>& E, bool P) : KeyTy(const ArrayRef<Type*>& E, bool P) :
ETypes(E), isPacked(P) {} ETypes(E), isPacked(P) {}
KeyTy(const StructType *ST) KeyTy(const StructType *ST)
: ETypes(ST->elements()), isPacked(ST->isPacked()) {} : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
bool operator==(const KeyTy& that) const { bool operator==(const KeyTy& that) const {
if (isPacked != that.isPacked) if (isPacked != that.isPacked)
return false; return false;
@ -98,25 +116,31 @@ struct AnonStructTypeKeyInfo {
return !this->operator==(that); return !this->operator==(that);
} }
}; };
static inline StructType* getEmptyKey() { static inline StructType* getEmptyKey() {
return DenseMapInfo<StructType*>::getEmptyKey(); return DenseMapInfo<StructType*>::getEmptyKey();
} }
static inline StructType* getTombstoneKey() { static inline StructType* getTombstoneKey() {
return DenseMapInfo<StructType*>::getTombstoneKey(); return DenseMapInfo<StructType*>::getTombstoneKey();
} }
static unsigned getHashValue(const KeyTy& Key) { static unsigned getHashValue(const KeyTy& Key) {
return hash_combine(hash_combine_range(Key.ETypes.begin(), return hash_combine(hash_combine_range(Key.ETypes.begin(),
Key.ETypes.end()), Key.ETypes.end()),
Key.isPacked); Key.isPacked);
} }
static unsigned getHashValue(const StructType *ST) { static unsigned getHashValue(const StructType *ST) {
return getHashValue(KeyTy(ST)); return getHashValue(KeyTy(ST));
} }
static bool isEqual(const KeyTy& LHS, const StructType *RHS) { static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
if (RHS == getEmptyKey() || RHS == getTombstoneKey()) if (RHS == getEmptyKey() || RHS == getTombstoneKey())
return false; return false;
return LHS == KeyTy(RHS); return LHS == KeyTy(RHS);
} }
static bool isEqual(const StructType *LHS, const StructType *RHS) { static bool isEqual(const StructType *LHS, const StructType *RHS) {
return LHS == RHS; return LHS == RHS;
} }
@ -127,11 +151,13 @@ struct FunctionTypeKeyInfo {
const Type *ReturnType; const Type *ReturnType;
ArrayRef<Type*> Params; ArrayRef<Type*> Params;
bool isVarArg; bool isVarArg;
KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) : KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
ReturnType(R), Params(P), isVarArg(V) {} ReturnType(R), Params(P), isVarArg(V) {}
KeyTy(const FunctionType *FT) KeyTy(const FunctionType *FT)
: ReturnType(FT->getReturnType()), Params(FT->params()), : ReturnType(FT->getReturnType()), Params(FT->params()),
isVarArg(FT->isVarArg()) {} isVarArg(FT->isVarArg()) {}
bool operator==(const KeyTy& that) const { bool operator==(const KeyTy& that) const {
if (ReturnType != that.ReturnType) if (ReturnType != that.ReturnType)
return false; return false;
@ -145,26 +171,32 @@ struct FunctionTypeKeyInfo {
return !this->operator==(that); return !this->operator==(that);
} }
}; };
static inline FunctionType* getEmptyKey() { static inline FunctionType* getEmptyKey() {
return DenseMapInfo<FunctionType*>::getEmptyKey(); return DenseMapInfo<FunctionType*>::getEmptyKey();
} }
static inline FunctionType* getTombstoneKey() { static inline FunctionType* getTombstoneKey() {
return DenseMapInfo<FunctionType*>::getTombstoneKey(); return DenseMapInfo<FunctionType*>::getTombstoneKey();
} }
static unsigned getHashValue(const KeyTy& Key) { static unsigned getHashValue(const KeyTy& Key) {
return hash_combine(Key.ReturnType, return hash_combine(Key.ReturnType,
hash_combine_range(Key.Params.begin(), hash_combine_range(Key.Params.begin(),
Key.Params.end()), Key.Params.end()),
Key.isVarArg); Key.isVarArg);
} }
static unsigned getHashValue(const FunctionType *FT) { static unsigned getHashValue(const FunctionType *FT) {
return getHashValue(KeyTy(FT)); return getHashValue(KeyTy(FT));
} }
static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) { static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
if (RHS == getEmptyKey() || RHS == getTombstoneKey()) if (RHS == getEmptyKey() || RHS == getTombstoneKey())
return false; return false;
return LHS == KeyTy(RHS); return LHS == KeyTy(RHS);
} }
static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) { static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
return LHS == RHS; return LHS == RHS;
} }
@ -174,7 +206,6 @@ struct FunctionTypeKeyInfo {
class MDNodeOpsKey { class MDNodeOpsKey {
ArrayRef<Metadata *> RawOps; ArrayRef<Metadata *> RawOps;
ArrayRef<MDOperand> Ops; ArrayRef<MDOperand> Ops;
unsigned Hash; unsigned Hash;
protected: protected:
@ -212,14 +243,15 @@ public:
}; };
template <class NodeTy> struct MDNodeKeyImpl; template <class NodeTy> struct MDNodeKeyImpl;
template <class NodeTy> struct MDNodeInfo;
/// Configuration point for MDNodeInfo::isEqual(). /// Configuration point for MDNodeInfo::isEqual().
template <class NodeTy> struct MDNodeSubsetEqualImpl { template <class NodeTy> struct MDNodeSubsetEqualImpl {
typedef MDNodeKeyImpl<NodeTy> KeyTy; using KeyTy = MDNodeKeyImpl<NodeTy>;
static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) { static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
return false; return false;
} }
static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) { static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
return false; return false;
} }
@ -252,7 +284,6 @@ template <> struct MDNodeKeyImpl<DILocation> {
MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope, MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
Metadata *InlinedAt) Metadata *InlinedAt)
: Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {} : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
MDNodeKeyImpl(const DILocation *L) MDNodeKeyImpl(const DILocation *L)
: Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()), : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
InlinedAt(L->getRawInlinedAt()) {} InlinedAt(L->getRawInlinedAt()) {}
@ -261,6 +292,7 @@ template <> struct MDNodeKeyImpl<DILocation> {
return Line == RHS->getLine() && Column == RHS->getColumn() && return Line == RHS->getLine() && Column == RHS->getColumn() &&
Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt(); Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Line, Column, Scope, InlinedAt); return hash_combine(Line, Column, Scope, InlinedAt);
} }
@ -270,6 +302,7 @@ template <> struct MDNodeKeyImpl<DILocation> {
template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey { template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
unsigned Tag; unsigned Tag;
MDString *Header; MDString *Header;
MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps) MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
: MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
MDNodeKeyImpl(const GenericDINode *N) MDNodeKeyImpl(const GenericDINode *N)
@ -299,6 +332,7 @@ template <> struct MDNodeKeyImpl<DISubrange> {
bool isKeyOf(const DISubrange *RHS) const { bool isKeyOf(const DISubrange *RHS) const {
return Count == RHS->getCount() && LowerBound == RHS->getLowerBound(); return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
} }
unsigned getHashValue() const { return hash_combine(Count, LowerBound); } unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
}; };
@ -313,6 +347,7 @@ template <> struct MDNodeKeyImpl<DIEnumerator> {
bool isKeyOf(const DIEnumerator *RHS) const { bool isKeyOf(const DIEnumerator *RHS) const {
return Value == RHS->getValue() && Name == RHS->getRawName(); return Value == RHS->getValue() && Name == RHS->getRawName();
} }
unsigned getHashValue() const { return hash_combine(Value, Name); } unsigned getHashValue() const { return hash_combine(Value, Name); }
}; };
@ -337,6 +372,7 @@ template <> struct MDNodeKeyImpl<DIBasicType> {
AlignInBits == RHS->getAlignInBits() && AlignInBits == RHS->getAlignInBits() &&
Encoding == RHS->getEncoding(); Encoding == RHS->getEncoding();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding); return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
} }
@ -384,6 +420,7 @@ template <> struct MDNodeKeyImpl<DIDerivedType> {
Flags == RHS->getFlags() && Flags == RHS->getFlags() &&
ExtraData == RHS->getRawExtraData(); ExtraData == RHS->getRawExtraData();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
// If this is a member inside an ODR type, only hash the type and the name. // If this is a member inside an ODR type, only hash the type and the name.
// Otherwise the hash will be stronger than // Otherwise the hash will be stronger than
@ -402,10 +439,12 @@ template <> struct MDNodeKeyImpl<DIDerivedType> {
}; };
template <> struct MDNodeSubsetEqualImpl<DIDerivedType> { template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
typedef MDNodeKeyImpl<DIDerivedType> KeyTy; using KeyTy = MDNodeKeyImpl<DIDerivedType>;
static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) { static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS); return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
} }
static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) { static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(), return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
RHS); RHS);
@ -480,6 +519,7 @@ template <> struct MDNodeKeyImpl<DICompositeType> {
TemplateParams == RHS->getRawTemplateParams() && TemplateParams == RHS->getRawTemplateParams() &&
Identifier == RHS->getRawIdentifier(); Identifier == RHS->getRawIdentifier();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
// Intentionally computes the hash on a subset of the operands for // Intentionally computes the hash on a subset of the operands for
// performance reason. The subset has to be significant enough to avoid // performance reason. The subset has to be significant enough to avoid
@ -504,6 +544,7 @@ template <> struct MDNodeKeyImpl<DISubroutineType> {
return Flags == RHS->getFlags() && CC == RHS->getCC() && return Flags == RHS->getFlags() && CC == RHS->getCC() &&
TypeArray == RHS->getRawTypeArray(); TypeArray == RHS->getRawTypeArray();
} }
unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); } unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
}; };
@ -527,6 +568,7 @@ template <> struct MDNodeKeyImpl<DIFile> {
CSKind == RHS->getChecksumKind() && CSKind == RHS->getChecksumKind() &&
Checksum == RHS->getRawChecksum(); Checksum == RHS->getRawChecksum();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Filename, Directory, CSKind, Checksum); return hash_combine(Filename, Directory, CSKind, Checksum);
} }
@ -601,6 +643,7 @@ template <> struct MDNodeKeyImpl<DISubprogram> {
Variables == RHS->getRawVariables() && Variables == RHS->getRawVariables() &&
ThrownTypes == RHS->getRawThrownTypes(); ThrownTypes == RHS->getRawThrownTypes();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
// If this is a declaration inside an ODR type, only hash the type and the // If this is a declaration inside an ODR type, only hash the type and the
// name. Otherwise the hash will be stronger than // name. Otherwise the hash will be stronger than
@ -619,11 +662,13 @@ template <> struct MDNodeKeyImpl<DISubprogram> {
}; };
template <> struct MDNodeSubsetEqualImpl<DISubprogram> { template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
typedef MDNodeKeyImpl<DISubprogram> KeyTy; using KeyTy = MDNodeKeyImpl<DISubprogram>;
static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) { static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope, return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
LHS.LinkageName, LHS.TemplateParams, RHS); LHS.LinkageName, LHS.TemplateParams, RHS);
} }
static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) { static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(), return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
LHS->getRawLinkageName(), LHS->getRawLinkageName(),
@ -672,6 +717,7 @@ template <> struct MDNodeKeyImpl<DILexicalBlock> {
return Scope == RHS->getRawScope() && File == RHS->getRawFile() && return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Line == RHS->getLine() && Column == RHS->getColumn(); Line == RHS->getLine() && Column == RHS->getColumn();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Scope, File, Line, Column); return hash_combine(Scope, File, Line, Column);
} }
@ -692,6 +738,7 @@ template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
return Scope == RHS->getRawScope() && File == RHS->getRawFile() && return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Discriminator == RHS->getDiscriminator(); Discriminator == RHS->getDiscriminator();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Scope, File, Discriminator); return hash_combine(Scope, File, Discriminator);
} }
@ -712,6 +759,7 @@ template <> struct MDNodeKeyImpl<DINamespace> {
return Scope == RHS->getRawScope() && Name == RHS->getRawName() && return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
ExportSymbols == RHS->getExportSymbols(); ExportSymbols == RHS->getExportSymbols();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Scope, Name); return hash_combine(Scope, Name);
} }
@ -723,6 +771,7 @@ template <> struct MDNodeKeyImpl<DIModule> {
MDString *ConfigurationMacros; MDString *ConfigurationMacros;
MDString *IncludePath; MDString *IncludePath;
MDString *ISysRoot; MDString *ISysRoot;
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *ISysRoot) MDString *IncludePath, MDString *ISysRoot)
: Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros), : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
@ -738,6 +787,7 @@ template <> struct MDNodeKeyImpl<DIModule> {
IncludePath == RHS->getRawIncludePath() && IncludePath == RHS->getRawIncludePath() &&
ISysRoot == RHS->getRawISysRoot(); ISysRoot == RHS->getRawISysRoot();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Scope, Name, return hash_combine(Scope, Name,
ConfigurationMacros, IncludePath, ISysRoot); ConfigurationMacros, IncludePath, ISysRoot);
@ -755,6 +805,7 @@ template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
bool isKeyOf(const DITemplateTypeParameter *RHS) const { bool isKeyOf(const DITemplateTypeParameter *RHS) const {
return Name == RHS->getRawName() && Type == RHS->getRawType(); return Name == RHS->getRawName() && Type == RHS->getRawType();
} }
unsigned getHashValue() const { return hash_combine(Name, Type); } unsigned getHashValue() const { return hash_combine(Name, Type); }
}; };
@ -774,6 +825,7 @@ template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
return Tag == RHS->getTag() && Name == RHS->getRawName() && return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Type == RHS->getRawType() && Value == RHS->getValue(); Type == RHS->getRawType() && Value == RHS->getValue();
} }
unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); } unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
}; };
@ -816,6 +868,7 @@ template <> struct MDNodeKeyImpl<DIGlobalVariable> {
RHS->getRawStaticDataMemberDeclaration() && RHS->getRawStaticDataMemberDeclaration() &&
AlignInBits == RHS->getAlignInBits(); AlignInBits == RHS->getAlignInBits();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
// We do not use AlignInBits in hashing function here on purpose: // We do not use AlignInBits in hashing function here on purpose:
// in most cases this param for local variable is zero (for function param // in most cases this param for local variable is zero (for function param
@ -856,6 +909,7 @@ template <> struct MDNodeKeyImpl<DILocalVariable> {
Type == RHS->getRawType() && Arg == RHS->getArg() && Type == RHS->getRawType() && Arg == RHS->getArg() &&
Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits(); Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
// We do not use AlignInBits in hashing function here on purpose: // We do not use AlignInBits in hashing function here on purpose:
// in most cases this param for local variable is zero (for function param // in most cases this param for local variable is zero (for function param
@ -877,6 +931,7 @@ template <> struct MDNodeKeyImpl<DIExpression> {
bool isKeyOf(const DIExpression *RHS) const { bool isKeyOf(const DIExpression *RHS) const {
return Elements == RHS->getElements(); return Elements == RHS->getElements();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine_range(Elements.begin(), Elements.end()); return hash_combine_range(Elements.begin(), Elements.end());
} }
@ -895,6 +950,7 @@ template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
return Variable == RHS->getRawVariable() && return Variable == RHS->getRawVariable() &&
Expression == RHS->getRawExpression(); Expression == RHS->getRawExpression();
} }
unsigned getHashValue() const { return hash_combine(Variable, Expression); } unsigned getHashValue() const { return hash_combine(Variable, Expression); }
}; };
@ -923,6 +979,7 @@ template <> struct MDNodeKeyImpl<DIObjCProperty> {
SetterName == RHS->getRawSetterName() && SetterName == RHS->getRawSetterName() &&
Attributes == RHS->getAttributes() && Type == RHS->getRawType(); Attributes == RHS->getAttributes() && Type == RHS->getRawType();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Name, File, Line, GetterName, SetterName, Attributes, return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
Type); Type);
@ -948,6 +1005,7 @@ template <> struct MDNodeKeyImpl<DIImportedEntity> {
Entity == RHS->getRawEntity() && Line == RHS->getLine() && Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
Name == RHS->getRawName(); Name == RHS->getRawName();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(Tag, Scope, Entity, Line, Name); return hash_combine(Tag, Scope, Entity, Line, Name);
} }
@ -969,6 +1027,7 @@ template <> struct MDNodeKeyImpl<DIMacro> {
return MIType == RHS->getMacinfoType() && Line == RHS->getLine() && return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Name == RHS->getRawName() && Value == RHS->getRawValue(); Name == RHS->getRawName() && Value == RHS->getRawValue();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(MIType, Line, Name, Value); return hash_combine(MIType, Line, Name, Value);
} }
@ -991,6 +1050,7 @@ template <> struct MDNodeKeyImpl<DIMacroFile> {
return MIType == RHS->getMacinfoType() && Line == RHS->getLine() && return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
File == RHS->getRawFile() && Elements == RHS->getRawElements(); File == RHS->getRawFile() && Elements == RHS->getRawElements();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
return hash_combine(MIType, Line, File, Elements); return hash_combine(MIType, Line, File, Elements);
} }
@ -998,23 +1058,29 @@ template <> struct MDNodeKeyImpl<DIMacroFile> {
/// \brief DenseMapInfo for MDNode subclasses. /// \brief DenseMapInfo for MDNode subclasses.
template <class NodeTy> struct MDNodeInfo { template <class NodeTy> struct MDNodeInfo {
typedef MDNodeKeyImpl<NodeTy> KeyTy; using KeyTy = MDNodeKeyImpl<NodeTy>;
typedef MDNodeSubsetEqualImpl<NodeTy> SubsetEqualTy; using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
static inline NodeTy *getEmptyKey() { static inline NodeTy *getEmptyKey() {
return DenseMapInfo<NodeTy *>::getEmptyKey(); return DenseMapInfo<NodeTy *>::getEmptyKey();
} }
static inline NodeTy *getTombstoneKey() { static inline NodeTy *getTombstoneKey() {
return DenseMapInfo<NodeTy *>::getTombstoneKey(); return DenseMapInfo<NodeTy *>::getTombstoneKey();
} }
static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); } static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
static unsigned getHashValue(const NodeTy *N) { static unsigned getHashValue(const NodeTy *N) {
return KeyTy(N).getHashValue(); return KeyTy(N).getHashValue();
} }
static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) { static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
if (RHS == getEmptyKey() || RHS == getTombstoneKey()) if (RHS == getEmptyKey() || RHS == getTombstoneKey())
return false; return false;
return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS); return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
} }
static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) { static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
if (LHS == RHS) if (LHS == RHS)
return true; return true;
@ -1024,7 +1090,7 @@ template <class NodeTy> struct MDNodeInfo {
} }
}; };
#define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info; #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
#include "llvm/IR/Metadata.def" #include "llvm/IR/Metadata.def"
/// \brief Map-like storage for metadata attachments. /// \brief Map-like storage for metadata attachments.
@ -1097,24 +1163,24 @@ public:
/// will be automatically deleted if this context is deleted. /// will be automatically deleted if this context is deleted.
SmallPtrSet<Module*, 4> OwnedModules; SmallPtrSet<Module*, 4> OwnedModules;
LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler; LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
void *InlineAsmDiagContext; void *InlineAsmDiagContext = nullptr;
LLVMContext::DiagnosticHandlerTy DiagnosticHandler; LLVMContext::DiagnosticHandlerTy DiagnosticHandler = nullptr;
void *DiagnosticContext; void *DiagnosticContext = nullptr;
bool RespectDiagnosticFilters; bool RespectDiagnosticFilters = false;
bool DiagnosticHotnessRequested; bool DiagnosticHotnessRequested = false;
std::unique_ptr<yaml::Output> DiagnosticsOutputFile; std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
LLVMContext::YieldCallbackTy YieldCallback; LLVMContext::YieldCallbackTy YieldCallback = nullptr;
void *YieldOpaqueHandle; void *YieldOpaqueHandle = nullptr;
typedef DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo> using IntMapTy =
IntMapTy; DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>;
IntMapTy IntConstants; IntMapTy IntConstants;
typedef DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo> using FPMapTy =
FPMapTy; DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>;
FPMapTy FPConstants; FPMapTy FPConstants;
FoldingSet<AttributeImpl> AttrsSet; FoldingSet<AttributeImpl> AttrsSet;
@ -1142,13 +1208,13 @@ public:
DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants; DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy; using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
ArrayConstantsTy ArrayConstants; ArrayConstantsTy ArrayConstants;
typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy; using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
StructConstantsTy StructConstants; StructConstantsTy StructConstants;
typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy; using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
VectorConstantsTy VectorConstants; VectorConstantsTy VectorConstants;
DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants; DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
@ -1163,8 +1229,8 @@ public:
ConstantUniqueMap<InlineAsm> InlineAsms; ConstantUniqueMap<InlineAsm> InlineAsms;
ConstantInt *TheTrueVal; ConstantInt *TheTrueVal = nullptr;
ConstantInt *TheFalseVal; ConstantInt *TheFalseVal = nullptr;
std::unique_ptr<ConstantTokenNone> TheNoneToken; std::unique_ptr<ConstantTokenNone> TheNoneToken;
@ -1173,30 +1239,28 @@ public:
Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
/// TypeAllocator - All dynamically allocated types are allocated from this. /// TypeAllocator - All dynamically allocated types are allocated from this.
/// They live forever until the context is torn down. /// They live forever until the context is torn down.
BumpPtrAllocator TypeAllocator; BumpPtrAllocator TypeAllocator;
DenseMap<unsigned, IntegerType*> IntegerTypes; DenseMap<unsigned, IntegerType*> IntegerTypes;
typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet; using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
FunctionTypeSet FunctionTypes; FunctionTypeSet FunctionTypes;
typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet; using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
StructTypeSet AnonStructTypes; StructTypeSet AnonStructTypes;
StringMap<StructType*> NamedStructTypes; StringMap<StructType*> NamedStructTypes;
unsigned NamedStructTypesUniqueID; unsigned NamedStructTypesUniqueID = 0;
DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes; DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes; DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes; DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
/// ValueHandles - This map keeps track of all of the value handles that are /// ValueHandles - This map keeps track of all of the value handles that are
/// watching a Value*. The Value::HasValueHandle bit is used to know /// watching a Value*. The Value::HasValueHandle bit is used to know
/// whether or not a value has an entry in this map. /// whether or not a value has an entry in this map.
typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy; using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
ValueHandlesTy ValueHandles; ValueHandlesTy ValueHandles;
/// CustomMDKindNames - Map to hold the metadata string to ID mapping. /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
@ -1254,6 +1318,6 @@ public:
OptBisect &getOptBisect(); OptBisect &getOptBisect();
}; };
} } // end namespace llvm
#endif #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H

View File

@ -11,7 +11,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/IR/Metadata.h"
#include "LLVMContextImpl.h" #include "LLVMContextImpl.h"
#include "MetadataImpl.h" #include "MetadataImpl.h"
#include "SymbolTableListTraitsImpl.h" #include "SymbolTableListTraitsImpl.h"
@ -27,6 +26,7 @@
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Argument.h" #include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h" #include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h" #include "llvm/IR/Constant.h"
@ -39,6 +39,7 @@
#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h" #include "llvm/IR/Instruction.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/TrackingMDRef.h" #include "llvm/IR/TrackingMDRef.h"
#include "llvm/IR/Type.h" #include "llvm/IR/Type.h"
@ -53,6 +54,7 @@
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
#include <tuple> #include <tuple>
#include <type_traits>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -233,7 +235,7 @@ void ReplaceableMetadataImpl::replaceAllUsesWith(Metadata *MD) {
return; return;
// Copy out uses since UseMap will get touched below. // Copy out uses since UseMap will get touched below.
typedef std::pair<void *, std::pair<OwnerTy, uint64_t>> UseTy; using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end()); SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end());
std::sort(Uses.begin(), Uses.end(), [](const UseTy &L, const UseTy &R) { std::sort(Uses.begin(), Uses.end(), [](const UseTy &L, const UseTy &R) {
return L.second.second < R.second.second; return L.second.second < R.second.second;
@ -286,7 +288,7 @@ void ReplaceableMetadataImpl::resolveAllUses(bool ResolveUsers) {
} }
// Copy out uses since UseMap could get touched below. // Copy out uses since UseMap could get touched below.
typedef std::pair<void *, std::pair<OwnerTy, uint64_t>> UseTy; using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;
SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end()); SmallVector<UseTy, 8> Uses(UseMap.begin(), UseMap.end());
std::sort(Uses.begin(), Uses.end(), [](const UseTy &L, const UseTy &R) { std::sort(Uses.begin(), Uses.end(), [](const UseTy &L, const UseTy &R) {
return L.second.second < R.second.second; return L.second.second < R.second.second;
@ -758,8 +760,8 @@ static T *uniquifyImpl(T *N, DenseSet<T *, InfoT> &Store) {
} }
template <class NodeTy> struct MDNode::HasCachedHash { template <class NodeTy> struct MDNode::HasCachedHash {
typedef char Yes[1]; using Yes = char[1];
typedef char No[2]; using No = char[2];
template <class U, U Val> struct SFINAE {}; template <class U, U Val> struct SFINAE {};
template <class U> template <class U>
@ -1484,7 +1486,7 @@ void GlobalObject::addTypeMetadata(unsigned Offset, Metadata *TypeID) {
addMetadata( addMetadata(
LLVMContext::MD_type, LLVMContext::MD_type,
*MDTuple::get(getContext(), *MDTuple::get(getContext(),
{ConstantAsMetadata::get(llvm::ConstantInt::get( {ConstantAsMetadata::get(ConstantInt::get(
Type::getInt64Ty(getContext()), Offset)), Type::getInt64Ty(getContext()), Offset)),
TypeID})); TypeID}));
} }