Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 5bf8ade

Browse files
committed
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
1 parent 15d6f7c commit 5bf8ade

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+173
-201
lines changed

include/llvm/IR/IRBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#include "llvm/IR/DataLayout.h"
2424
#include "llvm/IR/Instructions.h"
2525
#include "llvm/IR/LLVMContext.h"
26-
#include "llvm/IR/Metadata.h"
2726
#include "llvm/IR/Operator.h"
2827
#include "llvm/IR/ValueHandle.h"
2928
#include "llvm/Support/CBindingWrapping.h"
3029

3130
namespace llvm {
31+
class MDNode;
3232

3333
/// \brief This provides the default implementation of the IRBuilder
3434
/// 'InsertHelper' method that is called whenever an instruction is created by

include/llvm/IR/Instruction.h

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -141,49 +141,31 @@ class Instruction : public User, public ilist_node<Instruction> {
141141

142142
/// getMetadata - Get the metadata of given kind attached to this Instruction.
143143
/// If the metadata is not found then return null.
144-
Value *getMetadata(unsigned KindID) const {
144+
MDNode *getMetadata(unsigned KindID) const {
145145
if (!hasMetadata()) return nullptr;
146146
return getMetadataImpl(KindID);
147147
}
148148

149149
/// getMetadata - Get the metadata of given kind attached to this Instruction.
150150
/// If the metadata is not found then return null.
151-
Value *getMetadata(StringRef Kind) const {
151+
MDNode *getMetadata(StringRef Kind) const {
152152
if (!hasMetadata()) return nullptr;
153153
return getMetadataImpl(Kind);
154154
}
155155

156-
/// Get the the metadata as an MDNode.
157-
///
158-
/// \pre Any KindID metadata is implemented using \a MDNode.
159-
MDNode *getMDNode(unsigned KindID) const {
160-
if (!hasMetadata())
161-
return nullptr;
162-
return getMDNodeImpl(KindID);
163-
}
164-
165-
/// Get the the metadata as an MDNode.
166-
///
167-
/// \pre Any KindID metadata is implemented using \a MDNode.
168-
MDNode *getMDNode(StringRef Kind) const {
169-
if (!hasMetadata())
170-
return nullptr;
171-
return getMDNodeImpl(Kind);
172-
}
173-
174156
/// getAllMetadata - Get all metadata attached to this Instruction. The first
175157
/// element of each pair returned is the KindID, the second element is the
176158
/// metadata value. This list is returned sorted by the KindID.
177159
void
178-
getAllMetadata(SmallVectorImpl<std::pair<unsigned, Value *>> &MDs) const {
160+
getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
179161
if (hasMetadata())
180162
getAllMetadataImpl(MDs);
181163
}
182164

183165
/// getAllMetadataOtherThanDebugLoc - This does the same thing as
184166
/// getAllMetadata, except that it filters out the debug location.
185167
void getAllMetadataOtherThanDebugLoc(
186-
SmallVectorImpl<std::pair<unsigned, Value *>> &MDs) const {
168+
SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {
187169
if (hasMetadataOtherThanDebugLoc())
188170
getAllMetadataOtherThanDebugLocImpl(MDs);
189171
}
@@ -195,9 +177,9 @@ class Instruction : public User, public ilist_node<Instruction> {
195177

196178
/// setMetadata - Set the metadata of the specified kind to the specified
197179
/// node. This updates/replaces metadata if already present, or removes it if
198-
/// MD is null.
199-
void setMetadata(unsigned KindID, Value *MD);
200-
void setMetadata(StringRef Kind, Value *MD);
180+
/// Node is null.
181+
void setMetadata(unsigned KindID, MDNode *Node);
182+
void setMetadata(StringRef Kind, MDNode *Node);
201183

202184
/// \brief Drop unknown metadata.
203185
/// Passes are required to drop metadata they don't understand. This is a
@@ -290,14 +272,12 @@ class Instruction : public User, public ilist_node<Instruction> {
290272
}
291273

292274
// These are all implemented in Metadata.cpp.
293-
Value *getMetadataImpl(unsigned KindID) const;
294-
Value *getMetadataImpl(StringRef Kind) const;
295-
MDNode *getMDNodeImpl(unsigned KindID) const;
296-
MDNode *getMDNodeImpl(StringRef Kind) const;
275+
MDNode *getMetadataImpl(unsigned KindID) const;
276+
MDNode *getMetadataImpl(StringRef Kind) const;
297277
void
298-
getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, Value *>> &) const;
278+
getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const;
299279
void getAllMetadataOtherThanDebugLocImpl(
300-
SmallVectorImpl<std::pair<unsigned, Value *>> &) const;
280+
SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const;
301281
void clearMetadataHashEntries();
302282
public:
303283
//===--------------------------------------------------------------------===//

include/llvm/IR/Metadata.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ class MDNode : public Value, public FoldingSetNode {
237237
};
238238

239239
//===----------------------------------------------------------------------===//
240-
/// \brief A tuple of metadata nodes.
240+
/// \brief A tuple of MDNodes.
241241
///
242242
/// Despite its name, a NamedMDNode isn't itself an MDNode. NamedMDNodes belong
243-
/// to modules, have names, and contain lists of metadata nodes.
243+
/// to modules, have names, and contain lists of MDNodes.
244244
class NamedMDNode : public ilist_node<NamedMDNode> {
245245
friend class SymbolTableListTraits<NamedMDNode, Module>;
246246
friend struct ilist_traits<NamedMDNode>;
@@ -250,7 +250,7 @@ class NamedMDNode : public ilist_node<NamedMDNode> {
250250

251251
std::string Name;
252252
Module *Parent;
253-
void *Operands; // SmallVector<TrackingVH<Value>, 4>
253+
void *Operands; // SmallVector<TrackingVH<MDNode>, 4>
254254

255255
void setParent(Module *M) { Parent = M; }
256256

@@ -305,24 +305,21 @@ class NamedMDNode : public ilist_node<NamedMDNode> {
305305
inline Module *getParent() { return Parent; }
306306
inline const Module *getParent() const { return Parent; }
307307

308-
Value *getOperand(unsigned i) const;
309-
MDNode *getOperandAsMDNode(unsigned i) const {
310-
return cast_or_null<MDNode>(getOperand(i));
311-
}
308+
MDNode *getOperand(unsigned i) const;
312309
unsigned getNumOperands() const;
313-
void addOperand(Value *M);
310+
void addOperand(MDNode *M);
314311
StringRef getName() const;
315312
void print(raw_ostream &ROS) const;
316313
void dump() const;
317314

318315
// ---------------------------------------------------------------------------
319316
// Operand Iterator interface...
320317
//
321-
typedef op_iterator_impl<Value *, Value> op_iterator;
318+
typedef op_iterator_impl<MDNode *, MDNode> op_iterator;
322319
op_iterator op_begin() { return op_iterator(this, 0); }
323320
op_iterator op_end() { return op_iterator(this, getNumOperands()); }
324321

325-
typedef op_iterator_impl<const Value *, Value> const_op_iterator;
322+
typedef op_iterator_impl<const MDNode *, MDNode> const_op_iterator;
326323
const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
327324
const_op_iterator op_end() const { return const_op_iterator(this, getNumOperands()); }
328325

lib/Analysis/BranchProbabilityInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ bool BranchProbabilityInfo::calcMetadataWeights(BasicBlock *BB) {
180180
if (!isa<BranchInst>(TI) && !isa<SwitchInst>(TI))
181181
return false;
182182

183-
MDNode *WeightsNode = TI->getMDNode(LLVMContext::MD_prof);
183+
MDNode *WeightsNode = TI->getMetadata(LLVMContext::MD_prof);
184184
if (!WeightsNode)
185185
return false;
186186

lib/Analysis/LoopInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ bool Loop::isSafeToClone() const {
235235
MDNode *Loop::getLoopID() const {
236236
MDNode *LoopID = nullptr;
237237
if (isLoopSimplifyForm()) {
238-
LoopID = getLoopLatch()->getTerminator()->getMDNode(LoopMDName);
238+
LoopID = getLoopLatch()->getTerminator()->getMetadata(LoopMDName);
239239
} else {
240240
// Go through each predecessor of the loop header and check the
241241
// terminator for the metadata.
@@ -247,7 +247,7 @@ MDNode *Loop::getLoopID() const {
247247
// Check if this terminator branches to the loop header.
248248
for (unsigned i = 0, ie = TI->getNumSuccessors(); i != ie; ++i) {
249249
if (TI->getSuccessor(i) == H) {
250-
MD = TI->getMDNode(LoopMDName);
250+
MD = TI->getMetadata(LoopMDName);
251251
break;
252252
}
253253
}
@@ -309,7 +309,7 @@ bool Loop::isAnnotatedParallel() const {
309309
// nested parallel loops). The loop identifier metadata refers to
310310
// itself so we can check both cases with the same routine.
311311
MDNode *loopIdMD =
312-
II->getMDNode(LLVMContext::MD_mem_parallel_loop_access);
312+
II->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
313313

314314
if (!loopIdMD)
315315
return false;

lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3668,7 +3668,7 @@ ScalarEvolution::GetMinTrailingZeros(const SCEV *S) {
36683668
/// metadata present in the IR.
36693669
static Optional<ConstantRange> GetRangeFromMetadata(Value *V) {
36703670
if (Instruction *I = dyn_cast<Instruction>(V)) {
3671-
if (MDNode *MD = I->getMDNode(LLVMContext::MD_range)) {
3671+
if (MDNode *MD = I->getMetadata(LLVMContext::MD_range)) {
36723672
ConstantRange TotalRange(
36733673
cast<IntegerType>(I->getType())->getBitWidth(), false);
36743674

lib/Analysis/ScopedNoAliasAA.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ ScopedNoAliasAA::getModRefInfo(ImmutableCallSite CS, const Location &Loc) {
213213
if (!EnableScopedNoAlias)
214214
return AliasAnalysis::getModRefInfo(CS, Loc);
215215

216-
if (!mayAliasInScopes(Loc.AATags.Scope, CS.getInstruction()->getMDNode(
216+
if (!mayAliasInScopes(Loc.AATags.Scope, CS.getInstruction()->getMetadata(
217217
LLVMContext::MD_noalias)))
218218
return NoModRef;
219219

220220
if (!mayAliasInScopes(
221-
CS.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
221+
CS.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
222222
Loc.AATags.NoAlias))
223223
return NoModRef;
224224

@@ -231,13 +231,13 @@ ScopedNoAliasAA::getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2) {
231231
return AliasAnalysis::getModRefInfo(CS1, CS2);
232232

233233
if (!mayAliasInScopes(
234-
CS1.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
235-
CS2.getInstruction()->getMDNode(LLVMContext::MD_noalias)))
234+
CS1.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
235+
CS2.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
236236
return NoModRef;
237237

238238
if (!mayAliasInScopes(
239-
CS2.getInstruction()->getMDNode(LLVMContext::MD_alias_scope),
240-
CS1.getInstruction()->getMDNode(LLVMContext::MD_noalias)))
239+
CS2.getInstruction()->getMetadata(LLVMContext::MD_alias_scope),
240+
CS1.getInstruction()->getMetadata(LLVMContext::MD_noalias)))
241241
return NoModRef;
242242

243243
return AliasAnalysis::getModRefInfo(CS1, CS2);

lib/Analysis/TypeBasedAliasAnalysis.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ TypeBasedAliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
493493

494494
// If this is an "immutable" type, we can assume the call doesn't write
495495
// to memory.
496-
if (const MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
496+
if (const MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
497497
if ((!isStructPathTBAA(M) && TBAANode(M).TypeIsImmutable()) ||
498498
(isStructPathTBAA(M) && TBAAStructTagNode(M).TypeIsImmutable()))
499499
Min = OnlyReadsMemory;
@@ -514,7 +514,8 @@ TypeBasedAliasAnalysis::getModRefInfo(ImmutableCallSite CS,
514514
return AliasAnalysis::getModRefInfo(CS, Loc);
515515

516516
if (const MDNode *L = Loc.AATags.TBAA)
517-
if (const MDNode *M = CS.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
517+
if (const MDNode *M =
518+
CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
518519
if (!Aliases(L, M))
519520
return NoModRef;
520521

@@ -527,9 +528,10 @@ TypeBasedAliasAnalysis::getModRefInfo(ImmutableCallSite CS1,
527528
if (!EnableTBAA)
528529
return AliasAnalysis::getModRefInfo(CS1, CS2);
529530

530-
if (const MDNode *M1 = CS1.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
531+
if (const MDNode *M1 =
532+
CS1.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
531533
if (const MDNode *M2 =
532-
CS2.getInstruction()->getMDNode(LLVMContext::MD_tbaa))
534+
CS2.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
533535
if (!Aliases(M1, M2))
534536
return NoModRef;
535537

@@ -613,20 +615,20 @@ MDNode *MDNode::getMostGenericTBAA(MDNode *A, MDNode *B) {
613615
void Instruction::getAAMetadata(AAMDNodes &N, bool Merge) const {
614616
if (Merge)
615617
N.TBAA =
616-
MDNode::getMostGenericTBAA(N.TBAA, getMDNode(LLVMContext::MD_tbaa));
618+
MDNode::getMostGenericTBAA(N.TBAA, getMetadata(LLVMContext::MD_tbaa));
617619
else
618-
N.TBAA = getMDNode(LLVMContext::MD_tbaa);
620+
N.TBAA = getMetadata(LLVMContext::MD_tbaa);
619621

620622
if (Merge)
621623
N.Scope =
622-
MDNode::intersect(N.Scope, getMDNode(LLVMContext::MD_alias_scope));
624+
MDNode::intersect(N.Scope, getMetadata(LLVMContext::MD_alias_scope));
623625
else
624-
N.Scope = getMDNode(LLVMContext::MD_alias_scope);
626+
N.Scope = getMetadata(LLVMContext::MD_alias_scope);
625627

626628
if (Merge)
627629
N.NoAlias =
628-
MDNode::intersect(N.NoAlias, getMDNode(LLVMContext::MD_noalias));
630+
MDNode::intersect(N.NoAlias, getMetadata(LLVMContext::MD_noalias));
629631
else
630-
N.NoAlias = getMDNode(LLVMContext::MD_noalias);
632+
N.NoAlias = getMetadata(LLVMContext::MD_noalias);
631633
}
632634

lib/Analysis/ValueTracking.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne,
862862
switch (I->getOpcode()) {
863863
default: break;
864864
case Instruction::Load:
865-
if (MDNode *MD = cast<LoadInst>(I)->getMDNode(LLVMContext::MD_range))
865+
if (MDNode *MD = cast<LoadInst>(I)->getMetadata(LLVMContext::MD_range))
866866
computeKnownBitsFromRangeMetadata(*MD, KnownZero);
867867
break;
868868
case Instruction::And: {
@@ -1258,7 +1258,7 @@ void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne,
12581258
}
12591259
case Instruction::Call:
12601260
case Instruction::Invoke:
1261-
if (MDNode *MD = cast<Instruction>(I)->getMDNode(LLVMContext::MD_range))
1261+
if (MDNode *MD = cast<Instruction>(I)->getMetadata(LLVMContext::MD_range))
12621262
computeKnownBitsFromRangeMetadata(*MD, KnownZero);
12631263
// If a range metadata is attached to this IntrinsicInst, intersect the
12641264
// explicit range specified by the metadata and the implicit range of
@@ -1533,7 +1533,7 @@ bool isKnownNonZero(Value *V, const DataLayout *TD, unsigned Depth,
15331533
}
15341534

15351535
if (Instruction* I = dyn_cast<Instruction>(V)) {
1536-
if (MDNode *Ranges = I->getMDNode(LLVMContext::MD_range)) {
1536+
if (MDNode *Ranges = I->getMetadata(LLVMContext::MD_range)) {
15371537
// If the possible ranges don't contain zero, then the value is
15381538
// definitely non-zero.
15391539
if (IntegerType* Ty = dyn_cast<IntegerType>(V->getType())) {

lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ static void WriteMetadataAttachment(const Function &F,
848848

849849
// Write metadata attachments
850850
// METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
851-
SmallVector<std::pair<unsigned, Value *>, 4> MDs;
851+
SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
852852

853853
for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
854854
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();

0 commit comments

Comments
 (0)