Index: include/llvm/Target/TargetLowering.h =================================================================== --- include/llvm/Target/TargetLowering.h (revision 165622) +++ include/llvm/Target/TargetLowering.h (working copy) @@ -146,7 +146,7 @@ // Return the pointer type for the given address space, defaults to // the pointer type from the data layout. // FIXME: The default needs to be removed once all the code is updated. - virtual MVT getPointerTy(uint32_t addrspace = 0) const { return PointerTy; } + virtual MVT getPointerTy(uint32_t AS = 0) const { return PointerTy; } virtual MVT getShiftAmountTy(EVT LHSTy) const; /// isSelectExpensive - Return true if the select operation is expensive for Index: include/llvm/Instructions.h =================================================================== --- include/llvm/Instructions.h (revision 165622) +++ include/llvm/Instructions.h (working copy) @@ -350,7 +350,16 @@ static unsigned getPointerOperandIndex() { return 1U; } unsigned getPointerAddressSpace() const { - return cast(getPointerOperand()->getType())->getAddressSpace(); + if (getPointerOperand()->getType()->isPointerTy()) + return cast(getPointerOperand()->getType()) + ->getAddressSpace(); + if (getPointerOperand()->getType()->isVectorTy() + && cast(getPointerOperand()->getType())->isPointerTy()) + return cast(cast( + getPointerOperand()->getType())->getElementType()) + ->getAddressSpace(); + llvm_unreachable("Only a vector of pointers or pointers can be used!"); + return 0; } // Methods for support type inquiry through isa, cast, and dyn_cast: @@ -3653,7 +3662,15 @@ /// @brief return the address space of the pointer. unsigned getAddressSpace() const { - return cast(getType())->getAddressSpace(); + if (getType()->isPointerTy()) + return cast(getType())->getAddressSpace(); + if (getType()->isVectorTy() && + cast(getType())->getElementType()->isPointerTy()) + return cast( + cast(getType())->getElementType()) + ->getAddressSpace(); + llvm_unreachable("Must be a pointer or a vector of pointers."); + return 0; } // Methods for support type inquiry through isa, cast, and dyn_cast: @@ -3695,7 +3712,16 @@ /// @brief return the address space of the pointer. unsigned getPointerAddressSpace() const { - return cast(getOperand(0)->getType())->getAddressSpace(); + Type *Ty = getOperand(0)->getType(); + if (Ty->isPointerTy()) + return cast(Ty)->getAddressSpace(); + if (Ty->isVectorTy() + && cast(Ty)->getElementType()->isPointerTy()) + return cast( + cast(Ty)->getElementType()) + ->getAddressSpace(); + llvm_unreachable("Must be a pointer or a vector of pointers."); + return 0; } // Methods for support type inquiry through isa, cast, and dyn_cast: Index: include/llvm/Transforms/Utils/Local.h =================================================================== --- include/llvm/Transforms/Utils/Local.h (revision 165622) +++ include/llvm/Transforms/Utils/Local.h (working copy) @@ -186,7 +186,8 @@ bool isInBounds = cast(GEP)->isInBounds() && !NoAssumptions; // Build a mask for high order bits. - unsigned IntPtrWidth = TD.getPointerSizeInBits(); + unsigned AS = cast(GEP)->getPointerAddressSpace(); + unsigned IntPtrWidth = TD.getPointerSizeInBits(AS); uint64_t PtrSizeMask = ~0ULL >> (64-IntPtrWidth); for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e; Index: include/llvm/DataLayout.h =================================================================== --- include/llvm/DataLayout.h (revision 165622) +++ include/llvm/DataLayout.h (working copy) @@ -233,7 +233,7 @@ /// Layout pointer alignment /// FIXME: The defaults need to be removed once all of /// the backends/clients are updated. - unsigned getPointerABIAlignment(unsigned AS = 0) const { + unsigned getPointerABIAlignment(unsigned AS) const { DenseMap::const_iterator val = Pointers.find(AS); if (val == Pointers.end()) { val = Pointers.find(0); @@ -243,7 +243,7 @@ /// Return target's alignment for stack-based pointers /// FIXME: The defaults need to be removed once all of /// the backends/clients are updated. - unsigned getPointerPrefAlignment(unsigned AS = 0) const { + unsigned getPointerPrefAlignment(unsigned AS) const { DenseMap::const_iterator val = Pointers.find(AS); if (val == Pointers.end()) { val = Pointers.find(0); @@ -253,7 +253,7 @@ /// Layout pointer size /// FIXME: The defaults need to be removed once all of /// the backends/clients are updated. - unsigned getPointerSize(unsigned AS = 0) const { + unsigned getPointerSize(unsigned AS) const { DenseMap::const_iterator val = Pointers.find(AS); if (val == Pointers.end()) { val = Pointers.find(0); @@ -263,7 +263,7 @@ /// Layout pointer size, in bits /// FIXME: The defaults need to be removed once all of /// the backends/clients are updated. - unsigned getPointerSizeInBits(unsigned AS = 0) const { + unsigned getPointerSizeInBits(unsigned AS) const { DenseMap::const_iterator val = Pointers.find(AS); if (val == Pointers.end()) { val = Pointers.find(0); Index: include/llvm-c/Target.h =================================================================== --- include/llvm-c/Target.h (revision 165622) +++ include/llvm-c/Target.h (working copy) @@ -170,7 +170,7 @@ /** Returns the pointer size in bytes for a target. See the method llvm::DataLayout::getPointerSize. */ -unsigned LLVMPointerSize(LLVMTargetDataRef); +unsigned LLVMPointerSize(LLVMTargetDataRef, unsigned AS); /** Returns the integer type that is the same size as a pointer on a target. See the method llvm::DataLayout::getIntPtrType. */ Index: lib/Analysis/CodeMetrics.cpp =================================================================== --- lib/Analysis/CodeMetrics.cpp (revision 165622) +++ lib/Analysis/CodeMetrics.cpp (working copy) @@ -91,14 +91,16 @@ // which doesn't contain values outside the range of a pointer. if (isa(CI) && TD && TD->isLegalInteger(Op->getType()->getScalarSizeInBits()) && - Op->getType()->getScalarSizeInBits() <= TD->getPointerSizeInBits()) + Op->getType()->getScalarSizeInBits() <= TD->getPointerSizeInBits( + cast(CI)->getAddressSpace())) return true; // A ptrtoint cast is free so long as the result is large enough to store // the pointer, and a legal integer type. if (isa(CI) && TD && TD->isLegalInteger(Op->getType()->getScalarSizeInBits()) && - Op->getType()->getScalarSizeInBits() >= TD->getPointerSizeInBits()) + Op->getType()->getScalarSizeInBits() >= TD->getPointerSizeInBits( + cast(CI)->getPointerAddressSpace())) return true; // trunc to a native type is free (assuming the target has compare and Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp (revision 165622) +++ lib/Analysis/InstructionSimplify.cpp (working copy) @@ -666,7 +666,8 @@ /// 'Offset' APInt must be the bitwidth of the target's pointer size. static bool accumulateGEPOffset(const DataLayout &TD, GEPOperator *GEP, APInt &Offset) { - unsigned IntPtrWidth = TD.getPointerSizeInBits(); + unsigned AS = GEP->getPointerAddressSpace(); + unsigned IntPtrWidth = TD.getPointerSizeInBits(AS); assert(IntPtrWidth == Offset.getBitWidth()); gep_type_iterator GTI = gep_type_begin(GEP); @@ -696,12 +697,14 @@ /// accumulates the total constant offset applied in the returned constant. It /// returns 0 if V is not a pointer, and returns the constant '0' if there are /// no constant offsets applied. +/// FIXME: This function also exists in InlineCost.cpp. static Constant *stripAndComputeConstantOffsets(const DataLayout &TD, Value *&V) { if (!V->getType()->isPointerTy()) return 0; - unsigned IntPtrWidth = TD.getPointerSizeInBits(); + unsigned AS = cast(V->getType())->getAddressSpace();; + unsigned IntPtrWidth = TD.getPointerSizeInBits(AS); APInt Offset = APInt::getNullValue(IntPtrWidth); // Even though we don't look through PHI nodes, we could be called on an @@ -1877,7 +1880,9 @@ // 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(LI) && - Q.TD->getPointerSizeInBits() == DstTy->getPrimitiveSizeInBits()) { + Q.TD->getPointerSizeInBits( + cast(LI)->getPointerAddressSpace()) == + DstTy->getPrimitiveSizeInBits()) { if (Constant *RHSC = dyn_cast(RHS)) { // Transfer the cast to the constant. if (Value *V = SimplifyICmpInst(Pred, SrcOp, Index: lib/Analysis/BasicAliasAnalysis.cpp =================================================================== --- lib/Analysis/BasicAliasAnalysis.cpp (revision 165622) +++ lib/Analysis/BasicAliasAnalysis.cpp (working copy) @@ -286,7 +286,8 @@ V = GEPOp->getOperand(0); continue; } - + + unsigned AS = GEPOp->getPointerAddressSpace(); // Walk the indices of the GEP, accumulating them into BaseOff/VarIndices. gep_type_iterator GTI = gep_type_begin(GEPOp); for (User::const_op_iterator I = GEPOp->op_begin()+1, @@ -315,7 +316,7 @@ // If the integer type is smaller than the pointer size, it is implicitly // sign extended to pointer size. unsigned Width = cast(Index->getType())->getBitWidth(); - if (TD->getPointerSizeInBits() > Width) + if (TD->getPointerSizeInBits(AS) > Width) Extension = EK_SignExt; // Use GetLinearExpression to decompose the index into a C1*V+C2 form. @@ -344,7 +345,7 @@ // Make sure that we have a scale that makes sense for this target's // pointer size. - if (unsigned ShiftBits = 64-TD->getPointerSizeInBits()) { + if (unsigned ShiftBits = 64-TD->getPointerSizeInBits(AS)) { Scale <<= ShiftBits; Scale = (int64_t)Scale >> ShiftBits; } Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp (revision 165622) +++ lib/Analysis/ConstantFolding.cpp (working copy) @@ -916,10 +916,11 @@ if (TD && CE->getOpcode() == Instruction::IntToPtr) { Constant *Input = CE->getOperand(0); unsigned InWidth = Input->getType()->getScalarSizeInBits(); - if (TD->getPointerSizeInBits() < InWidth) { + unsigned AS = cast(CE->getType())->getAddressSpace(); + if (TD->getPointerSizeInBits(AS) < InWidth) { Constant *Mask = ConstantInt::get(CE->getContext(), APInt::getLowBitsSet(InWidth, - TD->getPointerSizeInBits())); + TD->getPointerSizeInBits(AS))); Input = ConstantExpr::getAnd(Input, Mask); } // Do a zext or trunc to get to the dest size. @@ -932,9 +933,10 @@ // the int size is >= the ptr size. This requires knowing the width of a // pointer, so it can't be done in ConstantExpr::getCast. if (ConstantExpr *CE = dyn_cast(Ops[0])) - if (TD && - TD->getPointerSizeInBits() <= CE->getType()->getScalarSizeInBits() && - CE->getOpcode() == Instruction::PtrToInt) + if (TD && CE->getOpcode() == Instruction::PtrToInt && + TD->getPointerSizeInBits( + cast(CE->getOperand(0)->getType())->getAddressSpace()) + <= CE->getType()->getScalarSizeInBits()) return FoldBitCast(CE->getOperand(0), DestTy, *TD); return ConstantExpr::getCast(Opcode, Ops[0], DestTy); Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp (revision 165622) +++ lib/Analysis/InlineCost.cpp (working copy) @@ -243,7 +243,8 @@ if (!TD) return false; - unsigned IntPtrWidth = TD->getPointerSizeInBits(); + unsigned AS = GEP.getPointerAddressSpace(); + unsigned IntPtrWidth = TD->getPointerSizeInBits(AS); assert(IntPtrWidth == Offset.getBitWidth()); for (gep_type_iterator GTI = gep_type_begin(GEP), GTE = gep_type_end(GEP); @@ -391,7 +392,8 @@ // Track base/offset pairs when converted to a plain integer provided the // integer is large enough to represent the pointer. unsigned IntegerSize = I.getType()->getScalarSizeInBits(); - if (TD && IntegerSize >= TD->getPointerSizeInBits()) { + unsigned AS = I.getPointerAddressSpace(); + if (TD && IntegerSize >= TD->getPointerSizeInBits(AS)) { std::pair BaseAndOffset = ConstantOffsetPtrs.lookup(I.getOperand(0)); if (BaseAndOffset.first) @@ -425,7 +427,8 @@ // modifications provided the integer is not too large. Value *Op = I.getOperand(0); unsigned IntegerSize = Op->getType()->getScalarSizeInBits(); - if (TD && IntegerSize <= TD->getPointerSizeInBits()) { + unsigned AS = I.getAddressSpace(); + if (TD && IntegerSize <= TD->getPointerSizeInBits(AS)) { std::pair BaseAndOffset = ConstantOffsetPtrs.lookup(Op); if (BaseAndOffset.first) ConstantOffsetPtrs[&I] = BaseAndOffset; @@ -760,7 +763,8 @@ if (!TD || !V->getType()->isPointerTy()) return 0; - unsigned IntPtrWidth = TD->getPointerSizeInBits(); + unsigned AS = cast(V->getType())->getAddressSpace();; + unsigned IntPtrWidth = TD->getPointerSizeInBits(AS); APInt Offset = APInt::getNullValue(IntPtrWidth); // Even though we don't look through PHI nodes, we could be called on an @@ -824,7 +828,8 @@ // size of the byval type by the target's pointer size. PointerType *PTy = cast(CS.getArgument(I)->getType()); unsigned TypeSize = TD->getTypeSizeInBits(PTy->getElementType()); - unsigned PointerSize = TD->getPointerSizeInBits(); + unsigned AS = PTy->getAddressSpace(); + unsigned PointerSize = TD->getPointerSizeInBits(AS); // Ceiling division. unsigned NumStores = (TypeSize + PointerSize - 1) / PointerSize; Index: lib/Analysis/ValueTracking.cpp =================================================================== --- lib/Analysis/ValueTracking.cpp (revision 165622) +++ lib/Analysis/ValueTracking.cpp (working copy) @@ -40,7 +40,8 @@ if (unsigned BitWidth = Ty->getScalarSizeInBits()) return BitWidth; assert(isa(Ty) && "Expected a pointer type!"); - return TD ? TD->getPointerSizeInBits() : 0; + return TD ? + TD->getPointerSizeInBits(cast(Ty)->getAddressSpace()) : 0; } static void ComputeMaskedBitsAddSub(bool Add, Value *Op0, Value *Op1, bool NSW, @@ -1621,7 +1622,8 @@ // Re-sign extend from the pointer size if needed to get overflow edge cases // right. - unsigned PtrSize = TD.getPointerSizeInBits(); + unsigned AS = GEP->getPointerAddressSpace(); + unsigned PtrSize = TD.getPointerSizeInBits(AS); if (PtrSize < 64) Offset = SignExtend64(Offset, PtrSize); Index: lib/Target/PowerPC/PPCRegisterInfo.cpp =================================================================== --- lib/Target/PowerPC/PPCRegisterInfo.cpp (revision 165622) +++ lib/Target/PowerPC/PPCRegisterInfo.cpp (working copy) @@ -498,7 +498,7 @@ } else if (CRSpillFrameIdx) { FrameIdx = CRSpillFrameIdx; } else { - MachineFrameInfo *MFI = ((MachineFunction &)MF).getFrameInfo(); + MachineFrameInfo *MFI = (const_cast(MF)).getFrameInfo(); FrameIdx = MFI->CreateFixedObject((uint64_t)4, (int64_t)-4, true); CRSpillFrameIdx = FrameIdx; } Index: lib/Target/PowerPC/PPCAsmPrinter.cpp =================================================================== --- lib/Target/PowerPC/PPCAsmPrinter.cpp (revision 165622) +++ lib/Target/PowerPC/PPCAsmPrinter.cpp (working copy) @@ -439,7 +439,7 @@ bool PPCLinuxAsmPrinter::doFinalization(Module &M) { const DataLayout *TD = TM.getDataLayout(); - bool isPPC64 = TD->getPointerSizeInBits() == 64; + bool isPPC64 = TD->getPointerSizeInBits(0) == 64; if (isPPC64 && !TOC.empty()) { const MCSectionELF *Section = OutStreamer.getContext().getELFSection(".toc", @@ -545,7 +545,7 @@ void PPCDarwinAsmPrinter:: EmitFunctionStubs(const MachineModuleInfoMachO::SymbolListTy &Stubs) { - bool isPPC64 = TM.getDataLayout()->getPointerSizeInBits() == 64; + bool isPPC64 = TM.getDataLayout()->getPointerSizeInBits(0) == 64; const TargetLoweringObjectFileMachO &TLOFMacho = static_cast(getObjFileLowering()); @@ -640,7 +640,7 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) { - bool isPPC64 = TM.getDataLayout()->getPointerSizeInBits() == 64; + bool isPPC64 = TM.getDataLayout()->getPointerSizeInBits(0) == 64; // Darwin/PPC always uses mach-o. const TargetLoweringObjectFileMachO &TLOFMacho = Index: lib/Target/NVPTX/NVPTXAsmPrinter.cpp =================================================================== --- lib/Target/NVPTX/NVPTXAsmPrinter.cpp (revision 165622) +++ lib/Target/NVPTX/NVPTXAsmPrinter.cpp (working copy) @@ -126,8 +126,9 @@ return Base; // Truncate/sext the offset to the pointer size. - if (TD.getPointerSizeInBits() != 64) { - int SExtAmount = 64-TD.getPointerSizeInBits(); + unsigned AS = cast(CE)->getPointerAddressSpace(); + if (TD.getPointerSizeInBits(AS) != 64) { + int SExtAmount = 64-TD.getPointerSizeInBits(AS); Offset = (Offset << SExtAmount) >> SExtAmount; } @@ -1378,7 +1379,7 @@ const FunctionType *FTy = dyn_cast(Ty); if (FTy) - return TD->getPointerPrefAlignment(); + return TD->getPointerPrefAlignment(0); return TD->getPrefTypeAlignment(Ty); } Index: lib/Target/ARM/ARMELFWriterInfo.cpp =================================================================== --- lib/Target/ARM/ARMELFWriterInfo.cpp (revision 165622) +++ lib/Target/ARM/ARMELFWriterInfo.cpp (working copy) @@ -26,7 +26,7 @@ //===----------------------------------------------------------------------===// ARMELFWriterInfo::ARMELFWriterInfo(TargetMachine &TM) - : TargetELFWriterInfo(TM.getDataLayout()->getPointerSizeInBits() == 64, + : TargetELFWriterInfo(TM.getDataLayout()->getPointerSizeInBits(0) == 64, TM.getDataLayout()->isLittleEndian()) { } Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp (revision 165622) +++ lib/Target/X86/X86ISelLowering.cpp (working copy) @@ -2649,7 +2649,7 @@ unsigned StackAlignment = TFI.getStackAlignment(); uint64_t AlignMask = StackAlignment - 1; int64_t Offset = StackSize; - uint64_t SlotSize = TD->getPointerSize(); + uint64_t SlotSize = TD->getPointerSize(0); if ( (Offset & AlignMask) <= (StackAlignment - SlotSize) ) { // Number smaller than 12 so just add the difference. Offset += ((StackAlignment - SlotSize) - (Offset & AlignMask)); @@ -3017,7 +3017,7 @@ if (ReturnAddrIndex == 0) { // Set up a frame object for the return address. - uint64_t SlotSize = TD->getPointerSize(); + uint64_t SlotSize = TD->getPointerSize(0); ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(SlotSize, -SlotSize, false); FuncInfo->setRAIndex(ReturnAddrIndex); @@ -7724,7 +7724,7 @@ IDX = DAG.getLoad(getPointerTy(), dl, Chain, IDX, MachinePointerInfo(), false, false, false, 0); - SDValue Scale = DAG.getConstant(Log2_64_Ceil(TD->getPointerSize()), + SDValue Scale = DAG.getConstant(Log2_64_Ceil(TD->getPointerSize(0)), getPointerTy()); IDX = DAG.getNode(ISD::SHL, dl, getPointerTy(), IDX, Scale); @@ -10345,7 +10345,7 @@ if (Depth > 0) { SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); SDValue Offset = - DAG.getConstant(TD->getPointerSize(), + DAG.getConstant(TD->getPointerSize(0), Subtarget->is64Bit() ? MVT::i64 : MVT::i32); return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), DAG.getNode(ISD::ADD, dl, getPointerTy(), @@ -10377,7 +10377,7 @@ SDValue X86TargetLowering::LowerFRAME_TO_ARGS_OFFSET(SDValue Op, SelectionDAG &DAG) const { - return DAG.getIntPtrConstant(2*TD->getPointerSize()); + return DAG.getIntPtrConstant(2*TD->getPointerSize(0)); } SDValue X86TargetLowering::LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const { @@ -10392,7 +10392,7 @@ unsigned StoreAddrReg = (Subtarget->is64Bit() ? X86::RCX : X86::ECX); SDValue StoreAddr = DAG.getNode(ISD::ADD, dl, getPointerTy(), Frame, - DAG.getIntPtrConstant(TD->getPointerSize())); + DAG.getIntPtrConstant(TD->getPointerSize(0))); StoreAddr = DAG.getNode(ISD::ADD, dl, getPointerTy(), StoreAddr, Offset); Chain = DAG.getStore(Chain, dl, Handler, StoreAddr, MachinePointerInfo(), false, false, 0); Index: lib/Target/X86/X86FrameLowering.cpp =================================================================== --- lib/Target/X86/X86FrameLowering.cpp (revision 165622) +++ lib/Target/X86/X86FrameLowering.cpp (working copy) @@ -317,7 +317,7 @@ bool HasFP = hasFP(MF); // Calculate amount of bytes used for return address storing. - int stackGrowth = -TD->getPointerSize(); + int stackGrowth = -TD->getPointerSize(0); // FIXME: This is dirty hack. The code itself is pretty mess right now. // It should be rewritten from scratch and generalized sometimes. @@ -717,7 +717,7 @@ std::vector &Moves = MMI.getFrameMoves(); const DataLayout *TD = MF.getTarget().getDataLayout(); uint64_t NumBytes = 0; - int stackGrowth = -TD->getPointerSize(); + int stackGrowth = -TD->getPointerSize(0); if (HasFP) { // Calculate required stack adjustment. Index: lib/Target/X86/X86AsmPrinter.cpp =================================================================== --- lib/Target/X86/X86AsmPrinter.cpp (revision 165622) +++ lib/Target/X86/X86AsmPrinter.cpp (working copy) @@ -693,7 +693,7 @@ for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { OutStreamer.EmitLabel(Stubs[i].first); OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(), - TD->getPointerSize(), 0); + TD->getPointerSize(0), 0); } Stubs.clear(); } Index: lib/Target/MSP430/MSP430ISelLowering.cpp =================================================================== --- lib/Target/MSP430/MSP430ISelLowering.cpp (revision 165622) +++ lib/Target/MSP430/MSP430ISelLowering.cpp (working copy) @@ -881,7 +881,7 @@ if (ReturnAddrIndex == 0) { // Set up a frame object for the return address. - uint64_t SlotSize = TD->getPointerSize(); + uint64_t SlotSize = TD->getPointerSize(0); ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(SlotSize, -SlotSize, true); FuncInfo->setRAIndex(ReturnAddrIndex); @@ -901,7 +901,7 @@ if (Depth > 0) { SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); SDValue Offset = - DAG.getConstant(TD->getPointerSize(), MVT::i16); + DAG.getConstant(TD->getPointerSize(0), MVT::i16); return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), DAG.getNode(ISD::ADD, dl, getPointerTy(), FrameAddr, Offset), Index: lib/Target/Target.cpp =================================================================== --- lib/Target/Target.cpp (revision 165622) +++ lib/Target/Target.cpp (working copy) @@ -54,8 +54,8 @@ return unwrap(TD)->isLittleEndian() ? LLVMLittleEndian : LLVMBigEndian; } -unsigned LLVMPointerSize(LLVMTargetDataRef TD) { - return unwrap(TD)->getPointerSize(); +unsigned LLVMPointerSize(LLVMTargetDataRef TD, unsigned AS) { + return unwrap(TD)->getPointerSize(AS); } LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) { Index: lib/Target/MBlaze/MBlazeELFWriterInfo.cpp =================================================================== --- lib/Target/MBlaze/MBlazeELFWriterInfo.cpp (revision 165622) +++ lib/Target/MBlaze/MBlazeELFWriterInfo.cpp (working copy) @@ -26,7 +26,7 @@ //===----------------------------------------------------------------------===// MBlazeELFWriterInfo::MBlazeELFWriterInfo(TargetMachine &TM) - : TargetELFWriterInfo(TM.getDataLayout()->getPointerSizeInBits() == 64, + : TargetELFWriterInfo(TM.getDataLayout()->getPointerSizeInBits(0) == 64, TM.getDataLayout()->isLittleEndian()) { } Index: lib/ExecutionEngine/Interpreter/Execution.cpp =================================================================== --- lib/ExecutionEngine/Interpreter/Execution.cpp (revision 165622) +++ lib/ExecutionEngine/Interpreter/Execution.cpp (working copy) @@ -1054,7 +1054,8 @@ GenericValue Dest, Src = getOperandValue(SrcVal, SF); assert(DstTy->isPointerTy() && "Invalid PtrToInt instruction"); - uint32_t PtrSize = TD.getPointerSizeInBits(); + unsigned AS = cast(DstTy)->getAddressSpace(); + uint32_t PtrSize = TD.getPointerSizeInBits(AS); if (PtrSize != Src.IntVal.getBitWidth()) Src.IntVal = Src.IntVal.zextOrTrunc(PtrSize); Index: lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp =================================================================== --- lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp (revision 165622) +++ lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp (working copy) @@ -376,7 +376,7 @@ case 'x': case 'X': if (HowLong >= 1) { if (HowLong == 1 && - TheInterpreter->getDataLayout()->getPointerSizeInBits() == 64 && + TheInterpreter->getDataLayout()->getPointerSizeInBits(0) == 64 && sizeof(long) < sizeof(int64_t)) { // Make sure we use %lld with a 64 bit argument because we might be // compiling LLI on a 32 bit compiler. Index: lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp =================================================================== --- lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp (revision 165622) +++ lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp (working copy) @@ -14,7 +14,9 @@ #include "JIT.h" #include "JITDwarfEmitter.h" +#include "llvm/DerivedTypes.h" #include "llvm/Function.h" +#include "llvm/GlobalVariable.h" #include "llvm/ADT/DenseMap.h" #include "llvm/CodeGen/JITCodeEmitter.h" #include "llvm/CodeGen/MachineFunction.h" @@ -66,7 +68,7 @@ void JITDwarfEmitter::EmitFrameMoves(intptr_t BaseLabelPtr, const std::vector &Moves) const { - unsigned PointerSize = TD->getPointerSize(); + unsigned PointerSize = TD->getPointerSize(0); int stackGrowth = stackGrowthDirection == TargetFrameLowering::StackGrowsUp ? PointerSize : -PointerSize; MCSymbol *BaseLabel = 0; @@ -378,7 +380,7 @@ for (unsigned i = 0, e = CallSites.size(); i < e; ++i) SizeSites += MCAsmInfo::getULEB128Size(CallSites[i].Action); - unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize(); + unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize(0); unsigned TypeOffset = sizeof(int8_t) + // Call site format // Call-site table length @@ -454,12 +456,12 @@ const GlobalVariable *GV = TypeInfos[M - 1]; if (GV) { - if (TD->getPointerSize() == sizeof(int32_t)) + if (TD->getPointerSize(GV->getType()->getAddressSpace()) == sizeof(int32_t)) JCE->emitInt32((intptr_t)Jit.getOrEmitGlobalVariable(GV)); else JCE->emitInt64((intptr_t)Jit.getOrEmitGlobalVariable(GV)); } else { - if (TD->getPointerSize() == sizeof(int32_t)) + if (TD->getPointerSize(0) == sizeof(int32_t)) JCE->emitInt32(0); else JCE->emitInt64(0); @@ -481,7 +483,7 @@ unsigned char* JITDwarfEmitter::EmitCommonEHFrame(const Function* Personality) const { - unsigned PointerSize = TD->getPointerSize(); + unsigned PointerSize = TD->getPointerSize(0); int stackGrowth = stackGrowthDirection == TargetFrameLowering::StackGrowsUp ? PointerSize : -PointerSize; @@ -541,7 +543,7 @@ unsigned char* StartFunction, unsigned char* EndFunction, unsigned char* ExceptionTable) const { - unsigned PointerSize = TD->getPointerSize(); + unsigned PointerSize = TD->getPointerSize(0); // EH frame header. unsigned char* StartEHPtr = (unsigned char*)JCE->getCurrentPCValue(); Index: lib/ExecutionEngine/ExecutionEngine.cpp =================================================================== --- lib/ExecutionEngine/ExecutionEngine.cpp (revision 165622) +++ lib/ExecutionEngine/ExecutionEngine.cpp (working copy) @@ -17,6 +17,7 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/Instructions.h" #include "llvm/Module.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/ADT/SmallString.h" @@ -267,7 +268,7 @@ void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE, const std::vector &InputArgv) { clear(); // Free the old contents. - unsigned PtrSize = EE->getDataLayout()->getPointerSize(); + unsigned PtrSize = EE->getDataLayout()->getPointerSize(0); Array = new char[(InputArgv.size()+1)*PtrSize]; DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array << "\n"); @@ -342,7 +343,7 @@ #ifndef NDEBUG /// isTargetNullPtr - Return whether the target pointer stored at Loc is null. static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) { - unsigned PtrSize = EE->getDataLayout()->getPointerSize(); + unsigned PtrSize = EE->getDataLayout()->getPointerSize(0); for (unsigned i = 0; i < PtrSize; ++i) if (*(i + (uint8_t*)Loc)) return false; @@ -644,13 +645,15 @@ } case Instruction::PtrToInt: { GenericValue GV = getConstantValue(Op0); - uint32_t PtrWidth = TD->getPointerSizeInBits(); + unsigned AS = cast(CE)->getPointerAddressSpace(); + uint32_t PtrWidth = TD->getPointerSizeInBits(AS); GV.IntVal = APInt(PtrWidth, uintptr_t(GV.PointerVal)); return GV; } case Instruction::IntToPtr: { GenericValue GV = getConstantValue(Op0); - uint32_t PtrWidth = TD->getPointerSizeInBits(); + unsigned AS = cast(CE)->getAddressSpace(); + uint32_t PtrWidth = TD->getPointerSizeInBits(AS); if (PtrWidth != GV.IntVal.getBitWidth()) GV.IntVal = GV.IntVal.zextOrTrunc(PtrWidth); assert(GV.IntVal.getBitWidth() <= 64 && "Bad pointer width"); Index: lib/Transforms/Utils/Local.cpp =================================================================== --- lib/Transforms/Utils/Local.cpp (revision 165622) +++ lib/Transforms/Utils/Local.cpp (working copy) @@ -806,7 +806,8 @@ const DataLayout *TD) { assert(V->getType()->isPointerTy() && "getOrEnforceKnownAlignment expects a pointer!"); - unsigned BitWidth = TD ? TD->getPointerSizeInBits() : 64; + unsigned AS = cast(V->getType())->getAddressSpace(); + unsigned BitWidth = TD ? TD->getPointerSizeInBits(AS) : 64; APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0); ComputeMaskedBits(V, KnownZero, KnownOne, TD); unsigned TrailZ = KnownZero.countTrailingOnes(); Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/AddressSanitizer.cpp (revision 165622) +++ lib/Transforms/Instrumentation/AddressSanitizer.cpp (working copy) @@ -742,7 +742,7 @@ BL.reset(new BlackList(ClBlackListFile)); C = &(M.getContext()); - LongSize = TD->getPointerSizeInBits(); + LongSize = TD->getPointerSizeInBits(0); IntptrTy = Type::getIntNTy(*C, LongSize); IntptrPtrTy = PointerType::get(IntptrTy, 0); Index: lib/Transforms/Scalar/SROA.cpp =================================================================== --- lib/Transforms/Scalar/SROA.cpp (revision 165622) +++ lib/Transforms/Scalar/SROA.cpp (working copy) @@ -447,6 +447,7 @@ bool computeConstantGEPOffset(GetElementPtrInst &GEPI, int64_t &GEPOffset) { GEPOffset = Offset; + unsigned int AS = GEPI.getPointerAddressSpace(); for (gep_type_iterator GTI = gep_type_begin(GEPI), GTE = gep_type_end(GEPI); GTI != GTE; ++GTI) { ConstantInt *OpC = dyn_cast(GTI.getOperand()); @@ -476,7 +477,7 @@ continue; } - APInt Index = OpC->getValue().sextOrTrunc(TD.getPointerSizeInBits()); + APInt Index = OpC->getValue().sextOrTrunc(TD.getPointerSizeInBits(AS)); Index *= APInt(Index.getBitWidth(), TD.getTypeAllocSize(GTI.getIndexedType())); Index += APInt(Index.getBitWidth(), (uint64_t)GEPOffset, @@ -1784,7 +1785,9 @@ break; if (SequentialType *SeqTy = dyn_cast(ElementTy)) { ElementTy = SeqTy->getElementType(); - Indices.push_back(IRB.getInt(APInt(TD.getPointerSizeInBits(), 0))); + Indices.push_back(IRB.getInt(APInt(TD.getPointerSizeInBits( + ElementTy->isPointerTy() ? + cast(ElementTy)->getAddressSpace(): 0), 0))); } else if (StructType *STy = dyn_cast(ElementTy)) { if (STy->element_begin() == STy->element_end()) break; // Nothing left to descend into. @@ -2239,7 +2242,8 @@ Value *getAdjustedAllocaPtr(IRBuilder<> &IRB, Type *PointerTy) { assert(BeginOffset >= NewAllocaBeginOffset); - APInt Offset(TD.getPointerSizeInBits(), BeginOffset - NewAllocaBeginOffset); + unsigned AS = cast(PointerTy)->getAddressSpace(); + APInt Offset(TD.getPointerSizeInBits(AS), BeginOffset - NewAllocaBeginOffset); return getAdjustedPtr(IRB, TD, &NewAI, Offset, PointerTy, getName("")); } @@ -2578,8 +2582,10 @@ const AllocaPartitioning::MemTransferOffsets &MTO = P.getMemTransferOffsets(II); + assert(OldPtr->getType()->isPointerTy() && "Must be a pointer type!"); + unsigned AS = cast(OldPtr->getType())->getAddressSpace(); // Compute the relative offset within the transfer. - unsigned IntPtrWidth = TD.getPointerSizeInBits(); + unsigned IntPtrWidth = TD.getPointerSizeInBits(AS); APInt RelOffset(IntPtrWidth, BeginOffset - (IsDest ? MTO.DestBegin : MTO.SourceBegin)); Index: lib/Transforms/Scalar/MemCpyOptimizer.cpp =================================================================== --- lib/Transforms/Scalar/MemCpyOptimizer.cpp (revision 165622) +++ lib/Transforms/Scalar/MemCpyOptimizer.cpp (working copy) @@ -174,10 +174,11 @@ // this width can be stored. If so, check to see whether we will end up // actually reducing the number of stores used. unsigned Bytes = unsigned(End-Start); - unsigned NumPointerStores = Bytes/TD.getPointerSize(); + unsigned AS = cast(TheStores[0])->getPointerAddressSpace(); + unsigned NumPointerStores = Bytes/TD.getPointerSize(AS); // Assume the remaining bytes if any are done a byte at a time. - unsigned NumByteStores = Bytes - NumPointerStores*TD.getPointerSize(); + unsigned NumByteStores = Bytes - NumPointerStores*TD.getPointerSize(AS); // If we will reduce the # stores (according to this heuristic), do the // transformation. This encourages merging 4 x i8 -> i32 and 2 x i16 -> i32 Index: lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCompares.cpp (revision 165622) +++ lib/Transforms/InstCombine/InstCombineCompares.cpp (working copy) @@ -365,11 +365,12 @@ // order the state machines in complexity of the generated code. Value *Idx = GEP->getOperand(2); + unsigned AS = GEP->getPointerAddressSpace(); // If the index is larger than the pointer size of the target, truncate the // index down like the GEP would do implicitly. We don't have to do this for // an inbounds GEP because the index can't be out of range. if (!GEP->isInBounds() && - Idx->getType()->getPrimitiveSizeInBits() > TD->getPointerSizeInBits()) + Idx->getType()->getPrimitiveSizeInBits() > TD->getPointerSizeInBits(AS)) Idx = Builder->CreateTrunc(Idx, TD->getIntPtrType(Idx->getContext())); // If the comparison is only true for one or two elements, emit direct @@ -528,10 +529,11 @@ } } + unsigned AS = cast(GEP)->getPointerAddressSpace(); // Okay, we know we have a single variable index, which must be a // pointer/array/vector index. If there is no offset, life is simple, return // the index. - unsigned IntPtrWidth = TD.getPointerSizeInBits(); + unsigned IntPtrWidth = TD.getPointerSizeInBits(AS); if (Offset == 0) { // Cast to intptrty in case a truncation occurs. If an extension is needed, // we don't need to bother extending: the extension won't affect where the @@ -1552,7 +1554,8 @@ // 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() == + TD->getPointerSizeInBits( + cast(LHSCI)->getPointerAddressSpace()) == cast(DestTy)->getBitWidth()) { Value *RHSOp = 0; if (Constant *RHSC = dyn_cast(ICI.getOperand(1))) { Index: lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCasts.cpp (revision 165622) +++ lib/Transforms/InstCombine/InstCombineCasts.cpp (working copy) @@ -1293,15 +1293,16 @@ // If the source integer type is not the intptr_t type for this target, do a // trunc or zext to the intptr_t type, then inttoptr of it. This allows the // cast to be exposed to other transforms. + unsigned AS = CI.getAddressSpace(); if (TD) { if (CI.getOperand(0)->getType()->getScalarSizeInBits() > - TD->getPointerSizeInBits()) { + TD->getPointerSizeInBits(AS)) { Value *P = Builder->CreateTrunc(CI.getOperand(0), TD->getIntPtrType(CI.getContext())); return new IntToPtrInst(P, CI.getType()); } if (CI.getOperand(0)->getType()->getScalarSizeInBits() < - TD->getPointerSizeInBits()) { + TD->getPointerSizeInBits(AS)) { Value *P = Builder->CreateZExt(CI.getOperand(0), TD->getIntPtrType(CI.getContext())); return new IntToPtrInst(P, CI.getType()); @@ -1368,13 +1369,14 @@ // If the destination integer type is not the intptr_t type for this target, // do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast // to be exposed to other transforms. + unsigned AS = CI.getPointerAddressSpace(); if (TD) { - if (CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits()) { + if (CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits(AS)) { Value *P = Builder->CreatePtrToInt(CI.getOperand(0), TD->getIntPtrType(CI.getContext())); return new TruncInst(P, CI.getType()); } - if (CI.getType()->getScalarSizeInBits() > TD->getPointerSizeInBits()) { + if (CI.getType()->getScalarSizeInBits() > TD->getPointerSizeInBits(AS)) { Value *P = Builder->CreatePtrToInt(CI.getOperand(0), TD->getIntPtrType(CI.getContext())); return new ZExtInst(P, CI.getType()); Index: lib/CodeGen/AsmPrinter/DIE.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DIE.cpp (revision 165622) +++ lib/CodeGen/AsmPrinter/DIE.cpp (working copy) @@ -200,7 +200,7 @@ case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return; case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return; case dwarf::DW_FORM_addr: - Size = Asm->getDataLayout().getPointerSize(); break; + Size = Asm->getDataLayout().getPointerSize(0); break; default: llvm_unreachable("DIE Value form not supported yet"); } Asm->OutStreamer.EmitIntValue(Integer, Size, 0/*addrspace*/); @@ -222,7 +222,7 @@ case dwarf::DW_FORM_data8: return sizeof(int64_t); case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer); case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer); - case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize(); + case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize(0); default: llvm_unreachable("DIE Value form not supported yet"); } } @@ -249,7 +249,7 @@ unsigned DIELabel::SizeOf(AsmPrinter *AP, unsigned Form) const { if (Form == dwarf::DW_FORM_data4) return 4; if (Form == dwarf::DW_FORM_strp) return 4; - return AP->getDataLayout().getPointerSize(); + return AP->getDataLayout().getPointerSize(0); } #ifndef NDEBUG @@ -273,7 +273,7 @@ unsigned DIEDelta::SizeOf(AsmPrinter *AP, unsigned Form) const { if (Form == dwarf::DW_FORM_data4) return 4; if (Form == dwarf::DW_FORM_strp) return 4; - return AP->getDataLayout().getPointerSize(); + return AP->getDataLayout().getPointerSize(0); } #ifndef NDEBUG Index: lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp (revision 165622) +++ lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp (working copy) @@ -112,7 +112,7 @@ switch (Encoding & 0x07) { default: llvm_unreachable("Invalid encoded value."); - case dwarf::DW_EH_PE_absptr: return TM.getDataLayout()->getPointerSize(); + case dwarf::DW_EH_PE_absptr: return TM.getDataLayout()->getPointerSize(0); case dwarf::DW_EH_PE_udata2: return 2; case dwarf::DW_EH_PE_udata4: return 4; case dwarf::DW_EH_PE_udata8: return 8; Index: lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp (revision 165622) +++ lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp (working copy) @@ -91,7 +91,7 @@ /// either condition is detected in a function which uses the GC. /// void OcamlGCMetadataPrinter::finishAssembly(AsmPrinter &AP) { - unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(); + unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(0); AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getTextSection()); EmitCamlGlobal(getModule(), AP, "code_end"); Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp (revision 165622) +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp (working copy) @@ -384,7 +384,7 @@ // DW_AT_ranges appropriately. TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4, DebugRangeSymbols.size() - * Asm->getDataLayout().getPointerSize()); + * Asm->getDataLayout().getPointerSize(0)); for (SmallVector::const_iterator RI = Ranges.begin(), RE = Ranges.end(); RI != RE; ++RI) { DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first)); @@ -450,7 +450,7 @@ // DW_AT_ranges appropriately. TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4, DebugRangeSymbols.size() - * Asm->getDataLayout().getPointerSize()); + * Asm->getDataLayout().getPointerSize(0)); for (SmallVector::const_iterator RI = Ranges.begin(), RE = Ranges.end(); RI != RE; ++RI) { DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first)); @@ -1765,7 +1765,7 @@ Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"), DwarfAbbrevSectionSym); Asm->OutStreamer.AddComment("Address Size (in bytes)"); - Asm->EmitInt8(Asm->getDataLayout().getPointerSize()); + Asm->EmitInt8(Asm->getDataLayout().getPointerSize(0)); emitDIE(Die); Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID())); @@ -1811,14 +1811,14 @@ Asm->EmitInt8(0); Asm->OutStreamer.AddComment("Op size"); - Asm->EmitInt8(Asm->getDataLayout().getPointerSize() + 1); + Asm->EmitInt8(Asm->getDataLayout().getPointerSize(0) + 1); Asm->OutStreamer.AddComment("DW_LNE_set_address"); Asm->EmitInt8(dwarf::DW_LNE_set_address); Asm->OutStreamer.AddComment("Section end label"); Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd), - Asm->getDataLayout().getPointerSize(), + Asm->getDataLayout().getPointerSize(0), 0/*AddrSpace*/); // Mark end of matrix. @@ -2047,7 +2047,7 @@ // Start the dwarf loc section. Asm->OutStreamer.SwitchSection( Asm->getObjFileLowering().getDwarfLocSection()); - unsigned char Size = Asm->getDataLayout().getPointerSize(); + unsigned char Size = Asm->getDataLayout().getPointerSize(0); Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0)); unsigned index = 1; for (SmallVector::iterator @@ -2144,7 +2144,7 @@ // Start the dwarf ranges section. Asm->OutStreamer.SwitchSection( Asm->getObjFileLowering().getDwarfRangesSection()); - unsigned char Size = Asm->getDataLayout().getPointerSize(); + unsigned char Size = Asm->getDataLayout().getPointerSize(0); for (SmallVector::iterator I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end(); I != E; ++I) { @@ -2202,7 +2202,7 @@ Asm->OutStreamer.AddComment("Dwarf Version"); Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->OutStreamer.AddComment("Address Size (in bytes)"); - Asm->EmitInt8(Asm->getDataLayout().getPointerSize()); + Asm->EmitInt8(Asm->getDataLayout().getPointerSize(0)); for (SmallVector::iterator I = InlinedSPNodes.begin(), E = InlinedSPNodes.end(); I != E; ++I) { @@ -2233,7 +2233,7 @@ if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc"); Asm->OutStreamer.EmitSymbolValue(LI->first, - Asm->getDataLayout().getPointerSize(),0); + Asm->getDataLayout().getPointerSize(0),0); } } Index: lib/CodeGen/AsmPrinter/DwarfException.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfException.cpp (revision 165622) +++ lib/CodeGen/AsmPrinter/DwarfException.cpp (working copy) @@ -417,7 +417,7 @@ // that we're omitting that bit. TTypeEncoding = dwarf::DW_EH_PE_omit; // dwarf::DW_EH_PE_absptr - TypeFormatSize = Asm->getDataLayout().getPointerSize(); + TypeFormatSize = Asm->getDataLayout().getPointerSize(0); } else { // Okay, we have actual filters or typeinfos to emit. As such, we need to // pick a type encoding for them. We're about to emit a list of pointers to Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp (revision 165622) +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp (working copy) @@ -385,7 +385,8 @@ // - __tlv_bootstrap - used to make sure support exists // - spare pointer, used when mapped by the runtime // - pointer to mangled symbol above with initializer - unsigned PtrSize = TD->getPointerSizeInBits()/8; + unsigned AS = GV->getType()->getAddressSpace(); + unsigned PtrSize = TD->getPointerSizeInBits(AS)/8; OutStreamer.EmitSymbolValue(GetExternalSymbolSymbol("_tlv_bootstrap"), PtrSize, 0); OutStreamer.EmitIntValue(0, PtrSize, 0); @@ -1299,7 +1300,7 @@ // Emit the function pointers in the target-specific order const DataLayout *TD = TM.getDataLayout(); - unsigned Align = Log2_32(TD->getPointerPrefAlignment()); + unsigned Align = Log2_32(TD->getPointerPrefAlignment(0)); std::stable_sort(Structors.begin(), Structors.end(), priority_order); for (unsigned i = 0, e = Structors.size(); i != e; ++i) { const MCSection *OutputSection = @@ -1480,8 +1481,9 @@ if (Offset == 0) return Base; + unsigned AS = cast(CE->getType())->getAddressSpace(); // Truncate/sext the offset to the pointer size. - unsigned Width = TD.getPointerSizeInBits(); + unsigned Width = TD.getPointerSizeInBits(AS); if (Width < 64) Offset = SignExtend64(Offset, Width); Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp (revision 165622) +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp (working copy) @@ -77,9 +77,9 @@ Flags, SectionKind::getDataRel(), 0, Label->getName()); - unsigned Size = TM.getDataLayout()->getPointerSize(); + unsigned Size = TM.getDataLayout()->getPointerSize(0); Streamer.SwitchSection(Sec); - Streamer.EmitValueToAlignment(TM.getDataLayout()->getPointerABIAlignment()); + Streamer.EmitValueToAlignment(TM.getDataLayout()->getPointerABIAlignment(0)); Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject); const MCExpr *E = MCConstantExpr::Create(Size, getContext()); Streamer.EmitELFSize(Label, E); Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp (revision 165622) +++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp (working copy) @@ -3449,9 +3449,12 @@ EVT VT = TLI.getOptimalMemOpType(Size, DstAlign, SrcAlign, IsZeroVal, MemcpyStrSrc, DAG.getMachineFunction()); + Type *vtType = VT.isExtended() ? VT.getTypeForEVT(*DAG.getContext()) : NULL; + unsigned AS = (vtType && vtType->isPointerTy()) ? + cast(vtType)->getAddressSpace() : 0; if (VT == MVT::Other) { - if (DstAlign >= TLI.getDataLayout()->getPointerPrefAlignment() || + if (DstAlign >= TLI.getDataLayout()->getPointerPrefAlignment(AS) || TLI.allowsUnalignedMemoryAccesses(VT)) { VT = TLI.getPointerTy(); } else { Index: lib/CodeGen/MachineFunction.cpp =================================================================== --- lib/CodeGen/MachineFunction.cpp (revision 165622) +++ lib/CodeGen/MachineFunction.cpp (working copy) @@ -550,7 +550,7 @@ // address of a block, in which case it is the pointer size. switch (getEntryKind()) { case MachineJumpTableInfo::EK_BlockAddress: - return TD.getPointerSize(); + return TD.getPointerSize(0); case MachineJumpTableInfo::EK_GPRel64BlockAddress: return 8; case MachineJumpTableInfo::EK_GPRel32BlockAddress: @@ -570,7 +570,7 @@ // alignment. switch (getEntryKind()) { case MachineJumpTableInfo::EK_BlockAddress: - return TD.getPointerABIAlignment(); + return TD.getPointerABIAlignment(0); case MachineJumpTableInfo::EK_GPRel64BlockAddress: return TD.getABIIntegerTypeAlignment(64); case MachineJumpTableInfo::EK_GPRel32BlockAddress: Index: tools/clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- tools/clang/lib/CodeGen/CGDebugInfo.cpp (revision 165622) +++ tools/clang/lib/CodeGen/CGDebugInfo.cpp (working copy) @@ -2475,7 +2475,7 @@ addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpPlus)); // offset of __forwarding field offset = CGM.getContext() - .toCharUnitsFromBits(target.getPointerSizeInBits()); + .toCharUnitsFromBits(target.getPointerSizeInBits(0)); addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpDeref)); addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpPlus)); Index: tools/lldb/source/Expression/IRInterpreter.cpp =================================================================== --- tools/lldb/source/Expression/IRInterpreter.cpp (revision 165622) +++ tools/lldb/source/Expression/IRInterpreter.cpp (working copy) @@ -205,7 +205,7 @@ m_decl_map(decl_map) { m_byte_order = (target_data.isLittleEndian() ? lldb::eByteOrderLittle : lldb::eByteOrderBig); - m_addr_byte_size = (target_data.getPointerSize()); + m_addr_byte_size = (target_data.getPointerSize(0)); } Region Malloc (size_t size, size_t align) Index: tools/lldb/source/Expression/IRDynamicChecks.cpp =================================================================== --- tools/lldb/source/Expression/IRDynamicChecks.cpp (revision 165622) +++ tools/lldb/source/Expression/IRDynamicChecks.cpp (working copy) @@ -280,7 +280,7 @@ llvm::Value *BuildPointerValidatorFunc(lldb::addr_t start_address) { IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), - (m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32); + (m_module.getPointerSize(0) == llvm::Module::Pointer64) ? 64 : 32); llvm::Type *param_array[1]; @@ -307,7 +307,7 @@ llvm::Value *BuildObjectCheckerFunc(lldb::addr_t start_address) { IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(), - (m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32); + (m_module.getPointerSize(0) == llvm::Module::Pointer64) ? 64 : 32); llvm::Type *param_array[2]; Index: tools/lldb/source/Expression/IRForTarget.cpp =================================================================== --- tools/lldb/source/Expression/IRForTarget.cpp (revision 165622) +++ tools/lldb/source/Expression/IRForTarget.cpp (working copy) @@ -300,8 +300,9 @@ IRForTarget::BuildFunctionPointer (llvm::Type *type, uint64_t ptr) { + unsigned AS = type->isPointerTy() ? cast(type)->getAddressSpace: 0; IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), - (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32); + (m_module->getPointerSize(AS) == Module::Pointer64) ? 64 : 32); PointerType *fun_ptr_ty = PointerType::getUnqual(type); Constant *fun_addr_int = ConstantInt::get(intptr_ty, ptr, false); return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty); @@ -840,7 +841,8 @@ Type *i8_ptr_ty = Type::getInt8PtrTy(m_module->getContext()); IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), - (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32); + (m_module->getPointerSize(ns_str->getType()->getAddressSpace()) + == Module::Pointer64) ? 64 : 32); Type *i32_ty = Type::getInt32Ty(m_module->getContext()); Type *i8_ty = Type::getInt8Ty(m_module->getContext()); @@ -1271,10 +1273,11 @@ ArrayRef srN_arg_types(type_array, 1); llvm::Type *srN_type = FunctionType::get(sel_ptr_type, srN_arg_types, false); + unsigned AS = srN_type->isPointerTy() ? cast(srN_type)->getAddressSpace() : 0; // Build the constant containing the pointer to the function IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), - (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32); + (m_module->getPointerSize(AS) == Module::Pointer64) ? 64 : 32); PointerType *srN_ptr_ty = PointerType::getUnqual(srN_type); Constant *srN_addr_int = ConstantInt::get(intptr_ty, sel_registerName_addr, false); m_sel_registerName = ConstantExpr::getIntToPtr(srN_addr_int, srN_ptr_ty); @@ -1724,9 +1727,9 @@ log->Printf("Found \"%s\" at 0x%llx", name.GetCString(), symbol_addr); Type *symbol_type = symbol->getType(); - + unsigned AS = symbol_type->isPointerTy() ? cast(symbol_type)->getAddressSpace() : 0; IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), - (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32); + (m_module->getPointerSize(AS) == Module::Pointer64) ? 64 : 32); Constant *symbol_addr_int = ConstantInt::get(intptr_ty, symbol_addr, false); @@ -1807,7 +1810,8 @@ return false; IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), - (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32); + (m_module->getPointerSize(global_variable->getAddressSpace()) + == Module::Pointer64) ? 64 : 32); Constant *class_addr = ConstantInt::get(intptr_ty, (uint64_t)class_ptr); Constant *class_bitcast = ConstantExpr::getIntToPtr(class_addr, load_instruction->getType()); @@ -2577,8 +2581,9 @@ { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + unsigned AS = type->isPointerTy() ? cast(type)->getAddressSpace() : 0; IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), - (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32); + (m_module->getPointerSize(AS) == Module::Pointer64) ? 64 : 32); llvm::Constant *offset_int = ConstantInt::get(intptr_ty, offset); @@ -2618,8 +2623,9 @@ if (!allocation) return false; + unsigned AS = 0; IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(), - (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32); + (m_module->getPointerSize(AS) == Module::Pointer64) ? 64 : 32); Constant *relocated_addr = ConstantInt::get(intptr_ty, (uint64_t)allocation); Constant *relocated_bitcast = ConstantExpr::getIntToPtr(relocated_addr, llvm::Type::getInt8PtrTy(m_module->getContext()));