llvm.org GIT mirror llvm / 5bf8ade
Revert "IR: MDNode => Value" Instead, we're going to separate metadata from the Value hierarchy. See PR21532. This reverts commit r221375. This reverts commit r221373. This reverts commit r221359. This reverts commit r221167. This reverts commit r221027. This reverts commit r221024. This reverts commit r221023. This reverts commit r220995. This reverts commit r220994. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221711 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
46 changed file(s) with 177 addition(s) and 205 deletion(s). Raw diff Collapse all Expand all
2222 #include "llvm/IR/DataLayout.h"
2323 #include "llvm/IR/Instructions.h"
2424 #include "llvm/IR/LLVMContext.h"
25 #include "llvm/IR/Metadata.h"
2625 #include "llvm/IR/Operator.h"
2726 #include "llvm/IR/ValueHandle.h"
2827 #include "llvm/Support/CBindingWrapping.h"
2928
3029 namespace llvm {
30 class MDNode;
3131
3232 /// \brief This provides the default implementation of the IRBuilder
3333 /// 'InsertHelper' method that is called whenever an instruction is created by
140140
141141 /// getMetadata - Get the metadata of given kind attached to this Instruction.
142142 /// If the metadata is not found then return null.
143 Value *getMetadata(unsigned KindID) const {
143 MDNode *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 Value *getMetadata(StringRef Kind) const {
150 MDNode *getMetadata(StringRef Kind) const {
151151 if (!hasMetadata()) return nullptr;
152152 return getMetadataImpl(Kind);
153 }
154
155 /// Get the the metadata as an MDNode.
156 ///
157 /// \pre Any KindID metadata is implemented using \a MDNode.
158 MDNode *getMDNode(unsigned KindID) const {
159 if (!hasMetadata())
160 return nullptr;
161 return getMDNodeImpl(KindID);
162 }
163
164 /// Get the the metadata as an MDNode.
165 ///
166 /// \pre Any KindID metadata is implemented using \a MDNode.
167 MDNode *getMDNode(StringRef Kind) const {
168 if (!hasMetadata())
169 return nullptr;
170 return getMDNodeImpl(Kind);
171153 }
172154
173155 /// getAllMetadata - Get all metadata attached to this Instruction. The first
174156 /// element of each pair returned is the KindID, the second element is the
175157 /// metadata value. This list is returned sorted by the KindID.
176158 void
177 getAllMetadata(SmallVectorImplValue *>> &MDs) const {
159 getAllMetadata(SmallVectorImplMDNode *>> &MDs) const {
178160 if (hasMetadata())
179161 getAllMetadataImpl(MDs);
180162 }
182164 /// getAllMetadataOtherThanDebugLoc - This does the same thing as
183165 /// getAllMetadata, except that it filters out the debug location.
184166 void getAllMetadataOtherThanDebugLoc(
185 SmallVectorImplValue *>> &MDs) const {
167 SmallVectorImplMDNode *>> &MDs) const {
186168 if (hasMetadataOtherThanDebugLoc())
187169 getAllMetadataOtherThanDebugLocImpl(MDs);
188170 }
194176
195177 /// setMetadata - Set the metadata of the specified kind to the specified
196178 /// node. This updates/replaces metadata if already present, or removes it if
197 /// MD is null.
198 void setMetadata(unsigned KindID, Value *MD);
199 void setMetadata(StringRef Kind, Value *MD);
179 /// Node is null.
180 void setMetadata(unsigned KindID, MDNode *Node);
181 void setMetadata(StringRef Kind, MDNode *Node);
200182
201183 /// \brief Drop unknown metadata.
202184 /// Passes are required to drop metadata they don't understand. This is a
289271 }
290272
291273 // These are all implemented in Metadata.cpp.
292 Value *getMetadataImpl(unsigned KindID) const;
293 Value *getMetadataImpl(StringRef Kind) const;
294 MDNode *getMDNodeImpl(unsigned KindID) const;
295 MDNode *getMDNodeImpl(StringRef Kind) const;
274 MDNode *getMetadataImpl(unsigned KindID) const;
275 MDNode *getMetadataImpl(StringRef Kind) const;
296276 void
297 getAllMetadataImpl(SmallVectorImplValue *>> &) const;
277 getAllMetadataImpl(SmallVectorImplMDNode *>> &) const;
298278 void getAllMetadataOtherThanDebugLocImpl(
299 SmallVectorImplValue *>> &) const;
279 SmallVectorImplMDNode *>> &) const;
300280 void clearMetadataHashEntries();
301281 public:
302282 //===--------------------------------------------------------------------===//
236236 };
237237
238238 //===----------------------------------------------------------------------===//
239 /// \brief A tuple of metadata nodes.
239 /// \brief A tuple of MDNodes.
240240 ///
241241 /// Despite its name, a NamedMDNode isn't itself an MDNode. NamedMDNodes belong
242 /// to modules, have names, and contain lists of metadata nodes.
242 /// to modules, have names, and contain lists of MDNodes.
243243 class NamedMDNode : public ilist_node {
244244 friend class SymbolTableListTraits;
245245 friend struct ilist_traits;
249249
250250 std::string Name;
251251 Module *Parent;
252 void *Operands; // SmallVectorValue>, 4>
252 void *Operands; // SmallVectorMDNode>, 4>
253253
254254 void setParent(Module *M) { Parent = M; }
255255
304304 inline Module *getParent() { return Parent; }
305305 inline const Module *getParent() const { return Parent; }
306306
307 Value *getOperand(unsigned i) const;
308 MDNode *getOperandAsMDNode(unsigned i) const {
309 return cast_or_null(getOperand(i));
310 }
307 MDNode *getOperand(unsigned i) const;
311308 unsigned getNumOperands() const;
312 void addOperand(Value *M);
309 void addOperand(MDNode *M);
313310 StringRef getName() const;
314311 void print(raw_ostream &ROS) const;
315312 void dump() const;
317314 // ---------------------------------------------------------------------------
318315 // Operand Iterator interface...
319316 //
320 typedef op_iterator_impl<Value *, Value> op_iterator;
317 typedef op_iterator_impl<MDNode *, MDNode> op_iterator;
321318 op_iterator op_begin() { return op_iterator(this, 0); }
322319 op_iterator op_end() { return op_iterator(this, getNumOperands()); }
323320
324 typedef op_iterator_implValue *, Value> const_op_iterator;
321 typedef op_iterator_implMDNode *, MDNode> const_op_iterator;
325322 const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
326323 const_op_iterator op_end() const { return const_op_iterator(this, getNumOperands()); }
327324
179179 if (!isa(TI) && !isa(TI))
180180 return false;
181181
182 MDNode *WeightsNode = TI->getMDNode(LLVMContext::MD_prof);
182 MDNode *WeightsNode = TI->getMetadata(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()->getMDNode(LoopMDName);
237 LoopID = getLoopLatch()->getTerminator()->getMetadata(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->getMDNode(LoopMDName);
249 MD = TI->getMetadata(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->getMDNode(LLVMContext::MD_mem_parallel_loop_access);
311 II->getMetadata(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->getMDNode(LLVMContext::MD_range)) {
3670 if (MDNode *MD = I->getMetadata(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, CS.getInstruction()->getMDNode(
215 if (!mayAliasInScopes(Loc.AATags.Scope, CS.getInstruction()->getMetadata(
216216 LLVMContext::MD_noalias)))
217217 return NoModRef;
218218
219219 if (!mayAliasInScopes(
220 CS.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
220 CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
221221 Loc.AATags.NoAlias))
222222 return NoModRef;
223223
230230 return AliasAnalysis::getModRefInfo(CS1, CS2);
231231
232232 if (!mayAliasInScopes(
233 CS1.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
234 CS2.getInstruction()->getMDNode(LLVMContext::MD_noalias)))
233 CS1.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
234 CS2.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
235235 return NoModRef;
236236
237237 if (!mayAliasInScopes(
238 CS2.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
239 CS1.getInstruction()->getMDNode(LLVMContext::MD_noalias)))
238 CS2.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
239 CS1.getInstruction()->getMetadata(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()->getMDNode(LLVMContext::MD_tbaa))
495 if (const MDNode *M = CS.getInstruction()->getMetadata(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 = CS.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
516 if (const MDNode *M =
517 CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
517518 if (!Aliases(L, M))
518519 return NoModRef;
519520
526527 if (!EnableTBAA)
527528 return AliasAnalysis::getModRefInfo(CS1, CS2);
528529
529 if (const MDNode *M1 = CS1.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
530 if (const MDNode *M1 =
531 CS1.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
530532 if (const MDNode *M2 =
531 CS2.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
533 CS2.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
532534 if (!Aliases(M1, M2))
533535 return NoModRef;
534536
612614 void Instruction::getAAMetadata(AAMDNodes &N, bool Merge) const {
613615 if (Merge)
614616 N.TBAA =
615 MDNode::getMostGenericTBAA(N.TBAA, getMDNode(LLVMContext::MD_tbaa));
617 MDNode::getMostGenericTBAA(N.TBAA, getMetadata(LLVMContext::MD_tbaa));
616618 else
617 N.TBAA = getMDNode(LLVMContext::MD_tbaa);
619 N.TBAA = getMetadata(LLVMContext::MD_tbaa);
618620
619621 if (Merge)
620622 N.Scope =
621 MDNode::intersect(N.Scope, getMDNode(LLVMContext::MD_alias_scope));
623 MDNode::intersect(N.Scope, getMetadata(LLVMContext::MD_alias_scope));
622624 else
623 N.Scope = getMDNode(LLVMContext::MD_alias_scope);
625 N.Scope = getMetadata(LLVMContext::MD_alias_scope);
624626
625627 if (Merge)
626628 N.NoAlias =
627 MDNode::intersect(N.NoAlias, getMDNode(LLVMContext::MD_noalias));
629 MDNode::intersect(N.NoAlias, getMetadata(LLVMContext::MD_noalias));
628630 else
629 N.NoAlias = getMDNode(LLVMContext::MD_noalias);
630 }
631
631 N.NoAlias = getMetadata(LLVMContext::MD_noalias);
632 }
633
861861 switch (I->getOpcode()) {
862862 default: break;
863863 case Instruction::Load:
864 if (MDNode *MD = cast(I)->getMDNode(LLVMContext::MD_range))
864 if (MDNode *MD = cast(I)->getMetadata(LLVMContext::MD_range))
865865 computeKnownBitsFromRangeMetadata(*MD, KnownZero);
866866 break;
867867 case Instruction::And: {
12571257 }
12581258 case Instruction::Call:
12591259 case Instruction::Invoke:
1260 if (MDNode *MD = cast(I)->getMDNode(LLVMContext::MD_range))
1260 if (MDNode *MD = cast(I)->getMetadata(LLVMContext::MD_range))
12611261 computeKnownBitsFromRangeMetadata(*MD, KnownZero);
12621262 // If a range metadata is attached to this IntrinsicInst, intersect the
12631263 // explicit range specified by the metadata and the implicit range of
15321532 }
15331533
15341534 if (Instruction* I = dyn_cast(V)) {
1535 if (MDNode *Ranges = I->getMDNode(LLVMContext::MD_range)) {
1535 if (MDNode *Ranges = I->getMetadata(LLVMContext::MD_range)) {
15361536 // If the possible ranges don't contain zero, then the value is
15371537 // definitely non-zero.
15381538 if (IntegerType* Ty = dyn_cast(V->getType())) {
847847
848848 // Write metadata attachments
849849 // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
850 SmallVectorValue *>, 4> MDs;
850 SmallVectorMDNode *>, 4> MDs;
851851
852852 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
853853 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
320320 EnumerateValueSymbolTable(M->getValueSymbolTable());
321321 EnumerateNamedMetadata(M);
322322
323 SmallVectorValue *>, 8> MDs;
323 SmallVectorMDNode *>, 8> MDs;
324324
325325 // Enumerate types used by function bodies and argument lists.
326326 for (const Function &F : *M) {
346346 MDs.clear();
347347 I.getAllMetadataOtherThanDebugLoc(MDs);
348348 for (unsigned i = 0, e = MDs.size(); i != e; ++i)
349 EnumerateMetadata(cast(MDs[i].second));
349 EnumerateMetadata(MDs[i].second);
350350
351351 if (!I.getDebugLoc().isUnknown()) {
352352 MDNode *Scope, *IA;
740740 FnLocalMDVector.push_back(MD);
741741 }
742742
743 SmallVectorValue *>, 8> MDs;
743 SmallVectorMDNode *>, 8> MDs;
744744 I->getAllMetadataOtherThanDebugLoc(MDs);
745745 for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
746 auto *N = cast(MDs[i].second);
746 MDNode *N = MDs[i].second;
747747 if (N->isFunctionLocal() && N->getFunction())
748748 FnLocalMDVector.push_back(N);
749749 }
13981398
13991399 if (const NamedMDNode *NMD = M.getNamedMetadata("llvm.ident")) {
14001400 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1401 const MDNode *N = NMD->getOperandAsMDNode(i);
1401 const MDNode *N = NMD->getOperand(i);
14021402 assert(N->getNumOperands() == 1 &&
14031403 "llvm.ident metadata entry can have only one operand");
14041404 const MDString *S = cast(N->getOperand(0));
449449
450450 SingleCU = CU_Nodes->getNumOperands() == 1;
451451
452 for (Value *N : CU_Nodes->operands()) {
453 DICompileUnit CUNode(cast(N));
452 for (MDNode *N : CU_Nodes->operands()) {
453 DICompileUnit CUNode(N);
454454 DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
455455 DIArray ImportedEntities = CUNode.getImportedEntities();
456456 for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
525525 const Module *M = MMI->getModule();
526526
527527 if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
528 for (Value *N : CU_Nodes->operands()) {
529 DICompileUnit TheCU(cast(N));
528 for (MDNode *N : CU_Nodes->operands()) {
529 DICompileUnit TheCU(N);
530530 // Construct subprogram DIE and add variables DIEs.
531531 DwarfCompileUnit *SPCU =
532532 static_cast(CUMap.lookup(TheCU));
21212121 } else
21222122 return nullptr;
21232123
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);
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);
21272127
21282128 AAMDNodes AAInfo;
21292129 I->getAAMetadata(AAInfo);
34793479 Type *Ty = I.getType();
34803480
34813481 bool isVolatile = I.isVolatile();
3482 bool isNonTemporal = I.getMDNode(LLVMContext::MD_nontemporal) != nullptr;
3483 bool isInvariant = I.getMDNode(LLVMContext::MD_invariant_load) != nullptr;
3482 bool isNonTemporal = I.getMetadata(LLVMContext::MD_nontemporal) != nullptr;
3483 bool isInvariant = I.getMetadata(LLVMContext::MD_invariant_load) != nullptr;
34843484 unsigned Alignment = I.getAlignment();
34853485
34863486 AAMDNodes AAInfo;
34873487 I.getAAMetadata(AAInfo);
3488 const MDNode *Ranges = I.getMDNode(LLVMContext::MD_range);
3488 const MDNode *Ranges = I.getMetadata(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.getMDNode(LLVMContext::MD_nontemporal) != nullptr;
3586 bool isNonTemporal = I.getMetadata(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()->getMDNode("srcloc");
6481 const MDNode *SrcLoc = CS.getInstruction()->getMetadata("srcloc");
64826482 AsmNodeOperands.push_back(DAG.getMDNode(SrcLoc));
64836483
64846484 // Remember the HasSideEffect, AlignStack, AsmDialect, MayLoad and MayStore
544544 /// plane. If something is not in the SlotTracker, return -1.
545545 int getLocalSlot(const Value *V);
546546 int getGlobalSlot(const GlobalValue *V);
547 int getMetadataSlot(const Value *MD);
547 int getMetadataSlot(const MDNode *N);
548548 int getAttributeGroupSlot(AttributeSet AS);
549549
550550 /// If you'd like to deal with a function instead of just a module, use
584584 void CreateModuleSlot(const GlobalValue *V);
585585
586586 /// CreateMetadataSlot - Insert the specified MDNode* into the slot table.
587 void CreateMetadataSlot(const Value *MD);
587 void CreateMetadataSlot(const MDNode *N);
588588
589589 /// CreateFunctionSlot - Insert the specified Value* into the slot table.
590590 void CreateFunctionSlot(const Value *V);
717717
718718 ST_DEBUG("Inserting Instructions:\n");
719719
720 SmallVectorValue *>, 4> MDForInst;
720 SmallVectorMDNode *>, 4> MDForInst;
721721
722722 // Add all of the basic blocks and instructions with no names.
723723 for (Function::const_iterator BB = TheFunction->begin(),
754754 // Process metadata attached with this instruction.
755755 I->getAllMetadata(MDForInst);
756756 for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
757 CreateMetadataSlot(cast(MDForInst[i].second));
757 CreateMetadataSlot(MDForInst[i].second);
758758 MDForInst.clear();
759759 }
760760 }
785785 return MI == mMap.end() ? -1 : (int)MI->second;
786786 }
787787
788 /// getMetadataSlot - Get the slot number of a metadata node.
789 int SlotTracker::getMetadataSlot(const Value *MD) {
788 /// getMetadataSlot - Get the slot number of a MDNode.
789 int SlotTracker::getMetadataSlot(const MDNode *N) {
790790 // Check for uninitialized state and do lazy initialization.
791791 initialize();
792792
793793 // Find the MDNode in the module map
794 mdn_iterator MI = mdnMap.find(cast(MD));
794 mdn_iterator MI = mdnMap.find(N);
795795 return MI == mdnMap.end() ? -1 : (int)MI->second;
796796 }
797797
845845 DestSlot << " [o]\n");
846846 }
847847
848 /// CreateModuleSlot - Insert the specified metadata into the slot table.
849 void SlotTracker::CreateMetadataSlot(const Value *MD) {
850 assert(MD && "Can't insert a null Value into SlotTracker!");
851 const MDNode *N = cast(MD);
848 /// CreateModuleSlot - Insert the specified MDNode* into the slot table.
849 void SlotTracker::CreateMetadataSlot(const MDNode *N) {
850 assert(N && "Can't insert a null Value into SlotTracker!");
852851
853852 // Don't insert if N is a function-local metadata, these are always printed
854853 // inline.
23152314 }
23162315
23172316 // Print Metadata info.
2318 SmallVectorValue *>, 4> InstMD;
2317 SmallVectorMDNode *>, 4> InstMD;
23192318 I.getAllMetadata(InstMD);
23202319 if (!InstMD.empty()) {
23212320 SmallVector MDNames;
23282327 Out << ", !";
23292328 }
23302329 Out << ' ';
2331 WriteAsOperandInternal(Out, cast(InstMD[i].second), &TypePrinter,
2332 &Machine, TheModule);
2330 WriteAsOperandInternal(Out, InstMD[i].second, &TypePrinter, &Machine,
2331 TheModule);
23332332 }
23342333 }
23352334 printInfoComment(I);
570570 }
571571
572572 void llvm::UpgradeInstWithTBAATag(Instruction *I) {
573 MDNode *MD = I->getMDNode(LLVMContext::MD_tbaa);
573 MDNode *MD = I->getMetadata(LLVMContext::MD_tbaa);
574574 assert(MD && "UpgradeInstWithTBAATag should have a TBAA tag");
575575 // Check if the tag uses struct-path aware TBAA format.
576576 if (isa(MD->getOperand(0)) && MD->getNumOperands() >= 3)
560560
561561 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef MD) {
562562 unwrap(Inst)
563 ->setMetadata(KindID, MD ? unwrap<Value>(MD) : nullptr);
563 ->setMetadata(KindID, MD ? unwrap<MDNode>(MD) : nullptr);
564564 }
565565
566566 /*--.. Conversion functions ................................................--*/
719719 NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
720720 if (!N)
721721 return;
722 Value *Op = Val ? unwrape>(Val) : nullptr;
722 MDNode *Op = Val ? unwrape>(Val) : nullptr;
723723 if (Op)
724724 N->addOperand(Op);
725725 }
948948 llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
949949 DITypeIdentifierMap Map;
950950 for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
951 DICompileUnit CU(CU_Nodes->getOperandAsMDNode(CUi));
951 DICompileUnit CU(CU_Nodes->getOperand(CUi));
952952 DIArray Retain = CU.getRetainedTypes();
953953 for (unsigned Ti = 0, Te = Retain.getNumElements(); Ti != Te; ++Ti) {
954954 if (!Retain.getElement(Ti).isCompositeType())
996996 InitializeTypeMap(M);
997997 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
998998 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
999 DICompileUnit CU(CU_Nodes->getOperandAsMDNode(i));
999 DICompileUnit CU(CU_Nodes->getOperand(i));
10001000 addCompileUnit(CU);
10011001 DIArray GVs = CU.getGlobalVariables();
10021002 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
15411541 if (!CU_Nodes)
15421542 return R;
15431543
1544 for (Value *N : CU_Nodes->operands()) {
1545 DICompileUnit CUNode(cast(N));
1544 for (MDNode *N : CU_Nodes->operands()) {
1545 DICompileUnit CUNode(N);
15461546 DIArray SPs = CUNode.getSubprograms();
15471547 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
15481548 DISubprogram SP(SPs.getElement(i));
9595 DiagnosticSeverity Severity)
9696 : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
9797 Instr(&I) {
98 if (const MDNode *SrcLoc = I.getMDNode("srcloc")) {
98 if (const MDNode *SrcLoc = I.getMetadata("srcloc")) {
9999 if (SrcLoc->getNumOperands() != 0)
100100 if (const ConstantInt *CI = dyn_cast(SrcLoc->getOperand(0)))
101101 LocCookie = CI->getZExtValue();
547547
548548 // Otherwise, enumerate and copy over metadata from the old instruction to the
549549 // new one.
550 SmallVectorValue *>, 4> TheMDs;
550 SmallVectorMDNode *>, 4> TheMDs;
551551 getAllMetadataOtherThanDebugLoc(TheMDs);
552552 for (const auto &MD : TheMDs)
553553 New->setMetadata(MD.first, MD.second);
790790
791791 // Update profile metadata if present and it matches our structural
792792 // expectations.
793 MDNode *ProfileData = getMDNode(LLVMContext::MD_prof);
793 MDNode *ProfileData = getMetadata(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 = cast(this)->getMDNode(LLVMContext::MD_fpmath);
2074 const MDNode *MD =
2075 cast(this)->getMetadata(LLVMContext::MD_fpmath);
20752076 if (!MD)
20762077 return 0.0;
20772078 ConstantFP *Accuracy = cast(MD->getOperand(0));
554554 // NamedMDNode implementation.
555555 //
556556
557 static SmallVector, 4> &getNMDOps(void *Operands) {
558 return *(SmallVector, 4> *)Operands;
557 static SmallVector, 4> &getNMDOps(void *Operands) {
558 return *(SmallVector, 4> *)Operands;
559559 }
560560
561561 NamedMDNode::NamedMDNode(const Twine &N)
562562 : Name(N.str()), Parent(nullptr),
563 Operands(new SmallVectorValue>, 4>()) {}
563 Operands(new SmallVectorMDNode>, 4>()) {}
564564
565565 NamedMDNode::~NamedMDNode() {
566566 dropAllReferences();
571571 return (unsigned)getNMDOps(Operands).size();
572572 }
573573
574 Value *NamedMDNode::getOperand(unsigned i) const {
574 MDNode *NamedMDNode::getOperand(unsigned i) const {
575575 assert(i < getNumOperands() && "Invalid Operand number!");
576576 return &*getNMDOps(Operands)[i];
577577 }
578578
579 void NamedMDNode::addOperand(Value *V) {
580 auto *M = cast(V);
579 void NamedMDNode::addOperand(MDNode *M) {
581580 assert(!M->isFunctionLocal() &&
582581 "NamedMDNode operands must not be function-local!");
583 getNMDOps(Operands).push_back(TrackingVH<Value>(M));
582 getNMDOps(Operands).push_back(TrackingVH<MDNode>(M));
584583 }
585584
586585 void NamedMDNode::eraseFromParent() {
599598 // Instruction Metadata method implementations.
600599 //
601600
602 void Instruction::setMetadata(StringRef Kind, Value *MD) {
603 if (!MD && !hasMetadata()) return;
604 setMetadata(getContext().getMDKindID(Kind), MD);
605 }
606
607 Value *Instruction::getMetadataImpl(StringRef Kind) const {
601 void Instruction::setMetadata(StringRef Kind, MDNode *Node) {
602 if (!Node && !hasMetadata())
603 return;
604 setMetadata(getContext().getMDKindID(Kind), Node);
605 }
606
607 MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
608608 return getMetadataImpl(getContext().getMDKindID(Kind));
609 }
610
611 MDNode *Instruction::getMDNodeImpl(unsigned KindID) const {
612 return cast_or_null(getMetadataImpl(KindID));
613 }
614
615 MDNode *Instruction::getMDNodeImpl(StringRef Kind) const {
616 return cast_or_null(getMetadataImpl(Kind));
617609 }
618610
619611 void Instruction::dropUnknownMetadata(ArrayRef KnownIDs) {
662654
663655 /// setMetadata - Set the metadata of of the specified kind to the specified
664656 /// node. This updates/replaces metadata if already present, or removes it if
665 /// MD is null.
666 void Instruction::setMetadata(unsigned KindID, Value *MD) {
667 if (!MD && !hasMetadata()) return;
668
669 // For now, we only expect MDNodes here.
670 MDNode *Node = cast_or_null(MD);
657 /// Node is null.
658 void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
659 if (!Node && !hasMetadata())
660 return;
671661
672662 // Handle 'dbg' as a special case since it is not stored in the hash table.
673663 if (KindID == LLVMContext::MD_dbg) {
728718 setMetadata(LLVMContext::MD_noalias, N.NoAlias);
729719 }
730720
731 Value *Instruction::getMetadataImpl(unsigned KindID) const {
721 MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
732722 // Handle 'dbg' as a special case since it is not stored in the hash table.
733723 if (KindID == LLVMContext::MD_dbg)
734724 return DbgLoc.getAsMDNode(getContext());
745735 }
746736
747737 void Instruction::getAllMetadataImpl(
748 SmallVectorImplValue *>> &Result) const {
738 SmallVectorImplMDNode *>> &Result) const {
749739 Result.clear();
750740
751741 // Handle 'dbg' as a special case since it is not stored in the hash table.
770760 }
771761
772762 void Instruction::getAllMetadataOtherThanDebugLocImpl(
773 SmallVectorImplValue *>> &Result) const {
763 SmallVectorImplMDNode *>> &Result) const {
774764 Result.clear();
775765 assert(hasMetadataHashEntry() &&
776766 getContext().pImpl->MetadataStore.count(this) &&
275275 const NamedMDNode *ModFlags = getModuleFlagsMetadata();
276276 if (!ModFlags) return;
277277
278 for (const Value *FlagMD : ModFlags->operands()) {
279 const MDNode *Flag = cast(FlagMD);
278 for (const MDNode *Flag : ModFlags->operands()) {
280279 ModFlagBehavior MFB;
281280 if (Flag->getNumOperands() >= 3 &&
282281 isValidModFlagBehavior(Flag->getOperand(0), MFB) &&
3939 }
4040
4141 // Get types from functions.
42 SmallVectorValue *>, 4> MDForInst;
42 SmallVectorMDNode *>, 4> MDForInst;
4343 for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) {
4444 incorporateType(FI->getType());
4545
7070 // Incorporate types hiding in metadata.
7171 I.getAllMetadataOtherThanDebugLoc(MDForInst);
7272 for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
73 incorporateMDNode(cast(MDForInst[i].second));
73 incorporateMDNode(MDForInst[i].second);
7474
7575 MDForInst.clear();
7676 }
8080 E = M.named_metadata_end(); I != E; ++I) {
8181 const NamedMDNode *NMD = I;
8282 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
83 incorporateMDNode(NMD->getOperandAsMDNode(i));
83 incorporateMDNode(NMD->getOperand(i));
8484 }
8585 }
8686
554554
555555 void Verifier::visitNamedMDNode(const NamedMDNode &NMD) {
556556 for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i) {
557 MDNode *MD = NMD.getOperandAsMDNode(i);
557 MDNode *MD = NMD.getOperand(i);
558558 if (!MD)
559559 continue;
560560
623623 // llvm.ident takes a list of metadata entry. Each entry has only one string.
624624 // Scan each llvm.ident entry and make sure that this requirement is met.
625625 for (unsigned i = 0, e = Idents->getNumOperands(); i != e; ++i) {
626 const MDNode *N = Idents->getOperandAsMDNode(i);
626 const MDNode *N = Idents->getOperand(i);
627627 Assert1(N->getNumOperands() == 1,
628628 "incorrect number of operands in llvm.ident metadata", N);
629629 Assert1(isa(N->getOperand(0)),
641641 DenseMap SeenIDs;
642642 SmallVector Requirements;
643643 for (unsigned I = 0, E = Flags->getNumOperands(); I != E; ++I) {
644 visitModuleFlag(Flags->getOperandAsMDNode(I), SeenIDs, Requirements);
644 visitModuleFlag(Flags->getOperand(I), SeenIDs, Requirements);
645645 }
646646
647647 // Validate that the requirements in the module are valid.
22662266 }
22672267 }
22682268
2269 if (MDNode *MD = I.getMDNode(LLVMContext::MD_fpmath)) {
2269 if (MDNode *MD = I.getMetadata(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.getMDNode(LLVMContext::MD_range)) {
2283 if (MDNode *Range = I.getMetadata(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->getMDNode(LLVMContext::MD_dbg))
2589 if (MDNode *MD = I->getMetadata(LLVMContext::MD_dbg))
25902590 Finder.processLocation(*M, DILocation(MD));
25912591 if (const CallInst *CI = dyn_cast(&*I))
25922592 processCallInst(Finder, *CI);
12861286 DenseMap Flags;
12871287 SmallSetVector Requirements;
12881288 for (unsigned I = 0, E = DstModFlags->getNumOperands(); I != E; ++I) {
1289 MDNode *Op = DstModFlags->getOperandAsMDNode(I);
1289 MDNode *Op = DstModFlags->getOperand(I);
12901290 ConstantInt *Behavior = cast(Op->getOperand(0));
12911291 MDString *ID = cast(Op->getOperand(1));
12921292
13011301 // requirements.
13021302 bool HasErr = false;
13031303 for (unsigned I = 0, E = SrcModFlags->getNumOperands(); I != E; ++I) {
1304 MDNode *SrcOp = SrcModFlags->getOperandAsMDNode(I);
1304 MDNode *SrcOp = SrcModFlags->getOperand(I);
13051305 ConstantInt *SrcBehavior = cast(SrcOp->getOperand(0));
13061306 MDString *ID = cast(SrcOp->getOperand(1));
13071307 MDNode *DstOp = Flags.lookup(ID);
370370 // Check if any operand is or contains a global variable in GVMap, and thus
371371 // converted to another value.
372372 for (unsigned i = 0; i < NumOperands; ++i) {
373 MDNode *Operand = cast(N->getOperand(i));
373 MDNode *Operand = N->getOperand(i);
374374 MDNode *NewOperand = remapMDNode(M, Operand);
375375 OperandChanged |= Operand != NewOperand;
376376 NewOperands.push_back(NewOperand);
7272 return;
7373 key_val_pair_t tmp;
7474 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
75 const MDNode *elem = NMD->getOperandAsMDNode(i);
75 const MDNode *elem = NMD->getOperand(i);
7676
7777 Value *entity = elem->getOperand(0);
7878 // entity may be null due to DCE
318318 }
319319
320320 bool llvm::getAlign(const CallInst &I, unsigned index, unsigned &align) {
321 if (MDNode *alignNode = I.getMDNode("callalign")) {
321 if (MDNode *alignNode = I.getMetadata("callalign")) {
322322 for (int i = 0, n = alignNode->getNumOperands(); i < n; i++) {
323323 if (const ConstantInt *CI =
324324 dyn_cast(alignNode->getOperand(i))) {
8686 Value *BitCast = Builder.CreateBitCast(Ptr,
8787 PointerType::get(v4i32,PtrTy->getPointerAddressSpace()));
8888 LoadInst *Load = Builder.CreateLoad(BitCast);
89 // FIXME: Should the DebugLoc really get dropped here?
90 SmallVectorValue *>, 8> MD;
89 SmallVectorMDNode *>, 8> MD;
9190 I.getAllMetadataOtherThanDebugLoc(MD);
9291 for (unsigned i = 0, e = MD.size(); i != e; ++i) {
9392 Load->setMetadata(MD[i].first, MD[i].second);
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->getMDNode(LLVMContext::MD_tbaa_struct)) {
119 if (MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa_struct)) {
120120 if (M->getNumOperands() == 3 &&
121121 M->getOperand(0) &&
122122 isa(M->getOperand(0)) &&
303303 static LoadInst *combineLoadToNewType(InstCombiner &IC, LoadInst &LI, Type *NewTy) {
304304 Value *Ptr = LI.getPointerOperand();
305305 unsigned AS = LI.getPointerAddressSpace();
306 SmallVectorValue *>, 8> MD;
306 SmallVectorMDNode *>, 8> MD;
307307 LI.getAllMetadata(MD);
308308
309309 LoadInst *NewLoad = IC.Builder->CreateAlignedLoad(
311311 LI.getAlignment(), LI.getName());
312312 for (const auto &MDPair : MD) {
313313 unsigned ID = MDPair.first;
314 Value *N = MDPair.second;
314 MDNode *N = MDPair.second;
315315 // Note, essentially every kind of metadata should be preserved here! This
316316 // routine is supposed to clone a load instruction changing *only its type*.
317317 // The only metadata it makes sense to drop is metadata which is invalidated
255255 NamedMDNode *Globals = M.getNamedMetadata("llvm.asan.globals");
256256 if (!Globals)
257257 return;
258 for (const Value *MDV : Globals->operands()) {
259 const MDNode *MDN = cast(MDV);
260
258 for (auto MDN : Globals->operands()) {
261259 // Metadata node contains the global and the fields of "Entry".
262260 assert(MDN->getNumOperands() == 5);
263261 Value *V = MDN->getOperand(0);
473473 if (!CUNode || CUNode->getNumOperands() == 0)
474474 return false;
475475
476 DICompileUnit CU(cast(CUNode->getOperand(0)));
476 DICompileUnit CU(CUNode->getOperand(0));
477477 if (!CU.Verify())
478478 return false;
479479
416416 std::string GCOVProfiler::mangleName(DICompileUnit CU, const char *NewStem) {
417417 if (NamedMDNode *GCov = M->getNamedMetadata("llvm.gcov")) {
418418 for (int i = 0, e = GCov->getNumOperands(); i != e; ++i) {
419 MDNode *N = GCov->getOperandAsMDNode(i);
419 MDNode *N = GCov->getOperand(i);
420420 if (N->getNumOperands() != 2) continue;
421421 MDString *GCovFile = dyn_cast(N->getOperand(0));
422422 MDNode *CompileUnit = dyn_cast(N->getOperand(1));
478478 // this pass over the original .o's as they're produced, or run it after
479479 // LTO, we'll generate the same .gcno files.
480480
481 DICompileUnit CU(CU_Nodes->getOperandAsMDNode(i));
481 DICompileUnit CU(CU_Nodes->getOperand(i));
482482 std::error_code EC;
483483 raw_fd_ostream out(mangleName(CU, "gcno"), EC, sys::fs::F_None);
484484 std::string EdgeDestinations;
565565 bool Result = false;
566566 bool InsertIndCounterIncrCode = false;
567567 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
568 DICompileUnit CU(CU_Nodes->getOperandAsMDNode(i));
568 DICompileUnit CU(CU_Nodes->getOperand(i));
569569 DIArray SPs = CU.getSubprograms();
570570 SmallVector, 8> CountersBySP;
571571 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
846846 NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
847847 if (CU_Nodes) {
848848 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
849 DICompileUnit CU(CU_Nodes->getOperandAsMDNode(i));
849 DICompileUnit CU(CU_Nodes->getOperand(i));
850850 std::string FilenameGcda = mangleName(CU, "gcda");
851851 uint32_t CfgChecksum = FileChecksums.empty() ? 0 : FileChecksums[i];
852852 Builder.CreateCall3(StartFile,
230230 }
231231
232232 static bool isVtableAccess(Instruction *I) {
233 if (MDNode *Tag = I->getMDNode(LLVMContext::MD_tbaa))
233 if (MDNode *Tag = I->getMetadata(LLVMContext::MD_tbaa))
234234 return Tag->isTBAAVtableAccess();
235235 return false;
236236 }
304304 if (NamedMDNode *NMD =
305305 M.getNamedMetadata("clang.arc.retainAutoreleasedReturnValueMarker"))
306306 if (NMD->getNumOperands() == 1) {
307 const MDNode *N = NMD->getOperandAsMDNode(0);
307 const MDNode *N = NMD->getOperand(0);
308308 if (N->getNumOperands() == 1)
309309 if (const MDString *S = dyn_cast(N->getOperand(0)))
310310 RetainRVMarker = S;
824824 // reference to said Node. Otherwise just return 0.
825825 if (Instruction *Inst = dyn_cast(Ptr)) {
826826 MDNode *Node;
827 if (!(Node = Inst->getMDNode(NodeId))) {
827 if (!(Node = Inst->getMetadata(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->getMDNode(ImpreciseReleaseMDKind);
1738 MDNode *ReleaseMetadata = Inst->getMetadata(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->getMDNode(ImpreciseReleaseMDKind);
2019 MDNode *ReleaseMetadata = Inst->getMetadata(ImpreciseReleaseMDKind);
20202020
20212021 switch (OldSeq) {
20222022 case S_Retain:
326326 // Transfer metadata from Op to the instructions in CV if it is known
327327 // to be safe to do so.
328328 void Scalarizer::transferMetadata(Instruction *Op, const ValueVector &CV) {
329 SmallVectorValue *>, 4> MDs;
329 SmallVectorMDNode *>, 4> MDs;
330330 Op->getAllMetadataOtherThanDebugLoc(MDs);
331331 for (unsigned I = 0, E = CV.size(); I != E; ++I) {
332332 if (Instruction *New = dyn_cast(CV[I])) {
333 for (auto MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI)
333 for (SmallVectorImpl>::iterator
334 MI = MDs.begin(),
335 ME = MDs.end();
336 MI != ME; ++MI)
334337 if (canTransferMetadata(MI->first))
335338 New->setMetadata(MI->first, MI->second);
336339 New->setDebugLoc(Op->getDebugLoc());
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->getMDNode(LLVMContext::MD_alias_scope))
299 if (const MDNode *M = J->getMetadata(LLVMContext::MD_alias_scope))
300300 MD.insert(M);
301 if (const MDNode *M = J->getMDNode(LLVMContext::MD_noalias))
301 if (const MDNode *M = J->getMetadata(LLVMContext::MD_noalias))
302302 MD.insert(M);
303303 }
304304
358358 if (!NI)
359359 continue;
360360
361 if (MDNode *M = NI->getMDNode(LLVMContext::MD_alias_scope)) {
361 if (MDNode *M = NI->getMetadata(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()->getMDNode(LLVMContext::MD_alias_scope))
367 CS.getInstruction()->getMetadata(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()->getMDNode(LLVMContext::MD_alias_scope))
372 CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope))
373373 NI->setMetadata(LLVMContext::MD_alias_scope, M);
374374 }
375375
376 if (MDNode *M = NI->getMDNode(LLVMContext::MD_noalias)) {
376 if (MDNode *M = NI->getMetadata(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 = CS.getInstruction()->getMDNode(LLVMContext::MD_noalias))
381 if (MDNode *CSM =
382 CS.getInstruction()->getMetadata(LLVMContext::MD_noalias))
382383 NewMD = MDNode::concatenate(NewMD, CSM);
383384 NI->setMetadata(LLVMContext::MD_noalias, NewMD);
384385 } else if (NI->mayReadOrWriteMemory()) {
385 if (MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_noalias))
386 if (MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_noalias))
386387 NI->setMetadata(LLVMContext::MD_noalias, M);
387388 }
388389 }
588589 if (!NoAliases.empty())
589590 NI->setMetadata(LLVMContext::MD_noalias,
590591 MDNode::concatenate(
591 NI->getMDNode(LLVMContext::MD_noalias),
592 NI->getMetadata(LLVMContext::MD_noalias),
592593 MDNode::get(CalledFunc->getContext(), NoAliases)));
593594
594595 // Next, we want to figure out all of the sets to which we might belong.
614615 if (!Scopes.empty())
615616 NI->setMetadata(
616617 LLVMContext::MD_alias_scope,
617 MDNode::concatenate(NI->getMDNode(LLVMContext::MD_alias_scope),
618 MDNode::concatenate(NI->getMetadata(LLVMContext::MD_alias_scope),
618619 MDNode::get(CalledFunc->getContext(), Scopes)));
619620 }
620621 }
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->getMDNode(LLVMContext::MD_prof);
130 MDNode *MD = SI->getMetadata(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->getMDNode(LLVMContext::MD_prof);
208 MDNode *MD = SI->getMetadata(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));
13071307 }
13081308
13091309 void llvm::combineMetadata(Instruction *K, const Instruction *J, ArrayRef KnownIDs) {
1310 SmallVectorValue *>, 4> Metadata;
1310 SmallVectorMDNode *>, 4> Metadata;
13111311 K->dropUnknownMetadata(KnownIDs);
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->getMDNode(Kind);
1316 MDNode *KMD = cast(Metadata[i].second);
1315 MDNode *JMD = J->getMetadata(Kind);
1316 MDNode *KMD = Metadata[i].second;
13171317
13181318 switch (Kind) {
13191319 default:
642642
643643 // Collect branch weights into a vector.
644644 SmallVector Weights;
645 MDNode *MD = SI->getMDNode(LLVMContext::MD_prof);
645 MDNode *MD = SI->getMetadata(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->getMDNode(LLVMContext::MD_prof);
740 MDNode *ProfMD = I->getMetadata(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->getMDNode(LLVMContext::MD_prof);
753 MDNode *MD = TI->getMetadata(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->getMDNode(LLVMContext::MD_prof);
1972 MDNode *ProfileData = BI->getMetadata(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));
207207 }
208208
209209 // Remap attached metadata.
210 SmallVectorValue *>, 4> MDs;
210 SmallVectorMDNode *>, 4> MDs;
211211 I->getAllMetadata(MDs);
212 for (auto MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) {
213 Value *Old = MI->second;
214 Value *New = MapValue(Old, VMap, Flags, TypeMapper, Materializer);
212 for (SmallVectorImpl>::iterator
213 MI = MDs.begin(),
214 ME = MDs.end();
215 MI != ME; ++MI) {
216 MDNode *Old = MI->second;
217 MDNode *New = MapValue(Old, VMap, Flags, TypeMapper, Materializer);
215218 if (New != Old)
216219 I->setMetadata(MI->first, New);
217220 }
530530
531531 /// \brief Propagate known metadata from one instruction to another.
532532 static void propagateMetadata(Instruction *To, const Instruction *From) {
533 SmallVectorValue *>, 4> Metadata;
533 SmallVectorMDNode *>, 4> Metadata;
534534 From->getAllMetadataOtherThanDebugLoc(Metadata);
535535
536536 for (auto M : Metadata) {
187187 /// \returns \p I after propagating metadata from \p VL.
188188 static Instruction *propagateMetadata(Instruction *I, ArrayRef VL) {
189189 Instruction *I0 = cast(VL[0]);
190 SmallVectorValue *>, 4> Metadata;
190 SmallVectorMDNode *>, 4> Metadata;
191191 I0->getAllMetadataOtherThanDebugLoc(Metadata);
192192
193193 for (unsigned i = 0, n = Metadata.size(); i != n; ++i) {
194194 unsigned Kind = Metadata[i].first;
195 MDNode *MD = cast_or_null(Metadata[i].second);
195 MDNode *MD = Metadata[i].second;
196196
197197 for (int i = 1, e = VL.size(); MD && i != e; i++) {
198198 Instruction *I = cast(VL[i]);
199 MDNode *IMD = I->getMDNode(Kind);
199 MDNode *IMD = I->getMetadata(Kind);
200200
201201 switch (Kind) {
202202 default:
5454 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
5555 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
5656 std::string Name;
57 DISubprogram SP(cast_or_null(NMD->getOperand(i)));
57 DISubprogram SP(NMD->getOperand(i));
5858 assert((!SP || SP.isSubprogram()) &&
5959 "A MDNode in llvm.dbg.sp should be null or a DISubprogram.");
6060 if (!SP)