llvm.org GIT mirror llvm / e754d3f
Revert r100191 since it breaks objc in clang git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100199 91177308-0d34-0410-b5e6-96231b3b80d8 Mon P Wang 9 years ago
28 changed file(s) with 146 addition(s) and 317 deletion(s). Raw diff Collapse all Expand all
533533 SDValue getStackArgumentTokenFactor(SDValue Chain);
534534
535535 SDValue getMemcpy(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
536 SDValue Size, unsigned Align, bool isVol, bool AlwaysInline,
536 SDValue Size, unsigned Align, bool AlwaysInline,
537537 const Value *DstSV, uint64_t DstSVOff,
538538 const Value *SrcSV, uint64_t SrcSVOff);
539539
540540 SDValue getMemmove(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
541 SDValue Size, unsigned Align, bool isVol,
541 SDValue Size, unsigned Align,
542542 const Value *DstSV, uint64_t DstOSVff,
543543 const Value *SrcSV, uint64_t SrcSVOff);
544544
545545 SDValue getMemset(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
546 SDValue Size, unsigned Align, bool isVol,
546 SDValue Size, unsigned Align,
547547 const Value *DstSV, uint64_t DstSVOff);
548548
549549 /// getSetCC - Helper function to make it easier to build SetCC's if you just
132132 return getAlignmentCst()->getZExtValue();
133133 }
134134
135 ConstantInt *getVolatileCst() const {
136 return cast(const_cast(getOperand(5)));
137 }
138 bool isVolatile() const {
139 return getVolatileCst()->getZExtValue() != 0;
140 }
141
142135 /// getDest - This is just like getRawDest, but it strips off any cast
143136 /// instructions that feed it, giving the original input. The returned
144137 /// value is guaranteed to be a pointer.
161154 void setAlignment(Constant* A) {
162155 setOperand(4, A);
163156 }
164
165 void setVolatile(Constant* V) {
166 setOperand(5, V);
167 }
168
157
169158 const Type *getAlignmentType() const {
170159 return getOperand(4)->getType();
171160 }
223223 //
224224
225225 def int_memcpy : Intrinsic<[],
226 [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty,
227 llvm_i32_ty, llvm_i1_ty],
226 [llvm_ptr_ty, llvm_ptr_ty, llvm_anyint_ty,
227 llvm_i32_ty],
228228 [IntrWriteArgMem, NoCapture<0>, NoCapture<1>]>;
229229 def int_memmove : Intrinsic<[],
230 [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty,
231 llvm_i32_ty, llvm_i1_ty],
230 [llvm_ptr_ty, llvm_ptr_ty, llvm_anyint_ty,
231 llvm_i32_ty],
232232 [IntrWriteArgMem, NoCapture<0>, NoCapture<1>]>;
233233 def int_memset : Intrinsic<[],
234 [llvm_anyptr_ty, llvm_i8_ty, llvm_anyint_ty,
235 llvm_i32_ty, llvm_i1_ty],
234 [llvm_ptr_ty, llvm_i8_ty, llvm_anyint_ty,
235 llvm_i32_ty],
236236 [IntrWriteArgMem, NoCapture<0>]>;
237237
238238 // These functions do not actually read memory, but they are sensitive to the
916916 Value *Args[] = { Arg1, Arg2, Arg3, Arg4 };
917917 return Insert(CallInst::Create(Callee, Args, Args+4), Name);
918918 }
919 CallInst *CreateCall5(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
920 Value *Arg4, Value *Arg5, const Twine &Name = "") {
921 Value *Args[] = { Arg1, Arg2, Arg3, Arg4, Arg5 };
922 return Insert(CallInst::Create(Callee, Args, Args+5), Name);
923 }
924919
925920 template
926921 CallInst *CreateCall(Value *Callee, InputIterator ArgBegin,
11861186 EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl,
11871187 SDValue Chain,
11881188 SDValue Op1, SDValue Op2,
1189 SDValue Op3, unsigned Align, bool isVolatile,
1189 SDValue Op3, unsigned Align,
11901190 bool AlwaysInline,
11911191 const Value *DstSV, uint64_t DstOff,
11921192 const Value *SrcSV, uint64_t SrcOff) {
12031203 EmitTargetCodeForMemmove(SelectionDAG &DAG, DebugLoc dl,
12041204 SDValue Chain,
12051205 SDValue Op1, SDValue Op2,
1206 SDValue Op3, unsigned Align, bool isVolatile,
1206 SDValue Op3, unsigned Align,
12071207 const Value *DstSV, uint64_t DstOff,
12081208 const Value *SrcSV, uint64_t SrcOff) {
12091209 return SDValue();
12191219 EmitTargetCodeForMemset(SelectionDAG &DAG, DebugLoc dl,
12201220 SDValue Chain,
12211221 SDValue Op1, SDValue Op2,
1222 SDValue Op3, unsigned Align, bool isVolatile,
1222 SDValue Op3, unsigned Align,
12231223 const Value *DstSV, uint64_t DstOff) {
12241224 return SDValue();
12251225 }
4545
4646 /// EmitMemCpy - Emit a call to the memcpy function to the builder. This
4747 /// always expects that the size has type 'intptr_t' and Dst/Src are pointers.
48 Value *EmitMemCpy(Value *Dst, Value *Src, Value *Len, unsigned Align,
49 bool isVolatile, IRBuilder<> &B, const TargetData *TD);
48 Value *EmitMemCpy(Value *Dst, Value *Src, Value *Len,
49 unsigned Align, IRBuilder<> &B, const TargetData *TD);
5050
5151 /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
5252 /// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src
5656
5757 /// EmitMemMove - Emit a call to the memmove function to the builder. This
5858 /// always expects that the size has type 'intptr_t' and Dst/Src are pointers.
59 Value *EmitMemMove(Value *Dst, Value *Src, Value *Len, unsigned Align,
60 bool isVolatile, IRBuilder<> &B, const TargetData *TD);
59 Value *EmitMemMove(Value *Dst, Value *Src, Value *Len,
60 unsigned Align, IRBuilder<> &B, const TargetData *TD);
6161
6262 /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is
6363 /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
6969 const TargetData *TD);
7070
7171 /// EmitMemSet - Emit a call to the memset function
72 Value *EmitMemSet(Value *Dst, Value *Val, Value *Len, bool isVolatile,
73 IRBuilder<> &B, const TargetData *TD);
72 Value *EmitMemSet(Value *Dst, Value *Val, Value *Len, IRBuilder<> &B,
73 const TargetData *TD);
7474
7575 /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name'
7676 /// (e.g. 'floor'). This function is known to take a single of type matching
32623262 static SDValue getMemcpyLoadsAndStores(SelectionDAG &DAG, DebugLoc dl,
32633263 SDValue Chain, SDValue Dst,
32643264 SDValue Src, uint64_t Size,
3265 unsigned Align, bool isVol,
3266 bool AlwaysInline,
3265 unsigned Align, bool AlwaysInline,
32673266 const Value *DstSV, uint64_t DstSVOff,
32683267 const Value *SrcSV, uint64_t SrcSVOff) {
32693268 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
33193318 Value = getMemsetStringVal(VT, dl, DAG, TLI, Str, SrcOff);
33203319 Store = DAG.getStore(Chain, dl, Value,
33213320 getMemBasePlusOffset(Dst, DstOff, DAG),
3322 DstSV, DstSVOff + DstOff, isVol, false, Align);
3321 DstSV, DstSVOff + DstOff, false, false, Align);
33233322 } else {
33243323 // The type might not be legal for the target. This should only happen
33253324 // if the type is smaller than a legal type, as on PPC, so the right
33303329 assert(NVT.bitsGE(VT));
33313330 Value = DAG.getExtLoad(ISD::EXTLOAD, dl, NVT, Chain,
33323331 getMemBasePlusOffset(Src, SrcOff, DAG),
3333 SrcSV, SrcSVOff + SrcOff, VT, isVol, false,
3332 SrcSV, SrcSVOff + SrcOff, VT, false, false,
33343333 MinAlign(SrcAlign, SrcOff));
33353334 Store = DAG.getTruncStore(Chain, dl, Value,
33363335 getMemBasePlusOffset(Dst, DstOff, DAG),
3337 DstSV, DstSVOff + DstOff, VT, isVol, false,
3336 DstSV, DstSVOff + DstOff, VT, false, false,
33383337 Align);
33393338 }
33403339 OutChains.push_back(Store);
33493348 static SDValue getMemmoveLoadsAndStores(SelectionDAG &DAG, DebugLoc dl,
33503349 SDValue Chain, SDValue Dst,
33513350 SDValue Src, uint64_t Size,
3352 unsigned Align, bool isVol,
3353 bool AlwaysInline,
3351 unsigned Align,bool AlwaysInline,
33543352 const Value *DstSV, uint64_t DstSVOff,
33553353 const Value *SrcSV, uint64_t SrcSVOff) {
33563354 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
33983396
33993397 Value = DAG.getLoad(VT, dl, Chain,
34003398 getMemBasePlusOffset(Src, SrcOff, DAG),
3401 SrcSV, SrcSVOff + SrcOff, isVol, false, SrcAlign);
3399 SrcSV, SrcSVOff + SrcOff, false, false, SrcAlign);
34023400 LoadValues.push_back(Value);
34033401 LoadChains.push_back(Value.getValue(1));
34043402 SrcOff += VTSize;
34133411
34143412 Store = DAG.getStore(Chain, dl, LoadValues[i],
34153413 getMemBasePlusOffset(Dst, DstOff, DAG),
3416 DstSV, DstSVOff + DstOff, isVol, false, Align);
3414 DstSV, DstSVOff + DstOff, false, false, Align);
34173415 OutChains.push_back(Store);
34183416 DstOff += VTSize;
34193417 }
34253423 static SDValue getMemsetStores(SelectionDAG &DAG, DebugLoc dl,
34263424 SDValue Chain, SDValue Dst,
34273425 SDValue Src, uint64_t Size,
3428 unsigned Align, bool isVol,
3426 unsigned Align,
34293427 const Value *DstSV, uint64_t DstSVOff) {
34303428 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
34313429
34643462 SDValue Value = getMemsetValue(Src, VT, DAG, dl);
34653463 SDValue Store = DAG.getStore(Chain, dl, Value,
34663464 getMemBasePlusOffset(Dst, DstOff, DAG),
3467 DstSV, DstSVOff + DstOff, isVol, false, 0);
3465 DstSV, DstSVOff + DstOff, false, false, 0);
34683466 OutChains.push_back(Store);
34693467 DstOff += VTSize;
34703468 }
34753473
34763474 SDValue SelectionDAG::getMemcpy(SDValue Chain, DebugLoc dl, SDValue Dst,
34773475 SDValue Src, SDValue Size,
3478 unsigned Align, bool isVol, bool AlwaysInline,
3476 unsigned Align, bool AlwaysInline,
34793477 const Value *DstSV, uint64_t DstSVOff,
34803478 const Value *SrcSV, uint64_t SrcSVOff) {
34813479
34893487
34903488 SDValue Result = getMemcpyLoadsAndStores(*this, dl, Chain, Dst, Src,
34913489 ConstantSize->getZExtValue(),Align,
3492 isVol, false, DstSV, DstSVOff, SrcSV, SrcSVOff);
3490 false, DstSV, DstSVOff, SrcSV, SrcSVOff);
34933491 if (Result.getNode())
34943492 return Result;
34953493 }
34983496 // code. If the target chooses to do this, this is the next best.
34993497 SDValue Result =
35003498 TLI.EmitTargetCodeForMemcpy(*this, dl, Chain, Dst, Src, Size, Align,
3501 isVol, AlwaysInline,
3499 AlwaysInline,
35023500 DstSV, DstSVOff, SrcSV, SrcSVOff);
35033501 if (Result.getNode())
35043502 return Result;
35083506 if (AlwaysInline) {
35093507 assert(ConstantSize && "AlwaysInline requires a constant size!");
35103508 return getMemcpyLoadsAndStores(*this, dl, Chain, Dst, Src,
3511 ConstantSize->getZExtValue(), Align, isVol,
3512 true, DstSV, DstSVOff, SrcSV, SrcSVOff);
3509 ConstantSize->getZExtValue(), Align, true,
3510 DstSV, DstSVOff, SrcSV, SrcSVOff);
35133511 }
35143512
35153513 // Emit a library call.
3516 assert(!isVol && "library memcpy does not support volatile");
35173514 TargetLowering::ArgListTy Args;
35183515 TargetLowering::ArgListEntry Entry;
35193516 Entry.Ty = TLI.getTargetData()->getIntPtrType(*getContext());
35343531
35353532 SDValue SelectionDAG::getMemmove(SDValue Chain, DebugLoc dl, SDValue Dst,
35363533 SDValue Src, SDValue Size,
3537 unsigned Align, bool isVol,
3534 unsigned Align,
35383535 const Value *DstSV, uint64_t DstSVOff,
35393536 const Value *SrcSV, uint64_t SrcSVOff) {
35403537
35483545
35493546 SDValue Result =
35503547 getMemmoveLoadsAndStores(*this, dl, Chain, Dst, Src,
3551 ConstantSize->getZExtValue(), Align, isVol,
3552 false, DstSV, DstSVOff, SrcSV, SrcSVOff);
3548 ConstantSize->getZExtValue(),
3549 Align, false, DstSV, DstSVOff, SrcSV, SrcSVOff);
35533550 if (Result.getNode())
35543551 return Result;
35553552 }
35573554 // Then check to see if we should lower the memmove with target-specific
35583555 // code. If the target chooses to do this, this is the next best.
35593556 SDValue Result =
3560 TLI.EmitTargetCodeForMemmove(*this, dl, Chain, Dst, Src, Size, Align, isVol,
3557 TLI.EmitTargetCodeForMemmove(*this, dl, Chain, Dst, Src, Size, Align,
35613558 DstSV, DstSVOff, SrcSV, SrcSVOff);
35623559 if (Result.getNode())
35633560 return Result;
35643561
35653562 // Emit a library call.
3566 assert(!isVol && "library memmove does not support volatile");
35673563 TargetLowering::ArgListTy Args;
35683564 TargetLowering::ArgListEntry Entry;
35693565 Entry.Ty = TLI.getTargetData()->getIntPtrType(*getContext());
35843580
35853581 SDValue SelectionDAG::getMemset(SDValue Chain, DebugLoc dl, SDValue Dst,
35863582 SDValue Src, SDValue Size,
3587 unsigned Align, bool isVol,
3583 unsigned Align,
35883584 const Value *DstSV, uint64_t DstSVOff) {
35893585
35903586 // Check to see if we should lower the memset to stores first.
35973593
35983594 SDValue Result =
35993595 getMemsetStores(*this, dl, Chain, Dst, Src, ConstantSize->getZExtValue(),
3600 Align, isVol, DstSV, DstSVOff);
3596 Align, DstSV, DstSVOff);
36013597 if (Result.getNode())
36023598 return Result;
36033599 }
36053601 // Then check to see if we should lower the memset with target-specific
36063602 // code. If the target chooses to do this, this is the next best.
36073603 SDValue Result =
3608 TLI.EmitTargetCodeForMemset(*this, dl, Chain, Dst, Src, Size, Align, isVol,
3604 TLI.EmitTargetCodeForMemset(*this, dl, Chain, Dst, Src, Size, Align,
36093605 DstSV, DstSVOff);
36103606 if (Result.getNode())
36113607 return Result;
36123608
36133609 // Emit a library call.
3614 assert(!isVol && "library memset does not support volatile");
36153610 const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(*getContext());
36163611 TargetLowering::ArgListTy Args;
36173612 TargetLowering::ArgListEntry Entry;
37303730 case Intrinsic::longjmp:
37313731 return "_longjmp"+!TLI.usesUnderscoreLongJmp();
37323732 case Intrinsic::memcpy: {
3733 // Assert for address < 256 since we support only user defined address
3734 // spaces.
3735 assert(cast(I.getOperand(1)->getType())->getAddressSpace()
3736 < 256 &&
3737 cast(I.getOperand(2)->getType())->getAddressSpace()
3738 < 256 &&
3739 "Unknown address space");
37403733 SDValue Op1 = getValue(I.getOperand(1));
37413734 SDValue Op2 = getValue(I.getOperand(2));
37423735 SDValue Op3 = getValue(I.getOperand(3));
37433736 unsigned Align = cast(I.getOperand(4))->getZExtValue();
3744 bool isVol = cast(I.getOperand(5))->getZExtValue();
3745 DAG.setRoot(DAG.getMemcpy(getRoot(), dl, Op1, Op2, Op3, Align, isVol, false,
3737 DAG.setRoot(DAG.getMemcpy(getRoot(), dl, Op1, Op2, Op3, Align, false,
37463738 I.getOperand(1), 0, I.getOperand(2), 0));
37473739 return 0;
37483740 }
37493741 case Intrinsic::memset: {
3750 // Assert for address < 256 since we support only user defined address
3751 // spaces.
3752 assert(cast(I.getOperand(1)->getType())->getAddressSpace()
3753 < 256 &&
3754 "Unknown address space");
37553742 SDValue Op1 = getValue(I.getOperand(1));
37563743 SDValue Op2 = getValue(I.getOperand(2));
37573744 SDValue Op3 = getValue(I.getOperand(3));
37583745 unsigned Align = cast(I.getOperand(4))->getZExtValue();
3759 bool isVol = cast(I.getOperand(5))->getZExtValue();
3760 DAG.setRoot(DAG.getMemset(getRoot(), dl, Op1, Op2, Op3, Align, isVol,
3746 DAG.setRoot(DAG.getMemset(getRoot(), dl, Op1, Op2, Op3, Align,
37613747 I.getOperand(1), 0));
37623748 return 0;
37633749 }
37643750 case Intrinsic::memmove: {
3765 // Assert for address < 256 since we support only user defined address
3766 // spaces.
3767 assert(cast(I.getOperand(1)->getType())->getAddressSpace()
3768 < 256 &&
3769 cast(I.getOperand(2)->getType())->getAddressSpace()
3770 < 256 &&
3771 "Unknown address space");
37723751 SDValue Op1 = getValue(I.getOperand(1));
37733752 SDValue Op2 = getValue(I.getOperand(2));
37743753 SDValue Op3 = getValue(I.getOperand(3));
37753754 unsigned Align = cast(I.getOperand(4))->getZExtValue();
3776 bool isVol = cast(I.getOperand(5))->getZExtValue();
37773755
37783756 // If the source and destination are known to not be aliases, we can
37793757 // lower memmove as memcpy.
37823760 Size = C->getZExtValue();
37833761 if (AA->alias(I.getOperand(1), Size, I.getOperand(2), Size) ==
37843762 AliasAnalysis::NoAlias) {
3785 DAG.setRoot(DAG.getMemcpy(getRoot(), dl, Op1, Op2, Op3, Align, isVol,
3786 false, I.getOperand(1), 0, I.getOperand(2), 0));
3763 DAG.setRoot(DAG.getMemcpy(getRoot(), dl, Op1, Op2, Op3, Align, false,
3764 I.getOperand(1), 0, I.getOperand(2), 0));
37873765 return 0;
37883766 }
37893767
3790 DAG.setRoot(DAG.getMemmove(getRoot(), dl, Op1, Op2, Op3, Align, isVol,
3768 DAG.setRoot(DAG.getMemmove(getRoot(), dl, Op1, Op2, Op3, Align,
37913769 I.getOperand(1), 0, I.getOperand(2), 0));
37923770 return 0;
37933771 }
860860 DebugLoc dl) {
861861 SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32);
862862 return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(),
863 /*isVolatile=*/false, /*AlwaysInline=*/false,
864 NULL, 0, NULL, 0);
863 /*AlwaysInline=*/false, NULL, 0, NULL, 0);
865864 }
866865
867866 /// LowerMemOpCallTo - Store the argument to the stack.
20532052 SDValue Chain,
20542053 SDValue Dst, SDValue Src,
20552054 SDValue Size, unsigned Align,
2056 bool isVolatile, bool AlwaysInline,
2055 bool AlwaysInline,
20572056 const Value *DstSV, uint64_t DstSVOff,
20582057 const Value *SrcSV, uint64_t SrcSVOff){
20592058 // Do repeated 4-byte loads and stores. To be improved.
20892088 Loads[i] = DAG.getLoad(VT, dl, Chain,
20902089 DAG.getNode(ISD::ADD, dl, MVT::i32, Src,
20912090 DAG.getConstant(SrcOff, MVT::i32)),
2092 SrcSV, SrcSVOff + SrcOff, isVolatile, false, 0);
2091 SrcSV, SrcSVOff + SrcOff, false, false, 0);
20932092 TFOps[i] = Loads[i].getValue(1);
20942093 SrcOff += VTSize;
20952094 }
21002099 TFOps[i] = DAG.getStore(Chain, dl, Loads[i],
21012100 DAG.getNode(ISD::ADD, dl, MVT::i32, Dst,
21022101 DAG.getConstant(DstOff, MVT::i32)),
2103 DstSV, DstSVOff + DstOff, isVolatile, false, 0);
2102 DstSV, DstSVOff + DstOff, false, false, 0);
21042103 DstOff += VTSize;
21052104 }
21062105 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
304304 SDValue Chain,
305305 SDValue Dst, SDValue Src,
306306 SDValue Size, unsigned Align,
307 bool isVolatile, bool AlwaysInline,
307 bool AlwaysInline,
308308 const Value *DstSV, uint64_t DstSVOff,
309309 const Value *SrcSV, uint64_t SrcSVOff);
310310 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
23912391 DebugLoc dl) {
23922392 SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32);
23932393 return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(),
2394 false, false, NULL, 0, NULL, 0);
2394 false, NULL, 0, NULL, 0);
23952395 }
23962396
23972397 /// LowerMemOpCallTo - Store the argument to the stack or remember it in case of
14321432 DebugLoc dl) {
14331433 SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), MVT::i32);
14341434 return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(),
1435 /*isVolatile*/false, /*AlwaysInline=*/true,
1436 NULL, 0, NULL, 0);
1435 /*AlwaysInline=*/true, NULL, 0, NULL, 0);
14371436 }
14381437
14391438 /// IsTailCallConvention - Return true if the calling convention is one that
65506549 SDValue Chain,
65516550 SDValue Dst, SDValue Src,
65526551 SDValue Size, unsigned Align,
6553 bool isVolatile,
65546552 const Value *DstSV,
65556553 uint64_t DstSVOff) {
65566554 ConstantSDNode *ConstantSize = dyn_cast(Size);
66796677 DAG.getConstant(Offset, AddrVT)),
66806678 Src,
66816679 DAG.getConstant(BytesLeft, SizeVT),
6682 Align, isVolatile, DstSV, DstSVOff + Offset);
6680 Align, DstSV, DstSVOff + Offset);
66836681 }
66846682
66856683 // TODO: Use a Tokenfactor, as in memcpy, instead of a single chain.
66906688 X86TargetLowering::EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl,
66916689 SDValue Chain, SDValue Dst, SDValue Src,
66926690 SDValue Size, unsigned Align,
6693 bool isVolatile, bool AlwaysInline,
6691 bool AlwaysInline,
66946692 const Value *DstSV, uint64_t DstSVOff,
66956693 const Value *SrcSV, uint64_t SrcSVOff) {
66966694 // This requires the copy size to be a constant, preferrably
67496747 DAG.getNode(ISD::ADD, dl, SrcVT, Src,
67506748 DAG.getConstant(Offset, SrcVT)),
67516749 DAG.getConstant(BytesLeft, SizeVT),
6752 Align, isVolatile, AlwaysInline,
6750 Align, AlwaysInline,
67536751 DstSV, DstSVOff + Offset,
67546752 SrcSV, SrcSVOff + Offset));
67556753 }
68326830 DebugLoc dl = Op.getDebugLoc();
68336831
68346832 return DAG.getMemcpy(Chain, dl, DstPtr, SrcPtr,
6835 DAG.getIntPtrConstant(24), 8, /*isVolatile*/false,
6836 false, DstSV, 0, SrcSV, 0);
6833 DAG.getIntPtrConstant(24), 8, false,
6834 DstSV, 0, SrcSV, 0);
68376835 }
68386836
68396837 SDValue
736736 SDValue Chain,
737737 SDValue Dst, SDValue Src,
738738 SDValue Size, unsigned Align,
739 bool isVolatile,
740739 const Value *DstSV, uint64_t DstSVOff);
741740 SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl,
742741 SDValue Chain,
743742 SDValue Dst, SDValue Src,
744743 SDValue Size, unsigned Align,
745 bool isVolatile, bool AlwaysInline,
744 bool AlwaysInline,
746745 const Value *DstSV, uint64_t DstSVOff,
747746 const Value *SrcSV, uint64_t SrcSVOff);
748747
752751 /// block, the number of args, and whether or not the second arg is
753752 /// in memory or not.
754753 MachineBasicBlock *EmitPCMP(MachineInstr *BInstr, MachineBasicBlock *BB,
755 unsigned argNum, bool inMem) const;
754 unsigned argNum, bool inMem) const;
756755
757756 /// Utility function to emit atomic bitwise operations (and, or, xor).
758757 /// It takes the bitwise instruction to expand, the associated machine basic
14421442 return DAG.getMemmove(Chain, dl, ST->getBasePtr(),
14431443 LD->getBasePtr(),
14441444 DAG.getConstant(StoreBits/8, MVT::i32),
1445 Alignment, false, ST->getSrcValue(),
1445 Alignment, ST->getSrcValue(),
14461446 ST->getSrcValueOffset(), LD->getSrcValue(),
14471447 LD->getSrcValueOffset());
14481448 }
135135 return 0; // If not 1/2/4/8 bytes, exit.
136136
137137 // Use an integer load+store unless we can find something better.
138 unsigned SrcAddrSp =
139 cast(MI->getOperand(2)->getType())->getAddressSpace();
140 unsigned DstAddrSp =
141 cast(MI->getOperand(1)->getType())->getAddressSpace();
142
143 const IntegerType* IntType = IntegerType::get(MI->getContext(), Size<<3);
144 Type *NewSrcPtrTy = PointerType::get(IntType, SrcAddrSp);
145 Type *NewDstPtrTy = PointerType::get(IntType, DstAddrSp);
138 Type *NewPtrTy =
139 PointerType::getUnqual(IntegerType::get(MI->getContext(), Size<<3));
146140
147141 // Memcpy forces the use of i8* for the source and destination. That means
148142 // that if you're using memcpy to move one double around, you'll get a cast
172166 break;
173167 }
174168
175 if (SrcETy->isSingleValueType()) {
176 NewSrcPtrTy = PointerType::get(SrcETy, SrcAddrSp);
177 NewDstPtrTy = PointerType::get(SrcETy, DstAddrSp);
178 }
169 if (SrcETy->isSingleValueType())
170 NewPtrTy = PointerType::getUnqual(SrcETy);
179171 }
180172 }
181173
185177 SrcAlign = std::max(SrcAlign, CopyAlign);
186178 DstAlign = std::max(DstAlign, CopyAlign);
187179
188 Value *Src = Builder->CreateBitCast(MI->getOperand(2), NewSrcPtrTy);
189 Value *Dest = Builder->CreateBitCast(MI->getOperand(1), NewDstPtrTy);
190 Instruction *L = new LoadInst(Src, "tmp", MI->isVolatile(), SrcAlign);
180 Value *Src = Builder->CreateBitCast(MI->getOperand(2), NewPtrTy);
181 Value *Dest = Builder->CreateBitCast(MI->getOperand(1), NewPtrTy);
182 Instruction *L = new LoadInst(Src, "tmp", false, SrcAlign);
191183 InsertNewInstBefore(L, *MI);
192 InsertNewInstBefore(new StoreInst(L, Dest, MI->isVolatile(), DstAlign),
193 *MI);
184 InsertNewInstBefore(new StoreInst(L, Dest, false, DstAlign), *MI);
194185
195186 // Set the size of the copy to 0, it will be deleted on the next iteration.
196187 MI->setOperand(3, Constant::getNullValue(MemOpLength->getType()));
283274 if (GVSrc->isConstant()) {
284275 Module *M = CI.getParent()->getParent()->getParent();
285276 Intrinsic::ID MemCpyID = Intrinsic::memcpy;
286 const Type *Tys[3] = { CI.getOperand(1)->getType(),
287 CI.getOperand(2)->getType(),
288 CI.getOperand(3)->getType() };
277 const Type *Tys[1];
278 Tys[0] = CI.getOperand(3)->getType();
289279 CI.setOperand(0,
290 Intrinsic::getDeclaration(M, MemCpyID, Tys, 3));
280 Intrinsic::getDeclaration(M, MemCpyID, Tys, 1));
291281 Changed = true;
292282 }
293283 }
412412 // interesting as a small compile-time optimization.
413413 Ranges.addStore(0, SI);
414414
415 Function *MemSetF = 0;
415416
416417 // Now that we have full information about ranges, loop over the ranges and
417418 // emit memset's for anything big enough to be worthwhile.
431432 // memset block. This ensure that the memset is dominated by any addressing
432433 // instruction needed by the start of the block.
433434 BasicBlock::iterator InsertPt = BI;
434
435
436 if (MemSetF == 0) {
437 const Type *Ty = Type::getInt64Ty(Context);
438 MemSetF = Intrinsic::getDeclaration(M, Intrinsic::memset, &Ty, 1);
439 }
440
435441 // Get the starting pointer of the block.
436442 StartPtr = Range.StartPtr;
437
438 // Determine alignment
439 unsigned Alignment = Range.Alignment;
440 if (Alignment == 0) {
441 const Type *EltType =
442 cast(StartPtr->getType())->getElementType();
443 Alignment = TD->getABITypeAlignment(EltType);
444 }
445
443
446444 // Cast the start ptr to be i8* as memset requires.
447 const PointerType* StartPTy = cast(StartPtr->getType());
448 const PointerType *i8Ptr = Type::getInt8PtrTy(Context,
449 StartPTy->getAddressSpace());
450 if (StartPTy!= i8Ptr)
445 const Type *i8Ptr = Type::getInt8PtrTy(Context);
446 if (StartPtr->getType() != i8Ptr)
451447 StartPtr = new BitCastInst(StartPtr, i8Ptr, StartPtr->getName(),
452448 InsertPt);
453
449
454450 Value *Ops[] = {
455451 StartPtr, ByteVal, // Start, value
456452 // size
457453 ConstantInt::get(Type::getInt64Ty(Context), Range.End-Range.Start),
458454 // align
459 ConstantInt::get(Type::getInt32Ty(Context), Alignment),
460 // volatile
461 ConstantInt::get(Type::getInt1Ty(Context), 0),
455 ConstantInt::get(Type::getInt32Ty(Context), Range.Alignment)
462456 };
463 const Type *Tys[] = { Ops[0]->getType(), Ops[2]->getType() };
464
465 Function *MemSetF = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 2);
466
467 Value *C = CallInst::Create(MemSetF, Ops, Ops+5, "", InsertPt);
457 Value *C = CallInst::Create(MemSetF, Ops, Ops+4, "", InsertPt);
468458 DEBUG(dbgs() << "Replace stores:\n";
469459 for (unsigned i = 0, e = Range.TheStores.size(); i != e; ++i)
470460 dbgs() << *Range.TheStores[i];
689679 return false;
690680
691681 // If all checks passed, then we can transform these memcpy's
692 const Type *ArgTys[3] = { M->getRawDest()->getType(),
693 MDep->getRawSource()->getType(),
694 M->getLength()->getType() };
682 const Type *Ty = M->getLength()->getType();
695683 Function *MemCpyFun = Intrinsic::getDeclaration(
696684 M->getParent()->getParent()->getParent(),
697 M->getIntrinsicID(), ArgTys, 3);
685 M->getIntrinsicID(), &Ty, 1);
698686
699 Value *Args[5] = {
700 M->getRawDest(), MDep->getRawSource(), M->getLength(),
701 M->getAlignmentCst(), M->getVolatileCst()
687 Value *Args[4] = {
688 M->getRawDest(), MDep->getRawSource(), M->getLength(), M->getAlignmentCst()
702689 };
703690
704 CallInst *C = CallInst::Create(MemCpyFun, Args, Args+5, "", M);
691 CallInst *C = CallInst::Create(MemCpyFun, Args, Args+4, "", M);
705692
706693
707694 // If C and M don't interfere, then this is a valid transformation. If they
740727
741728 // If not, then we know we can transform this.
742729 Module *Mod = M->getParent()->getParent()->getParent();
743 const Type *ArgTys[3] = { M->getRawDest()->getType(),
744 M->getRawSource()->getType(),
745 M->getLength()->getType() };
746 M->setOperand(0,Intrinsic::getDeclaration(Mod, Intrinsic::memcpy, ArgTys, 3));
730 const Type *Ty = M->getLength()->getType();
731 M->setOperand(0, Intrinsic::getDeclaration(Mod, Intrinsic::memcpy, &Ty, 1));
747732
748733 // MemDep may have over conservative information about this instruction, just
749734 // conservatively flush it from the cache.
857857 EltPtr = new BitCastInst(EltPtr, BytePtrTy, EltPtr->getName(), MI);
858858
859859 // Cast the other pointer (if we have one) to BytePtrTy.
860 if (OtherElt && OtherElt->getType() != BytePtrTy) {
861 // Preserve address space of OtherElt
862 const PointerType* OtherPTy = cast(OtherElt->getType());
863 const PointerType* PTy = cast(BytePtrTy);
864 if (OtherPTy->getElementType() != PTy->getElementType()) {
865 Type *NewOtherPTy = PointerType::get(PTy->getElementType(),
866 OtherPTy->getAddressSpace());
867 OtherElt = new BitCastInst(OtherElt, NewOtherPTy,
868 OtherElt->getNameStr(), MI);
869 }
870 }
860 if (OtherElt && OtherElt->getType() != BytePtrTy)
861 OtherElt = new BitCastInst(OtherElt, BytePtrTy, OtherElt->getName(), MI);
871862
872863 unsigned EltSize = TD->getTypeAllocSize(EltTy);
873864
878869 SROADest ? OtherElt : EltPtr, // Src ptr
879870 ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
880871 // Align
881 ConstantInt::get(Type::getInt32Ty(MI->getContext()), OtherEltAlign),
882 MI->getVolatileCst()
872 ConstantInt::get(Type::getInt32Ty(MI->getContext()), OtherEltAlign)
883873 };
884 // In case we fold the address space overloaded memcpy of A to B
885 // with memcpy of B to C, change the function to be a memcpy of A to C.
886 const Type *Tys[] = { Ops[0]->getType(), Ops[1]->getType(),
887 Ops[2]->getType() };
888 Module *M = MI->getParent()->getParent()->getParent();
889 TheFn = Intrinsic::getDeclaration(M, MI->getIntrinsicID(), Tys, 3);
890 CallInst::Create(TheFn, Ops, Ops + 5, "", MI);
874 CallInst::Create(TheFn, Ops, Ops + 4, "", MI);
891875 } else {
892876 assert(isa(MI));
893877 Value *Ops[] = {
894878 EltPtr, MI->getOperand(2), // Dest, Value,
895879 ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
896 Zero, // Align
897 ConstantInt::get(Type::getInt1Ty(MI->getContext()), 0) // isVolatile
880 Zero // Align
898881 };
899 const Type *Tys[] = { Ops[0]->getType(), Ops[2]->getType() };
900 Module *M = MI->getParent()->getParent()->getParent();
901 TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 2);
902 CallInst::Create(TheFn, Ops, Ops + 5, "", MI);
882 CallInst::Create(TheFn, Ops, Ops + 4, "", MI);
903883 }
904884 }
905885 DeadInsts.push_back(MI);
141141 // We have enough information to now generate the memcpy call to do the
142142 // concatenation for us. Make a memcpy to copy the nul byte with align = 1.
143143 EmitMemCpy(CpyDst, Src,
144 ConstantInt::get(TD->getIntPtrType(*Context), Len+1),
145 1, false, B, TD);
144 ConstantInt::get(TD->getIntPtrType(*Context), Len+1), 1, B, TD);
146145 }
147146 };
148147
383382 CI->getOperand(3), B, TD);
384383 else
385384 EmitMemCpy(Dst, Src,
386 ConstantInt::get(TD->getIntPtrType(*Context), Len),
387 1, false, B, TD);
385 ConstantInt::get(TD->getIntPtrType(*Context), Len), 1, B, TD);
388386 return Dst;
389387 }
390388 };
412410
413411 if (SrcLen == 0) {
414412 // strncpy(x, "", y) -> memset(x, '\0', y, 1)
415 EmitMemSet(Dst, ConstantInt::get(Type::getInt8Ty(*Context), '\0'),
416 LenOp, false, B, TD);
413 EmitMemSet(Dst, ConstantInt::get(Type::getInt8Ty(*Context), '\0'), LenOp,
414 B, TD);
417415 return Dst;
418416 }
419417
433431
434432 // strncpy(x, s, c) -> memcpy(x, s, c, 1) [s and c are constant]
435433 EmitMemCpy(Dst, Src,
436 ConstantInt::get(TD->getIntPtrType(*Context), Len),
437 1, false, B, TD);
434 ConstantInt::get(TD->getIntPtrType(*Context), Len), 1, B, TD);
438435
439436 return Dst;
440437 }
595592
596593 // memcpy(x, y, n) -> llvm.memcpy(x, y, n, 1)
597594 EmitMemCpy(CI->getOperand(1), CI->getOperand(2),
598 CI->getOperand(3), 1, false, B, TD);
595 CI->getOperand(3), 1, B, TD);
599596 return CI->getOperand(1);
600597 }
601598 };
617614
618615 // memmove(x, y, n) -> llvm.memmove(x, y, n, 1)
619616 EmitMemMove(CI->getOperand(1), CI->getOperand(2),
620 CI->getOperand(3), 1, false, B, TD);
617 CI->getOperand(3), 1, B, TD);
621618 return CI->getOperand(1);
622619 }
623620 };
639636
640637 // memset(p, v, n) -> llvm.memset(p, v, n, 1)
641638 Value *Val = B.CreateIntCast(CI->getOperand(2), Type::getInt8Ty(*Context),
642 false);
643 EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), false, B, TD);
639 false);
640 EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), B, TD);
644641 return CI->getOperand(1);
645642 }
646643 };
1001998 // sprintf(str, fmt) -> llvm.memcpy(str, fmt, strlen(fmt)+1, 1)
1002999 EmitMemCpy(CI->getOperand(1), CI->getOperand(2), // Copy the nul byte.
10031000 ConstantInt::get(TD->getIntPtrType(*Context),
1004 FormatStr.size()+1), 1, false, B, TD);
1001 FormatStr.size()+1), 1, B, TD);
10051002 return ConstantInt::get(CI->getType(), FormatStr.size());
10061003 }
10071004
10151012 // sprintf(dst, "%c", chr) --> *(i8*)dst = chr; *((i8*)dst+1) = 0
10161013 if (!CI->getOperand(3)->getType()->isIntegerTy()) return 0;
10171014 Value *V = B.CreateTrunc(CI->getOperand(3),
1018 Type::getInt8Ty(*Context), "char");
1015 Type::getInt8Ty(*Context), "char");
10191016 Value *Ptr = CastToCStr(CI->getOperand(1), B);
10201017 B.CreateStore(V, Ptr);
10211018 Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::getInt32Ty(*Context), 1),
1022 "nul");
1019 "nul");
10231020 B.CreateStore(Constant::getNullValue(Type::getInt8Ty(*Context)), Ptr);
10241021
10251022 return ConstantInt::get(CI->getType(), 1);
10361033 Value *IncLen = B.CreateAdd(Len,
10371034 ConstantInt::get(Len->getType(), 1),
10381035 "leninc");
1039 EmitMemCpy(CI->getOperand(1), CI->getOperand(3), IncLen, 1, false, B, TD);
1036 EmitMemCpy(CI->getOperand(1), CI->getOperand(3), IncLen, 1, B, TD);
10401037
10411038 // The sprintf result is the unincremented number of bytes in the string.
10421039 return B.CreateIntCast(Len, CI->getType(), false);
108108
109109 /// EmitMemCpy - Emit a call to the memcpy function to the builder. This always
110110 /// expects that Len has type 'intptr_t' and Dst/Src are pointers.
111 Value *llvm::EmitMemCpy(Value *Dst, Value *Src, Value *Len, unsigned Align,
112 bool isVolatile, IRBuilder<> &B, const TargetData *TD) {
113 Module *M = B.GetInsertBlock()->getParent()->getParent();
114 const Type *ArgTys[3] = { Dst->getType(), Src->getType(), Len->getType() };
115 Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, ArgTys, 3);
111 Value *llvm::EmitMemCpy(Value *Dst, Value *Src, Value *Len,
112 unsigned Align, IRBuilder<> &B, const TargetData *TD) {
113 Module *M = B.GetInsertBlock()->getParent()->getParent();
114 const Type *Ty = Len->getType();
115 Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, &Ty, 1);
116116 Dst = CastToCStr(Dst, B);
117117 Src = CastToCStr(Src, B);
118 return B.CreateCall5(MemCpy, Dst, Src, Len,
119 ConstantInt::get(B.getInt32Ty(), Align),
120 ConstantInt::get(B.getInt1Ty(), isVolatile));
118 return B.CreateCall4(MemCpy, Dst, Src, Len,
119 ConstantInt::get(B.getInt32Ty(), Align));
121120 }
122121
123122 /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
146145
147146 /// EmitMemMove - Emit a call to the memmove function to the builder. This
148147 /// always expects that the size has type 'intptr_t' and Dst/Src are pointers.
149 Value *llvm::EmitMemMove(Value *Dst, Value *Src, Value *Len, unsigned Align,
150 bool isVolatile, IRBuilder<> &B, const TargetData *TD) {
151 Module *M = B.GetInsertBlock()->getParent()->getParent();
152 LLVMContext &Context = B.GetInsertBlock()->getContext();
153 const Type *ArgTys[3] = { Dst->getType(), Src->getType(),
154 TD->getIntPtrType(Context) };
155 Value *MemMove = Intrinsic::getDeclaration(M, Intrinsic::memmove, ArgTys, 3);
148 Value *llvm::EmitMemMove(Value *Dst, Value *Src, Value *Len,
149 unsigned Align, IRBuilder<> &B, const TargetData *TD) {
150 Module *M = B.GetInsertBlock()->getParent()->getParent();
151 LLVMContext &Context = B.GetInsertBlock()->getContext();
152 const Type *Ty = TD->getIntPtrType(Context);
153 Value *MemMove = Intrinsic::getDeclaration(M, Intrinsic::memmove, &Ty, 1);
156154 Dst = CastToCStr(Dst, B);
157155 Src = CastToCStr(Src, B);
158156 Value *A = ConstantInt::get(B.getInt32Ty(), Align);
159 Value *Vol = ConstantInt::get(B.getInt1Ty(), isVolatile);
160 return B.CreateCall5(MemMove, Dst, Src, Len, A, Vol);
157 return B.CreateCall4(MemMove, Dst, Src, Len, A);
161158 }
162159
163160 /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is
208205 }
209206
210207 /// EmitMemSet - Emit a call to the memset function
211 Value *llvm::EmitMemSet(Value *Dst, Value *Val, Value *Len, bool isVolatile,
212 IRBuilder<> &B, const TargetData *TD) {
208 Value *llvm::EmitMemSet(Value *Dst, Value *Val,
209 Value *Len, IRBuilder<> &B, const TargetData *TD) {
213210 Module *M = B.GetInsertBlock()->getParent()->getParent();
214211 Intrinsic::ID IID = Intrinsic::memset;
215 const Type *Tys[2] = { Dst->getType(), Len->getType() };
216 Value *MemSet = Intrinsic::getDeclaration(M, IID, Tys, 2);
212 const Type *Tys[1];
213 Tys[0] = Len->getType();
214 Value *MemSet = Intrinsic::getDeclaration(M, IID, Tys, 1);
217215 Value *Align = ConstantInt::get(B.getInt32Ty(), 1);
218 Value *Vol = ConstantInt::get(B.getInt1Ty(), isVolatile);
219 return B.CreateCall5(MemSet, CastToCStr(Dst, B), Val, Len, Align, Vol);
216 return B.CreateCall4(MemSet, CastToCStr(Dst, B), Val, Len, Align);
220217 }
221218
222219 /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name' (e.g.
383380 if (Name == "__memcpy_chk") {
384381 if (isFoldable(4, 3, false)) {
385382 EmitMemCpy(CI->getOperand(1), CI->getOperand(2), CI->getOperand(3),
386 1, false, B, TD);
383 1, B, TD);
387384 replaceCall(CI->getOperand(1));
388385 return true;
389386 }
398395 if (Name == "__memmove_chk") {
399396 if (isFoldable(4, 3, false)) {
400397 EmitMemMove(CI->getOperand(1), CI->getOperand(2), CI->getOperand(3),
401 1, false, B, TD);
398 1, B, TD);
402399 replaceCall(CI->getOperand(1));
403400 return true;
404401 }
409406 if (isFoldable(4, 3, false)) {
410407 Value *Val = B.CreateIntCast(CI->getOperand(2), B.getInt8Ty(),
411408 false);
412 EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), false, B, TD);
409 EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), B, TD);
413410 replaceCall(CI->getOperand(1));
414411 return true;
415412 }
296296 I->getName(),
297297 &*Caller->begin()->begin());
298298 // Emit a memcpy.
299 const Type *Tys[3] = {VoidPtrTy, VoidPtrTy, Type::getInt64Ty(Context)};
299 const Type *Tys[] = { Type::getInt64Ty(Context) };
300300 Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(),
301301 Intrinsic::memcpy,
302 Tys, 3);
302 Tys, 1);
303303 Value *DestCast = new BitCastInst(NewAlloca, VoidPtrTy, "tmp", TheCall);
304304 Value *SrcCast = new BitCastInst(*AI, VoidPtrTy, "tmp", TheCall);
305305
308308 Size = ConstantExpr::getSizeOf(AggTy);
309309 else
310310 Size = ConstantInt::get(Type::getInt64Ty(Context),
311 TD->getTypeStoreSize(AggTy));
311 TD->getTypeStoreSize(AggTy));
312312
313313 // Always generate a memcpy of alignment 1 here because we don't know
314314 // the alignment of the src pointer. Other optimizations can infer
315315 // better alignment.
316316 Value *CallArgs[] = {
317317 DestCast, SrcCast, Size,
318 ConstantInt::get(Type::getInt32Ty(Context), 1),
319 ConstantInt::get(Type::getInt1Ty(Context), 0)
318 ConstantInt::get(Type::getInt32Ty(Context), 1)
320319 };
321320 CallInst *TheMemCpy =
322 CallInst::Create(MemCpyFn, CallArgs, CallArgs+5, "", TheCall);
321 CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
323322
324323 // If we have a call graph, update it.
325324 if (CG) {
144144 }
145145 break;
146146
147 case 'm': {
148 // This upgrades the llvm.memcpy, llvm.memmove, and llvm.memset to the
149 // new format that allows overloading the pointer for different address
150 // space (e.g., llvm.memcpy.i16 => llvm.memcpy.p0i8.p0i8.i16)
151 const char* NewFnName = NULL;
152 if (Name.compare(5,8,"memcpy.i",8) == 0) {
153 if (Name[13] == '8')
154 NewFnName = "llvm.memcpy.p0i8.p0i8.i8";
155 else if (Name.compare(13,2,"16") == 0)
156 NewFnName = "llvm.memcpy.p0i8.p0i8.i16";
157 else if (Name.compare(13,2,"32") == 0)
158 NewFnName = "llvm.memcpy.p0i8.p0i8.i32";
159 else if (Name.compare(13,2,"64") == 0)
160 NewFnName = "llvm.memcpy.p0i8.p0i8.i64";
161 } else if (Name.compare(5,9,"memmove.i",9) == 0) {
162 if (Name[14] == '8')
163 NewFnName = "llvm.memmove.p0i8.p0i8.i8";
164 else if (Name.compare(14,2,"16") == 0)
165 NewFnName = "llvm.memmove.p0i8.p0i8.i16";
166 else if (Name.compare(14,2,"32") == 0)
167 NewFnName = "llvm.memmove.p0i8.p0i8.i32";
168 else if (Name.compare(14,2,"64") == 0)
169 NewFnName = "llvm.memmove.p0i8.p0i8.i64";
170 }
171 else if (Name.compare(5,8,"memset.i",8) == 0) {
172 if (Name[13] == '8')
173 NewFnName = "llvm.memset.p0i8.i8";
174 else if (Name.compare(13,2,"16") == 0)
175 NewFnName = "llvm.memset.p0i8.i16";
176 else if (Name.compare(13,2,"32") == 0)
177 NewFnName = "llvm.memset.p0i8.i32";
178 else if (Name.compare(13,2,"64") == 0)
179 NewFnName = "llvm.memset.p0i8.i64";
180 }
181 if (NewFnName) {
182 const FunctionType *FTy = F->getFunctionType();
183 NewFn = cast(M->getOrInsertFunction(NewFnName,
184 FTy->getReturnType(),
185 FTy->getParamType(0),
186 FTy->getParamType(1),
187 FTy->getParamType(2),
188 FTy->getParamType(3),
189 Type::getInt1Ty(F->getContext()),
190 (Type *)0));
191 return true;
192 }
193 break;
194 }
195147 case 'p':
196148 // This upgrades the llvm.part.select overloaded intrinsic names to only
197149 // use one type specifier in the name. We only care about the old format
519471 CI->eraseFromParent();
520472 }
521473 break;
522 case Intrinsic::memcpy:
523 case Intrinsic::memmove:
524 case Intrinsic::memset: {
525 // Add isVolatile
526 const llvm::Type *I1Ty = llvm::Type::getInt1Ty(CI->getContext());
527 Value *Operands[5] = { CI->getOperand(1), CI->getOperand(2),
528 CI->getOperand(3), CI->getOperand(4),
529 llvm::ConstantInt::get(I1Ty, 0) };
530 CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+5,
531 CI->getName(), CI);
532 NewCI->setTailCall(CI->isTailCall());
533 NewCI->setCallingConv(CI->getCallingConv());
534 // Handle any uses of the old CallInst.
535 if (!CI->use_empty())
536 // Replace all uses of the old call with the new cast which has the
537 // correct type.
538 CI->replaceAllUsesWith(NewCI);
539
540 // Clean up the old call now that it has been completely upgraded.
541 CI->eraseFromParent();
542 break;
543 }
544474 }
545475 }
546476
102102 ret i32 %sub
103103 ; CHECK: @test4
104104 ; CHECK: load i32* @G
105 ; CHECK: memset.p0i8.i32
105 ; CHECK: memset.i32
106106 ; CHECK-NOT: load
107107 ; CHECK: sub i32 %tmp, %tmp
108108 }
117117 ret i32 %sub
118118 ; CHECK: @test5
119119 ; CHECK: load i32* @G
120 ; CHECK: memcpy.p0i8.p0i8.i32
120 ; CHECK: memcpy.i32
121121 ; CHECK-NOT: load
122122 ; CHECK: sub i32 %tmp, %tmp
123123 }
77 tail call void @llvm.memcpy.i64( i8* %tmp.1, i8* %tmp.3, i64 100000, i32 1 )
88 tail call void @llvm.memset.i32( i8* %tmp.3, i8 14, i32 10000, i32 0 )
99 tail call void @llvm.memmove.i32( i8* %tmp.1, i8* %tmp.3, i32 123124, i32 1 )
10 tail call void @llvm.memmove.i64( i8* %tmp.1, i8* %tmp.3, i64 123124, i32 1 )
1110 ret void
1211 }
1312
1918
2019 declare void @llvm.memmove.i32(i8*, i8*, i32, i32)
2120
22 declare void @llvm.memmove.i64(i8*, i8*, i32, i32)
66
77 define i32 @t() nounwind ssp {
88 ; CHECK: @t
9 ; CHECK: @llvm.memset.p0i8.i64
9 ; CHECK: @llvm.memset.i64
1010 entry:
1111 %0 = alloca %struct.data, align 8 ; <%struct.data*> [#uses=1]
1212 %1 = bitcast %struct.data* %0 to i8* ; [#uses=1]
112112 %1 = bitcast %struct.data* %0 to i8*
113113 %2 = call i64 @llvm.objectsize.i64(i8* %1, i1 false) nounwind
114114 ; CHECK-NOT: @llvm.objectsize
115 ; CHECK: @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 1824, i32 8, i1 false)
115 ; CHECK: @llvm.memset.i64(i8* %1, i8 0, i64 1824, i32 8)
116116 %3 = call i8* @__memset_chk(i8* %1, i32 0, i64 1824, i64 %2) nounwind
117117 ret i32 0
118118 }
127127 %1 = tail call i32 @llvm.objectsize.i32(i8* %0, i1 false)
128128 %2 = load i8** @s, align 8
129129 ; CHECK-NOT: @llvm.objectsize
130 ; CHECK: @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %1, i32 10, i32 1, i1 false)
130 ; CHECK: @llvm.memcpy.i32(i8* %0, i8* %1, i32 10, i32 1)
131131 %3 = tail call i8* @__memcpy_chk(i8* %0, i8* %2, i32 10, i32 %1) nounwind
132132 ret void
133133 }
33 ; The resulting memset is only 4-byte aligned, despite containing
44 ; a 16-byte alignmed store in the middle.
55
6 ; CHECK: call void @llvm.memset.p0i8.i64(i8* %a01, i8 0, i64 16, i32 4, i1 false)
6 ; CHECK: call void @llvm.memset.i64(i8* %a01, i8 0, i64 16, i32 4)
77
88 define void @foo(i32* %p) {
99 %a0 = getelementptr i32* %p, i64 0
2020 %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0
2121 %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0
2222 %rslt1 = call i8* @strcpy( i8* %arg1, i8* %arg2 )
23 ; CHECK: @llvm.memcpy.p0i8.p0i8.i32
23 ; CHECK: @llvm.memcpy.i32
2424 ret i32 0
2525 }
2626
0 ; RUN: not llvm-as < %s |& grep {llvm intrinsics cannot be defined}
11 ; PR1047
22
3 define void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1) {
3 define void @llvm.memcpy.i32(i8*, i8*, i32, i32) {
44 entry:
55 ret void
66 }