From c261df9fab0c95e2362b518d071ac2ec37d0a9df Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 27 Sep 2009 23:27:42 +0000 Subject: [PATCH] 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 --- docs/LangRef.html | 8 +++--- lib/VMCore/Type.cpp | 51 +++++++----------------------------- lib/VMCore/Verifier.cpp | 58 ++++++----------------------------------- 3 files changed, 22 insertions(+), 95 deletions(-) diff --git a/docs/LangRef.html b/docs/LangRef.html index 6f5fbb3f35b..38536925f2d 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -1489,9 +1489,9 @@ Classifications
Overview:
-

The metadata type represents embedded metadata. The only derived type that - may contain metadata is metadata* or a function type that returns or - takes metadata typed parameters, but not pointer to metadata types.

+

The metadata type represents embedded metadata. No derived types may be + created from metadata except for function + arguments.

Syntax:
@@ -1601,7 +1601,7 @@ Classifications 
Variable argument functions can access their arguments with the variable argument handling intrinsic functions. '<returntype>' is a any type except - label and metadata.

+ label.

Examples:
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 820789d89e7..087464de465 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -365,9 +365,6 @@ const IntegerType *Type::getInt64Ty(LLVMContext &C) { /// isValidReturnType - Return true if the specified type is valid as a return /// type. bool FunctionType::isValidReturnType(const Type *RetTy) { - if (const PointerType *PTy = dyn_cast(RetTy)) - return PTy->getElementType()->getTypeID() != MetadataTyID; - return RetTy->getTypeID() != LabelTyID && RetTy->getTypeID() != MetadataTyID; } @@ -375,12 +372,7 @@ bool FunctionType::isValidReturnType(const Type *RetTy) { /// isValidArgumentType - Return true if the specified type is valid as an /// argument type. bool FunctionType::isValidArgumentType(const Type *ArgTy) { - if ((!ArgTy->isFirstClassType() && !isa(ArgTy)) || - (isa(ArgTy) && - cast(ArgTy)->getElementType()->getTypeID() == MetadataTyID)) - return false; - - return true; + return ArgTy->isFirstClassType() || isa(ArgTy); } FunctionType::FunctionType(const Type *Result, @@ -817,15 +809,8 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) { } bool ArrayType::isValidElementType(const Type *ElemTy) { - if (ElemTy->getTypeID() == VoidTyID || ElemTy->getTypeID() == LabelTyID || - ElemTy->getTypeID() == MetadataTyID || isa(ElemTy)) - return false; - - if (const PointerType *PTy = dyn_cast(ElemTy)) - if (PTy->getElementType()->getTypeID() == MetadataTyID) - return false; - - return true; + return ElemTy->getTypeID() != VoidTyID && ElemTy->getTypeID() != LabelTyID && + ElemTy->getTypeID() != MetadataTyID && !isa(ElemTy); } 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) { - if (ElemTy->isInteger() || ElemTy->isFloatingPoint() || - isa(ElemTy)) - return true; - - return false; + return ElemTy->isInteger() || ElemTy->isFloatingPoint() || + isa(ElemTy); } //===----------------------------------------------------------------------===// @@ -896,15 +878,8 @@ StructType *StructType::get(LLVMContext &Context, const Type *type, ...) { } bool StructType::isValidElementType(const Type *ElemTy) { - if (ElemTy->getTypeID() == VoidTyID || ElemTy->getTypeID() == LabelTyID || - ElemTy->getTypeID() == MetadataTyID || isa(ElemTy)) - return false; - - if (const PointerType *PTy = dyn_cast(ElemTy)) - if (PTy->getElementType()->getTypeID() == MetadataTyID) - return false; - - return true; + return ElemTy->getTypeID() != VoidTyID && ElemTy->getTypeID() != LabelTyID && + ElemTy->getTypeID() != MetadataTyID && !isa(ElemTy); } @@ -941,15 +916,9 @@ PointerType *Type::getPointerTo(unsigned addrs) const { } bool PointerType::isValidElementType(const Type *ElemTy) { - if (ElemTy->getTypeID() == VoidTyID || - ElemTy->getTypeID() == LabelTyID) - return false; - - if (const PointerType *PTy = dyn_cast(ElemTy)) - if (PTy->getElementType()->getTypeID() == MetadataTyID) - return false; - - return true; + return ElemTy->getTypeID() != VoidTyID && + ElemTy->getTypeID() != LabelTyID && + ElemTy->getTypeID() != MetadataTyID; } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 140e6bd8b15..4f7c84769b0 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -447,28 +447,6 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) { Assert1(!GV.isConstant(), "'common' global may not be marked constant!", &GV); } - - // Verify that any metadata used in a global initializer points only to - // other globals. - if (MDNode *FirstNode = dyn_cast(GV.getInitializer())) { - SmallVector 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(V)) - NodesToAnalyze.push_back(Next); - else - Assert3(isa(V), - "reference to instruction from global metadata node", - &GV, N, V); - } - } - } } else { Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() || GV.hasExternalWeakLinkage(), @@ -622,12 +600,12 @@ void Verifier::visitFunction(Function &F) { "# formal arguments must match # of arguments for function type!", &F, FT); Assert1(F.getReturnType()->isFirstClassType() || - F.getReturnType() == Type::getVoidTy(F.getContext()) || + F.getReturnType()->getTypeID() == Type::VoidTyID || isa(F.getReturnType()), "Functions cannot return aggregate values!", &F); Assert1(!F.hasStructRetAttr() || - F.getReturnType() == Type::getVoidTy(F.getContext()), + F.getReturnType()->getTypeID() == Type::VoidTyID, "Invalid struct return type!", &F); const AttrListPtr &Attrs = F.getAttributes(); @@ -654,9 +632,6 @@ void Verifier::visitFunction(Function &F) { bool isLLVMdotName = F.getName().size() >= 5 && 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... unsigned i = 0; @@ -763,7 +738,7 @@ void Verifier::visitTerminatorInst(TerminatorInst &I) { void Verifier::visitReturnInst(ReturnInst &RI) { Function *F = RI.getParent()->getParent(); unsigned N = RI.getNumOperands(); - if (F->getReturnType() == Type::getVoidTy(RI.getContext())) + if (F->getReturnType()->getTypeID() == Type::VoidTyID) Assert2(N == 0, "Found return instr that returns non-void in Function of void " "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. if (!CS.getCalledFunction() || CS.getCalledFunction()->getName().size() < 5 || 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(), PE = FTy->param_end(); PI != PE; ++PI) Assert1(PI->get() != Type::getMetadataTy(I->getContext()), @@ -1297,8 +1270,6 @@ void Verifier::visitLoadInst(LoadInst &LI) { const Type *ElTy = PTy->getElementType(); Assert2(ElTy == LI.getType(), "Load result type does not match pointer operand type!", &LI, ElTy); - Assert1(ElTy != Type::getMetadataTy(LI.getContext()), - "Can't load metadata!", &LI); visitInstruction(LI); } @@ -1309,8 +1280,6 @@ void Verifier::visitStoreInst(StoreInst &SI) { Assert2(ElTy == SI.getOperand(0)->getType(), "Stored value type does not match pointer operand type!", &SI, ElTy); - Assert1(ElTy != Type::getMetadataTy(SI.getContext()), - "Can't store metadata!", &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 // value type. - Assert1(I.getType() == Type::getVoidTy(I.getContext()) || - I.getType()->isFirstClassType() - || ((isa(I) || isa(I)) - && isa(I.getType())), + Assert1(I.getType()->getTypeID() == Type::VoidTyID || + I.getType()->isFirstClassType(), "Instruction returns a non-scalar type!", &I); - // Check that the instruction doesn't produce metadata or metadata*. Calls - // all already checked against the callee type. - Assert1(I.getType() != Type::getMetadataTy(I.getContext()) || + // Check that the instruction doesn't produce metadata. Calls are already + // checked against the callee type. + Assert1(I.getType()->getTypeID() != Type::MetadataTyID || isa(I) || isa(I), "Invalid use of metadata!", &I); - if (const PointerType *PTy = dyn_cast(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 // themselves, actually have parent basic blocks. If the use is not an // instruction, it is an error! @@ -1404,11 +1367,6 @@ void Verifier::visitInstruction(Instruction &I) { Assert1(0, "Instruction operands must be first-class values!", &I); } - if (const PointerType *PTy = - dyn_cast(I.getOperand(i)->getType())) - Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()), - "Invalid use of metadata pointer.", &I); - if (Function *F = dyn_cast(I.getOperand(i))) { // Check to make sure that the "address of" an intrinsic function is never // taken. -- 2.34.1