LLVM  mainline
Metadata.h
Go to the documentation of this file.
00001 //===- llvm/IR/Metadata.h - Metadata definitions ----------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 /// @file
00011 /// This file contains the declarations for metadata subclasses.
00012 /// They represent the different flavors of metadata that live in LLVM.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_IR_METADATA_H
00017 #define LLVM_IR_METADATA_H
00018 
00019 #include "llvm/ADT/ArrayRef.h"
00020 #include "llvm/ADT/DenseMap.h"
00021 #include "llvm/ADT/ilist_node.h"
00022 #include "llvm/ADT/iterator_range.h"
00023 #include "llvm/IR/Constant.h"
00024 #include "llvm/IR/MetadataTracking.h"
00025 #include "llvm/IR/Value.h"
00026 #include "llvm/Support/ErrorHandling.h"
00027 #include <type_traits>
00028 
00029 namespace llvm {
00030 class LLVMContext;
00031 class Module;
00032 template<typename ValueSubClass, typename ItemParentClass>
00033   class SymbolTableListTraits;
00034 
00035 enum LLVMConstants : uint32_t {
00036   DEBUG_METADATA_VERSION = 3 // Current debug info version number.
00037 };
00038 
00039 /// \brief Root of the metadata hierarchy.
00040 ///
00041 /// This is a root class for typeless data in the IR.
00042 class Metadata {
00043   friend class ReplaceableMetadataImpl;
00044 
00045   /// \brief RTTI.
00046   const unsigned char SubclassID;
00047 
00048 protected:
00049   /// \brief Active type of storage.
00050   enum StorageType { Uniqued, Distinct, Temporary };
00051 
00052   /// \brief Storage flag for non-uniqued, otherwise unowned, metadata.
00053   unsigned Storage : 2;
00054   // TODO: expose remaining bits to subclasses.
00055 
00056   unsigned short SubclassData16;
00057   unsigned SubclassData32;
00058 
00059 public:
00060   enum MetadataKind {
00061     MDTupleKind,
00062     DILocationKind,
00063     GenericDINodeKind,
00064     DISubrangeKind,
00065     DIEnumeratorKind,
00066     DIBasicTypeKind,
00067     DIDerivedTypeKind,
00068     DICompositeTypeKind,
00069     DISubroutineTypeKind,
00070     DIFileKind,
00071     DICompileUnitKind,
00072     DISubprogramKind,
00073     DILexicalBlockKind,
00074     DILexicalBlockFileKind,
00075     DINamespaceKind,
00076     DITemplateTypeParameterKind,
00077     DITemplateValueParameterKind,
00078     DIGlobalVariableKind,
00079     DILocalVariableKind,
00080     DIExpressionKind,
00081     DIObjCPropertyKind,
00082     DIImportedEntityKind,
00083     ConstantAsMetadataKind,
00084     LocalAsMetadataKind,
00085     MDStringKind
00086   };
00087 
00088 protected:
00089   Metadata(unsigned ID, StorageType Storage)
00090       : SubclassID(ID), Storage(Storage), SubclassData16(0), SubclassData32(0) {
00091   }
00092   ~Metadata() = default;
00093 
00094   /// \brief Default handling of a changed operand, which asserts.
00095   ///
00096   /// If subclasses pass themselves in as owners to a tracking node reference,
00097   /// they must provide an implementation of this method.
00098   void handleChangedOperand(void *, Metadata *) {
00099     llvm_unreachable("Unimplemented in Metadata subclass");
00100   }
00101 
00102 public:
00103   unsigned getMetadataID() const { return SubclassID; }
00104 
00105   /// \brief User-friendly dump.
00106   ///
00107   /// If \c M is provided, metadata nodes will be numbered canonically;
00108   /// otherwise, pointer addresses are substituted.
00109   ///
00110   /// Note: this uses an explicit overload instead of default arguments so that
00111   /// the nullptr version is easy to call from a debugger.
00112   ///
00113   /// @{
00114   void dump() const;
00115   void dump(const Module *M) const;
00116   /// @}
00117 
00118   /// \brief Print.
00119   ///
00120   /// Prints definition of \c this.
00121   ///
00122   /// If \c M is provided, metadata nodes will be numbered canonically;
00123   /// otherwise, pointer addresses are substituted.
00124   void print(raw_ostream &OS, const Module *M = nullptr) const;
00125 
00126   /// \brief Print as operand.
00127   ///
00128   /// Prints reference of \c this.
00129   ///
00130   /// If \c M is provided, metadata nodes will be numbered canonically;
00131   /// otherwise, pointer addresses are substituted.
00132   void printAsOperand(raw_ostream &OS, const Module *M = nullptr) const;
00133 };
00134 
00135 #define HANDLE_METADATA(CLASS) class CLASS;
00136 #include "llvm/IR/Metadata.def"
00137 
00138 // Provide specializations of isa so that we don't need definitions of
00139 // subclasses to see if the metadata is a subclass.
00140 #define HANDLE_METADATA_LEAF(CLASS)                                            \
00141   template <> struct isa_impl<CLASS, Metadata> {                               \
00142     static inline bool doit(const Metadata &MD) {                              \
00143       return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
00144     }                                                                          \
00145   };
00146 #include "llvm/IR/Metadata.def"
00147 
00148 inline raw_ostream &operator<<(raw_ostream &OS, const Metadata &MD) {
00149   MD.print(OS);
00150   return OS;
00151 }
00152 
00153 /// \brief Metadata wrapper in the Value hierarchy.
00154 ///
00155 /// A member of the \a Value hierarchy to represent a reference to metadata.
00156 /// This allows, e.g., instrinsics to have metadata as operands.
00157 ///
00158 /// Notably, this is the only thing in either hierarchy that is allowed to
00159 /// reference \a LocalAsMetadata.
00160 class MetadataAsValue : public Value {
00161   friend class ReplaceableMetadataImpl;
00162   friend class LLVMContextImpl;
00163 
00164   Metadata *MD;
00165 
00166   MetadataAsValue(Type *Ty, Metadata *MD);
00167   ~MetadataAsValue() override;
00168 
00169   /// \brief Drop use of metadata (during teardown).
00170   void dropUse() { MD = nullptr; }
00171 
00172 public:
00173   static MetadataAsValue *get(LLVMContext &Context, Metadata *MD);
00174   static MetadataAsValue *getIfExists(LLVMContext &Context, Metadata *MD);
00175   Metadata *getMetadata() const { return MD; }
00176 
00177   static bool classof(const Value *V) {
00178     return V->getValueID() == MetadataAsValueVal;
00179   }
00180 
00181 private:
00182   void handleChangedMetadata(Metadata *MD);
00183   void track();
00184   void untrack();
00185 };
00186 
00187 /// \brief Shared implementation of use-lists for replaceable metadata.
00188 ///
00189 /// Most metadata cannot be RAUW'ed.  This is a shared implementation of
00190 /// use-lists and associated API for the two that support it (\a ValueAsMetadata
00191 /// and \a TempMDNode).
00192 class ReplaceableMetadataImpl {
00193   friend class MetadataTracking;
00194 
00195 public:
00196   typedef MetadataTracking::OwnerTy OwnerTy;
00197 
00198 private:
00199   LLVMContext &Context;
00200   uint64_t NextIndex;
00201   SmallDenseMap<void *, std::pair<OwnerTy, uint64_t>, 4> UseMap;
00202 
00203 public:
00204   ReplaceableMetadataImpl(LLVMContext &Context)
00205       : Context(Context), NextIndex(0) {}
00206   ~ReplaceableMetadataImpl() {
00207     assert(UseMap.empty() && "Cannot destroy in-use replaceable metadata");
00208   }
00209 
00210   LLVMContext &getContext() const { return Context; }
00211 
00212   /// \brief Replace all uses of this with MD.
00213   ///
00214   /// Replace all uses of this with \c MD, which is allowed to be null.
00215   void replaceAllUsesWith(Metadata *MD);
00216 
00217   /// \brief Resolve all uses of this.
00218   ///
00219   /// Resolve all uses of this, turning off RAUW permanently.  If \c
00220   /// ResolveUsers, call \a MDNode::resolve() on any users whose last operand
00221   /// is resolved.
00222   void resolveAllUses(bool ResolveUsers = true);
00223 
00224 private:
00225   void addRef(void *Ref, OwnerTy Owner);
00226   void dropRef(void *Ref);
00227   void moveRef(void *Ref, void *New, const Metadata &MD);
00228 
00229   static ReplaceableMetadataImpl *get(Metadata &MD);
00230 };
00231 
00232 /// \brief Value wrapper in the Metadata hierarchy.
00233 ///
00234 /// This is a custom value handle that allows other metadata to refer to
00235 /// classes in the Value hierarchy.
00236 ///
00237 /// Because of full uniquing support, each value is only wrapped by a single \a
00238 /// ValueAsMetadata object, so the lookup maps are far more efficient than
00239 /// those using ValueHandleBase.
00240 class ValueAsMetadata : public Metadata, ReplaceableMetadataImpl {
00241   friend class ReplaceableMetadataImpl;
00242   friend class LLVMContextImpl;
00243 
00244   Value *V;
00245 
00246   /// \brief Drop users without RAUW (during teardown).
00247   void dropUsers() {
00248     ReplaceableMetadataImpl::resolveAllUses(/* ResolveUsers */ false);
00249   }
00250 
00251 protected:
00252   ValueAsMetadata(unsigned ID, Value *V)
00253       : Metadata(ID, Uniqued), ReplaceableMetadataImpl(V->getContext()), V(V) {
00254     assert(V && "Expected valid value");
00255   }
00256   ~ValueAsMetadata() = default;
00257 
00258 public:
00259   static ValueAsMetadata *get(Value *V);
00260   static ConstantAsMetadata *getConstant(Value *C) {
00261     return cast<ConstantAsMetadata>(get(C));
00262   }
00263   static LocalAsMetadata *getLocal(Value *Local) {
00264     return cast<LocalAsMetadata>(get(Local));
00265   }
00266 
00267   static ValueAsMetadata *getIfExists(Value *V);
00268   static ConstantAsMetadata *getConstantIfExists(Value *C) {
00269     return cast_or_null<ConstantAsMetadata>(getIfExists(C));
00270   }
00271   static LocalAsMetadata *getLocalIfExists(Value *Local) {
00272     return cast_or_null<LocalAsMetadata>(getIfExists(Local));
00273   }
00274 
00275   Value *getValue() const { return V; }
00276   Type *getType() const { return V->getType(); }
00277   LLVMContext &getContext() const { return V->getContext(); }
00278 
00279   static void handleDeletion(Value *V);
00280   static void handleRAUW(Value *From, Value *To);
00281 
00282 protected:
00283   /// \brief Handle collisions after \a Value::replaceAllUsesWith().
00284   ///
00285   /// RAUW isn't supported directly for \a ValueAsMetadata, but if the wrapped
00286   /// \a Value gets RAUW'ed and the target already exists, this is used to
00287   /// merge the two metadata nodes.
00288   void replaceAllUsesWith(Metadata *MD) {
00289     ReplaceableMetadataImpl::replaceAllUsesWith(MD);
00290   }
00291 
00292 public:
00293   static bool classof(const Metadata *MD) {
00294     return MD->getMetadataID() == LocalAsMetadataKind ||
00295            MD->getMetadataID() == ConstantAsMetadataKind;
00296   }
00297 };
00298 
00299 class ConstantAsMetadata : public ValueAsMetadata {
00300   friend class ValueAsMetadata;
00301 
00302   ConstantAsMetadata(Constant *C)
00303       : ValueAsMetadata(ConstantAsMetadataKind, C) {}
00304 
00305 public:
00306   static ConstantAsMetadata *get(Constant *C) {
00307     return ValueAsMetadata::getConstant(C);
00308   }
00309   static ConstantAsMetadata *getIfExists(Constant *C) {
00310     return ValueAsMetadata::getConstantIfExists(C);
00311   }
00312 
00313   Constant *getValue() const {
00314     return cast<Constant>(ValueAsMetadata::getValue());
00315   }
00316 
00317   static bool classof(const Metadata *MD) {
00318     return MD->getMetadataID() == ConstantAsMetadataKind;
00319   }
00320 };
00321 
00322 class LocalAsMetadata : public ValueAsMetadata {
00323   friend class ValueAsMetadata;
00324 
00325   LocalAsMetadata(Value *Local)
00326       : ValueAsMetadata(LocalAsMetadataKind, Local) {
00327     assert(!isa<Constant>(Local) && "Expected local value");
00328   }
00329 
00330 public:
00331   static LocalAsMetadata *get(Value *Local) {
00332     return ValueAsMetadata::getLocal(Local);
00333   }
00334   static LocalAsMetadata *getIfExists(Value *Local) {
00335     return ValueAsMetadata::getLocalIfExists(Local);
00336   }
00337 
00338   static bool classof(const Metadata *MD) {
00339     return MD->getMetadataID() == LocalAsMetadataKind;
00340   }
00341 };
00342 
00343 /// \brief Transitional API for extracting constants from Metadata.
00344 ///
00345 /// This namespace contains transitional functions for metadata that points to
00346 /// \a Constants.
00347 ///
00348 /// In prehistory -- when metadata was a subclass of \a Value -- \a MDNode
00349 /// operands could refer to any \a Value.  There's was a lot of code like this:
00350 ///
00351 /// \code
00352 ///     MDNode *N = ...;
00353 ///     auto *CI = dyn_cast<ConstantInt>(N->getOperand(2));
00354 /// \endcode
00355 ///
00356 /// Now that \a Value and \a Metadata are in separate hierarchies, maintaining
00357 /// the semantics for \a isa(), \a cast(), \a dyn_cast() (etc.) requires three
00358 /// steps: cast in the \a Metadata hierarchy, extraction of the \a Value, and
00359 /// cast in the \a Value hierarchy.  Besides creating boiler-plate, this
00360 /// requires subtle control flow changes.
00361 ///
00362 /// The end-goal is to create a new type of metadata, called (e.g.) \a MDInt,
00363 /// so that metadata can refer to numbers without traversing a bridge to the \a
00364 /// Value hierarchy.  In this final state, the code above would look like this:
00365 ///
00366 /// \code
00367 ///     MDNode *N = ...;
00368 ///     auto *MI = dyn_cast<MDInt>(N->getOperand(2));
00369 /// \endcode
00370 ///
00371 /// The API in this namespace supports the transition.  \a MDInt doesn't exist
00372 /// yet, and even once it does, changing each metadata schema to use it is its
00373 /// own mini-project.  In the meantime this API prevents us from introducing
00374 /// complex and bug-prone control flow that will disappear in the end.  In
00375 /// particular, the above code looks like this:
00376 ///
00377 /// \code
00378 ///     MDNode *N = ...;
00379 ///     auto *CI = mdconst::dyn_extract<ConstantInt>(N->getOperand(2));
00380 /// \endcode
00381 ///
00382 /// The full set of provided functions includes:
00383 ///
00384 ///   mdconst::hasa                <=> isa
00385 ///   mdconst::extract             <=> cast
00386 ///   mdconst::extract_or_null     <=> cast_or_null
00387 ///   mdconst::dyn_extract         <=> dyn_cast
00388 ///   mdconst::dyn_extract_or_null <=> dyn_cast_or_null
00389 ///
00390 /// The target of the cast must be a subclass of \a Constant.
00391 namespace mdconst {
00392 
00393 namespace detail {
00394 template <class T> T &make();
00395 template <class T, class Result> struct HasDereference {
00396   typedef char Yes[1];
00397   typedef char No[2];
00398   template <size_t N> struct SFINAE {};
00399 
00400   template <class U, class V>
00401   static Yes &hasDereference(SFINAE<sizeof(static_cast<V>(*make<U>()))> * = 0);
00402   template <class U, class V> static No &hasDereference(...);
00403 
00404   static const bool value =
00405       sizeof(hasDereference<T, Result>(nullptr)) == sizeof(Yes);
00406 };
00407 template <class V, class M> struct IsValidPointer {
00408   static const bool value = std::is_base_of<Constant, V>::value &&
00409                             HasDereference<M, const Metadata &>::value;
00410 };
00411 template <class V, class M> struct IsValidReference {
00412   static const bool value = std::is_base_of<Constant, V>::value &&
00413                             std::is_convertible<M, const Metadata &>::value;
00414 };
00415 } // end namespace detail
00416 
00417 /// \brief Check whether Metadata has a Value.
00418 ///
00419 /// As an analogue to \a isa(), check whether \c MD has an \a Value inside of
00420 /// type \c X.
00421 template <class X, class Y>
00422 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, bool>::type
00423 hasa(Y &&MD) {
00424   assert(MD && "Null pointer sent into hasa");
00425   if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
00426     return isa<X>(V->getValue());
00427   return false;
00428 }
00429 template <class X, class Y>
00430 inline
00431     typename std::enable_if<detail::IsValidReference<X, Y &>::value, bool>::type
00432     hasa(Y &MD) {
00433   return hasa(&MD);
00434 }
00435 
00436 /// \brief Extract a Value from Metadata.
00437 ///
00438 /// As an analogue to \a cast(), extract the \a Value subclass \c X from \c MD.
00439 template <class X, class Y>
00440 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
00441 extract(Y &&MD) {
00442   return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
00443 }
00444 template <class X, class Y>
00445 inline
00446     typename std::enable_if<detail::IsValidReference<X, Y &>::value, X *>::type
00447     extract(Y &MD) {
00448   return extract(&MD);
00449 }
00450 
00451 /// \brief Extract a Value from Metadata, allowing null.
00452 ///
00453 /// As an analogue to \a cast_or_null(), extract the \a Value subclass \c X
00454 /// from \c MD, allowing \c MD to be null.
00455 template <class X, class Y>
00456 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
00457 extract_or_null(Y &&MD) {
00458   if (auto *V = cast_or_null<ConstantAsMetadata>(MD))
00459     return cast<X>(V->getValue());
00460   return nullptr;
00461 }
00462 
00463 /// \brief Extract a Value from Metadata, if any.
00464 ///
00465 /// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X
00466 /// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a
00467 /// Value it does contain is of the wrong subclass.
00468 template <class X, class Y>
00469 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
00470 dyn_extract(Y &&MD) {
00471   if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
00472     return dyn_cast<X>(V->getValue());
00473   return nullptr;
00474 }
00475 
00476 /// \brief Extract a Value from Metadata, if any, allowing null.
00477 ///
00478 /// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X
00479 /// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a
00480 /// Value it does contain is of the wrong subclass, allowing \c MD to be null.
00481 template <class X, class Y>
00482 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type
00483 dyn_extract_or_null(Y &&MD) {
00484   if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
00485     return dyn_cast<X>(V->getValue());
00486   return nullptr;
00487 }
00488 
00489 } // end namespace mdconst
00490 
00491 //===----------------------------------------------------------------------===//
00492 /// \brief A single uniqued string.
00493 ///
00494 /// These are used to efficiently contain a byte sequence for metadata.
00495 /// MDString is always unnamed.
00496 class MDString : public Metadata {
00497   friend class StringMapEntry<MDString>;
00498 
00499   MDString(const MDString &) = delete;
00500   MDString &operator=(MDString &&) = delete;
00501   MDString &operator=(const MDString &) = delete;
00502 
00503   StringMapEntry<MDString> *Entry;
00504   MDString() : Metadata(MDStringKind, Uniqued), Entry(nullptr) {}
00505   MDString(MDString &&) : Metadata(MDStringKind, Uniqued) {}
00506 
00507 public:
00508   static MDString *get(LLVMContext &Context, StringRef Str);
00509   static MDString *get(LLVMContext &Context, const char *Str) {
00510     return get(Context, Str ? StringRef(Str) : StringRef());
00511   }
00512 
00513   StringRef getString() const;
00514 
00515   unsigned getLength() const { return (unsigned)getString().size(); }
00516 
00517   typedef StringRef::iterator iterator;
00518 
00519   /// \brief Pointer to the first byte of the string.
00520   iterator begin() const { return getString().begin(); }
00521 
00522   /// \brief Pointer to one byte past the end of the string.
00523   iterator end() const { return getString().end(); }
00524 
00525   const unsigned char *bytes_begin() const { return getString().bytes_begin(); }
00526   const unsigned char *bytes_end() const { return getString().bytes_end(); }
00527 
00528   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast.
00529   static bool classof(const Metadata *MD) {
00530     return MD->getMetadataID() == MDStringKind;
00531   }
00532 };
00533 
00534 /// \brief A collection of metadata nodes that might be associated with a
00535 /// memory access used by the alias-analysis infrastructure.
00536 struct AAMDNodes {
00537   explicit AAMDNodes(MDNode *T = nullptr, MDNode *S = nullptr,
00538                      MDNode *N = nullptr)
00539       : TBAA(T), Scope(S), NoAlias(N) {}
00540 
00541   bool operator==(const AAMDNodes &A) const {
00542     return TBAA == A.TBAA && Scope == A.Scope && NoAlias == A.NoAlias;
00543   }
00544 
00545   bool operator!=(const AAMDNodes &A) const { return !(*this == A); }
00546 
00547   explicit operator bool() const { return TBAA || Scope || NoAlias; }
00548 
00549   /// \brief The tag for type-based alias analysis.
00550   MDNode *TBAA;
00551 
00552   /// \brief The tag for alias scope specification (used with noalias).
00553   MDNode *Scope;
00554 
00555   /// \brief The tag specifying the noalias scope.
00556   MDNode *NoAlias;
00557 };
00558 
00559 // Specialize DenseMapInfo for AAMDNodes.
00560 template<>
00561 struct DenseMapInfo<AAMDNodes> {
00562   static inline AAMDNodes getEmptyKey() {
00563     return AAMDNodes(DenseMapInfo<MDNode *>::getEmptyKey(), 0, 0);
00564   }
00565   static inline AAMDNodes getTombstoneKey() {
00566     return AAMDNodes(DenseMapInfo<MDNode *>::getTombstoneKey(), 0, 0);
00567   }
00568   static unsigned getHashValue(const AAMDNodes &Val) {
00569     return DenseMapInfo<MDNode *>::getHashValue(Val.TBAA) ^
00570            DenseMapInfo<MDNode *>::getHashValue(Val.Scope) ^
00571            DenseMapInfo<MDNode *>::getHashValue(Val.NoAlias);
00572   }
00573   static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS) {
00574     return LHS == RHS;
00575   }
00576 };
00577 
00578 /// \brief Tracking metadata reference owned by Metadata.
00579 ///
00580 /// Similar to \a TrackingMDRef, but it's expected to be owned by an instance
00581 /// of \a Metadata, which has the option of registering itself for callbacks to
00582 /// re-unique itself.
00583 ///
00584 /// In particular, this is used by \a MDNode.
00585 class MDOperand {
00586   MDOperand(MDOperand &&) = delete;
00587   MDOperand(const MDOperand &) = delete;
00588   MDOperand &operator=(MDOperand &&) = delete;
00589   MDOperand &operator=(const MDOperand &) = delete;
00590 
00591   Metadata *MD;
00592 
00593 public:
00594   MDOperand() : MD(nullptr) {}
00595   ~MDOperand() { untrack(); }
00596 
00597   Metadata *get() const { return MD; }
00598   operator Metadata *() const { return get(); }
00599   Metadata *operator->() const { return get(); }
00600   Metadata &operator*() const { return *get(); }
00601 
00602   void reset() {
00603     untrack();
00604     MD = nullptr;
00605   }
00606   void reset(Metadata *MD, Metadata *Owner) {
00607     untrack();
00608     this->MD = MD;
00609     track(Owner);
00610   }
00611 
00612 private:
00613   void track(Metadata *Owner) {
00614     if (MD) {
00615       if (Owner)
00616         MetadataTracking::track(this, *MD, *Owner);
00617       else
00618         MetadataTracking::track(MD);
00619     }
00620   }
00621   void untrack() {
00622     assert(static_cast<void *>(this) == &MD && "Expected same address");
00623     if (MD)
00624       MetadataTracking::untrack(MD);
00625   }
00626 };
00627 
00628 template <> struct simplify_type<MDOperand> {
00629   typedef Metadata *SimpleType;
00630   static SimpleType getSimplifiedValue(MDOperand &MD) { return MD.get(); }
00631 };
00632 
00633 template <> struct simplify_type<const MDOperand> {
00634   typedef Metadata *SimpleType;
00635   static SimpleType getSimplifiedValue(const MDOperand &MD) { return MD.get(); }
00636 };
00637 
00638 /// \brief Pointer to the context, with optional RAUW support.
00639 ///
00640 /// Either a raw (non-null) pointer to the \a LLVMContext, or an owned pointer
00641 /// to \a ReplaceableMetadataImpl (which has a reference to \a LLVMContext).
00642 class ContextAndReplaceableUses {
00643   PointerUnion<LLVMContext *, ReplaceableMetadataImpl *> Ptr;
00644 
00645   ContextAndReplaceableUses() = delete;
00646   ContextAndReplaceableUses(ContextAndReplaceableUses &&) = delete;
00647   ContextAndReplaceableUses(const ContextAndReplaceableUses &) = delete;
00648   ContextAndReplaceableUses &operator=(ContextAndReplaceableUses &&) = delete;
00649   ContextAndReplaceableUses &
00650   operator=(const ContextAndReplaceableUses &) = delete;
00651 
00652 public:
00653   ContextAndReplaceableUses(LLVMContext &Context) : Ptr(&Context) {}
00654   ContextAndReplaceableUses(
00655       std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses)
00656       : Ptr(ReplaceableUses.release()) {
00657     assert(getReplaceableUses() && "Expected non-null replaceable uses");
00658   }
00659   ~ContextAndReplaceableUses() { delete getReplaceableUses(); }
00660 
00661   operator LLVMContext &() { return getContext(); }
00662 
00663   /// \brief Whether this contains RAUW support.
00664   bool hasReplaceableUses() const {
00665     return Ptr.is<ReplaceableMetadataImpl *>();
00666   }
00667   LLVMContext &getContext() const {
00668     if (hasReplaceableUses())
00669       return getReplaceableUses()->getContext();
00670     return *Ptr.get<LLVMContext *>();
00671   }
00672   ReplaceableMetadataImpl *getReplaceableUses() const {
00673     if (hasReplaceableUses())
00674       return Ptr.get<ReplaceableMetadataImpl *>();
00675     return nullptr;
00676   }
00677 
00678   /// \brief Assign RAUW support to this.
00679   ///
00680   /// Make this replaceable, taking ownership of \c ReplaceableUses (which must
00681   /// not be null).
00682   void
00683   makeReplaceable(std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses) {
00684     assert(ReplaceableUses && "Expected non-null replaceable uses");
00685     assert(&ReplaceableUses->getContext() == &getContext() &&
00686            "Expected same context");
00687     delete getReplaceableUses();
00688     Ptr = ReplaceableUses.release();
00689   }
00690 
00691   /// \brief Drop RAUW support.
00692   ///
00693   /// Cede ownership of RAUW support, returning it.
00694   std::unique_ptr<ReplaceableMetadataImpl> takeReplaceableUses() {
00695     assert(hasReplaceableUses() && "Expected to own replaceable uses");
00696     std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses(
00697         getReplaceableUses());
00698     Ptr = &ReplaceableUses->getContext();
00699     return ReplaceableUses;
00700   }
00701 };
00702 
00703 struct TempMDNodeDeleter {
00704   inline void operator()(MDNode *Node) const;
00705 };
00706 
00707 #define HANDLE_MDNODE_LEAF(CLASS)                                              \
00708   typedef std::unique_ptr<CLASS, TempMDNodeDeleter> Temp##CLASS;
00709 #define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS)
00710 #include "llvm/IR/Metadata.def"
00711 
00712 /// \brief Metadata node.
00713 ///
00714 /// Metadata nodes can be uniqued, like constants, or distinct.  Temporary
00715 /// metadata nodes (with full support for RAUW) can be used to delay uniquing
00716 /// until forward references are known.  The basic metadata node is an \a
00717 /// MDTuple.
00718 ///
00719 /// There is limited support for RAUW at construction time.  At construction
00720 /// time, if any operand is a temporary node (or an unresolved uniqued node,
00721 /// which indicates a transitive temporary operand), the node itself will be
00722 /// unresolved.  As soon as all operands become resolved, it will drop RAUW
00723 /// support permanently.
00724 ///
00725 /// If an unresolved node is part of a cycle, \a resolveCycles() needs
00726 /// to be called on some member of the cycle once all temporary nodes have been
00727 /// replaced.
00728 class MDNode : public Metadata {
00729   friend class ReplaceableMetadataImpl;
00730   friend class LLVMContextImpl;
00731 
00732   MDNode(const MDNode &) = delete;
00733   void operator=(const MDNode &) = delete;
00734   void *operator new(size_t) = delete;
00735 
00736   unsigned NumOperands;
00737   unsigned NumUnresolved;
00738 
00739 protected:
00740   ContextAndReplaceableUses Context;
00741 
00742   void *operator new(size_t Size, unsigned NumOps);
00743   void operator delete(void *Mem);
00744 
00745   /// \brief Required by std, but never called.
00746   void operator delete(void *, unsigned) {
00747     llvm_unreachable("Constructor throws?");
00748   }
00749 
00750   /// \brief Required by std, but never called.
00751   void operator delete(void *, unsigned, bool) {
00752     llvm_unreachable("Constructor throws?");
00753   }
00754 
00755   MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
00756          ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = None);
00757   ~MDNode() = default;
00758 
00759   void dropAllReferences();
00760 
00761   MDOperand *mutable_begin() { return mutable_end() - NumOperands; }
00762   MDOperand *mutable_end() { return reinterpret_cast<MDOperand *>(this); }
00763 
00764   typedef iterator_range<MDOperand *> mutable_op_range;
00765   mutable_op_range mutable_operands() {
00766     return mutable_op_range(mutable_begin(), mutable_end());
00767   }
00768 
00769 public:
00770   static inline MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs);
00771   static inline MDTuple *getIfExists(LLVMContext &Context,
00772                                      ArrayRef<Metadata *> MDs);
00773   static inline MDTuple *getDistinct(LLVMContext &Context,
00774                                      ArrayRef<Metadata *> MDs);
00775   static inline TempMDTuple getTemporary(LLVMContext &Context,
00776                                          ArrayRef<Metadata *> MDs);
00777 
00778   /// \brief Create a (temporary) clone of this.
00779   TempMDNode clone() const;
00780 
00781   /// \brief Deallocate a node created by getTemporary.
00782   ///
00783   /// Calls \c replaceAllUsesWith(nullptr) before deleting, so any remaining
00784   /// references will be reset.
00785   static void deleteTemporary(MDNode *N);
00786 
00787   LLVMContext &getContext() const { return Context.getContext(); }
00788 
00789   /// \brief Replace a specific operand.
00790   void replaceOperandWith(unsigned I, Metadata *New);
00791 
00792   /// \brief Check if node is fully resolved.
00793   ///
00794   /// If \a isTemporary(), this always returns \c false; if \a isDistinct(),
00795   /// this always returns \c true.
00796   ///
00797   /// If \a isUniqued(), returns \c true if this has already dropped RAUW
00798   /// support (because all operands are resolved).
00799   ///
00800   /// As forward declarations are resolved, their containers should get
00801   /// resolved automatically.  However, if this (or one of its operands) is
00802   /// involved in a cycle, \a resolveCycles() needs to be called explicitly.
00803   bool isResolved() const { return !Context.hasReplaceableUses(); }
00804 
00805   bool isUniqued() const { return Storage == Uniqued; }
00806   bool isDistinct() const { return Storage == Distinct; }
00807   bool isTemporary() const { return Storage == Temporary; }
00808 
00809   /// \brief RAUW a temporary.
00810   ///
00811   /// \pre \a isTemporary() must be \c true.
00812   void replaceAllUsesWith(Metadata *MD) {
00813     assert(isTemporary() && "Expected temporary node");
00814     assert(!isResolved() && "Expected RAUW support");
00815     Context.getReplaceableUses()->replaceAllUsesWith(MD);
00816   }
00817 
00818   /// \brief Resolve cycles.
00819   ///
00820   /// Once all forward declarations have been resolved, force cycles to be
00821   /// resolved.
00822   ///
00823   /// \pre No operands (or operands' operands, etc.) have \a isTemporary().
00824   void resolveCycles();
00825 
00826   /// \brief Replace a temporary node with a permanent one.
00827   ///
00828   /// Try to create a uniqued version of \c N -- in place, if possible -- and
00829   /// return it.  If \c N cannot be uniqued, return a distinct node instead.
00830   template <class T>
00831   static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
00832   replaceWithPermanent(std::unique_ptr<T, TempMDNodeDeleter> N) {
00833     return cast<T>(N.release()->replaceWithPermanentImpl());
00834   }
00835 
00836   /// \brief Replace a temporary node with a uniqued one.
00837   ///
00838   /// Create a uniqued version of \c N -- in place, if possible -- and return
00839   /// it.  Takes ownership of the temporary node.
00840   ///
00841   /// \pre N does not self-reference.
00842   template <class T>
00843   static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
00844   replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N) {
00845     return cast<T>(N.release()->replaceWithUniquedImpl());
00846   }
00847 
00848   /// \brief Replace a temporary node with a distinct one.
00849   ///
00850   /// Create a distinct version of \c N -- in place, if possible -- and return
00851   /// it.  Takes ownership of the temporary node.
00852   template <class T>
00853   static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
00854   replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
00855     return cast<T>(N.release()->replaceWithDistinctImpl());
00856   }
00857 
00858 private:
00859   MDNode *replaceWithPermanentImpl();
00860   MDNode *replaceWithUniquedImpl();
00861   MDNode *replaceWithDistinctImpl();
00862 
00863 protected:
00864   /// \brief Set an operand.
00865   ///
00866   /// Sets the operand directly, without worrying about uniquing.
00867   void setOperand(unsigned I, Metadata *New);
00868 
00869   void storeDistinctInContext();
00870   template <class T, class StoreT>
00871   static T *storeImpl(T *N, StorageType Storage, StoreT &Store);
00872 
00873 private:
00874   void handleChangedOperand(void *Ref, Metadata *New);
00875 
00876   void resolve();
00877   void resolveAfterOperandChange(Metadata *Old, Metadata *New);
00878   void decrementUnresolvedOperandCount();
00879   unsigned countUnresolvedOperands();
00880 
00881   /// \brief Mutate this to be "uniqued".
00882   ///
00883   /// Mutate this so that \a isUniqued().
00884   /// \pre \a isTemporary().
00885   /// \pre already added to uniquing set.
00886   void makeUniqued();
00887 
00888   /// \brief Mutate this to be "distinct".
00889   ///
00890   /// Mutate this so that \a isDistinct().
00891   /// \pre \a isTemporary().
00892   void makeDistinct();
00893 
00894   void deleteAsSubclass();
00895   MDNode *uniquify();
00896   void eraseFromStore();
00897 
00898   template <class NodeTy> struct HasCachedHash;
00899   template <class NodeTy>
00900   static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
00901     N->recalculateHash();
00902   }
00903   template <class NodeTy>
00904   static void dispatchRecalculateHash(NodeTy *N, std::false_type) {}
00905   template <class NodeTy>
00906   static void dispatchResetHash(NodeTy *N, std::true_type) {
00907     N->setHash(0);
00908   }
00909   template <class NodeTy>
00910   static void dispatchResetHash(NodeTy *N, std::false_type) {}
00911 
00912 public:
00913   typedef const MDOperand *op_iterator;
00914   typedef iterator_range<op_iterator> op_range;
00915 
00916   op_iterator op_begin() const {
00917     return const_cast<MDNode *>(this)->mutable_begin();
00918   }
00919   op_iterator op_end() const {
00920     return const_cast<MDNode *>(this)->mutable_end();
00921   }
00922   op_range operands() const { return op_range(op_begin(), op_end()); }
00923 
00924   const MDOperand &getOperand(unsigned I) const {
00925     assert(I < NumOperands && "Out of range");
00926     return op_begin()[I];
00927   }
00928 
00929   /// \brief Return number of MDNode operands.
00930   unsigned getNumOperands() const { return NumOperands; }
00931 
00932   /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
00933   static bool classof(const Metadata *MD) {
00934     switch (MD->getMetadataID()) {
00935     default:
00936       return false;
00937 #define HANDLE_MDNODE_LEAF(CLASS)                                              \
00938   case CLASS##Kind:                                                            \
00939     return true;
00940 #include "llvm/IR/Metadata.def"
00941     }
00942   }
00943 
00944   /// \brief Check whether MDNode is a vtable access.
00945   bool isTBAAVtableAccess() const;
00946 
00947   /// \brief Methods for metadata merging.
00948   static MDNode *concatenate(MDNode *A, MDNode *B);
00949   static MDNode *intersect(MDNode *A, MDNode *B);
00950   static MDNode *getMostGenericTBAA(MDNode *A, MDNode *B);
00951   static MDNode *getMostGenericFPMath(MDNode *A, MDNode *B);
00952   static MDNode *getMostGenericRange(MDNode *A, MDNode *B);
00953   static MDNode *getMostGenericAliasScope(MDNode *A, MDNode *B);
00954 };
00955 
00956 /// \brief Tuple of metadata.
00957 ///
00958 /// This is the simple \a MDNode arbitrary tuple.  Nodes are uniqued by
00959 /// default based on their operands.
00960 class MDTuple : public MDNode {
00961   friend class LLVMContextImpl;
00962   friend class MDNode;
00963 
00964   MDTuple(LLVMContext &C, StorageType Storage, unsigned Hash,
00965           ArrayRef<Metadata *> Vals)
00966       : MDNode(C, MDTupleKind, Storage, Vals) {
00967     setHash(Hash);
00968   }
00969   ~MDTuple() { dropAllReferences(); }
00970 
00971   void setHash(unsigned Hash) { SubclassData32 = Hash; }
00972   void recalculateHash();
00973 
00974   static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
00975                           StorageType Storage, bool ShouldCreate = true);
00976 
00977   TempMDTuple cloneImpl() const {
00978     return getTemporary(getContext(),
00979                         SmallVector<Metadata *, 4>(op_begin(), op_end()));
00980   }
00981 
00982 public:
00983   /// \brief Get the hash, if any.
00984   unsigned getHash() const { return SubclassData32; }
00985 
00986   static MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
00987     return getImpl(Context, MDs, Uniqued);
00988   }
00989   static MDTuple *getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
00990     return getImpl(Context, MDs, Uniqued, /* ShouldCreate */ false);
00991   }
00992 
00993   /// \brief Return a distinct node.
00994   ///
00995   /// Return a distinct node -- i.e., a node that is not uniqued.
00996   static MDTuple *getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
00997     return getImpl(Context, MDs, Distinct);
00998   }
00999 
01000   /// \brief Return a temporary node.
01001   ///
01002   /// For use in constructing cyclic MDNode structures. A temporary MDNode is
01003   /// not uniqued, may be RAUW'd, and must be manually deleted with
01004   /// deleteTemporary.
01005   static TempMDTuple getTemporary(LLVMContext &Context,
01006                                   ArrayRef<Metadata *> MDs) {
01007     return TempMDTuple(getImpl(Context, MDs, Temporary));
01008   }
01009 
01010   /// \brief Return a (temporary) clone of this.
01011   TempMDTuple clone() const { return cloneImpl(); }
01012 
01013   static bool classof(const Metadata *MD) {
01014     return MD->getMetadataID() == MDTupleKind;
01015   }
01016 };
01017 
01018 MDTuple *MDNode::get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
01019   return MDTuple::get(Context, MDs);
01020 }
01021 MDTuple *MDNode::getIfExists(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
01022   return MDTuple::getIfExists(Context, MDs);
01023 }
01024 MDTuple *MDNode::getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
01025   return MDTuple::getDistinct(Context, MDs);
01026 }
01027 TempMDTuple MDNode::getTemporary(LLVMContext &Context,
01028                                  ArrayRef<Metadata *> MDs) {
01029   return MDTuple::getTemporary(Context, MDs);
01030 }
01031 
01032 void TempMDNodeDeleter::operator()(MDNode *Node) const {
01033   MDNode::deleteTemporary(Node);
01034 }
01035 
01036 /// \brief Typed iterator through MDNode operands.
01037 ///
01038 /// An iterator that transforms an \a MDNode::iterator into an iterator over a
01039 /// particular Metadata subclass.
01040 template <class T>
01041 class TypedMDOperandIterator
01042     : std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void, T *> {
01043   MDNode::op_iterator I = nullptr;
01044 
01045 public:
01046   TypedMDOperandIterator() = default;
01047   explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
01048   T *operator*() const { return cast_or_null<T>(*I); }
01049   TypedMDOperandIterator &operator++() {
01050     ++I;
01051     return *this;
01052   }
01053   TypedMDOperandIterator operator++(int) {
01054     TypedMDOperandIterator Temp(*this);
01055     ++I;
01056     return Temp;
01057   }
01058   bool operator==(const TypedMDOperandIterator &X) const { return I == X.I; }
01059   bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
01060 };
01061 
01062 /// \brief Typed, array-like tuple of metadata.
01063 ///
01064 /// This is a wrapper for \a MDTuple that makes it act like an array holding a
01065 /// particular type of metadata.
01066 template <class T> class MDTupleTypedArrayWrapper {
01067   const MDTuple *N = nullptr;
01068 
01069 public:
01070   MDTupleTypedArrayWrapper() = default;
01071   MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
01072 
01073   template <class U>
01074   MDTupleTypedArrayWrapper(
01075       const MDTupleTypedArrayWrapper<U> &Other,
01076       typename std::enable_if<std::is_convertible<U *, T *>::value>::type * =
01077           nullptr)
01078       : N(Other.get()) {}
01079 
01080   template <class U>
01081   explicit MDTupleTypedArrayWrapper(
01082       const MDTupleTypedArrayWrapper<U> &Other,
01083       typename std::enable_if<!std::is_convertible<U *, T *>::value>::type * =
01084           nullptr)
01085       : N(Other.get()) {}
01086 
01087   explicit operator bool() const { return get(); }
01088   explicit operator MDTuple *() const { return get(); }
01089 
01090   MDTuple *get() const { return const_cast<MDTuple *>(N); }
01091   MDTuple *operator->() const { return get(); }
01092   MDTuple &operator*() const { return *get(); }
01093 
01094   // FIXME: Fix callers and remove condition on N.
01095   unsigned size() const { return N ? N->getNumOperands() : 0u; }
01096   T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); }
01097 
01098   // FIXME: Fix callers and remove condition on N.
01099   typedef TypedMDOperandIterator<T> iterator;
01100   iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
01101   iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
01102 };
01103 
01104 #define HANDLE_METADATA(CLASS)                                                 \
01105   typedef MDTupleTypedArrayWrapper<CLASS> CLASS##Array;
01106 #include "llvm/IR/Metadata.def"
01107 
01108 //===----------------------------------------------------------------------===//
01109 /// \brief A tuple of MDNodes.
01110 ///
01111 /// Despite its name, a NamedMDNode isn't itself an MDNode. NamedMDNodes belong
01112 /// to modules, have names, and contain lists of MDNodes.
01113 ///
01114 /// TODO: Inherit from Metadata.
01115 class NamedMDNode : public ilist_node<NamedMDNode> {
01116   friend class SymbolTableListTraits<NamedMDNode, Module>;
01117   friend struct ilist_traits<NamedMDNode>;
01118   friend class LLVMContextImpl;
01119   friend class Module;
01120   NamedMDNode(const NamedMDNode &) = delete;
01121 
01122   std::string Name;
01123   Module *Parent;
01124   void *Operands; // SmallVector<TrackingMDRef, 4>
01125 
01126   void setParent(Module *M) { Parent = M; }
01127 
01128   explicit NamedMDNode(const Twine &N);
01129 
01130   template<class T1, class T2>
01131   class op_iterator_impl :
01132       public std::iterator<std::bidirectional_iterator_tag, T2> {
01133     const NamedMDNode *Node;
01134     unsigned Idx;
01135     op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) { }
01136 
01137     friend class NamedMDNode;
01138 
01139   public:
01140     op_iterator_impl() : Node(nullptr), Idx(0) { }
01141 
01142     bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; }
01143     bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
01144     op_iterator_impl &operator++() {
01145       ++Idx;
01146       return *this;
01147     }
01148     op_iterator_impl operator++(int) {
01149       op_iterator_impl tmp(*this);
01150       operator++();
01151       return tmp;
01152     }
01153     op_iterator_impl &operator--() {
01154       --Idx;
01155       return *this;
01156     }
01157     op_iterator_impl operator--(int) {
01158       op_iterator_impl tmp(*this);
01159       operator--();
01160       return tmp;
01161     }
01162 
01163     T1 operator*() const { return Node->getOperand(Idx); }
01164   };
01165 
01166 public:
01167   /// \brief Drop all references and remove the node from parent module.
01168   void eraseFromParent();
01169 
01170   /// \brief Remove all uses and clear node vector.
01171   void dropAllReferences();
01172 
01173   ~NamedMDNode();
01174 
01175   /// \brief Get the module that holds this named metadata collection.
01176   inline Module *getParent() { return Parent; }
01177   inline const Module *getParent() const { return Parent; }
01178 
01179   MDNode *getOperand(unsigned i) const;
01180   unsigned getNumOperands() const;
01181   void addOperand(MDNode *M);
01182   void setOperand(unsigned I, MDNode *New);
01183   StringRef getName() const;
01184   void print(raw_ostream &ROS) const;
01185   void dump() const;
01186 
01187   // ---------------------------------------------------------------------------
01188   // Operand Iterator interface...
01189   //
01190   typedef op_iterator_impl<MDNode *, MDNode> op_iterator;
01191   op_iterator op_begin() { return op_iterator(this, 0); }
01192   op_iterator op_end()   { return op_iterator(this, getNumOperands()); }
01193 
01194   typedef op_iterator_impl<const MDNode *, MDNode> const_op_iterator;
01195   const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
01196   const_op_iterator op_end()   const { return const_op_iterator(this, getNumOperands()); }
01197 
01198   inline iterator_range<op_iterator>  operands() {
01199     return iterator_range<op_iterator>(op_begin(), op_end());
01200   }
01201   inline iterator_range<const_op_iterator> operands() const {
01202     return iterator_range<const_op_iterator>(op_begin(), op_end());
01203   }
01204 };
01205 
01206 } // end llvm namespace
01207 
01208 #endif