llvm.org GIT mirror llvm / 3a84a63
IR: MDNode => Value: Instruction::getMetadata() Change `Instruction::getMetadata()` to return `Value` as part of PR21433. Update most callers to use `Instruction::getMDNode()`, which wraps the result in a `cast_or_null<MDNode>`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221024 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
22 changed file(s) with 84 addition(s) and 87 deletion(s). Raw diff Collapse all Expand all
140140
141141 /// getMetadata - Get the metadata of given kind attached to this Instruction.
142142 /// If the metadata is not found then return null.
143 MDNode *getMetadata(unsigned KindID) const {
143 Value *getMetadata(unsigned KindID) const {
144144 if (!hasMetadata()) return nullptr;
145145 return getMetadataImpl(KindID);
146146 }
147147
148148 /// getMetadata - Get the metadata of given kind attached to this Instruction.
149149 /// If the metadata is not found then return null.
150 MDNode *getMetadata(StringRef Kind) const {
150 Value *getMetadata(StringRef Kind) const {
151151 if (!hasMetadata()) return nullptr;
152152 return getMetadataImpl(Kind);
153153 }
288288 }
289289
290290 // These are all implemented in Metadata.cpp.
291 MDNode *getMetadataImpl(unsigned KindID) const;
292 MDNode *getMetadataImpl(StringRef Kind) const;
291 Value *getMetadataImpl(unsigned KindID) const;
292 Value *getMetadataImpl(StringRef Kind) const;
293293 MDNode *getMDNodeImpl(unsigned KindID) const;
294294 MDNode *getMDNodeImpl(StringRef Kind) const;
295295 void getAllMetadataImpl(SmallVectorImpl > &)const;
179179 if (!isa(TI) && !isa(TI))
180180 return false;
181181
182 MDNode *WeightsNode = TI->getMetadata(LLVMContext::MD_prof);
182 MDNode *WeightsNode = TI->getMDNode(LLVMContext::MD_prof);
183183 if (!WeightsNode)
184184 return false;
185185
234234 MDNode *Loop::getLoopID() const {
235235 MDNode *LoopID = nullptr;
236236 if (isLoopSimplifyForm()) {
237 LoopID = getLoopLatch()->getTerminator()->getMetadata(LoopMDName);
237 LoopID = getLoopLatch()->getTerminator()->getMDNode(LoopMDName);
238238 } else {
239239 // Go through each predecessor of the loop header and check the
240240 // terminator for the metadata.
246246 // Check if this terminator branches to the loop header.
247247 for (unsigned i = 0, ie = TI->getNumSuccessors(); i != ie; ++i) {
248248 if (TI->getSuccessor(i) == H) {
249 MD = TI->getMetadata(LoopMDName);
249 MD = TI->getMDNode(LoopMDName);
250250 break;
251251 }
252252 }
308308 // nested parallel loops). The loop identifier metadata refers to
309309 // itself so we can check both cases with the same routine.
310310 MDNode *loopIdMD =
311 II->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
311 II->getMDNode(LLVMContext::MD_mem_parallel_loop_access);
312312
313313 if (!loopIdMD)
314314 return false;
36673667 /// metadata present in the IR.
36683668 static Optional GetRangeFromMetadata(Value *V) {
36693669 if (Instruction *I = dyn_cast(V)) {
3670 if (MDNode *MD = I->getMetadata(LLVMContext::MD_range)) {
3670 if (MDNode *MD = I->getMDNode(LLVMContext::MD_range)) {
36713671 ConstantRange TotalRange(
36723672 cast(I->getType())->getBitWidth(), false);
36733673
212212 if (!EnableScopedNoAlias)
213213 return AliasAnalysis::getModRefInfo(CS, Loc);
214214
215 if (!mayAliasInScopes(Loc.AATags.Scope,
216 CS.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
215 if (!mayAliasInScopes(Loc.AATags.Scope, CS.getInstruction()->getMDNode(
216 LLVMContext::MD_noalias)))
217217 return NoModRef;
218218
219219 if (!mayAliasInScopes(
220 CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
221 Loc.AATags.NoAlias))
220 CS.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
221 Loc.AATags.NoAlias))
222222 return NoModRef;
223223
224224 return AliasAnalysis::getModRefInfo(CS, Loc);
230230 return AliasAnalysis::getModRefInfo(CS1, CS2);
231231
232232 if (!mayAliasInScopes(
233 CS1.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
234 CS2.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
233 CS1.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
234 CS2.getInstruction()->getMDNode(LLVMContext::MD_noalias)))
235235 return NoModRef;
236236
237237 if (!mayAliasInScopes(
238 CS2.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
239 CS1.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
238 CS2.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
239 CS1.getInstruction()->getMDNode(LLVMContext::MD_noalias)))
240240 return NoModRef;
241241
242242 return AliasAnalysis::getModRefInfo(CS1, CS2);
492492
493493 // If this is an "immutable" type, we can assume the call doesn't write
494494 // to memory.
495 if (const MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
495 if (const MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
496496 if ((!isStructPathTBAA(M) && TBAANode(M).TypeIsImmutable()) ||
497497 (isStructPathTBAA(M) && TBAAStructTagNode(M).TypeIsImmutable()))
498498 Min = OnlyReadsMemory;
513513 return AliasAnalysis::getModRefInfo(CS, Loc);
514514
515515 if (const MDNode *L = Loc.AATags.TBAA)
516 if (const MDNode *M =
517 CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
516 if (const MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
518517 if (!Aliases(L, M))
519518 return NoModRef;
520519
527526 if (!EnableTBAA)
528527 return AliasAnalysis::getModRefInfo(CS1, CS2);
529528
530 if (const MDNode *M1 =
531 CS1.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
529 if (const MDNode *M1 = CS1.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
532530 if (const MDNode *M2 =
533 CS2.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
531 CS2.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
534532 if (!Aliases(M1, M2))
535533 return NoModRef;
536534
613611
614612 void Instruction::getAAMetadata(AAMDNodes &N, bool Merge) const {
615613 if (Merge)
616 N.TBAA = MDNode::getMostGenericTBAA(N.TBAA,
617 getMetadata(LLVMContext::MD_tbaa));
614 N.TBAA =
615 MDNode::getMostGenericTBAA(N.TBAA, getMDNode(LLVMContext::MD_tbaa));
618616 else
619 N.TBAA = getMetadata(LLVMContext::MD_tbaa);
617 N.TBAA = getMDNode(LLVMContext::MD_tbaa);
620618
621619 if (Merge)
622 N.Scope = MDNode::intersect(N.Scope,
623 getMetadata(LLVMContext::MD_alias_scope));
620 N.Scope =
621 MDNode::intersect(N.Scope, getMDNode(LLVMContext::MD_alias_scope));
624622 else
625 N.Scope = getMetadata(LLVMContext::MD_alias_scope);
623 N.Scope = getMDNode(LLVMContext::MD_alias_scope);
626624
627625 if (Merge)
628 N.NoAlias = MDNode::intersect(N.NoAlias,
629 getMetadata(LLVMContext::MD_noalias));
626 N.NoAlias =
627 MDNode::intersect(N.NoAlias, getMDNode(LLVMContext::MD_noalias));
630628 else
631 N.NoAlias = getMetadata(LLVMContext::MD_noalias);
632 }
633
629 N.NoAlias = getMDNode(LLVMContext::MD_noalias);
630 }
631
861861 switch (I->getOpcode()) {
862862 default: break;
863863 case Instruction::Load:
864 if (MDNode *MD = cast(I)->getMetadata(LLVMContext::MD_range))
864 if (MDNode *MD = cast(I)->getMDNode(LLVMContext::MD_range))
865865 computeKnownBitsFromRangeMetadata(*MD, KnownZero);
866866 break;
867867 case Instruction::And: {
12601260 }
12611261 case Instruction::Call:
12621262 case Instruction::Invoke:
1263 if (MDNode *MD = cast(I)->getMetadata(LLVMContext::MD_range))
1263 if (MDNode *MD = cast(I)->getMDNode(LLVMContext::MD_range))
12641264 computeKnownBitsFromRangeMetadata(*MD, KnownZero);
12651265 // If a range metadata is attached to this IntrinsicInst, intersect the
12661266 // explicit range specified by the metadata and the implicit range of
15351535 }
15361536
15371537 if (Instruction* I = dyn_cast(V)) {
1538 if (MDNode *Ranges = I->getMetadata(LLVMContext::MD_range)) {
1538 if (MDNode *Ranges = I->getMDNode(LLVMContext::MD_range)) {
15391539 // If the possible ranges don't contain zero, then the value is
15401540 // definitely non-zero.
15411541 if (IntegerType* Ty = dyn_cast(V->getType())) {
21212121 } else
21222122 return nullptr;
21232123
2124 bool IsNonTemporal = I->getMetadata(LLVMContext::MD_nontemporal) != nullptr;
2125 bool IsInvariant = I->getMetadata(LLVMContext::MD_invariant_load) != nullptr;
2126 const MDNode *Ranges = I->getMetadata(LLVMContext::MD_range);
2124 bool IsNonTemporal = I->getMDNode(LLVMContext::MD_nontemporal) != nullptr;
2125 bool IsInvariant = I->getMDNode(LLVMContext::MD_invariant_load) != nullptr;
2126 const MDNode *Ranges = I->getMDNode(LLVMContext::MD_range);
21272127
21282128 AAMDNodes AAInfo;
21292129 I->getAAMetadata(AAInfo);
34793479 Type *Ty = I.getType();
34803480
34813481 bool isVolatile = I.isVolatile();
3482 bool isNonTemporal = I.getMetadata(LLVMContext::MD_nontemporal) != nullptr;
3483 bool isInvariant = I.getMetadata(LLVMContext::MD_invariant_load) != nullptr;
3482 bool isNonTemporal = I.getMDNode(LLVMContext::MD_nontemporal) != nullptr;
3483 bool isInvariant = I.getMDNode(LLVMContext::MD_invariant_load) != nullptr;
34843484 unsigned Alignment = I.getAlignment();
34853485
34863486 AAMDNodes AAInfo;
34873487 I.getAAMetadata(AAInfo);
3488 const MDNode *Ranges = I.getMetadata(LLVMContext::MD_range);
3488 const MDNode *Ranges = I.getMDNode(LLVMContext::MD_range);
34893489
34903490 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
34913491 SmallVector ValueVTs;
35833583 NumValues));
35843584 EVT PtrVT = Ptr.getValueType();
35853585 bool isVolatile = I.isVolatile();
3586 bool isNonTemporal = I.getMetadata(LLVMContext::MD_nontemporal) != nullptr;
3586 bool isNonTemporal = I.getMDNode(LLVMContext::MD_nontemporal) != nullptr;
35873587 unsigned Alignment = I.getAlignment();
35883588
35893589 AAMDNodes AAInfo;
64786478 // If we have a !srcloc metadata node associated with it, we want to attach
64796479 // this to the ultimately generated inline asm machineinstr. To do this, we
64806480 // pass in the third operand as this (potentially null) inline asm MDNode.
6481 const MDNode *SrcLoc = CS.getInstruction()->getMetadata("srcloc");
6481 const MDNode *SrcLoc = CS.getInstruction()->getMDNode("srcloc");
64826482 AsmNodeOperands.push_back(DAG.getMDNode(SrcLoc));
64836483
64846484 // Remember the HasSideEffect, AlignStack, AsmDialect, MayLoad and MayStore
578578 }
579579
580580 void llvm::UpgradeInstWithTBAATag(Instruction *I) {
581 MDNode *MD = I->getMetadata(LLVMContext::MD_tbaa);
581 MDNode *MD = I->getMDNode(LLVMContext::MD_tbaa);
582582 assert(MD && "UpgradeInstWithTBAATag should have a TBAA tag");
583583 // Check if the tag uses struct-path aware TBAA format.
584584 if (isa(MD->getOperand(0)) && MD->getNumOperands() >= 3)
9595 DiagnosticSeverity Severity)
9696 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
9797 Instr(&I) {
98 if (const MDNode *SrcLoc = I.getMetadata("srcloc")) {
98 if (const MDNode *SrcLoc = I.getMDNode("srcloc")) {
9999 if (SrcLoc->getNumOperands() != 0)
100100 if (const ConstantInt *CI = dyn_cast(SrcLoc->getOperand(0)))
101101 LocCookie = CI->getZExtValue();
790790
791791 // Update profile metadata if present and it matches our structural
792792 // expectations.
793 MDNode *ProfileData = getMetadata(LLVMContext::MD_prof);
793 MDNode *ProfileData = getMDNode(LLVMContext::MD_prof);
794794 if (!ProfileData || ProfileData->getNumOperands() != 3)
795795 return;
796796
20712071 /// An accuracy of 0.0 means that the operation should be performed with the
20722072 /// default precision.
20732073 float FPMathOperator::getFPAccuracy() const {
2074 const MDNode *MD =
2075 cast(this)->getMetadata(LLVMContext::MD_fpmath);
2074 const MDNode *MD = cast(this)->getMDNode(LLVMContext::MD_fpmath);
20762075 if (!MD)
20772076 return 0.0;
20782077 ConstantFP *Accuracy = cast(MD->getOperand(0));
604604 setMetadata(getContext().getMDKindID(Kind), MD);
605605 }
606606
607 MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
607 Value *Instruction::getMetadataImpl(StringRef Kind) const {
608608 return getMetadataImpl(getContext().getMDKindID(Kind));
609609 }
610610
611611 MDNode *Instruction::getMDNodeImpl(unsigned KindID) const {
612 return getMetadataImpl(KindID);
612 return cast_or_null(getMetadataImpl(KindID));
613613 }
614614
615615 MDNode *Instruction::getMDNodeImpl(StringRef Kind) const {
616 return getMetadataImpl(Kind);
616 return cast_or_null(getMetadataImpl(Kind));
617617 }
618618
619619 void Instruction::dropUnknownMetadata(ArrayRef KnownIDs) {
728728 setMetadata(LLVMContext::MD_noalias, N.NoAlias);
729729 }
730730
731 MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
731 Value *Instruction::getMetadataImpl(unsigned KindID) const {
732732 // Handle 'dbg' as a special case since it is not stored in the hash table.
733733 if (KindID == LLVMContext::MD_dbg)
734734 return DbgLoc.getAsMDNode(getContext());
22662266 }
22672267 }
22682268
2269 if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) {
2269 if (MDNode *MD = I.getMDNode(LLVMContext::MD_fpmath)) {
22702270 Assert1(I.getType()->isFPOrFPVectorTy(),
22712271 "fpmath requires a floating point result!", &I);
22722272 Assert1(MD->getNumOperands() == 1, "fpmath takes one operand!", &I);
22802280 }
22812281 }
22822282
2283 if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) {
2283 if (MDNode *Range = I.getMDNode(LLVMContext::MD_range)) {
22842284 Assert1(isa(I) || isa(I) || isa(I),
22852285 "Ranges are only for loads, calls and invokes!", &I);
22862286 visitRangeMetadata(I, Range, I.getType());
25862586 void DebugInfoVerifier::processInstructions(DebugInfoFinder &Finder) {
25872587 for (const Function &F : *M)
25882588 for (auto I = inst_begin(&F), E = inst_end(&F); I != E; ++I) {
2589 if (MDNode *MD = I->getMetadata(LLVMContext::MD_dbg))
2589 if (MDNode *MD = I->getMDNode(LLVMContext::MD_dbg))
25902590 Finder.processLocation(*M, DILocation(MD));
25912591 if (const CallInst *CI = dyn_cast(&*I))
25922592 processCallInst(Finder, *CI);
318318 }
319319
320320 bool llvm::getAlign(const CallInst &I, unsigned index, unsigned &align) {
321 if (MDNode *alignNode = I.getMetadata("callalign")) {
321 if (MDNode *alignNode = I.getMDNode("callalign")) {
322322 for (int i = 0, n = alignNode->getNumOperands(); i < n; i++) {
323323 if (const ConstantInt *CI =
324324 dyn_cast(alignNode->getOperand(i))) {
116116
117117 // If the memcpy has metadata describing the members, see if we can
118118 // get the TBAA tag describing our copy.
119 if (MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa_struct)) {
119 if (MDNode *M = MI->getMDNode(LLVMContext::MD_tbaa_struct)) {
120120 if (M->getNumOperands() == 3 &&
121121 M->getOperand(0) &&
122122 isa(M->getOperand(0)) &&
230230 }
231231
232232 static bool isVtableAccess(Instruction *I) {
233 if (MDNode *Tag = I->getMetadata(LLVMContext::MD_tbaa))
233 if (MDNode *Tag = I->getMDNode(LLVMContext::MD_tbaa))
234234 return Tag->isTBAAVtableAccess();
235235 return false;
236236 }
824824 // reference to said Node. Otherwise just return 0.
825825 if (Instruction *Inst = dyn_cast(Ptr)) {
826826 MDNode *Node;
827 if (!(Node = Inst->getMetadata(NodeId))) {
827 if (!(Node = Inst->getMDNode(NodeId))) {
828828 // We do not have any node. Generate and attatch the hash MDString to the
829829 // instruction.
830830
17351735 NestingDetected = true;
17361736 }
17371737
1738 MDNode *ReleaseMetadata = Inst->getMetadata(ImpreciseReleaseMDKind);
1738 MDNode *ReleaseMetadata = Inst->getMDNode(ImpreciseReleaseMDKind);
17391739 Sequence NewSeq = ReleaseMetadata ? S_MovableRelease : S_Release;
17401740 ANNOTATE_BOTTOMUP(Inst, Arg, S.GetSeq(), NewSeq);
17411741 S.ResetSequenceProgress(NewSeq);
20162016
20172017 Sequence OldSeq = S.GetSeq();
20182018
2019 MDNode *ReleaseMetadata = Inst->getMetadata(ImpreciseReleaseMDKind);
2019 MDNode *ReleaseMetadata = Inst->getMDNode(ImpreciseReleaseMDKind);
20202020
20212021 switch (OldSeq) {
20222022 case S_Retain:
296296 for (Function::const_iterator I = CalledFunc->begin(), IE = CalledFunc->end();
297297 I != IE; ++I)
298298 for (BasicBlock::const_iterator J = I->begin(), JE = I->end(); J != JE; ++J) {
299 if (const MDNode *M = J->getMetadata(LLVMContext::MD_alias_scope))
299 if (const MDNode *M = J->getMDNode(LLVMContext::MD_alias_scope))
300300 MD.insert(M);
301 if (const MDNode *M = J->getMetadata(LLVMContext::MD_noalias))
301 if (const MDNode *M = J->getMDNode(LLVMContext::MD_noalias))
302302 MD.insert(M);
303303 }
304304
358358 if (!NI)
359359 continue;
360360
361 if (MDNode *M = NI->getMetadata(LLVMContext::MD_alias_scope)) {
361 if (MDNode *M = NI->getMDNode(LLVMContext::MD_alias_scope)) {
362362 MDNode *NewMD = MDMap[M];
363363 // If the call site also had alias scope metadata (a list of scopes to
364364 // which instructions inside it might belong), propagate those scopes to
365365 // the inlined instructions.
366366 if (MDNode *CSM =
367 CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope))
367 CS.getInstruction()->getMDNode(LLVMContext::MD_alias_scope))
368368 NewMD = MDNode::concatenate(NewMD, CSM);
369369 NI->setMetadata(LLVMContext::MD_alias_scope, NewMD);
370370 } else if (NI->mayReadOrWriteMemory()) {
371371 if (MDNode *M =
372 CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope))
372 CS.getInstruction()->getMDNode(LLVMContext::MD_alias_scope))
373373 NI->setMetadata(LLVMContext::MD_alias_scope, M);
374374 }
375375
376 if (MDNode *M = NI->getMetadata(LLVMContext::MD_noalias)) {
376 if (MDNode *M = NI->getMDNode(LLVMContext::MD_noalias)) {
377377 MDNode *NewMD = MDMap[M];
378378 // If the call site also had noalias metadata (a list of scopes with
379379 // which instructions inside it don't alias), propagate those scopes to
380380 // the inlined instructions.
381 if (MDNode *CSM =
382 CS.getInstruction()->getMetadata(LLVMContext::MD_noalias))
381 if (MDNode *CSM = CS.getInstruction()->getMDNode(LLVMContext::MD_noalias))
383382 NewMD = MDNode::concatenate(NewMD, CSM);
384383 NI->setMetadata(LLVMContext::MD_noalias, NewMD);
385384 } else if (NI->mayReadOrWriteMemory()) {
386 if (MDNode *M =
387 CS.getInstruction()->getMetadata(LLVMContext::MD_noalias))
385 if (MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_noalias))
388386 NI->setMetadata(LLVMContext::MD_noalias, M);
389387 }
390388 }
588586 }
589587
590588 if (!NoAliases.empty())
591 NI->setMetadata(LLVMContext::MD_noalias, MDNode::concatenate(
592 NI->getMetadata(LLVMContext::MD_noalias),
593 MDNode::get(CalledFunc->getContext(), NoAliases)));
589 NI->setMetadata(LLVMContext::MD_noalias,
590 MDNode::concatenate(
591 NI->getMDNode(LLVMContext::MD_noalias),
592 MDNode::get(CalledFunc->getContext(), NoAliases)));
594593
595594 // Next, we want to figure out all of the sets to which we might belong.
596595 // We might belong to a set if the noalias argument is in the set of
613612 }
614613
615614 if (!Scopes.empty())
616 NI->setMetadata(LLVMContext::MD_alias_scope, MDNode::concatenate(
617 NI->getMetadata(LLVMContext::MD_alias_scope),
618 MDNode::get(CalledFunc->getContext(), Scopes)));
615 NI->setMetadata(
616 LLVMContext::MD_alias_scope,
617 MDNode::concatenate(NI->getMDNode(LLVMContext::MD_alias_scope),
618 MDNode::get(CalledFunc->getContext(), Scopes)));
619619 }
620620 }
621621 }
127127 // Check to see if this branch is going to the same place as the default
128128 // dest. If so, eliminate it as an explicit compare.
129129 if (i.getCaseSuccessor() == DefaultDest) {
130 MDNode* MD = SI->getMetadata(LLVMContext::MD_prof);
130 MDNode *MD = SI->getMDNode(LLVMContext::MD_prof);
131131 unsigned NCases = SI->getNumCases();
132132 // Fold the case metadata into the default if there will be any branches
133133 // left, unless the metadata doesn't match the switch.
205205 BranchInst *NewBr = Builder.CreateCondBr(Cond,
206206 FirstCase.getCaseSuccessor(),
207207 SI->getDefaultDest());
208 MDNode* MD = SI->getMetadata(LLVMContext::MD_prof);
208 MDNode *MD = SI->getMDNode(LLVMContext::MD_prof);
209209 if (MD && MD->getNumOperands() == 3) {
210210 ConstantInt *SICase = dyn_cast(MD->getOperand(2));
211211 ConstantInt *SIDef = dyn_cast(MD->getOperand(1));
13121312 K->getAllMetadataOtherThanDebugLoc(Metadata);
13131313 for (unsigned i = 0, n = Metadata.size(); i < n; ++i) {
13141314 unsigned Kind = Metadata[i].first;
1315 MDNode *JMD = J->getMetadata(Kind);
1315 MDNode *JMD = J->getMDNode(Kind);
13161316 MDNode *KMD = Metadata[i].second;
13171317
13181318 switch (Kind) {
642642
643643 // Collect branch weights into a vector.
644644 SmallVector Weights;
645 MDNode* MD = SI->getMetadata(LLVMContext::MD_prof);
645 MDNode *MD = SI->getMDNode(LLVMContext::MD_prof);
646646 bool HasWeight = MD && (MD->getNumOperands() == 2 + SI->getNumCases());
647647 if (HasWeight)
648648 for (unsigned MD_i = 1, MD_e = MD->getNumOperands(); MD_i < MD_e;
737737 }
738738
739739 static inline bool HasBranchWeights(const Instruction* I) {
740 MDNode* ProfMD = I->getMetadata(LLVMContext::MD_prof);
740 MDNode *ProfMD = I->getMDNode(LLVMContext::MD_prof);
741741 if (ProfMD && ProfMD->getOperand(0))
742742 if (MDString* MDS = dyn_cast(ProfMD->getOperand(0)))
743743 return MDS->getString().equals("branch_weights");
750750 /// metadata.
751751 static void GetBranchWeights(TerminatorInst *TI,
752752 SmallVectorImpl &Weights) {
753 MDNode* MD = TI->getMetadata(LLVMContext::MD_prof);
753 MDNode *MD = TI->getMDNode(LLVMContext::MD_prof);
754754 assert(MD);
755755 for (unsigned i = 1, e = MD->getNumOperands(); i < e; ++i) {
756756 ConstantInt *CI = cast(MD->getOperand(i));
19691969 uint64_t &ProbTrue, uint64_t &ProbFalse) {
19701970 assert(BI->isConditional() &&
19711971 "Looking for probabilities on unconditional branch?");
1972 MDNode *ProfileData = BI->getMetadata(LLVMContext::MD_prof);
1972 MDNode *ProfileData = BI->getMDNode(LLVMContext::MD_prof);
19731973 if (!ProfileData || ProfileData->getNumOperands() != 3) return false;
19741974 ConstantInt *CITrue = dyn_cast(ProfileData->getOperand(1));
19751975 ConstantInt *CIFalse = dyn_cast(ProfileData->getOperand(2));
196196
197197 for (int i = 1, e = VL.size(); MD && i != e; i++) {
198198 Instruction *I = cast(VL[i]);
199 MDNode *IMD = I->getMetadata(Kind);
199 MDNode *IMD = I->getMDNode(Kind);
200200
201201 switch (Kind) {
202202 default: