[llvm-commits] [llvm] r167223 - in /llvm/trunk: include/llvm/Instructions.h include/llvm/Type.h lib/VMCore/Type.cpp

Chandler Carruth chandlerc at gmail.com
Thu Nov 1 02:37:49 PDT 2012


Author: chandlerc
Date: Thu Nov  1 04:37:49 2012
New Revision: 167223

URL: http://llvm.org/viewvc/llvm-project?rev=167223&view=rev
Log:
Teach Type::getPointerAddressSpace to look through pointer vectors
politely and document this feature.

This simple API extension then allows us to write all of the
Instructions' address space query methods much more simply. No
functionality change intended here.

Modified:
    llvm/trunk/include/llvm/Instructions.h
    llvm/trunk/include/llvm/Type.h
    llvm/trunk/lib/VMCore/Type.cpp

Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=167223&r1=167222&r2=167223&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Thu Nov  1 04:37:49 2012
@@ -226,7 +226,7 @@
   static unsigned getPointerOperandIndex() { return 0U; }
 
   unsigned getPointerAddressSpace() const {
-    return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
+    return getPointerOperand()->getType()->getPointerAddressSpace();
   }
 
 
@@ -348,16 +348,7 @@
   static unsigned getPointerOperandIndex() { return 1U; }
 
   unsigned getPointerAddressSpace() const {
-    if (getPointerOperand()->getType()->isPointerTy())
-      return cast<PointerType>(getPointerOperand()->getType())
-        ->getAddressSpace();
-    if (getPointerOperand()->getType()->isVectorTy()
-        && cast<VectorType>(getPointerOperand()->getType())->isPointerTy())
-      return cast<PointerType>(cast<VectorType>(
-            getPointerOperand()->getType())->getElementType())
-        ->getAddressSpace();
-    llvm_unreachable("Only a vector of pointers or pointers can be used!");
-    return 0;
+    return getPointerOperand()->getType()->getPointerAddressSpace();
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -527,7 +518,7 @@
   const Value *getNewValOperand() const { return getOperand(2); }
   
   unsigned getPointerAddressSpace() const {
-    return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
+    return getPointerOperand()->getType()->getPointerAddressSpace();
   }
   
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -670,7 +661,7 @@
   const Value *getValOperand() const { return getOperand(1); }
 
   unsigned getPointerAddressSpace() const {
-    return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
+    return getPointerOperand()->getType()->getPointerAddressSpace();
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -801,7 +792,7 @@
   }
 
   unsigned getPointerAddressSpace() const {
-    return cast<PointerType>(getPointerOperandType())->getAddressSpace();
+    return getPointerOperand()->getType()->getPointerAddressSpace();
   }
 
   /// getPointerOperandType - Method to return the pointer operand as a
@@ -3616,15 +3607,7 @@
 
   /// @brief return the address space of the pointer.
   unsigned getAddressSpace() const {
-    if (getType()->isPointerTy()) 
-      return cast<PointerType>(getType())->getAddressSpace();
-    if (getType()->isVectorTy() &&
-        cast<VectorType>(getType())->getElementType()->isPointerTy())
-      return cast<PointerType>(
-          cast<VectorType>(getType())->getElementType())
-        ->getAddressSpace();
-    llvm_unreachable("Must be a pointer or a vector of pointers.");
-    return 0;
+    return getType()->getPointerAddressSpace();
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -3665,16 +3648,7 @@
 
   /// @brief return the address space of the pointer.
   unsigned getPointerAddressSpace() const {
-    Type *Ty = getOperand(0)->getType();
-    if (Ty->isPointerTy())
-      return cast<PointerType>(Ty)->getAddressSpace();
-    if (Ty->isVectorTy()
-        && cast<VectorType>(Ty)->getElementType()->isPointerTy())
-      return cast<PointerType>(
-          cast<VectorType>(Ty)->getElementType())
-        ->getAddressSpace();
-    llvm_unreachable("Must be a pointer or a vector of pointers.");
-    return 0;
+    return getOperand(0)->getType()->getPointerAddressSpace();
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:

Modified: llvm/trunk/include/llvm/Type.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Type.h?rev=167223&r1=167222&r2=167223&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Type.h (original)
+++ llvm/trunk/include/llvm/Type.h Thu Nov  1 04:37:49 2012
@@ -346,8 +346,10 @@
   unsigned getVectorNumElements() const;
   Type *getVectorElementType() const { return getSequentialElementType(); }
 
-  unsigned getPointerAddressSpace() const;
   Type *getPointerElementType() const { return getSequentialElementType(); }
+
+  /// \brief Get the address space of this pointer or pointer vector type.
+  unsigned getPointerAddressSpace() const;
   
   //===--------------------------------------------------------------------===//
   // Static members exported by the Type class itself.  Useful for getting

Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=167223&r1=167222&r2=167223&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Thu Nov  1 04:37:49 2012
@@ -215,7 +215,7 @@
 }
 
 unsigned Type::getPointerAddressSpace() const {
-  return cast<PointerType>(this)->getAddressSpace();
+  return cast<PointerType>(getScalarType())->getAddressSpace();
 }
 
 





More information about the llvm-commits mailing list