llvm.org GIT mirror llvm / 426c2bf
Revert the majority of the next patch in the address space series: r165941: Resubmit the changes to llvm core to update the functions to support different pointer sizes on a per address space basis. Despite this commit log, this change primarily changed stuff outside of VMCore, and those changes do not carry any tests for correctness (or even plausibility), and we have consistently found questionable or flat out incorrect cases in these changes. Most of them are probably correct, but we need to devise a system that makes it more clear when we have handled the address space concerns correctly, and ideally each pass that gets updated would receive an accompanying test case that exercises that pass specificaly w.r.t. alternate address spaces. However, from this commit, I have retained the new C API entry points. Those were an orthogonal change that probably should have been split apart, but they seem entirely good. In several places the changes were very obvious cleanups with no actual multiple address space code added; these I have not reverted when I spotted them. In a few other places there were merge conflicts due to a cleaner solution being implemented later, often not using address spaces at all. In those cases, I've preserved the new code which isn't address space dependent. This is part of my ongoing effort to clean out the partial address space code which carries high risk and low test coverage, and not likely to be finished before the 3.2 release looms closer. Duncan and I would both like to see the above issues addressed before we return to these changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167222 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 7 years ago
33 changed file(s) with 92 addition(s) and 124 deletion(s). Raw diff Collapse all Expand all
230230 }
231231
232232 /// Layout pointer alignment
233 unsigned getPointerABIAlignment(unsigned AS) const {
233 /// FIXME: The defaults need to be removed once all of
234 /// the backends/clients are updated.
235 unsigned getPointerABIAlignment(unsigned AS = 0) const {
234236 DenseMap::const_iterator val = Pointers.find(AS);
235237 if (val == Pointers.end()) {
236238 val = Pointers.find(0);
238240 return val->second.ABIAlign;
239241 }
240242 /// Return target's alignment for stack-based pointers
241 unsigned getPointerPrefAlignment(unsigned AS) const {
243 /// FIXME: The defaults need to be removed once all of
244 /// the backends/clients are updated.
245 unsigned getPointerPrefAlignment(unsigned AS = 0) const {
242246 DenseMap::const_iterator val = Pointers.find(AS);
243247 if (val == Pointers.end()) {
244248 val = Pointers.find(0);
246250 return val->second.PrefAlign;
247251 }
248252 /// Layout pointer size
249 unsigned getPointerSize(unsigned AS) const {
253 /// FIXME: The defaults need to be removed once all of
254 /// the backends/clients are updated.
255 unsigned getPointerSize(unsigned AS = 0) const {
250256 DenseMap::const_iterator val = Pointers.find(AS);
251257 if (val == Pointers.end()) {
252258 val = Pointers.find(0);
254260 return val->second.TypeBitWidth;
255261 }
256262 /// Layout pointer size, in bits
257 unsigned getPointerSizeInBits(unsigned AS) const {
263 /// FIXME: The defaults need to be removed once all of
264 /// the backends/clients are updated.
265 unsigned getPointerSizeInBits(unsigned AS = 0) const {
258266 return getPointerSize(AS) * 8;
259267 }
260268 /// Size examples:
187187 bool isInBounds = cast(GEP)->isInBounds() && !NoAssumptions;
188188
189189 // Build a mask for high order bits.
190 unsigned AS = cast(GEP)->getPointerAddressSpace();
191 unsigned IntPtrWidth = TD.getPointerSizeInBits(AS);
190 unsigned IntPtrWidth = TD.getPointerSizeInBits();
192191 uint64_t PtrSizeMask = ~0ULL >> (64-IntPtrWidth);
193192
194193 for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e;
285285 V = GEPOp->getOperand(0);
286286 continue;
287287 }
288
289 unsigned AS = GEPOp->getPointerAddressSpace();
288
290289 // Walk the indices of the GEP, accumulating them into BaseOff/VarIndices.
291290 gep_type_iterator GTI = gep_type_begin(GEPOp);
292291 for (User::const_op_iterator I = GEPOp->op_begin()+1,
315314 // If the integer type is smaller than the pointer size, it is implicitly
316315 // sign extended to pointer size.
317316 unsigned Width = cast(Index->getType())->getBitWidth();
318 if (TD->getPointerSizeInBits(AS) > Width)
317 if (TD->getPointerSizeInBits() > Width)
319318 Extension = EK_SignExt;
320319
321320 // Use GetLinearExpression to decompose the index into a C1*V+C2 form.
344343
345344 // Make sure that we have a scale that makes sense for this target's
346345 // pointer size.
347 if (unsigned ShiftBits = 64-TD->getPointerSizeInBits(AS)) {
346 if (unsigned ShiftBits = 64-TD->getPointerSizeInBits()) {
348347 Scale <<= ShiftBits;
349348 Scale = (int64_t)Scale >> ShiftBits;
350349 }
9090 // which doesn't contain values outside the range of a pointer.
9191 if (isa(CI) && TD &&
9292 TD->isLegalInteger(Op->getType()->getScalarSizeInBits()) &&
93 Op->getType()->getScalarSizeInBits() <= TD->getPointerSizeInBits(
94 cast(CI)->getAddressSpace()))
93 Op->getType()->getScalarSizeInBits() <= TD->getPointerSizeInBits())
9594 return true;
9695
9796 // A ptrtoint cast is free so long as the result is large enough to store
9897 // the pointer, and a legal integer type.
9998 if (isa(CI) && TD &&
10099 TD->isLegalInteger(Op->getType()->getScalarSizeInBits()) &&
101 Op->getType()->getScalarSizeInBits() >= TD->getPointerSizeInBits(
102 cast(CI)->getPointerAddressSpace()))
100 Op->getType()->getScalarSizeInBits() >= TD->getPointerSizeInBits())
103101 return true;
104102
105103 // trunc to a native type is free (assuming the target has compare and
915915 if (TD && CE->getOpcode() == Instruction::IntToPtr) {
916916 Constant *Input = CE->getOperand(0);
917917 unsigned InWidth = Input->getType()->getScalarSizeInBits();
918 unsigned AS = cast(CE->getType())->getAddressSpace();
919 if (TD->getPointerSizeInBits(AS) < InWidth) {
918 if (TD->getPointerSizeInBits() < InWidth) {
920919 Constant *Mask =
921920 ConstantInt::get(CE->getContext(), APInt::getLowBitsSet(InWidth,
922 TD->getPointerSizeInBits(AS)));
921 TD->getPointerSizeInBits()));
923922 Input = ConstantExpr::getAnd(Input, Mask);
924923 }
925924 // Do a zext or trunc to get to the dest size.
932931 // the int size is >= the ptr size. This requires knowing the width of a
933932 // pointer, so it can't be done in ConstantExpr::getCast.
934933 if (ConstantExpr *CE = dyn_cast(Ops[0]))
935 if (TD && CE->getOpcode() == Instruction::PtrToInt &&
936 TD->getPointerSizeInBits(
937 cast(CE->getOperand(0)->getType())->getAddressSpace())
938 <= CE->getType()->getScalarSizeInBits())
934 if (TD &&
935 TD->getPointerSizeInBits() <= CE->getType()->getScalarSizeInBits() &&
936 CE->getOpcode() == Instruction::PtrToInt)
939937 return FoldBitCast(CE->getOperand(0), DestTy, *TD);
940938
941939 return ConstantExpr::getCast(Opcode, Ops[0], DestTy);
242242 if (!TD)
243243 return false;
244244
245 unsigned AS = GEP.getPointerAddressSpace();
246 unsigned IntPtrWidth = TD->getPointerSizeInBits(AS);
245 unsigned IntPtrWidth = TD->getPointerSizeInBits();
247246 assert(IntPtrWidth == Offset.getBitWidth());
248247
249248 for (gep_type_iterator GTI = gep_type_begin(GEP), GTE = gep_type_end(GEP);
391390 // Track base/offset pairs when converted to a plain integer provided the
392391 // integer is large enough to represent the pointer.
393392 unsigned IntegerSize = I.getType()->getScalarSizeInBits();
394 unsigned AS = I.getPointerAddressSpace();
395 if (TD && IntegerSize >= TD->getPointerSizeInBits(AS)) {
393 if (TD && IntegerSize >= TD->getPointerSizeInBits()) {
396394 std::pair BaseAndOffset
397395 = ConstantOffsetPtrs.lookup(I.getOperand(0));
398396 if (BaseAndOffset.first)
426424 // modifications provided the integer is not too large.
427425 Value *Op = I.getOperand(0);
428426 unsigned IntegerSize = Op->getType()->getScalarSizeInBits();
429 unsigned AS = I.getAddressSpace();
430 if (TD && IntegerSize <= TD->getPointerSizeInBits(AS)) {
427 if (TD && IntegerSize <= TD->getPointerSizeInBits()) {
431428 std::pair BaseAndOffset = ConstantOffsetPtrs.lookup(Op);
432429 if (BaseAndOffset.first)
433430 ConstantOffsetPtrs[&I] = BaseAndOffset;
762759 if (!TD || !V->getType()->isPointerTy())
763760 return 0;
764761
765 unsigned AS = cast(V->getType())->getAddressSpace();;
766 unsigned IntPtrWidth = TD->getPointerSizeInBits(AS);
762 unsigned IntPtrWidth = TD->getPointerSizeInBits();
767763 APInt Offset = APInt::getNullValue(IntPtrWidth);
768764
769765 // Even though we don't look through PHI nodes, we could be called on an
827823 // size of the byval type by the target's pointer size.
828824 PointerType *PTy = cast(CS.getArgument(I)->getType());
829825 unsigned TypeSize = TD->getTypeSizeInBits(PTy->getElementType());
830 unsigned AS = PTy->getAddressSpace();
831 unsigned PointerSize = TD->getPointerSizeInBits(AS);
826 unsigned PointerSize = TD->getPointerSizeInBits();
832827 // Ceiling division.
833828 unsigned NumStores = (TypeSize + PointerSize - 1) / PointerSize;
834829
665665 /// 'Offset' APInt must be the bitwidth of the target's pointer size.
666666 static bool accumulateGEPOffset(const DataLayout &TD, GEPOperator *GEP,
667667 APInt &Offset) {
668 unsigned AS = GEP->getPointerAddressSpace();
669 unsigned IntPtrWidth = TD.getPointerSizeInBits(AS);
668 unsigned IntPtrWidth = TD.getPointerSizeInBits();
670669 assert(IntPtrWidth == Offset.getBitWidth());
671670
672671 gep_type_iterator GTI = gep_type_begin(GEP);
696695 /// accumulates the total constant offset applied in the returned constant. It
697696 /// returns 0 if V is not a pointer, and returns the constant '0' if there are
698697 /// no constant offsets applied.
699 /// FIXME: This function also exists in InlineCost.cpp.
700698 static Constant *stripAndComputeConstantOffsets(const DataLayout &TD,
701699 Value *&V) {
702700 if (!V->getType()->isPointerTy())
703701 return 0;
704702
705 unsigned AS = cast(V->getType())->getAddressSpace();;
706 unsigned IntPtrWidth = TD.getPointerSizeInBits(AS);
703 unsigned IntPtrWidth = TD.getPointerSizeInBits();
707704 APInt Offset = APInt::getNullValue(IntPtrWidth);
708705
709706 // Even though we don't look through PHI nodes, we could be called on an
18791876 // Turn icmp (ptrtoint x), (ptrtoint/constant) into a compare of the input
18801877 // if the integer type is the same size as the pointer type.
18811878 if (MaxRecurse && Q.TD && isa(LI) &&
1882 Q.TD->getPointerSizeInBits(
1883 cast(LI)->getPointerAddressSpace()) ==
1884 DstTy->getPrimitiveSizeInBits()) {
1879 Q.TD->getPointerSizeInBits() == DstTy->getPrimitiveSizeInBits()) {
18851880 if (Constant *RHSC = dyn_cast(RHS)) {
18861881 // Transfer the cast to the constant.
18871882 if (Value *V = SimplifyICmpInst(Pred, SrcOp,
3939 if (unsigned BitWidth = Ty->getScalarSizeInBits())
4040 return BitWidth;
4141 assert(isa(Ty) && "Expected a pointer type!");
42 return TD ?
43 TD->getPointerSizeInBits(cast(Ty)->getAddressSpace()) : 0;
42 return TD ? TD->getPointerSizeInBits() : 0;
4443 }
4544
4645 static void ComputeMaskedBitsAddSub(bool Add, Value *Op0, Value *Op1, bool NSW,
16191618
16201619 // Re-sign extend from the pointer size if needed to get overflow edge cases
16211620 // right.
1622 unsigned AS = GEP->getPointerAddressSpace();
1623 unsigned PtrSize = TD.getPointerSizeInBits(AS);
1621 unsigned PtrSize = TD.getPointerSizeInBits();
16241622 if (PtrSize < 64)
16251623 Offset = SignExtend64(Offset, PtrSize);
16261624
384384 // - __tlv_bootstrap - used to make sure support exists
385385 // - spare pointer, used when mapped by the runtime
386386 // - pointer to mangled symbol above with initializer
387 unsigned AS = GV->getType()->getAddressSpace();
388 unsigned PtrSize = TD->getPointerSizeInBits(AS)/8;
387 unsigned PtrSize = TD->getPointerSizeInBits()/8;
389388 OutStreamer.EmitSymbolValue(GetExternalSymbolSymbol("_tlv_bootstrap"),
390389 PtrSize, 0);
391390 OutStreamer.EmitIntValue(0, PtrSize, 0);
12991298
13001299 // Emit the function pointers in the target-specific order
13011300 const DataLayout *TD = TM.getDataLayout();
1302 unsigned Align = Log2_32(TD->getPointerPrefAlignment(0));
1301 unsigned Align = Log2_32(TD->getPointerPrefAlignment());
13031302 std::stable_sort(Structors.begin(), Structors.end(), priority_order);
13041303 for (unsigned i = 0, e = Structors.size(); i != e; ++i) {
13051304 const MCSection *OutputSection =
14801479 if (Offset == 0)
14811480 return Base;
14821481
1483 unsigned AS = cast(CE->getType())->getAddressSpace();
14841482 // Truncate/sext the offset to the pointer size.
1485 unsigned Width = TD.getPointerSizeInBits(AS);
1483 unsigned Width = TD.getPointerSizeInBits();
14861484 if (Width < 64)
14871485 Offset = SignExtend64(Offset, Width);
14881486
111111
112112 switch (Encoding & 0x07) {
113113 default: llvm_unreachable("Invalid encoded value.");
114 case dwarf::DW_EH_PE_absptr: return TM.getDataLayout()->getPointerSize(0);
114 case dwarf::DW_EH_PE_absptr: return TM.getDataLayout()->getPointerSize();
115115 case dwarf::DW_EH_PE_udata2: return 2;
116116 case dwarf::DW_EH_PE_udata4: return 4;
117117 case dwarf::DW_EH_PE_udata8: return 8;
199199 case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
200200 case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
201201 case dwarf::DW_FORM_addr:
202 Size = Asm->getDataLayout().getPointerSize(0); break;
202 Size = Asm->getDataLayout().getPointerSize(); break;
203203 default: llvm_unreachable("DIE Value form not supported yet");
204204 }
205205 Asm->OutStreamer.EmitIntValue(Integer, Size, 0/*addrspace*/);
221221 case dwarf::DW_FORM_data8: return sizeof(int64_t);
222222 case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer);
223223 case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer);
224 case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize(0);
224 case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize();
225225 default: llvm_unreachable("DIE Value form not supported yet");
226226 }
227227 }
248248 unsigned DIELabel::SizeOf(AsmPrinter *AP, unsigned Form) const {
249249 if (Form == dwarf::DW_FORM_data4) return 4;
250250 if (Form == dwarf::DW_FORM_strp) return 4;
251 return AP->getDataLayout().getPointerSize(0);
251 return AP->getDataLayout().getPointerSize();
252252 }
253253
254254 #ifndef NDEBUG
272272 unsigned DIEDelta::SizeOf(AsmPrinter *AP, unsigned Form) const {
273273 if (Form == dwarf::DW_FORM_data4) return 4;
274274 if (Form == dwarf::DW_FORM_strp) return 4;
275 return AP->getDataLayout().getPointerSize(0);
275 return AP->getDataLayout().getPointerSize();
276276 }
277277
278278 #ifndef NDEBUG
383383 // DW_AT_ranges appropriately.
384384 TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
385385 DebugRangeSymbols.size()
386 * Asm->getDataLayout().getPointerSize(0));
386 * Asm->getDataLayout().getPointerSize());
387387 for (SmallVector::const_iterator RI = Ranges.begin(),
388388 RE = Ranges.end(); RI != RE; ++RI) {
389389 DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
449449 // DW_AT_ranges appropriately.
450450 TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
451451 DebugRangeSymbols.size()
452 * Asm->getDataLayout().getPointerSize(0));
452 * Asm->getDataLayout().getPointerSize());
453453 for (SmallVector::const_iterator RI = Ranges.begin(),
454454 RE = Ranges.end(); RI != RE; ++RI) {
455455 DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
17641764 Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"),
17651765 DwarfAbbrevSectionSym);
17661766 Asm->OutStreamer.AddComment("Address Size (in bytes)");
1767 Asm->EmitInt8(Asm->getDataLayout().getPointerSize(0));
1767 Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
17681768
17691769 emitDIE(Die);
17701770 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID()));
18101810 Asm->EmitInt8(0);
18111811
18121812 Asm->OutStreamer.AddComment("Op size");
1813 Asm->EmitInt8(Asm->getDataLayout().getPointerSize(0) + 1);
1813 Asm->EmitInt8(Asm->getDataLayout().getPointerSize() + 1);
18141814 Asm->OutStreamer.AddComment("DW_LNE_set_address");
18151815 Asm->EmitInt8(dwarf::DW_LNE_set_address);
18161816
18171817 Asm->OutStreamer.AddComment("Section end label");
18181818
18191819 Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd),
1820 Asm->getDataLayout().getPointerSize(0),
1820 Asm->getDataLayout().getPointerSize(),
18211821 0/*AddrSpace*/);
18221822
18231823 // Mark end of matrix.
20462046 // Start the dwarf loc section.
20472047 Asm->OutStreamer.SwitchSection(
20482048 Asm->getObjFileLowering().getDwarfLocSection());
2049 unsigned char Size = Asm->getDataLayout().getPointerSize(0);
2049 unsigned char Size = Asm->getDataLayout().getPointerSize();
20502050 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0));
20512051 unsigned index = 1;
20522052 for (SmallVector::iterator
21432143 // Start the dwarf ranges section.
21442144 Asm->OutStreamer.SwitchSection(
21452145 Asm->getObjFileLowering().getDwarfRangesSection());
2146 unsigned char Size = Asm->getDataLayout().getPointerSize(0);
2146 unsigned char Size = Asm->getDataLayout().getPointerSize();
21472147 for (SmallVector::iterator
21482148 I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end();
21492149 I != E; ++I) {
22012201 Asm->OutStreamer.AddComment("Dwarf Version");
22022202 Asm->EmitInt16(dwarf::DWARF_VERSION);
22032203 Asm->OutStreamer.AddComment("Address Size (in bytes)");
2204 Asm->EmitInt8(Asm->getDataLayout().getPointerSize(0));
2204 Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
22052205
22062206 for (SmallVector::iterator I = InlinedSPNodes.begin(),
22072207 E = InlinedSPNodes.end(); I != E; ++I) {
22322232
22332233 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc");
22342234 Asm->OutStreamer.EmitSymbolValue(LI->first,
2235 Asm->getDataLayout().getPointerSize(0),0);
2235 Asm->getDataLayout().getPointerSize(),0);
22362236 }
22372237 }
22382238
416416 // that we're omitting that bit.
417417 TTypeEncoding = dwarf::DW_EH_PE_omit;
418418 // dwarf::DW_EH_PE_absptr
419 TypeFormatSize = Asm->getDataLayout().getPointerSize(0);
419 TypeFormatSize = Asm->getDataLayout().getPointerSize();
420420 } else {
421421 // Okay, we have actual filters or typeinfos to emit. As such, we need to
422422 // pick a type encoding for them. We're about to emit a list of pointers to
9090 /// either condition is detected in a function which uses the GC.
9191 ///
9292 void OcamlGCMetadataPrinter::finishAssembly(AsmPrinter &AP) {
93 unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(0);
93 unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize();
9494
9595 AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getTextSection());
9696 EmitCamlGlobal(getModule(), AP, "code_end");
549549 // address of a block, in which case it is the pointer size.
550550 switch (getEntryKind()) {
551551 case MachineJumpTableInfo::EK_BlockAddress:
552 return TD.getPointerSize(0);
552 return TD.getPointerSize();
553553 case MachineJumpTableInfo::EK_GPRel64BlockAddress:
554554 return 8;
555555 case MachineJumpTableInfo::EK_GPRel32BlockAddress:
569569 // alignment.
570570 switch (getEntryKind()) {
571571 case MachineJumpTableInfo::EK_BlockAddress:
572 return TD.getPointerABIAlignment(0);
572 return TD.getPointerABIAlignment();
573573 case MachineJumpTableInfo::EK_GPRel64BlockAddress:
574574 return TD.getABIIntegerTypeAlignment(64);
575575 case MachineJumpTableInfo::EK_GPRel32BlockAddress:
34353435 EVT VT = TLI.getOptimalMemOpType(Size, DstAlign, SrcAlign,
34363436 IsZeroVal, MemcpyStrSrc,
34373437 DAG.getMachineFunction());
3438 Type *vtType = VT.isExtended() ? VT.getTypeForEVT(*DAG.getContext()) : NULL;
3439 unsigned AS = (vtType && vtType->isPointerTy()) ?
3440 cast(vtType)->getAddressSpace() : 0;
34413438
34423439 if (VT == MVT::Other) {
3443 if (DstAlign >= TLI.getDataLayout()->getPointerPrefAlignment(AS) ||
3440 if (DstAlign >= TLI.getDataLayout()->getPointerPrefAlignment() ||
34443441 TLI.allowsUnalignedMemoryAccesses(VT)) {
34453442 VT = TLI.getPointerTy();
34463443 } else {
7676 Flags,
7777 SectionKind::getDataRel(),
7878 0, Label->getName());
79 unsigned Size = TM.getDataLayout()->getPointerSize(0);
79 unsigned Size = TM.getDataLayout()->getPointerSize();
8080 Streamer.SwitchSection(Sec);
81 Streamer.EmitValueToAlignment(TM.getDataLayout()->getPointerABIAlignment(0));
81 Streamer.EmitValueToAlignment(TM.getDataLayout()->getPointerABIAlignment());
8282 Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject);
8383 const MCExpr *E = MCConstantExpr::Create(Size, getContext());
8484 Streamer.EmitELFSize(Label, E);
1616
1717 #include "llvm/Constants.h"
1818 #include "llvm/DerivedTypes.h"
19 #include "llvm/Instructions.h"
2019 #include "llvm/Module.h"
2120 #include "llvm/ExecutionEngine/GenericValue.h"
2221 #include "llvm/ADT/SmallString.h"
267266 void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
268267 const std::vector &InputArgv) {
269268 clear(); // Free the old contents.
270 unsigned PtrSize = EE->getDataLayout()->getPointerSize(0);
269 unsigned PtrSize = EE->getDataLayout()->getPointerSize();
271270 Array = new char[(InputArgv.size()+1)*PtrSize];
272271
273272 DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array << "\n");
342341 #ifndef NDEBUG
343342 /// isTargetNullPtr - Return whether the target pointer stored at Loc is null.
344343 static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) {
345 unsigned PtrSize = EE->getDataLayout()->getPointerSize(0);
344 unsigned PtrSize = EE->getDataLayout()->getPointerSize();
346345 for (unsigned i = 0; i < PtrSize; ++i)
347346 if (*(i + (uint8_t*)Loc))
348347 return false;
10531053 GenericValue Dest, Src = getOperandValue(SrcVal, SF);
10541054 assert(DstTy->isPointerTy() && "Invalid PtrToInt instruction");
10551055
1056 unsigned AS = cast(DstTy)->getAddressSpace();
1057 uint32_t PtrSize = TD.getPointerSizeInBits(AS);
1056 uint32_t PtrSize = TD.getPointerSizeInBits();
10581057 if (PtrSize != Src.IntVal.getBitWidth())
10591058 Src.IntVal = Src.IntVal.zextOrTrunc(PtrSize);
10601059
375375 case 'x': case 'X':
376376 if (HowLong >= 1) {
377377 if (HowLong == 1 &&
378 TheInterpreter->getDataLayout()->getPointerSizeInBits(0) == 64 &&
378 TheInterpreter->getDataLayout()->getPointerSizeInBits() == 64 &&
379379 sizeof(long) < sizeof(int64_t)) {
380380 // Make sure we use %lld with a 64 bit argument because we might be
381381 // compiling LLI on a 32 bit compiler.
1313
1414 #include "JIT.h"
1515 #include "JITDwarfEmitter.h"
16 #include "llvm/DerivedTypes.h"
1716 #include "llvm/Function.h"
18 #include "llvm/GlobalVariable.h"
1917 #include "llvm/ADT/DenseMap.h"
2018 #include "llvm/CodeGen/JITCodeEmitter.h"
2119 #include "llvm/CodeGen/MachineFunction.h"
6765 void
6866 JITDwarfEmitter::EmitFrameMoves(intptr_t BaseLabelPtr,
6967 const std::vector &Moves) const {
70 unsigned PointerSize = TD->getPointerSize(0);
68 unsigned PointerSize = TD->getPointerSize();
7169 int stackGrowth = stackGrowthDirection == TargetFrameLowering::StackGrowsUp ?
7270 PointerSize : -PointerSize;
7371 MCSymbol *BaseLabel = 0;
379377 for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
380378 SizeSites += MCAsmInfo::getULEB128Size(CallSites[i].Action);
381379
382 unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize(0);
380 unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize();
383381
384382 unsigned TypeOffset = sizeof(int8_t) + // Call site format
385383 // Call-site table length
455453 const GlobalVariable *GV = TypeInfos[M - 1];
456454
457455 if (GV) {
458 if (TD->getPointerSize(GV->getType()->getAddressSpace()) == sizeof(int32_t))
456 if (TD->getPointerSize() == sizeof(int32_t))
459457 JCE->emitInt32((intptr_t)Jit.getOrEmitGlobalVariable(GV));
460458 else
461459 JCE->emitInt64((intptr_t)Jit.getOrEmitGlobalVariable(GV));
462460 } else {
463 if (TD->getPointerSize(0) == sizeof(int32_t))
461 if (TD->getPointerSize() == sizeof(int32_t))
464462 JCE->emitInt32(0);
465463 else
466464 JCE->emitInt64(0);
482480
483481 unsigned char*
484482 JITDwarfEmitter::EmitCommonEHFrame(const Function* Personality) const {
485 unsigned PointerSize = TD->getPointerSize(0);
483 unsigned PointerSize = TD->getPointerSize();
486484 int stackGrowth = stackGrowthDirection == TargetFrameLowering::StackGrowsUp ?
487485 PointerSize : -PointerSize;
488486
542540 unsigned char* StartFunction,
543541 unsigned char* EndFunction,
544542 unsigned char* ExceptionTable) const {
545 unsigned PointerSize = TD->getPointerSize(0);
543 unsigned PointerSize = TD->getPointerSize();
546544
547545 // EH frame header.
548546 unsigned char* StartEHPtr = (unsigned char*)JCE->getCurrentPCValue();
880880
881881 if (ReturnAddrIndex == 0) {
882882 // Set up a frame object for the return address.
883 uint64_t SlotSize = TD->getPointerSize(0);
883 uint64_t SlotSize = TD->getPointerSize();
884884 ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(SlotSize, -SlotSize,
885885 true);
886886 FuncInfo->setRAIndex(ReturnAddrIndex);
900900 if (Depth > 0) {
901901 SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
902902 SDValue Offset =
903 DAG.getConstant(TD->getPointerSize(0), MVT::i16);
903 DAG.getConstant(TD->getPointerSize(), MVT::i16);
904904 return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
905905 DAG.getNode(ISD::ADD, dl, getPointerTy(),
906906 FrameAddr, Offset),
125125 return Base;
126126
127127 // Truncate/sext the offset to the pointer size.
128 unsigned AS = PtrVal->getType()->isPointerTy() ?
129 cast(PtrVal->getType())->getAddressSpace() : 0;
130 if (TD.getPointerSizeInBits(AS) != 64) {
131 int SExtAmount = 64-TD.getPointerSizeInBits(AS);
128 if (TD.getPointerSizeInBits() != 64) {
129 int SExtAmount = 64-TD.getPointerSizeInBits();
132130 Offset = (Offset << SExtAmount) >> SExtAmount;
133131 }
134132
13791377
13801378 const FunctionType *FTy = dyn_cast(Ty);
13811379 if (FTy)
1382 return TD->getPointerPrefAlignment(0);
1380 return TD->getPointerPrefAlignment();
13831381 return TD->getPrefTypeAlignment(Ty);
13841382 }
13851383
442442 bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
443443 const DataLayout *TD = TM.getDataLayout();
444444
445 bool isPPC64 = TD->getPointerSizeInBits(0) == 64;
445 bool isPPC64 = TD->getPointerSizeInBits() == 64;
446446
447447 if (isPPC64 && !TOC.empty()) {
448448 const MCSectionELF *Section = OutStreamer.getContext().getELFSection(".toc",
548548
549549 void PPCDarwinAsmPrinter::
550550 EmitFunctionStubs(const MachineModuleInfoMachO::SymbolListTy &Stubs) {
551 bool isPPC64 = TM.getDataLayout()->getPointerSizeInBits(0) == 64;
551 bool isPPC64 = TM.getDataLayout()->getPointerSizeInBits() == 64;
552552
553553 const TargetLoweringObjectFileMachO &TLOFMacho =
554554 static_cast(getObjFileLowering());
643643
644644
645645 bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
646 bool isPPC64 = TM.getDataLayout()->getPointerSizeInBits(0) == 64;
646 bool isPPC64 = TM.getDataLayout()->getPointerSizeInBits() == 64;
647647
648648 // Darwin/PPC always uses mach-o.
649649 const TargetLoweringObjectFileMachO &TLOFMacho =
497497 } else if (CRSpillFrameIdx) {
498498 FrameIdx = CRSpillFrameIdx;
499499 } else {
500 MachineFrameInfo *MFI = (const_cast(MF)).getFrameInfo();
500 MachineFrameInfo *MFI = ((MachineFunction &)MF).getFrameInfo();
501501 FrameIdx = MFI->CreateFixedObject((uint64_t)4, (int64_t)-4, true);
502502 CRSpillFrameIdx = FrameIdx;
503503 }
691691 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
692692 OutStreamer.EmitLabel(Stubs[i].first);
693693 OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(),
694 TD->getPointerSize(0), 0);
694 TD->getPointerSize(), 0);
695695 }
696696 Stubs.clear();
697697 }
78237823 IDX = DAG.getLoad(getPointerTy(), dl, Chain, IDX, MachinePointerInfo(),
78247824 false, false, false, 0);
78257825
7826 SDValue Scale = DAG.getConstant(Log2_64_Ceil(TD->getPointerSize(0)),
7826 SDValue Scale = DAG.getConstant(Log2_64_Ceil(TD->getPointerSize()),
78277827 getPointerTy());
78287828 IDX = DAG.getNode(ISD::SHL, dl, getPointerTy(), IDX, Scale);
78297829
12951295 // If the source integer type is not the intptr_t type for this target, do a
12961296 // trunc or zext to the intptr_t type, then inttoptr of it. This allows the
12971297 // cast to be exposed to other transforms.
1298 unsigned AS = CI.getAddressSpace();
12991298 if (TD) {
13001299 if (CI.getOperand(0)->getType()->getScalarSizeInBits() >
1301 TD->getPointerSizeInBits(AS)) {
1300 TD->getPointerSizeInBits()) {
13021301 Value *P = Builder->CreateTrunc(CI.getOperand(0),
13031302 TD->getIntPtrType(CI.getContext()));
13041303 return new IntToPtrInst(P, CI.getType());
13051304 }
13061305 if (CI.getOperand(0)->getType()->getScalarSizeInBits() <
1307 TD->getPointerSizeInBits(AS)) {
1306 TD->getPointerSizeInBits()) {
13081307 Value *P = Builder->CreateZExt(CI.getOperand(0),
13091308 TD->getIntPtrType(CI.getContext()));
13101309 return new IntToPtrInst(P, CI.getType());
13711370 // If the destination integer type is not the intptr_t type for this target,
13721371 // do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast
13731372 // to be exposed to other transforms.
1374 unsigned AS = CI.getPointerAddressSpace();
13751373 if (TD) {
1376 if (CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits(AS)) {
1374 if (CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits()) {
13771375 Value *P = Builder->CreatePtrToInt(CI.getOperand(0),
13781376 TD->getIntPtrType(CI.getContext()));
13791377 return new TruncInst(P, CI.getType());
13801378 }
1381 if (CI.getType()->getScalarSizeInBits() > TD->getPointerSizeInBits(AS)) {
1379 if (CI.getType()->getScalarSizeInBits() > TD->getPointerSizeInBits()) {
13821380 Value *P = Builder->CreatePtrToInt(CI.getOperand(0),
13831381 TD->getIntPtrType(CI.getContext()));
13841382 return new ZExtInst(P, CI.getType());
364364 // order the state machines in complexity of the generated code.
365365 Value *Idx = GEP->getOperand(2);
366366
367 unsigned AS = GEP->getPointerAddressSpace();
368367 // If the index is larger than the pointer size of the target, truncate the
369368 // index down like the GEP would do implicitly. We don't have to do this for
370369 // an inbounds GEP because the index can't be out of range.
371370 if (!GEP->isInBounds() &&
372 Idx->getType()->getPrimitiveSizeInBits() > TD->getPointerSizeInBits(AS))
371 Idx->getType()->getPrimitiveSizeInBits() > TD->getPointerSizeInBits())
373372 Idx = Builder->CreateTrunc(Idx, TD->getIntPtrType(Idx->getContext()));
374373
375374 // If the comparison is only true for one or two elements, emit direct
528527 }
529528 }
530529
531 unsigned AS = cast(GEP)->getPointerAddressSpace();
532530 // Okay, we know we have a single variable index, which must be a
533531 // pointer/array/vector index. If there is no offset, life is simple, return
534532 // the index.
535 unsigned IntPtrWidth = TD.getPointerSizeInBits(AS);
533 unsigned IntPtrWidth = TD.getPointerSizeInBits();
536534 if (Offset == 0) {
537535 // Cast to intptrty in case a truncation occurs. If an extension is needed,
538536 // we don't need to bother extending: the extension won't affect where the
15531551 // Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the
15541552 // integer type is the same size as the pointer type.
15551553 if (TD && LHSCI->getOpcode() == Instruction::PtrToInt &&
1556 TD->getPointerSizeInBits(
1557 cast(LHSCI)->getPointerAddressSpace()) ==
1554 TD->getPointerSizeInBits() ==
15581555 cast(DestTy)->getBitWidth()) {
15591556 Value *RHSOp = 0;
15601557 if (Constant *RHSC = dyn_cast(ICI.getOperand(1))) {
703703 BL.reset(new BlackList(ClBlackListFile));
704704
705705 C = &(M.getContext());
706 LongSize = TD->getPointerSizeInBits(0);
706 LongSize = TD->getPointerSizeInBits();
707707 IntptrTy = Type::getIntNTy(*C, LongSize);
708708 IntptrPtrTy = PointerType::get(IntptrTy, 0);
709709
173173 // this width can be stored. If so, check to see whether we will end up
174174 // actually reducing the number of stores used.
175175 unsigned Bytes = unsigned(End-Start);
176 unsigned AS = cast(TheStores[0])->getPointerAddressSpace();
177 unsigned NumPointerStores = Bytes/TD.getPointerSize(AS);
176 unsigned NumPointerStores = Bytes/TD.getPointerSize();
178177
179178 // Assume the remaining bytes if any are done a byte at a time.
180 unsigned NumByteStores = Bytes - NumPointerStores*TD.getPointerSize(AS);
179 unsigned NumByteStores = Bytes - NumPointerStores*TD.getPointerSize();
181180
182181 // If we will reduce the # stores (according to this heuristic), do the
183182 // transformation. This encourages merging 4 x i8 -> i32 and 2 x i16 -> i32
443443
444444 bool computeConstantGEPOffset(GetElementPtrInst &GEPI, int64_t &GEPOffset) {
445445 GEPOffset = Offset;
446 unsigned int AS = GEPI.getPointerAddressSpace();
447446 for (gep_type_iterator GTI = gep_type_begin(GEPI), GTE = gep_type_end(GEPI);
448447 GTI != GTE; ++GTI) {
449448 ConstantInt *OpC = dyn_cast(GTI.getOperand());
473472 continue;
474473 }
475474
476 APInt Index = OpC->getValue().sextOrTrunc(TD.getPointerSizeInBits(AS));
475 APInt Index = OpC->getValue().sextOrTrunc(TD.getPointerSizeInBits());
477476 Index *= APInt(Index.getBitWidth(),
478477 TD.getTypeAllocSize(GTI.getIndexedType()));
479478 Index += APInt(Index.getBitWidth(), (uint64_t)GEPOffset,
23942393
23952394 Value *getAdjustedAllocaPtr(IRBuilder<> &IRB, Type *PointerTy) {
23962395 assert(BeginOffset >= NewAllocaBeginOffset);
2397 unsigned AS = cast(PointerTy)->getAddressSpace();
2398 APInt Offset(TD.getPointerSizeInBits(AS), BeginOffset - NewAllocaBeginOffset);
2396 APInt Offset(TD.getPointerSizeInBits(), BeginOffset - NewAllocaBeginOffset);
23992397 return getAdjustedPtr(IRB, TD, &NewAI, Offset, PointerTy, getName(""));
24002398 }
24012399
27922790 const AllocaPartitioning::MemTransferOffsets &MTO
27932791 = P.getMemTransferOffsets(II);
27942792
2795 assert(OldPtr->getType()->isPointerTy() && "Must be a pointer type!");
2796 unsigned AS = cast(OldPtr->getType())->getAddressSpace();
27972793 // Compute the relative offset within the transfer.
2798 unsigned IntPtrWidth = TD.getPointerSizeInBits(AS);
2794 unsigned IntPtrWidth = TD.getPointerSizeInBits();
27992795 APInt RelOffset(IntPtrWidth, BeginOffset - (IsDest ? MTO.DestBegin
28002796 : MTO.SourceBegin));
28012797
805805 const DataLayout *TD) {
806806 assert(V->getType()->isPointerTy() &&
807807 "getOrEnforceKnownAlignment expects a pointer!");
808 unsigned AS = cast(V->getType())->getAddressSpace();
809 unsigned BitWidth = TD ? TD->getPointerSizeInBits(AS) : 64;
808 unsigned BitWidth = TD ? TD->getPointerSizeInBits() : 64;
810809 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
811810 ComputeMaskedBits(V, KnownZero, KnownOne, TD);
812811 unsigned TrailZ = KnownZero.countTrailingOnes();