LLVM  8.0.1
Namespaces | Functions
llvm::mdconst Namespace Reference

Transitional API for extracting constants from Metadata. More...

Namespaces

 detail
 

Functions

template<class X , class Y >
std::enable_if< detail::IsValidPointer< X, Y >::value, bool >::type hasa (Y &&MD)
 Check whether Metadata has a Value. More...
 
template<class X , class Y >
std::enable_if< detail::IsValidReference< X, Y & >::value, bool >::type hasa (Y &MD)
 
template<class X , class Y >
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type extract (Y &&MD)
 Extract a Value from Metadata. More...
 
template<class X , class Y >
std::enable_if< detail::IsValidReference< X, Y & >::value, X * >::type extract (Y &MD)
 
template<class X , class Y >
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type extract_or_null (Y &&MD)
 Extract a Value from Metadata, allowing null. More...
 
template<class X , class Y >
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type dyn_extract (Y &&MD)
 Extract a Value from Metadata, if any. More...
 
template<class X , class Y >
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type dyn_extract_or_null (Y &&MD)
 Extract a Value from Metadata, if any, allowing null. More...
 

Detailed Description

Transitional API for extracting constants from Metadata.

This namespace contains transitional functions for metadata that points to Constants.

In prehistory – when metadata was a subclass of ValueMDNode operands could refer to any Value. There's was a lot of code like this:

MDNode *N = ...;
auto *CI = dyn_cast<ConstantInt>(N->getOperand(2));

Now that Value and Metadata are in separate hierarchies, maintaining the semantics for isa(), cast(), dyn_cast() (etc.) requires three steps: cast in the Metadata hierarchy, extraction of the Value, and cast in the Value hierarchy. Besides creating boiler-plate, this requires subtle control flow changes.

The end-goal is to create a new type of metadata, called (e.g.) MDInt, so that metadata can refer to numbers without traversing a bridge to the Value hierarchy. In this final state, the code above would look like this:

MDNode *N = ...;
auto *MI = dyn_cast<MDInt>(N->getOperand(2));

The API in this namespace supports the transition. MDInt doesn't exist yet, and even once it does, changing each metadata schema to use it is its own mini-project. In the meantime this API prevents us from introducing complex and bug-prone control flow that will disappear in the end. In particular, the above code looks like this:

MDNode *N = ...;
auto *CI = mdconst::dyn_extract<ConstantInt>(N->getOperand(2));

The full set of provided functions includes:

mdconst::hasa <=> isa mdconst::extract <=> cast mdconst::extract_or_null <=> cast_or_null mdconst::dyn_extract <=> dyn_cast mdconst::dyn_extract_or_null <=> dyn_cast_or_null

The target of the cast must be a subclass of Constant.

Function Documentation

◆ dyn_extract()

template<class X , class Y >
std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type llvm::mdconst::dyn_extract ( Y &&  MD)
inline

Extract a Value from Metadata, if any.

As an analogue to dyn_cast_or_null(), extract the Value subclass X from MD, return null if MD doesn't contain a Value or if the Value it does contain is of the wrong subclass.

Definition at line 578 of file Metadata.h.

References llvm::dyn_cast(), and X.

◆ dyn_extract_or_null()

template<class X , class Y >
std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type llvm::mdconst::dyn_extract_or_null ( Y &&  MD)
inline

Extract a Value from Metadata, if any, allowing null.

As an analogue to dyn_cast_or_null(), extract the Value subclass X from MD, return null if MD doesn't contain a Value or if the Value it does contain is of the wrong subclass, allowing MD to be null.

Definition at line 591 of file Metadata.h.

References llvm::dyn_cast(), and X.

◆ extract() [1/2]

template<class X , class Y >
std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type llvm::mdconst::extract ( Y &&  MD)
inline

Extract a Value from Metadata.

As an analogue to cast(), extract the Value subclass X from MD.

Definition at line 549 of file Metadata.h.

References X.

◆ extract() [2/2]

template<class X , class Y >
std::enable_if<detail::IsValidReference<X, Y &>::value, X *>::type llvm::mdconst::extract ( Y MD)
inline

Definition at line 555 of file Metadata.h.

References extract, and X.

◆ extract_or_null()

template<class X , class Y >
std::enable_if<detail::IsValidPointer<X, Y>::value, X *>::type llvm::mdconst::extract_or_null ( Y &&  MD)
inline

Extract a Value from Metadata, allowing null.

As an analogue to cast_or_null(), extract the Value subclass X from MD, allowing MD to be null.

Definition at line 565 of file Metadata.h.

References X.

◆ hasa() [1/2]

template<class X , class Y >
std::enable_if<detail::IsValidPointer<X, Y>::value, bool>::type llvm::mdconst::hasa ( Y &&  MD)
inline

Check whether Metadata has a Value.

As an analogue to isa(), check whether MD has an Value inside of type X.

Definition at line 531 of file Metadata.h.

References assert().

◆ hasa() [2/2]

template<class X , class Y >
std::enable_if<detail::IsValidReference<X, Y &>::value, bool>::type llvm::mdconst::hasa ( Y MD)
inline

Definition at line 540 of file Metadata.h.

References X.