LLVM 22.0.0git
|
Transitional API for extracting constants from Metadata. More...
Namespaces | |
namespace | detail |
Functions | |
template<class X, class Y> | |
std::enable_if_t< detail::IsValidPointer< X, Y >::value, bool > | hasa (Y &&MD) |
Check whether Metadata has a Value. | |
template<class X, class Y> | |
std::enable_if_t< detail::IsValidReference< X, Y & >::value, bool > | hasa (Y &MD) |
template<class X, class Y> | |
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > | extract (Y &&MD) |
Extract a Value from Metadata. | |
template<class X, class Y> | |
std::enable_if_t< detail::IsValidReference< X, Y & >::value, X * > | extract (Y &MD) |
template<class X, class Y> | |
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > | extract_or_null (Y &&MD) |
Extract a Value from Metadata, allowing null. | |
template<class X, class Y> | |
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > | dyn_extract (Y &&MD) |
Extract a Value from Metadata, if any. | |
template<class X, class Y> | |
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > | dyn_extract_or_null (Y &&MD) |
Extract a Value from Metadata, if any, allowing null. |
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 Value – MDNode operands could refer to any Value. There's was a lot of code like this:
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:
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:
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.
|
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 694 of file Metadata.h.
References llvm::dyn_cast(), and Y.
Referenced by llvm::memprof::CallStackTrie::addCallStack(), llvm::buildOpSpirvDecorations(), llvm::cacheAnnotationFromMD(), computeFunctionSummary(), llvm::TargetLoweringObjectFileELF::emitModuleMetadata(), llvm::hlsl::rootsig::extractMdFloatValue(), extractMdIntValue(), llvm::hlsl::rootsig::extractMdIntValue(), llvm::extractProfTotalWeight(), llvm::getAlign(), llvm::DOTGraphTraits< DOTFuncInfo * >::getEdgeAttributes(), GetFunctionFromMDNode(), getLocCookie(), llvm::getValueProfDataFromInst(), haveCommonPrefix(), insertSpirvDecorations(), IsScalarTBAANodeImpl(), llvm::mayHaveValueProfileOfKind(), llvm::PseudoProbeManager::PseudoProbeManager(), llvm::AMDGPUPALMetadata::readFromIR(), saveFilteredNewMIBNodes(), and llvm::scaleProfData().
|
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 707 of file Metadata.h.
References llvm::dyn_cast(), llvm::dyn_cast_or_null(), and Y.
Referenced by llvm::cacheAnnotationFromMD(), llvm::getDebugMetadataVersionFromModule(), llvm::UpgradeDebugInfo(), llvm::UpgradeModuleFlags(), llvm::UpgradeNVVMAnnotations(), and llvm::TBAAVerifier::visitTBAAMetadata().
|
inline |
Extract a Value from Metadata.
As an analogue to cast(), extract the Value subclass X
from MD
.
Definition at line 666 of file Metadata.h.
References llvm::cast(), and Y.
Referenced by llvm::AAMDNodes::adjustForAccess(), collectMetadataInfo(), llvm::computeKnownBitsFromRangeMetadata(), llvm::MDBuilder::createMutableTBAAAccessTag(), llvm::diagnoseDontCall(), llvm::MachineInstr::emitInlineAsmError(), llvm::AsmPrinter::emitKCFITypeId(), llvm::X86AsmPrinter::emitKCFITypeId(), llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::emitKernelAttrs(), llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::emitKernelLanguage(), llvm::TargetLoweringObjectFile::emitPseudoProbeDescMetadata(), llvm::AAMDNodes::extendToTBAA(), llvm::extractProfTotalWeight(), llvm::getConstantRangeFromMetadata(), llvm::FPMathOperator::getFPAccuracy(), llvm::AMDGPUMachineFunction::getLDSKernelIdMetadata(), llvm::SelectionDAG::getLoad(), llvm::RISCVELFTargetObjectFile::getModuleMetadata(), llvm::MDNode::getMostGenericAlignmentOrDereferenceable(), llvm::MDNode::getMostGenericFPMath(), llvm::MDNode::getMostGenericNoaliasAddrspace(), llvm::MDNode::getMostGenericRange(), GetObjCImageInfo(), llvm::AMDGPUSubtarget::getReqdWorkGroupSize(), llvm::SwitchInstProfUpdateWrapper::getSuccessorWeight(), llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::getWorkGroupDimensions(), handleValVerMetadata(), llvm::AMDGPU::hasValueInRangeLikeMetadata(), llvm::AMDGPUSubtarget::hasWavefrontsEvenlySplittingXDim(), processUse(), rangeMetadataExcludesValue(), setUnsafeStackSize(), llvm::AAMDNodes::shiftTBAAStruct(), translateBranchMetadata(), unrollAndJamCountPragmaValue(), unrollCountPragmaValue(), upgradeNVVMFnVectorAttr(), and upgradeSingleNVVMAnnotation().
|
inline |
Definition at line 671 of file Metadata.h.
|
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 681 of file Metadata.h.
References llvm::cast(), llvm::cast_or_null(), and Y.
Referenced by llvm::AArch64FunctionInfo::AArch64FunctionInfo(), llvm::addStringMetadataToLoop(), llvm::CodeViewDebug::beginModule(), llvm::buildModuleSummaryIndex(), computeFunctionSummary(), llvm::AsmPrinter::doInitialization(), llvm::AMDGPU::getAMDHSACodeObjectVersion(), llvm::getOptionalBoolLoopAttribute(), llvm::getOptionalIntLoopAttribute(), getProductPatch(), getProductRelease(), getProductVersion(), getTranslationTime(), llvm::AMDGPUTTIImpl::getUnrollingPreferences(), hasELFSignedGOTHelper(), llvm::dxil::ModuleShaderFlags::initialize(), llvm::lowertypetests::isJumpTableCanonical(), llvm::MachineModuleInfoELF::MachineModuleInfoELF(), llvm::RISCVMachineFunctionInfo::RISCVMachineFunctionInfo(), and llvm::setKCFIType().
|
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 649 of file Metadata.h.
References assert(), llvm::dyn_cast(), llvm::isa(), and Y.
Referenced by llvm::AAMDNodes::adjustForAccess(), llvm::MachineInstr::getLocCookieMD(), and hasa().