Remove the "metadata*" type and simplify the code it complicated. This was only

used to support GlobalVariables storing MDNodes, back when they were derived
from Constant before the introduction of NamedMDNode, but never removed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82943 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky
2009-09-27 23:27:42 +00:00
parent ae03af2663
commit c261df9fab
3 changed files with 22 additions and 95 deletions

View File

@ -1489,9 +1489,9 @@ Classifications</a> </div>
<div class="doc_text"> <div class="doc_text">
<h5>Overview:</h5> <h5>Overview:</h5>
<p>The metadata type represents embedded metadata. The only derived type that <p>The metadata type represents embedded metadata. No derived types may be
may contain metadata is <tt>metadata*</tt> or a function type that returns or created from metadata except for <a href="#t_function">function</a>
takes metadata typed parameters, but not pointer to metadata types.</p> arguments.
<h5>Syntax:</h5> <h5>Syntax:</h5>
<pre> <pre>
@ -1601,7 +1601,7 @@ Classifications</a> </div>
Variable argument functions can access their arguments with Variable argument functions can access their arguments with
the <a href="#int_varargs">variable argument handling intrinsic</a> the <a href="#int_varargs">variable argument handling intrinsic</a>
functions. '<tt>&lt;returntype&gt;</tt>' is a any type except functions. '<tt>&lt;returntype&gt;</tt>' is a any type except
<a href="#t_label">label</a> and <a href="#t_metadata">metadata</a>.</p> <a href="#t_label">label</a>.</p>
<h5>Examples:</h5> <h5>Examples:</h5>
<table class="layout"> <table class="layout">

View File

@ -365,9 +365,6 @@ const IntegerType *Type::getInt64Ty(LLVMContext &C) {
/// isValidReturnType - Return true if the specified type is valid as a return /// isValidReturnType - Return true if the specified type is valid as a return
/// type. /// type.
bool FunctionType::isValidReturnType(const Type *RetTy) { bool FunctionType::isValidReturnType(const Type *RetTy) {
if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
return PTy->getElementType()->getTypeID() != MetadataTyID;
return RetTy->getTypeID() != LabelTyID && return RetTy->getTypeID() != LabelTyID &&
RetTy->getTypeID() != MetadataTyID; RetTy->getTypeID() != MetadataTyID;
} }
@ -375,12 +372,7 @@ bool FunctionType::isValidReturnType(const Type *RetTy) {
/// isValidArgumentType - Return true if the specified type is valid as an /// isValidArgumentType - Return true if the specified type is valid as an
/// argument type. /// argument type.
bool FunctionType::isValidArgumentType(const Type *ArgTy) { bool FunctionType::isValidArgumentType(const Type *ArgTy) {
if ((!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy)) || return ArgTy->isFirstClassType() || isa<OpaqueType>(ArgTy);
(isa<PointerType>(ArgTy) &&
cast<PointerType>(ArgTy)->getElementType()->getTypeID() == MetadataTyID))
return false;
return true;
} }
FunctionType::FunctionType(const Type *Result, FunctionType::FunctionType(const Type *Result,
@ -817,15 +809,8 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
} }
bool ArrayType::isValidElementType(const Type *ElemTy) { bool ArrayType::isValidElementType(const Type *ElemTy) {
if (ElemTy->getTypeID() == VoidTyID || ElemTy->getTypeID() == LabelTyID || return ElemTy->getTypeID() != VoidTyID && ElemTy->getTypeID() != LabelTyID &&
ElemTy->getTypeID() == MetadataTyID || isa<FunctionType>(ElemTy)) ElemTy->getTypeID() != MetadataTyID && !isa<FunctionType>(ElemTy);
return false;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
if (PTy->getElementType()->getTypeID() == MetadataTyID)
return false;
return true;
} }
VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) { VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
@ -849,11 +834,8 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
} }
bool VectorType::isValidElementType(const Type *ElemTy) { bool VectorType::isValidElementType(const Type *ElemTy) {
if (ElemTy->isInteger() || ElemTy->isFloatingPoint() || return ElemTy->isInteger() || ElemTy->isFloatingPoint() ||
isa<OpaqueType>(ElemTy)) isa<OpaqueType>(ElemTy);
return true;
return false;
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -896,15 +878,8 @@ StructType *StructType::get(LLVMContext &Context, const Type *type, ...) {
} }
bool StructType::isValidElementType(const Type *ElemTy) { bool StructType::isValidElementType(const Type *ElemTy) {
if (ElemTy->getTypeID() == VoidTyID || ElemTy->getTypeID() == LabelTyID || return ElemTy->getTypeID() != VoidTyID && ElemTy->getTypeID() != LabelTyID &&
ElemTy->getTypeID() == MetadataTyID || isa<FunctionType>(ElemTy)) ElemTy->getTypeID() != MetadataTyID && !isa<FunctionType>(ElemTy);
return false;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
if (PTy->getElementType()->getTypeID() == MetadataTyID)
return false;
return true;
} }
@ -941,15 +916,9 @@ PointerType *Type::getPointerTo(unsigned addrs) const {
} }
bool PointerType::isValidElementType(const Type *ElemTy) { bool PointerType::isValidElementType(const Type *ElemTy) {
if (ElemTy->getTypeID() == VoidTyID || return ElemTy->getTypeID() != VoidTyID &&
ElemTy->getTypeID() == LabelTyID) ElemTy->getTypeID() != LabelTyID &&
return false; ElemTy->getTypeID() != MetadataTyID;
if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy))
if (PTy->getElementType()->getTypeID() == MetadataTyID)
return false;
return true;
} }

View File

@ -447,28 +447,6 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) {
Assert1(!GV.isConstant(), "'common' global may not be marked constant!", Assert1(!GV.isConstant(), "'common' global may not be marked constant!",
&GV); &GV);
} }
// Verify that any metadata used in a global initializer points only to
// other globals.
if (MDNode *FirstNode = dyn_cast<MDNode>(GV.getInitializer())) {
SmallVector<const MDNode *, 4> NodesToAnalyze;
NodesToAnalyze.push_back(FirstNode);
while (!NodesToAnalyze.empty()) {
const MDNode *N = NodesToAnalyze.back();
NodesToAnalyze.pop_back();
for (MDNode::const_elem_iterator I = N->elem_begin(),
E = N->elem_end(); I != E; ++I)
if (const Value *V = *I) {
if (const MDNode *Next = dyn_cast<MDNode>(V))
NodesToAnalyze.push_back(Next);
else
Assert3(isa<Constant>(V),
"reference to instruction from global metadata node",
&GV, N, V);
}
}
}
} else { } else {
Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() || Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() ||
GV.hasExternalWeakLinkage(), GV.hasExternalWeakLinkage(),
@ -622,12 +600,12 @@ void Verifier::visitFunction(Function &F) {
"# formal arguments must match # of arguments for function type!", "# formal arguments must match # of arguments for function type!",
&F, FT); &F, FT);
Assert1(F.getReturnType()->isFirstClassType() || Assert1(F.getReturnType()->isFirstClassType() ||
F.getReturnType() == Type::getVoidTy(F.getContext()) || F.getReturnType()->getTypeID() == Type::VoidTyID ||
isa<StructType>(F.getReturnType()), isa<StructType>(F.getReturnType()),
"Functions cannot return aggregate values!", &F); "Functions cannot return aggregate values!", &F);
Assert1(!F.hasStructRetAttr() || Assert1(!F.hasStructRetAttr() ||
F.getReturnType() == Type::getVoidTy(F.getContext()), F.getReturnType()->getTypeID() == Type::VoidTyID,
"Invalid struct return type!", &F); "Invalid struct return type!", &F);
const AttrListPtr &Attrs = F.getAttributes(); const AttrListPtr &Attrs = F.getAttributes();
@ -654,9 +632,6 @@ void Verifier::visitFunction(Function &F) {
bool isLLVMdotName = F.getName().size() >= 5 && bool isLLVMdotName = F.getName().size() >= 5 &&
F.getName().substr(0, 5) == "llvm."; F.getName().substr(0, 5) == "llvm.";
if (!isLLVMdotName)
Assert1(F.getReturnType() != Type::getMetadataTy(F.getContext()),
"Function may not return metadata unless it's an intrinsic", &F);
// Check that the argument values match the function type for this function... // Check that the argument values match the function type for this function...
unsigned i = 0; unsigned i = 0;
@ -763,7 +738,7 @@ void Verifier::visitTerminatorInst(TerminatorInst &I) {
void Verifier::visitReturnInst(ReturnInst &RI) { void Verifier::visitReturnInst(ReturnInst &RI) {
Function *F = RI.getParent()->getParent(); Function *F = RI.getParent()->getParent();
unsigned N = RI.getNumOperands(); unsigned N = RI.getNumOperands();
if (F->getReturnType() == Type::getVoidTy(RI.getContext())) if (F->getReturnType()->getTypeID() == Type::VoidTyID)
Assert2(N == 0, Assert2(N == 0,
"Found return instr that returns non-void in Function of void " "Found return instr that returns non-void in Function of void "
"return type!", &RI, F->getReturnType()); "return type!", &RI, F->getReturnType());
@ -1126,8 +1101,6 @@ void Verifier::VerifyCallSite(CallSite CS) {
// Verify that there's no metadata unless it's a direct call to an intrinsic. // Verify that there's no metadata unless it's a direct call to an intrinsic.
if (!CS.getCalledFunction() || CS.getCalledFunction()->getName().size() < 5 || if (!CS.getCalledFunction() || CS.getCalledFunction()->getName().size() < 5 ||
CS.getCalledFunction()->getName().substr(0, 5) != "llvm.") { CS.getCalledFunction()->getName().substr(0, 5) != "llvm.") {
Assert1(FTy->getReturnType() != Type::getMetadataTy(I->getContext()),
"Only intrinsics may return metadata", I);
for (FunctionType::param_iterator PI = FTy->param_begin(), for (FunctionType::param_iterator PI = FTy->param_begin(),
PE = FTy->param_end(); PI != PE; ++PI) PE = FTy->param_end(); PI != PE; ++PI)
Assert1(PI->get() != Type::getMetadataTy(I->getContext()), Assert1(PI->get() != Type::getMetadataTy(I->getContext()),
@ -1297,8 +1270,6 @@ void Verifier::visitLoadInst(LoadInst &LI) {
const Type *ElTy = PTy->getElementType(); const Type *ElTy = PTy->getElementType();
Assert2(ElTy == LI.getType(), Assert2(ElTy == LI.getType(),
"Load result type does not match pointer operand type!", &LI, ElTy); "Load result type does not match pointer operand type!", &LI, ElTy);
Assert1(ElTy != Type::getMetadataTy(LI.getContext()),
"Can't load metadata!", &LI);
visitInstruction(LI); visitInstruction(LI);
} }
@ -1309,8 +1280,6 @@ void Verifier::visitStoreInst(StoreInst &SI) {
Assert2(ElTy == SI.getOperand(0)->getType(), Assert2(ElTy == SI.getOperand(0)->getType(),
"Stored value type does not match pointer operand type!", "Stored value type does not match pointer operand type!",
&SI, ElTy); &SI, ElTy);
Assert1(ElTy != Type::getMetadataTy(SI.getContext()),
"Can't store metadata!", &SI);
visitInstruction(SI); visitInstruction(SI);
} }
@ -1365,22 +1334,16 @@ void Verifier::visitInstruction(Instruction &I) {
// Check that the return value of the instruction is either void or a legal // Check that the return value of the instruction is either void or a legal
// value type. // value type.
Assert1(I.getType() == Type::getVoidTy(I.getContext()) || Assert1(I.getType()->getTypeID() == Type::VoidTyID ||
I.getType()->isFirstClassType() I.getType()->isFirstClassType(),
|| ((isa<CallInst>(I) || isa<InvokeInst>(I))
&& isa<StructType>(I.getType())),
"Instruction returns a non-scalar type!", &I); "Instruction returns a non-scalar type!", &I);
// Check that the instruction doesn't produce metadata or metadata*. Calls // Check that the instruction doesn't produce metadata. Calls are already
// all already checked against the callee type. // checked against the callee type.
Assert1(I.getType() != Type::getMetadataTy(I.getContext()) || Assert1(I.getType()->getTypeID() != Type::MetadataTyID ||
isa<CallInst>(I) || isa<InvokeInst>(I), isa<CallInst>(I) || isa<InvokeInst>(I),
"Invalid use of metadata!", &I); "Invalid use of metadata!", &I);
if (const PointerType *PTy = dyn_cast<PointerType>(I.getType()))
Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()),
"Instructions may not produce pointer to metadata.", &I);
// Check that all uses of the instruction, if they are instructions // Check that all uses of the instruction, if they are instructions
// themselves, actually have parent basic blocks. If the use is not an // themselves, actually have parent basic blocks. If the use is not an
// instruction, it is an error! // instruction, it is an error!
@ -1404,11 +1367,6 @@ void Verifier::visitInstruction(Instruction &I) {
Assert1(0, "Instruction operands must be first-class values!", &I); Assert1(0, "Instruction operands must be first-class values!", &I);
} }
if (const PointerType *PTy =
dyn_cast<PointerType>(I.getOperand(i)->getType()))
Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()),
"Invalid use of metadata pointer.", &I);
if (Function *F = dyn_cast<Function>(I.getOperand(i))) { if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
// Check to make sure that the "address of" an intrinsic function is never // Check to make sure that the "address of" an intrinsic function is never
// taken. // taken.