llvm/llvm/lib/IR/Metadata.cpp

//===- Metadata.cpp - Implement Metadata classes --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the Metadata classes.
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/Metadata.h"
#include "LLVMContextImpl.h"
#include "MetadataImpl.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DebugProgramInstruction.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalObject.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/TrackingMDRef.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>
#include <vector>

usingnamespacellvm;

MetadataAsValue::MetadataAsValue(Type *Ty, Metadata *MD)
    :{}

MetadataAsValue::~MetadataAsValue() {}

/// Canonicalize metadata arguments to intrinsics.
///
/// To support bitcode upgrades (and assembly semantic sugar) for \a
/// MetadataAsValue, we need to canonicalize certain metadata.
///
///   - nullptr is replaced by an empty MDNode.
///   - An MDNode with a single null operand is replaced by an empty MDNode.
///   - An MDNode whose only operand is a \a ConstantAsMetadata gets skipped.
///
/// This maintains readability of bitcode from when metadata was a type of
/// value, and these bridges were unnecessary.
static Metadata *canonicalizeMetadataForValue(LLVMContext &Context,
                                              Metadata *MD) {}

MetadataAsValue *MetadataAsValue::get(LLVMContext &Context, Metadata *MD) {}

MetadataAsValue *MetadataAsValue::getIfExists(LLVMContext &Context,
                                              Metadata *MD) {}

void MetadataAsValue::handleChangedMetadata(Metadata *MD) {}

void MetadataAsValue::track() {}

void MetadataAsValue::untrack() {}

DbgVariableRecord *DebugValueUser::getUser() {}
const DbgVariableRecord *DebugValueUser::getUser() const {}

void DebugValueUser::handleChangedValue(void *Old, Metadata *New) {}

void DebugValueUser::trackDebugValue(size_t Idx) {}

void DebugValueUser::trackDebugValues() {}

void DebugValueUser::untrackDebugValue(size_t Idx) {}

void DebugValueUser::untrackDebugValues() {}

void DebugValueUser::retrackDebugValues(DebugValueUser &X) {}

bool MetadataTracking::track(void *Ref, Metadata &MD, OwnerTy Owner) {}

void MetadataTracking::untrack(void *Ref, Metadata &MD) {}

bool MetadataTracking::retrack(void *Ref, Metadata &MD, void *New) {}

bool MetadataTracking::isReplaceable(const Metadata &MD) {}

SmallVector<Metadata *> ReplaceableMetadataImpl::getAllArgListUsers() {}

SmallVector<DbgVariableRecord *>
ReplaceableMetadataImpl::getAllDbgVariableRecordUsers() {}

void ReplaceableMetadataImpl::addRef(void *Ref, OwnerTy Owner) {}

void ReplaceableMetadataImpl::dropRef(void *Ref) {}

void ReplaceableMetadataImpl::moveRef(void *Ref, void *New,
                                      const Metadata &MD) {}

void ReplaceableMetadataImpl::SalvageDebugInfo(const Constant &C) {}

void ReplaceableMetadataImpl::replaceAllUsesWith(Metadata *MD) {}

void ReplaceableMetadataImpl::resolveAllUses(bool ResolveUsers) {}

// Special handing of DIArgList is required in the RemoveDIs project, see
// commentry in DIArgList::handleChangedOperand for details. Hidden behind
// conditional compilation to avoid a compile time regression.
ReplaceableMetadataImpl *ReplaceableMetadataImpl::getOrCreate(Metadata &MD) {}

ReplaceableMetadataImpl *ReplaceableMetadataImpl::getIfExists(Metadata &MD) {}

bool ReplaceableMetadataImpl::isReplaceable(const Metadata &MD) {}

static DISubprogram *getLocalFunctionMetadata(Value *V) {}

ValueAsMetadata *ValueAsMetadata::get(Value *V) {}

ValueAsMetadata *ValueAsMetadata::getIfExists(Value *V) {}

void ValueAsMetadata::handleDeletion(Value *V) {}

void ValueAsMetadata::handleRAUW(Value *From, Value *To) {}

//===----------------------------------------------------------------------===//
// MDString implementation.
//

MDString *MDString::get(LLVMContext &Context, StringRef Str) {}

StringRef MDString::getString() const {}

//===----------------------------------------------------------------------===//
// MDNode implementation.
//

// Assert that the MDNode types will not be unaligned by the objects
// prepended to them.
#define HANDLE_MDNODE_LEAF
#include "llvm/IR/Metadata.def"

void *MDNode::operator new(size_t Size, size_t NumOps, StorageType Storage) {}

void MDNode::operator delete(void *N) {}

MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
               ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2)
    :{}

TempMDNode MDNode::clone() const {}

MDNode::Header::Header(size_t NumOps, StorageType Storage) {}

MDNode::Header::~Header() {}

void *MDNode::Header::getSmallPtr() {}

void MDNode::Header::resize(size_t NumOps) {}

void MDNode::Header::resizeSmall(size_t NumOps) {}

void MDNode::Header::resizeSmallToLarge(size_t NumOps) {}

static bool isOperandUnresolved(Metadata *Op) {}

void MDNode::countUnresolvedOperands() {}

void MDNode::makeUniqued() {}

void MDNode::makeDistinct() {}

void MDNode::resolve() {}

void MDNode::dropReplaceableUses() {}

void MDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) {}

void MDNode::decrementUnresolvedOperandCount() {}

void MDNode::resolveCycles() {}

static bool hasSelfReference(MDNode *N) {}

MDNode *MDNode::replaceWithPermanentImpl() {}

MDNode *MDNode::replaceWithUniquedImpl() {}

MDNode *MDNode::replaceWithDistinctImpl() {}

void MDTuple::recalculateHash() {}

void MDNode::dropAllReferences() {}

void MDNode::handleChangedOperand(void *Ref, Metadata *New) {}

void MDNode::deleteAsSubclass() {}

template <class T, class InfoT>
static T *uniquifyImpl(T *N, DenseSet<T *, InfoT> &Store) {}

template <class NodeTy> struct MDNode::HasCachedHash {};

MDNode *MDNode::uniquify() {}

void MDNode::eraseFromStore() {}

MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
                          StorageType Storage, bool ShouldCreate) {}

void MDNode::deleteTemporary(MDNode *N) {}

void MDNode::storeDistinctInContext() {}

void MDNode::replaceOperandWith(unsigned I, Metadata *New) {}

void MDNode::setOperand(unsigned I, Metadata *New) {}

/// Get a node or a self-reference that looks like it.
///
/// Special handling for finding self-references, for use by \a
/// MDNode::concatenate() and \a MDNode::intersect() to maintain behaviour from
/// when self-referencing nodes were still uniqued.  If the first operand has
/// the same operands as \c Ops, return the first operand instead.
static MDNode *getOrSelfReference(LLVMContext &Context,
                                  ArrayRef<Metadata *> Ops) {}

MDNode *MDNode::concatenate(MDNode *A, MDNode *B) {}

MDNode *MDNode::intersect(MDNode *A, MDNode *B) {}

MDNode *MDNode::getMostGenericAliasScope(MDNode *A, MDNode *B) {}

MDNode *MDNode::getMostGenericFPMath(MDNode *A, MDNode *B) {}

// Call instructions with branch weights are only used in SamplePGO as
// documented in
/// https://llvm.org/docs/BranchWeightMetadata.html#callinst).
MDNode *MDNode::mergeDirectCallProfMetadata(MDNode *A, MDNode *B,
                                            const Instruction *AInstr,
                                            const Instruction *BInstr) {}

// Pass in both instructions and nodes. Instruction information (e.g.,
// instruction type) helps interpret profiles and make implementation clearer.
MDNode *MDNode::getMergedProfMetadata(MDNode *A, MDNode *B,
                                      const Instruction *AInstr,
                                      const Instruction *BInstr) {}

static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {}

static bool canBeMerged(const ConstantRange &A, const ConstantRange &B) {}

static bool tryMergeRange(SmallVectorImpl<ConstantInt *> &EndPoints,
                          ConstantInt *Low, ConstantInt *High) {}

static void addRange(SmallVectorImpl<ConstantInt *> &EndPoints,
                     ConstantInt *Low, ConstantInt *High) {}

MDNode *MDNode::getMostGenericRange(MDNode *A, MDNode *B) {}

MDNode *MDNode::getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B) {}

//===----------------------------------------------------------------------===//
// NamedMDNode implementation.
//

static SmallVector<TrackingMDRef, 4> &getNMDOps(void *Operands) {}

NamedMDNode::NamedMDNode(const Twine &N)
    :{}

NamedMDNode::~NamedMDNode() {}

unsigned NamedMDNode::getNumOperands() const {}

MDNode *NamedMDNode::getOperand(unsigned i) const {}

void NamedMDNode::addOperand(MDNode *M) {}

void NamedMDNode::setOperand(unsigned I, MDNode *New) {}

void NamedMDNode::eraseFromParent() {}

void NamedMDNode::clearOperands() {}

StringRef NamedMDNode::getName() const {}

//===----------------------------------------------------------------------===//
// Instruction Metadata method implementations.
//

MDNode *MDAttachments::lookup(unsigned ID) const {}

void MDAttachments::get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const {}

void MDAttachments::getAll(
    SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {}

void MDAttachments::set(unsigned ID, MDNode *MD) {}

void MDAttachments::insert(unsigned ID, MDNode &MD) {}

bool MDAttachments::erase(unsigned ID) {}

MDNode *Value::getMetadata(StringRef Kind) const {}

MDNode *Value::getMetadataImpl(unsigned KindID) const {}

void Value::getMetadata(unsigned KindID, SmallVectorImpl<MDNode *> &MDs) const {}

void Value::getMetadata(StringRef Kind, SmallVectorImpl<MDNode *> &MDs) const {}

void Value::getAllMetadata(
    SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {}

void Value::setMetadata(unsigned KindID, MDNode *Node) {}

void Value::setMetadata(StringRef Kind, MDNode *Node) {}

void Value::addMetadata(unsigned KindID, MDNode &MD) {}

void Value::addMetadata(StringRef Kind, MDNode &MD) {}

bool Value::eraseMetadata(unsigned KindID) {}

void Value::eraseMetadataIf(function_ref<bool(unsigned, MDNode *)> Pred) {}

void Value::clearMetadata() {}

void Instruction::setMetadata(StringRef Kind, MDNode *Node) {}

MDNode *Instruction::getMetadataImpl(StringRef Kind) const {}

void Instruction::eraseMetadataIf(function_ref<bool(unsigned, MDNode *)> Pred) {}

void Instruction::dropUnknownNonDebugMetadata(ArrayRef<unsigned> KnownIDs) {}

void Instruction::updateDIAssignIDMapping(DIAssignID *ID) {}

void Instruction::setMetadata(unsigned KindID, MDNode *Node) {}

void Instruction::addAnnotationMetadata(SmallVector<StringRef> Annotations) {}

void Instruction::addAnnotationMetadata(StringRef Name) {}

AAMDNodes Instruction::getAAMetadata() const {}

void Instruction::setAAMetadata(const AAMDNodes &N) {}

void Instruction::setNoSanitizeMetadata() {}

void Instruction::getAllMetadataImpl(
    SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {}

bool Instruction::extractProfTotalWeight(uint64_t &TotalVal) const {}

void GlobalObject::copyMetadata(const GlobalObject *Other, unsigned Offset) {}

void GlobalObject::addTypeMetadata(unsigned Offset, Metadata *TypeID) {}

void GlobalObject::setVCallVisibilityMetadata(VCallVisibility Visibility) {}

GlobalObject::VCallVisibility GlobalObject::getVCallVisibility() const {}

void Function::setSubprogram(DISubprogram *SP) {}

DISubprogram *Function::getSubprogram() const {}

bool Function::shouldEmitDebugInfoForProfiling() const {}

void GlobalVariable::addDebugInfo(DIGlobalVariableExpression *GV) {}

void GlobalVariable::getDebugInfo(
    SmallVectorImpl<DIGlobalVariableExpression *> &GVs) const {}