/// getMetadata - Get the metadata of given kind attached to this Instruction.
/// If the metadata is not found then return null.
- MDNode *getMetadata(unsigned KindID) const {
+ Value *getMetadata(unsigned KindID) const {
if (!hasMetadata()) return nullptr;
return getMetadataImpl(KindID);
}
/// getMetadata - Get the metadata of given kind attached to this Instruction.
/// If the metadata is not found then return null.
- MDNode *getMetadata(StringRef Kind) const {
+ Value *getMetadata(StringRef Kind) const {
if (!hasMetadata()) return nullptr;
return getMetadataImpl(Kind);
}
}
// These are all implemented in Metadata.cpp.
- MDNode *getMetadataImpl(unsigned KindID) const;
- MDNode *getMetadataImpl(StringRef Kind) const;
+ Value *getMetadataImpl(unsigned KindID) const;
+ Value *getMetadataImpl(StringRef Kind) const;
MDNode *getMDNodeImpl(unsigned KindID) const;
MDNode *getMDNodeImpl(StringRef Kind) const;
void getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,MDNode*> > &)const;
if (!isa<BranchInst>(TI) && !isa<SwitchInst>(TI))
return false;
- MDNode *WeightsNode = TI->getMetadata(LLVMContext::MD_prof);
+ MDNode *WeightsNode = TI->getMDNode(LLVMContext::MD_prof);
if (!WeightsNode)
return false;
MDNode *Loop::getLoopID() const {
MDNode *LoopID = nullptr;
if (isLoopSimplifyForm()) {
- LoopID = getLoopLatch()->getTerminator()->getMetadata(LoopMDName);
+ LoopID = getLoopLatch()->getTerminator()->getMDNode(LoopMDName);
} else {
// Go through each predecessor of the loop header and check the
// terminator for the metadata.
// Check if this terminator branches to the loop header.
for (unsigned i = 0, ie = TI->getNumSuccessors(); i != ie; ++i) {
if (TI->getSuccessor(i) == H) {
- MD = TI->getMetadata(LoopMDName);
+ MD = TI->getMDNode(LoopMDName);
break;
}
}
// nested parallel loops). The loop identifier metadata refers to
// itself so we can check both cases with the same routine.
MDNode *loopIdMD =
- II->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
+ II->getMDNode(LLVMContext::MD_mem_parallel_loop_access);
if (!loopIdMD)
return false;
/// metadata present in the IR.
static Optional<ConstantRange> GetRangeFromMetadata(Value *V) {
if (Instruction *I = dyn_cast<Instruction>(V)) {
- if (MDNode *MD = I->getMetadata(LLVMContext::MD_range)) {
+ if (MDNode *MD = I->getMDNode(LLVMContext::MD_range)) {
ConstantRange TotalRange(
cast<IntegerType>(I->getType())->getBitWidth(), false);
if (!EnableScopedNoAlias)
return AliasAnalysis::getModRefInfo(CS, Loc);
- if (!mayAliasInScopes(Loc.AATags.Scope,
- CS.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
+ if (!mayAliasInScopes(Loc.AATags.Scope, CS.getInstruction()->getMDNode(
+ LLVMContext::MD_noalias)))
return NoModRef;
if (!mayAliasInScopes(
- CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
- Loc.AATags.NoAlias))
+ CS.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
+ Loc.AATags.NoAlias))
return NoModRef;
return AliasAnalysis::getModRefInfo(CS, Loc);
return AliasAnalysis::getModRefInfo(CS1, CS2);
if (!mayAliasInScopes(
- CS1.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
- CS2.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
+ CS1.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
+ CS2.getInstruction()->getMDNode(LLVMContext::MD_noalias)))
return NoModRef;
if (!mayAliasInScopes(
- CS2.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
- CS1.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
+ CS2.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
+ CS1.getInstruction()->getMDNode(LLVMContext::MD_noalias)))
return NoModRef;
return AliasAnalysis::getModRefInfo(CS1, CS2);
// If this is an "immutable" type, we can assume the call doesn't write
// to memory.
- if (const MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
+ if (const MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
if ((!isStructPathTBAA(M) && TBAANode(M).TypeIsImmutable()) ||
(isStructPathTBAA(M) && TBAAStructTagNode(M).TypeIsImmutable()))
Min = OnlyReadsMemory;
return AliasAnalysis::getModRefInfo(CS, Loc);
if (const MDNode *L = Loc.AATags.TBAA)
- if (const MDNode *M =
- CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
+ if (const MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
if (!Aliases(L, M))
return NoModRef;
if (!EnableTBAA)
return AliasAnalysis::getModRefInfo(CS1, CS2);
- if (const MDNode *M1 =
- CS1.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
+ if (const MDNode *M1 = CS1.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
if (const MDNode *M2 =
- CS2.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
+ CS2.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
if (!Aliases(M1, M2))
return NoModRef;
void Instruction::getAAMetadata(AAMDNodes &N, bool Merge) const {
if (Merge)
- N.TBAA = MDNode::getMostGenericTBAA(N.TBAA,
- getMetadata(LLVMContext::MD_tbaa));
+ N.TBAA =
+ MDNode::getMostGenericTBAA(N.TBAA, getMDNode(LLVMContext::MD_tbaa));
else
- N.TBAA = getMetadata(LLVMContext::MD_tbaa);
+ N.TBAA = getMDNode(LLVMContext::MD_tbaa);
if (Merge)
- N.Scope = MDNode::intersect(N.Scope,
- getMetadata(LLVMContext::MD_alias_scope));
+ N.Scope =
+ MDNode::intersect(N.Scope, getMDNode(LLVMContext::MD_alias_scope));
else
- N.Scope = getMetadata(LLVMContext::MD_alias_scope);
+ N.Scope = getMDNode(LLVMContext::MD_alias_scope);
if (Merge)
- N.NoAlias = MDNode::intersect(N.NoAlias,
- getMetadata(LLVMContext::MD_noalias));
+ N.NoAlias =
+ MDNode::intersect(N.NoAlias, getMDNode(LLVMContext::MD_noalias));
else
- N.NoAlias = getMetadata(LLVMContext::MD_noalias);
+ N.NoAlias = getMDNode(LLVMContext::MD_noalias);
}
switch (I->getOpcode()) {
default: break;
case Instruction::Load:
- if (MDNode *MD = cast<LoadInst>(I)->getMetadata(LLVMContext::MD_range))
+ if (MDNode *MD = cast<LoadInst>(I)->getMDNode(LLVMContext::MD_range))
computeKnownBitsFromRangeMetadata(*MD, KnownZero);
break;
case Instruction::And: {
}
case Instruction::Call:
case Instruction::Invoke:
- if (MDNode *MD = cast<Instruction>(I)->getMetadata(LLVMContext::MD_range))
+ if (MDNode *MD = cast<Instruction>(I)->getMDNode(LLVMContext::MD_range))
computeKnownBitsFromRangeMetadata(*MD, KnownZero);
// If a range metadata is attached to this IntrinsicInst, intersect the
// explicit range specified by the metadata and the implicit range of
}
if (Instruction* I = dyn_cast<Instruction>(V)) {
- if (MDNode *Ranges = I->getMetadata(LLVMContext::MD_range)) {
+ if (MDNode *Ranges = I->getMDNode(LLVMContext::MD_range)) {
// If the possible ranges don't contain zero, then the value is
// definitely non-zero.
if (IntegerType* Ty = dyn_cast<IntegerType>(V->getType())) {
} else
return nullptr;
- bool IsNonTemporal = I->getMetadata(LLVMContext::MD_nontemporal) != nullptr;
- bool IsInvariant = I->getMetadata(LLVMContext::MD_invariant_load) != nullptr;
- const MDNode *Ranges = I->getMetadata(LLVMContext::MD_range);
+ bool IsNonTemporal = I->getMDNode(LLVMContext::MD_nontemporal) != nullptr;
+ bool IsInvariant = I->getMDNode(LLVMContext::MD_invariant_load) != nullptr;
+ const MDNode *Ranges = I->getMDNode(LLVMContext::MD_range);
AAMDNodes AAInfo;
I->getAAMetadata(AAInfo);
Type *Ty = I.getType();
bool isVolatile = I.isVolatile();
- bool isNonTemporal = I.getMetadata(LLVMContext::MD_nontemporal) != nullptr;
- bool isInvariant = I.getMetadata(LLVMContext::MD_invariant_load) != nullptr;
+ bool isNonTemporal = I.getMDNode(LLVMContext::MD_nontemporal) != nullptr;
+ bool isInvariant = I.getMDNode(LLVMContext::MD_invariant_load) != nullptr;
unsigned Alignment = I.getAlignment();
AAMDNodes AAInfo;
I.getAAMetadata(AAInfo);
- const MDNode *Ranges = I.getMetadata(LLVMContext::MD_range);
+ const MDNode *Ranges = I.getMDNode(LLVMContext::MD_range);
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
SmallVector<EVT, 4> ValueVTs;
NumValues));
EVT PtrVT = Ptr.getValueType();
bool isVolatile = I.isVolatile();
- bool isNonTemporal = I.getMetadata(LLVMContext::MD_nontemporal) != nullptr;
+ bool isNonTemporal = I.getMDNode(LLVMContext::MD_nontemporal) != nullptr;
unsigned Alignment = I.getAlignment();
AAMDNodes AAInfo;
// If we have a !srcloc metadata node associated with it, we want to attach
// this to the ultimately generated inline asm machineinstr. To do this, we
// pass in the third operand as this (potentially null) inline asm MDNode.
- const MDNode *SrcLoc = CS.getInstruction()->getMetadata("srcloc");
+ const MDNode *SrcLoc = CS.getInstruction()->getMDNode("srcloc");
AsmNodeOperands.push_back(DAG.getMDNode(SrcLoc));
// Remember the HasSideEffect, AlignStack, AsmDialect, MayLoad and MayStore
}
void llvm::UpgradeInstWithTBAATag(Instruction *I) {
- MDNode *MD = I->getMetadata(LLVMContext::MD_tbaa);
+ MDNode *MD = I->getMDNode(LLVMContext::MD_tbaa);
assert(MD && "UpgradeInstWithTBAATag should have a TBAA tag");
// Check if the tag uses struct-path aware TBAA format.
if (isa<MDNode>(MD->getOperand(0)) && MD->getNumOperands() >= 3)
DiagnosticSeverity Severity)
: DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
Instr(&I) {
- if (const MDNode *SrcLoc = I.getMetadata("srcloc")) {
+ if (const MDNode *SrcLoc = I.getMDNode("srcloc")) {
if (SrcLoc->getNumOperands() != 0)
if (const ConstantInt *CI = dyn_cast<ConstantInt>(SrcLoc->getOperand(0)))
LocCookie = CI->getZExtValue();
// Update profile metadata if present and it matches our structural
// expectations.
- MDNode *ProfileData = getMetadata(LLVMContext::MD_prof);
+ MDNode *ProfileData = getMDNode(LLVMContext::MD_prof);
if (!ProfileData || ProfileData->getNumOperands() != 3)
return;
/// An accuracy of 0.0 means that the operation should be performed with the
/// default precision.
float FPMathOperator::getFPAccuracy() const {
- const MDNode *MD =
- cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
+ const MDNode *MD = cast<Instruction>(this)->getMDNode(LLVMContext::MD_fpmath);
if (!MD)
return 0.0;
ConstantFP *Accuracy = cast<ConstantFP>(MD->getOperand(0));
setMetadata(getContext().getMDKindID(Kind), MD);
}
-MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
+Value *Instruction::getMetadataImpl(StringRef Kind) const {
return getMetadataImpl(getContext().getMDKindID(Kind));
}
MDNode *Instruction::getMDNodeImpl(unsigned KindID) const {
- return getMetadataImpl(KindID);
+ return cast_or_null<MDNode>(getMetadataImpl(KindID));
}
MDNode *Instruction::getMDNodeImpl(StringRef Kind) const {
- return getMetadataImpl(Kind);
+ return cast_or_null<MDNode>(getMetadataImpl(Kind));
}
void Instruction::dropUnknownMetadata(ArrayRef<unsigned> KnownIDs) {
setMetadata(LLVMContext::MD_noalias, N.NoAlias);
}
-MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
+Value *Instruction::getMetadataImpl(unsigned KindID) const {
// Handle 'dbg' as a special case since it is not stored in the hash table.
if (KindID == LLVMContext::MD_dbg)
return DbgLoc.getAsMDNode(getContext());
}
}
- if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) {
+ if (MDNode *MD = I.getMDNode(LLVMContext::MD_fpmath)) {
Assert1(I.getType()->isFPOrFPVectorTy(),
"fpmath requires a floating point result!", &I);
Assert1(MD->getNumOperands() == 1, "fpmath takes one operand!", &I);
}
}
- if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) {
+ if (MDNode *Range = I.getMDNode(LLVMContext::MD_range)) {
Assert1(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I),
"Ranges are only for loads, calls and invokes!", &I);
visitRangeMetadata(I, Range, I.getType());
void DebugInfoVerifier::processInstructions(DebugInfoFinder &Finder) {
for (const Function &F : *M)
for (auto I = inst_begin(&F), E = inst_end(&F); I != E; ++I) {
- if (MDNode *MD = I->getMetadata(LLVMContext::MD_dbg))
+ if (MDNode *MD = I->getMDNode(LLVMContext::MD_dbg))
Finder.processLocation(*M, DILocation(MD));
if (const CallInst *CI = dyn_cast<CallInst>(&*I))
processCallInst(Finder, *CI);
}
bool llvm::getAlign(const CallInst &I, unsigned index, unsigned &align) {
- if (MDNode *alignNode = I.getMetadata("callalign")) {
+ if (MDNode *alignNode = I.getMDNode("callalign")) {
for (int i = 0, n = alignNode->getNumOperands(); i < n; i++) {
if (const ConstantInt *CI =
dyn_cast<ConstantInt>(alignNode->getOperand(i))) {
// If the memcpy has metadata describing the members, see if we can
// get the TBAA tag describing our copy.
- if (MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa_struct)) {
+ if (MDNode *M = MI->getMDNode(LLVMContext::MD_tbaa_struct)) {
if (M->getNumOperands() == 3 &&
M->getOperand(0) &&
isa<ConstantInt>(M->getOperand(0)) &&
}
static bool isVtableAccess(Instruction *I) {
- if (MDNode *Tag = I->getMetadata(LLVMContext::MD_tbaa))
+ if (MDNode *Tag = I->getMDNode(LLVMContext::MD_tbaa))
return Tag->isTBAAVtableAccess();
return false;
}
// reference to said Node. Otherwise just return 0.
if (Instruction *Inst = dyn_cast<Instruction>(Ptr)) {
MDNode *Node;
- if (!(Node = Inst->getMetadata(NodeId))) {
+ if (!(Node = Inst->getMDNode(NodeId))) {
// We do not have any node. Generate and attatch the hash MDString to the
// instruction.
NestingDetected = true;
}
- MDNode *ReleaseMetadata = Inst->getMetadata(ImpreciseReleaseMDKind);
+ MDNode *ReleaseMetadata = Inst->getMDNode(ImpreciseReleaseMDKind);
Sequence NewSeq = ReleaseMetadata ? S_MovableRelease : S_Release;
ANNOTATE_BOTTOMUP(Inst, Arg, S.GetSeq(), NewSeq);
S.ResetSequenceProgress(NewSeq);
Sequence OldSeq = S.GetSeq();
- MDNode *ReleaseMetadata = Inst->getMetadata(ImpreciseReleaseMDKind);
+ MDNode *ReleaseMetadata = Inst->getMDNode(ImpreciseReleaseMDKind);
switch (OldSeq) {
case S_Retain:
for (Function::const_iterator I = CalledFunc->begin(), IE = CalledFunc->end();
I != IE; ++I)
for (BasicBlock::const_iterator J = I->begin(), JE = I->end(); J != JE; ++J) {
- if (const MDNode *M = J->getMetadata(LLVMContext::MD_alias_scope))
+ if (const MDNode *M = J->getMDNode(LLVMContext::MD_alias_scope))
MD.insert(M);
- if (const MDNode *M = J->getMetadata(LLVMContext::MD_noalias))
+ if (const MDNode *M = J->getMDNode(LLVMContext::MD_noalias))
MD.insert(M);
}
if (!NI)
continue;
- if (MDNode *M = NI->getMetadata(LLVMContext::MD_alias_scope)) {
+ if (MDNode *M = NI->getMDNode(LLVMContext::MD_alias_scope)) {
MDNode *NewMD = MDMap[M];
// If the call site also had alias scope metadata (a list of scopes to
// which instructions inside it might belong), propagate those scopes to
// the inlined instructions.
if (MDNode *CSM =
- CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope))
+ CS.getInstruction()->getMDNode(LLVMContext::MD_alias_scope))
NewMD = MDNode::concatenate(NewMD, CSM);
NI->setMetadata(LLVMContext::MD_alias_scope, NewMD);
} else if (NI->mayReadOrWriteMemory()) {
if (MDNode *M =
- CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope))
+ CS.getInstruction()->getMDNode(LLVMContext::MD_alias_scope))
NI->setMetadata(LLVMContext::MD_alias_scope, M);
}
- if (MDNode *M = NI->getMetadata(LLVMContext::MD_noalias)) {
+ if (MDNode *M = NI->getMDNode(LLVMContext::MD_noalias)) {
MDNode *NewMD = MDMap[M];
// If the call site also had noalias metadata (a list of scopes with
// which instructions inside it don't alias), propagate those scopes to
// the inlined instructions.
- if (MDNode *CSM =
- CS.getInstruction()->getMetadata(LLVMContext::MD_noalias))
+ if (MDNode *CSM = CS.getInstruction()->getMDNode(LLVMContext::MD_noalias))
NewMD = MDNode::concatenate(NewMD, CSM);
NI->setMetadata(LLVMContext::MD_noalias, NewMD);
} else if (NI->mayReadOrWriteMemory()) {
- if (MDNode *M =
- CS.getInstruction()->getMetadata(LLVMContext::MD_noalias))
+ if (MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_noalias))
NI->setMetadata(LLVMContext::MD_noalias, M);
}
}
}
if (!NoAliases.empty())
- NI->setMetadata(LLVMContext::MD_noalias, MDNode::concatenate(
- NI->getMetadata(LLVMContext::MD_noalias),
- MDNode::get(CalledFunc->getContext(), NoAliases)));
+ NI->setMetadata(LLVMContext::MD_noalias,
+ MDNode::concatenate(
+ NI->getMDNode(LLVMContext::MD_noalias),
+ MDNode::get(CalledFunc->getContext(), NoAliases)));
// Next, we want to figure out all of the sets to which we might belong.
// We might belong to a set if the noalias argument is in the set of
}
if (!Scopes.empty())
- NI->setMetadata(LLVMContext::MD_alias_scope, MDNode::concatenate(
- NI->getMetadata(LLVMContext::MD_alias_scope),
- MDNode::get(CalledFunc->getContext(), Scopes)));
+ NI->setMetadata(
+ LLVMContext::MD_alias_scope,
+ MDNode::concatenate(NI->getMDNode(LLVMContext::MD_alias_scope),
+ MDNode::get(CalledFunc->getContext(), Scopes)));
}
}
}
// Check to see if this branch is going to the same place as the default
// dest. If so, eliminate it as an explicit compare.
if (i.getCaseSuccessor() == DefaultDest) {
- MDNode* MD = SI->getMetadata(LLVMContext::MD_prof);
+ MDNode *MD = SI->getMDNode(LLVMContext::MD_prof);
unsigned NCases = SI->getNumCases();
// Fold the case metadata into the default if there will be any branches
// left, unless the metadata doesn't match the switch.
BranchInst *NewBr = Builder.CreateCondBr(Cond,
FirstCase.getCaseSuccessor(),
SI->getDefaultDest());
- MDNode* MD = SI->getMetadata(LLVMContext::MD_prof);
+ MDNode *MD = SI->getMDNode(LLVMContext::MD_prof);
if (MD && MD->getNumOperands() == 3) {
ConstantInt *SICase = dyn_cast<ConstantInt>(MD->getOperand(2));
ConstantInt *SIDef = dyn_cast<ConstantInt>(MD->getOperand(1));
K->getAllMetadataOtherThanDebugLoc(Metadata);
for (unsigned i = 0, n = Metadata.size(); i < n; ++i) {
unsigned Kind = Metadata[i].first;
- MDNode *JMD = J->getMetadata(Kind);
+ MDNode *JMD = J->getMDNode(Kind);
MDNode *KMD = Metadata[i].second;
switch (Kind) {
// Collect branch weights into a vector.
SmallVector<uint32_t, 8> Weights;
- MDNode* MD = SI->getMetadata(LLVMContext::MD_prof);
+ MDNode *MD = SI->getMDNode(LLVMContext::MD_prof);
bool HasWeight = MD && (MD->getNumOperands() == 2 + SI->getNumCases());
if (HasWeight)
for (unsigned MD_i = 1, MD_e = MD->getNumOperands(); MD_i < MD_e;
}
static inline bool HasBranchWeights(const Instruction* I) {
- MDNode* ProfMD = I->getMetadata(LLVMContext::MD_prof);
+ MDNode *ProfMD = I->getMDNode(LLVMContext::MD_prof);
if (ProfMD && ProfMD->getOperand(0))
if (MDString* MDS = dyn_cast<MDString>(ProfMD->getOperand(0)))
return MDS->getString().equals("branch_weights");
/// metadata.
static void GetBranchWeights(TerminatorInst *TI,
SmallVectorImpl<uint64_t> &Weights) {
- MDNode* MD = TI->getMetadata(LLVMContext::MD_prof);
+ MDNode *MD = TI->getMDNode(LLVMContext::MD_prof);
assert(MD);
for (unsigned i = 1, e = MD->getNumOperands(); i < e; ++i) {
ConstantInt *CI = cast<ConstantInt>(MD->getOperand(i));
uint64_t &ProbTrue, uint64_t &ProbFalse) {
assert(BI->isConditional() &&
"Looking for probabilities on unconditional branch?");
- MDNode *ProfileData = BI->getMetadata(LLVMContext::MD_prof);
+ MDNode *ProfileData = BI->getMDNode(LLVMContext::MD_prof);
if (!ProfileData || ProfileData->getNumOperands() != 3) return false;
ConstantInt *CITrue = dyn_cast<ConstantInt>(ProfileData->getOperand(1));
ConstantInt *CIFalse = dyn_cast<ConstantInt>(ProfileData->getOperand(2));
for (int i = 1, e = VL.size(); MD && i != e; i++) {
Instruction *I = cast<Instruction>(VL[i]);
- MDNode *IMD = I->getMetadata(Kind);
+ MDNode *IMD = I->getMDNode(Kind);
switch (Kind) {
default: