Add some cleanup to the DataLayout changes requested by Chandler.
authorMicah Villmow <villmow@gmail.com>
Wed, 24 Oct 2012 18:36:13 +0000 (18:36 +0000)
committerMicah Villmow <villmow@gmail.com>
Wed, 24 Oct 2012 18:36:13 +0000 (18:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166607 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DataLayout.h
lib/Analysis/ConstantFolding.cpp
lib/Analysis/InlineCost.cpp
lib/Analysis/InstructionSimplify.cpp
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/ExecutionEngine/ExecutionEngine.cpp
lib/Target/NVPTX/NVPTXAsmPrinter.cpp
lib/Transforms/InstCombine/InstCombineCompares.cpp
lib/Transforms/Scalar/SROA.cpp
lib/Transforms/Utils/Local.cpp
lib/VMCore/DataLayout.cpp

index 0a37353da5c1cbdd8df01a2c439369728f25b92f..d778556684c3d511e79dffc5cf29a85ee9cd0962 100644 (file)
@@ -262,6 +262,14 @@ public:
     }
     return 8*val->second.TypeBitWidth;
   }
+  /// Layout pointer size, in bits, based on the type.
+  /// If this function is called with a pointer type, then
+  /// the type size of the pointer is returned.
+  /// If this function is called with a vector of pointers,
+  /// then the type size of the pointer is returned.
+  /// Otherwise the type sizeo f a default pointer is returned.
+  unsigned getPointerTypeSizeInBits(Type* Ty)    const;
+
   /// Size examples:
   ///
   /// Type        SizeInBits  StoreSizeInBits  AllocSizeInBits[*]
index c0e9020d919574bdc66714c4d15d3271d98ad652..de6d61d78b2ab0f2a016155076f1be17a4449f6a 100644 (file)
@@ -937,8 +937,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
     // pointer, so it can't be done in ConstantExpr::getCast.
     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0]))
       if (TD && CE->getOpcode() == Instruction::PtrToInt &&
-          TD->getPointerSizeInBits(
-            cast<PointerType>(CE->getOperand(0)->getType())->getAddressSpace())
+          TD->getTypeSizeInBits(CE->getOperand(0)->getType())
           <= CE->getType()->getScalarSizeInBits())
         return FoldBitCast(CE->getOperand(0), DestTy, *TD);
 
index ede1bf30dbf7dfeefe54bad7887bd5cfaef68143..64e183d60cf3593d865161d142cf11cddc061078 100644 (file)
@@ -828,8 +828,7 @@ bool CallAnalyzer::analyzeCall(CallSite CS) {
         // size of the byval type by the target's pointer size.
         PointerType *PTy = cast<PointerType>(CS.getArgument(I)->getType());
         unsigned TypeSize = TD->getTypeSizeInBits(PTy->getElementType());
-        unsigned AS = PTy->getAddressSpace();
-        unsigned PointerSize = TD->getPointerSizeInBits(AS);
+        unsigned PointerSize = TD->getTypeSizeInBits(PTy);
         // Ceiling division.
         unsigned NumStores = (TypeSize + PointerSize - 1) / PointerSize;
 
index 016c328e9e85e5a90a8a9b3c63fff99e5fea559f..7ef74f67cea47f9bb24d5d6304370596a908dfbd 100644 (file)
@@ -1880,9 +1880,7 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
     // Turn icmp (ptrtoint x), (ptrtoint/constant) into a compare of the input
     // if the integer type is the same size as the pointer type.
     if (MaxRecurse && Q.TD && isa<PtrToIntInst>(LI) &&
-        Q.TD->getPointerSizeInBits(
-          cast<PtrToIntInst>(LI)->getPointerAddressSpace()) ==
-        DstTy->getPrimitiveSizeInBits()) {
+        Q.TD->getTypeSizeInBits(SrcTy) == DstTy->getPrimitiveSizeInBits()) {
       if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
         // Transfer the cast to the constant.
         if (Value *V = SimplifyICmpInst(Pred, SrcOp,
index faadc0fa666be618f89b33a837104b4ee5e41967..4b70ae9586f8c3fee57bb3679be5a8badab10d1b 100644 (file)
@@ -385,8 +385,8 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
     //   - __tlv_bootstrap - used to make sure support exists
     //   - spare pointer, used when mapped by the runtime
     //   - pointer to mangled symbol above with initializer
-    unsigned AS = GV->getType()->getAddressSpace();
-    unsigned PtrSize = TD->getPointerSizeInBits(AS)/8;
+    assert(GV->getType()->isPointerTy() && "GV must be a pointer type!");
+    unsigned PtrSize = TD->getTypeSizeInBits(GV->getType())/8;
     OutStreamer.EmitSymbolValue(GetExternalSymbolSymbol("_tlv_bootstrap"),
                           PtrSize, 0);
     OutStreamer.EmitIntValue(0, PtrSize, 0);
@@ -1481,9 +1481,9 @@ static const MCExpr *lowerConstant(const Constant *CV, AsmPrinter &AP) {
     if (Offset == 0)
       return Base;
 
-    unsigned AS = cast<PointerType>(CE->getType())->getAddressSpace();
+    assert(CE->getType()->isPointerTy() && "We must have a pointer type!");
     // Truncate/sext the offset to the pointer size.
-    unsigned Width = TD.getPointerSizeInBits(AS);
+    unsigned Width = TD.getTypeSizeInBits(CE->getType());
     if (Width < 64)
       Offset = SignExtend64(Offset, Width);
 
index 94a2542e7ad6b5a0d4c318a6459f2a27da82629b..99f6ec691ab8e914801d0adbbe32d9249acb8c94 100644 (file)
@@ -645,16 +645,17 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
     }
     case Instruction::PtrToInt: {
       GenericValue GV = getConstantValue(Op0);
-      unsigned AS = cast<PointerType>(CE->getOperand(1)->getType())
-        ->getAddressSpace();
-      uint32_t PtrWidth = TD->getPointerSizeInBits(AS);
+      assert(CE->getOperand(1)->getType()->isPointerTy() &&
+          "Must be a pointer type!");
+      uint32_t PtrWidth = TD->getTypeSizeInBits(CE->getOperand(1)->getType());
       GV.IntVal = APInt(PtrWidth, uintptr_t(GV.PointerVal));
       return GV;
     }
     case Instruction::IntToPtr: {
       GenericValue GV = getConstantValue(Op0);
-      unsigned AS = cast<PointerType>(CE->getType())->getAddressSpace();
-      uint32_t PtrWidth = TD->getPointerSizeInBits(AS);
+      assert(CE->getOperand(1)->getType()->isPointerTy() &&
+          "Must be a pointer type!");
+      uint32_t PtrWidth = TD->getTypeSizeInBits(CE->getType());
       if (PtrWidth != GV.IntVal.getBitWidth())
         GV.IntVal = GV.IntVal.zextOrTrunc(PtrWidth);
       assert(GV.IntVal.getBitWidth() <= 64 && "Bad pointer width");
index 5ac9fa5e5938e40248e0308b365eb22b91fdf0bf..971d1b89a8b58df6bee380e09aa0476d58e67607 100644 (file)
@@ -126,10 +126,9 @@ const MCExpr *nvptx::LowerConstant(const Constant *CV, AsmPrinter &AP) {
       return Base;
 
     // Truncate/sext the offset to the pointer size.
-    unsigned AS = PtrVal->getType()->isPointerTy() ?
-      cast<PointerType>(PtrVal->getType())->getAddressSpace() : 0;
-    if (TD.getPointerSizeInBits(AS) != 64) {
-      int SExtAmount = 64-TD.getPointerSizeInBits(AS);
+    unsigned PtrSize = TD.getPointerTypeSizeInBits(PtrVal->getType());
+    if (PtrSize != 64) {
+      int SExtAmount = 64-PtrSize;
       Offset = (Offset << SExtAmount) >> SExtAmount;
     }
 
index 057496d2102fdc486bff5ab2c2af25220f141e04..055c3b15147448d46f9187339f80cc98e7042051 100644 (file)
@@ -1554,8 +1554,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
   // Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the
   // integer type is the same size as the pointer type.
   if (TD && LHSCI->getOpcode() == Instruction::PtrToInt &&
-      TD->getPointerSizeInBits(
-        cast<PtrToIntInst>(LHSCI)->getPointerAddressSpace()) ==
+      TD->getTypeSizeInBits(DestTy) ==
          cast<IntegerType>(DestTy)->getBitWidth()) {
     Value *RHSOp = 0;
     if (Constant *RHSC = dyn_cast<Constant>(ICI.getOperand(1))) {
index 71c62257e7f64b85aee702b23f59d967147b3ebe..728ce997a97d09265486ac3dbb6524f8e201324e 100644 (file)
@@ -2364,8 +2364,9 @@ private:
 
   Value *getAdjustedAllocaPtr(IRBuilder<> &IRB, Type *PointerTy) {
     assert(BeginOffset >= NewAllocaBeginOffset);
-    unsigned AS = cast<PointerType>(PointerTy)->getAddressSpace();
-    APInt Offset(TD.getPointerSizeInBits(AS), BeginOffset - NewAllocaBeginOffset);
+    assert(PointerTy->isPointerTy() &&
+        "Type must be pointer type!");
+    APInt Offset(TD.getTypeSizeInBits(PointerTy), BeginOffset - NewAllocaBeginOffset);
     return getAdjustedPtr(IRB, TD, &NewAI, Offset, PointerTy, getName(""));
   }
 
@@ -2687,9 +2688,8 @@ private:
       = P.getMemTransferOffsets(II);
 
     assert(OldPtr->getType()->isPointerTy() && "Must be a pointer type!");
-    unsigned AS = cast<PointerType>(OldPtr->getType())->getAddressSpace();
     // Compute the relative offset within the transfer.
-    unsigned IntPtrWidth = TD.getPointerSizeInBits(AS);
+    unsigned IntPtrWidth = TD.getTypeSizeInBits(OldPtr->getType());
     APInt RelOffset(IntPtrWidth, BeginOffset - (IsDest ? MTO.DestBegin
                                                        : MTO.SourceBegin));
 
index 9729687a83eff584d3aaf1d630ef2ef4ac6c2382..b03c878ef33d152e2979aefb23cc39c9676116f5 100644 (file)
@@ -807,7 +807,7 @@ unsigned llvm::getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
   assert(V->getType()->isPointerTy() &&
          "getOrEnforceKnownAlignment expects a pointer!");
   unsigned AS = cast<PointerType>(V->getType())->getAddressSpace();
-  unsigned BitWidth = TD ? TD->getPointerSizeInBits(AS) : 64;
+  unsigned BitWidth = TD ? TD->getTypeSizeInBits(V->getType()) : 64;
   APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
   ComputeMaskedBits(V, KnownZero, KnownOne, TD);
   unsigned TrailZ = KnownZero.countTrailingOnes();
index 8d7a8e267cc84f5b2dd1f9e647b7e27b668610b5..104e5da057f077c46d16ce7d378f005ef9dfd903 100644 (file)
@@ -524,6 +524,14 @@ std::string DataLayout::getStringRepresentation() const {
   return OS.str();
 }
 
+unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const
+{
+    if (Ty->isPointerTy()) return getTypeSizeInBits(Ty);
+    if (Ty->isVectorTy()
+        && cast<VectorType>(Ty)->getElementType()->isPointerTy())
+      return getTypeSizeInBits(cast<VectorType>(Ty)->getElementType());
+    return getPointerSizeInBits(0);
+}
 
 uint64_t DataLayout::getTypeSizeInBits(Type *Ty) const {
   assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");