Introduce isOpaqueTy and use it rather than isa<OpaqueType>. Also, move some
authorDuncan Sands <baldrick@free.fr>
Tue, 16 Feb 2010 14:50:09 +0000 (14:50 +0000)
committerDuncan Sands <baldrick@free.fr>
Tue, 16 Feb 2010 14:50:09 +0000 (14:50 +0000)
methods to try to have the type predicates be more logically positioned.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96349 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Type.h
lib/AsmParser/LLParser.cpp
lib/Linker/LinkModules.cpp
lib/Target/CBackend/CBackend.cpp
lib/Target/MSIL/MSILWriter.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/ConstantFold.cpp
lib/VMCore/Function.cpp
lib/VMCore/Type.cpp
lib/VMCore/Value.cpp

index 8780db749d77e001f5a9f0d9dacd46b9f4c368bf..74f7a606ff644c3bc1e1d661f113d6a1103cbdb5 100644 (file)
@@ -182,6 +182,9 @@ public:
   // are defined in private classes defined in Type.cpp for primitive types.
   //
 
+  /// getDescription - Return the string representation of the type.
+  std::string getDescription() const;
+
   /// getTypeID - Return the type id for the type.  This will return one
   /// of the TypeID enum elements defined above.
   ///
@@ -205,15 +208,21 @@ public:
   /// isPPC_FP128Ty - Return true if this is powerpc long double.
   bool isPPC_FP128Ty() const { return ID == PPC_FP128TyID; }
 
+  /// isFloatingPointTy - Return true if this is one of the five floating point
+  /// types
+  bool isFloatingPointTy() const { return ID == FloatTyID || ID == DoubleTyID ||
+      ID == X86_FP80TyID || ID == FP128TyID || ID == PPC_FP128TyID; }
+
+  /// isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP.
+  ///
+  bool isFPOrFPVectorTy() const;
   /// isLabelTy - Return true if this is 'label'.
   bool isLabelTy() const { return ID == LabelTyID; }
 
   /// isMetadataTy - Return true if this is 'metadata'.
   bool isMetadataTy() const { return ID == MetadataTyID; }
 
-  /// getDescription - Return the string representation of the type.
-  std::string getDescription() const;
-
   /// isIntegerTy - True if this is an instance of IntegerType.
   ///
   bool isIntegerTy() const { return ID == IntegerTyID; } 
@@ -226,15 +235,6 @@ public:
   ///
   bool isIntOrIntVectorTy() const;
   
-  /// isFloatingPointTy - Return true if this is one of the five floating point
-  /// types
-  bool isFloatingPointTy() const { return ID == FloatTyID || ID == DoubleTyID ||
-      ID == X86_FP80TyID || ID == FP128TyID || ID == PPC_FP128TyID; }
-
-  /// isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP.
-  ///
-  bool isFPOrFPVectorTy() const;
   /// isFunctionTy - True if this is an instance of FunctionType.
   ///
   bool isFunctionTy() const { return ID == FunctionTyID; }
@@ -255,6 +255,10 @@ public:
   ///
   bool isPointerTy() const { return ID == PointerTyID; }
 
+  /// isOpaqueTy - True if this is an instance of OpaqueType.
+  ///
+  bool isOpaqueTy() const { return ID == OpaqueTyID; }
+
   /// isVectorTy - True if this is an instance of VectorType.
   ///
   bool isVectorTy() const { return ID == VectorTyID; }
index 89ab270bf3d55ebc6bd9ed9b67af589aa6f59653..8083a07fdbcd54715d430a8472315db4bec9cbef 100644 (file)
@@ -791,7 +791,7 @@ GlobalValue *LLParser::GetGlobalVal(const std::string &Name, const Type *Ty,
   GlobalValue *FwdVal;
   if (const FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType())) {
     // Function types can return opaque but functions can't.
-    if (isa<OpaqueType>(FT->getReturnType())) {
+    if (FT->getReturnType()->isOpaqueTy()) {
       Error(Loc, "function may not return opaque type");
       return 0;
     }
@@ -836,7 +836,7 @@ GlobalValue *LLParser::GetGlobalVal(unsigned ID, const Type *Ty, LocTy Loc) {
   GlobalValue *FwdVal;
   if (const FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType())) {
     // Function types can return opaque but functions can't.
-    if (isa<OpaqueType>(FT->getReturnType())) {
+    if (FT->getReturnType()->isOpaqueTy()) {
       Error(Loc, "function may not return opaque type");
       return 0;
     }
@@ -1515,7 +1515,7 @@ bool LLParser::ParseArgumentList(std::vector<ArgInfo> &ArgList,
         Name = "";
       }
 
-      if (!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy))
+      if (!ArgTy->isFirstClassType() && !ArgTy->isOpaqueTy())
         return Error(TypeLoc, "invalid type for function argument");
 
       ArgList.push_back(ArgInfo(TypeLoc, ArgTy, Attrs, Name));
@@ -1785,7 +1785,7 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name,
   }
 
   // Don't make placeholders with invalid type.
-  if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && !Ty->isLabelTy()) {
+  if (!Ty->isFirstClassType() && !Ty->isOpaqueTy() && !Ty->isLabelTy()) {
     P.Error(Loc, "invalid use of a non-first-class type");
     return 0;
   }
@@ -1826,7 +1826,7 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty,
     return 0;
   }
 
-  if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && !Ty->isLabelTy()) {
+  if (!Ty->isFirstClassType() && !Ty->isOpaqueTy() && !Ty->isLabelTy()) {
     P.Error(Loc, "invalid use of a non-first-class type");
     return 0;
   }
@@ -2542,7 +2542,7 @@ bool LLParser::ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V,
   case ValID::t_Undef:
     // FIXME: LabelTy should not be a first-class type.
     if ((!Ty->isFirstClassType() || Ty->isLabelTy()) &&
-        !isa<OpaqueType>(Ty))
+        !Ty->isOpaqueTy())
       return Error(ID.Loc, "invalid type for undef constant");
     V = UndefValue::get(Ty);
     return false;
@@ -2662,7 +2662,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
   }
 
   if (!FunctionType::isValidReturnType(RetType) ||
-      isa<OpaqueType>(RetType))
+      RetType->isOpaqueTy())
     return Error(RetTypeLoc, "invalid function return type");
 
   LocTy NameLoc = Lex.getLoc();
index 7f441b0a471516fdd6936f31335c4e99ee6a60d1..8487c83ce36ab910fddc391d34580794d6636250 100644 (file)
@@ -159,7 +159,7 @@ static bool RecursiveResolveTypesI(const Type *DstTy, const Type *SrcTy,
   if (DstTy == SrcTy) return false;       // If already equal, noop
 
   // If we found our opaque type, resolve it now!
-  if (isa<OpaqueType>(DstTy) || isa<OpaqueType>(SrcTy))
+  if (DstTy->isOpaqueTy() || SrcTy->isOpaqueTy())
     return ResolveTypes(DstTy, SrcTy);
 
   // Two types cannot be resolved together if they are of different primitive
index c753555c72777c5e2ba426766f9a0bf9465a50d8..f65b1aa251326cca715906b989de06d311d9e760 100644 (file)
@@ -385,7 +385,7 @@ bool CBackendNameAllUsedStructsAndMergeFunctions::runOnModule(Module &M) {
     
     // If this isn't a struct or array type, remove it from our set of types
     // to name. This simplifies emission later.
-    if (!I->second->isStructTy() && !isa<OpaqueType>(I->second) &&
+    if (!I->second->isStructTy() && !I->second->isOpaqueTy() &&
         !I->second->isArrayTy()) {
       TST.remove(I);
     } else {
@@ -597,7 +597,7 @@ raw_ostream &CWriter::printType(formatted_raw_ostream &Out,
   }
 
   // Check to see if the type is named.
-  if (!IgnoreName || isa<OpaqueType>(Ty)) {
+  if (!IgnoreName || Ty->isOpaqueTy()) {
     std::map<const Type *, std::string>::iterator I = TypeNames.find(Ty);
     if (I != TypeNames.end()) return Out << I->second << ' ' << NameSoFar;
   }
@@ -700,7 +700,7 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
   }
 
   // Check to see if the type is named.
-  if (!IgnoreName || isa<OpaqueType>(Ty)) {
+  if (!IgnoreName || Ty->isOpaqueTy()) {
     std::map<const Type *, std::string>::iterator I = TypeNames.find(Ty);
     if (I != TypeNames.end()) return Out << I->second << ' ' << NameSoFar;
   }
index 6f94800884d27ca1a7ef368231878295e2c3265d..dafc7b10acfd1a34e6466c6471750af0edbdf0fe 100644 (file)
@@ -57,7 +57,7 @@ bool MSILModule::runOnModule(Module &M) {
   TypeSymbolTable& Table = M.getTypeSymbolTable();
   std::set<const Type *> Types = getAnalysis<FindUsedTypes>().getTypes();
   for (TypeSymbolTable::iterator I = Table.begin(), E = Table.end(); I!=E; ) {
-    if (!I->second->isStructTy() && !isa<OpaqueType>(I->second))
+    if (!I->second->isStructTy() && !I->second->isOpaqueTy())
       Table.remove(I++);
     else {
       std::set<const Type *>::iterator T = Types.find(I->second);
index 82e9a6ace59efbc74691556f19fca4c141191097..1ed13843f0fb5bf395ec197c4d5c7d8e8ec7cc05 100644 (file)
@@ -377,7 +377,7 @@ namespace {
 
       // If this is a structure or opaque type, add a name for the type.
       if (((Ty->isStructTy() && cast<StructType>(Ty)->getNumElements())
-            || isa<OpaqueType>(Ty)) && !TP.hasTypeName(Ty)) {
+            || Ty->isOpaqueTy()) && !TP.hasTypeName(Ty)) {
         TP.addTypeName(Ty, "%"+utostr(unsigned(NumberedTypes.size())));
         NumberedTypes.push_back(Ty);
       }
@@ -432,7 +432,7 @@ static void AddModuleTypesToPrinter(TypePrinting &TP,
     if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
       const Type *PETy = PTy->getElementType();
       if ((PETy->isPrimitiveType() || PETy->isIntegerTy()) &&
-          !isa<OpaqueType>(PETy))
+          !PETy->isOpaqueTy())
         continue;
     }
 
index 261816804e4c99c1b9643fd2d81b42c5fd9dd31c..b3df371d2c69c613afe212d738f7ce93464d8856 100644 (file)
@@ -1427,7 +1427,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
 /// isZeroSizedType - This type is zero sized if its an array or structure of
 /// zero sized types.  The only leaf zero sized type is an empty structure.
 static bool isMaybeZeroSizedType(const Type *Ty) {
-  if (isa<OpaqueType>(Ty)) return true;  // Can't say.
+  if (Ty->isOpaqueTy()) return true;  // Can't say.
   if (const StructType *STy = dyn_cast<StructType>(Ty)) {
 
     // If all of elements have zero size, this does too.
index 5af55102a63d764e344d2ec5b9a9bd7b9ef427c6..dbc283e49ac68314ff89792b423e5082494e2c6d 100644 (file)
@@ -155,7 +155,7 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
   : GlobalValue(PointerType::getUnqual(Ty), 
                 Value::FunctionVal, 0, 0, Linkage, name) {
   assert(FunctionType::isValidReturnType(getReturnType()) &&
-         !isa<OpaqueType>(getReturnType()) && "invalid return type");
+         !getReturnType()->isOpaqueTy() && "invalid return type");
   SymTab = new ValueSymbolTable();
 
   // If the function has arguments, mark them as lazily built.
index c9987c3624f6a5fcdd033f14ab69d1101c4fe552..9b2c2cab81fb30859bee8b9e3c291a7b41f87ba2 100644 (file)
@@ -447,7 +447,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) {
-  return ArgTy->isFirstClassType() || isa<OpaqueType>(ArgTy);
+  return ArgTy->isFirstClassType() || ArgTy->isOpaqueTy();
 }
 
 FunctionType::FunctionType(const Type *Result,
@@ -613,7 +613,7 @@ void Type::PromoteAbstractToConcrete() {
     // Concrete types are leaves in the tree.  Since an SCC will either be all
     // abstract or all concrete, we only need to check one type.
     if (SCC[0]->isAbstract()) {
-      if (isa<OpaqueType>(SCC[0]))
+      if (SCC[0]->isOpaqueTy())
         return;     // Not going to be concrete, sorry.
 
       // If all of the children of all of the types in this SCC are concrete,
@@ -660,7 +660,7 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
                        std::map<const Type *, const Type *> &EqTypes) {
   if (Ty == Ty2) return true;
   if (Ty->getTypeID() != Ty2->getTypeID()) return false;
-  if (isa<OpaqueType>(Ty))
+  if (Ty->isOpaqueTy())
     return false;  // Two unequal opaque types are never equal
 
   std::map<const Type*, const Type*>::iterator It = EqTypes.find(Ty);
@@ -912,7 +912,7 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
 
 bool VectorType::isValidElementType(const Type *ElemTy) {
   return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
-         isa<OpaqueType>(ElemTy);
+         ElemTy->isOpaqueTy();
 }
 
 //===----------------------------------------------------------------------===//
index 1cc3d54a044cb5a37efcaaed37aa4678429d4844..a36d2628250dc0a73f60d51daf2907f2960f3194 100644 (file)
@@ -45,11 +45,11 @@ Value::Value(const Type *ty, unsigned scid)
     UseList(0), Name(0) {
   if (isa<CallInst>(this) || isa<InvokeInst>(this))
     assert((VTy->isFirstClassType() || VTy->isVoidTy() ||
-            isa<OpaqueType>(ty) || VTy->isStructTy()) &&
+            ty->isOpaqueTy() || VTy->isStructTy()) &&
            "invalid CallInst  type!");
   else if (!isa<Constant>(this) && !isa<BasicBlock>(this))
     assert((VTy->isFirstClassType() || VTy->isVoidTy() ||
-            isa<OpaqueType>(ty)) &&
+            ty->isOpaqueTy()) &&
            "Cannot create non-first-class values except for constants!");
 }