@@ -16,7 +16,7 @@ using namespace llvm;
16
16
17
17
void llvm::createMemCpyLoopKnownSize (Instruction *InsertBefore, Value *SrcAddr,
18
18
Value *DstAddr, ConstantInt *CopyLen,
19
- unsigned SrcAlign, unsigned DstAlign,
19
+ Align SrcAlign, Align DstAlign,
20
20
bool SrcIsVolatile, bool DstIsVolatile,
21
21
const TargetTransformInfo &TTI) {
22
22
// No need to expand zero length copies.
@@ -33,8 +33,8 @@ void llvm::createMemCpyLoopKnownSize(Instruction *InsertBefore, Value *SrcAddr,
33
33
unsigned DstAS = cast<PointerType>(DstAddr->getType ())->getAddressSpace ();
34
34
35
35
Type *TypeOfCopyLen = CopyLen->getType ();
36
- Type *LoopOpType = TTI.getMemcpyLoopLoweringType (Ctx, CopyLen, SrcAS, DstAS,
37
- SrcAlign, DstAlign);
36
+ Type *LoopOpType = TTI.getMemcpyLoopLoweringType (
37
+ Ctx, CopyLen, SrcAS, DstAS, SrcAlign. value () , DstAlign. value () );
38
38
39
39
unsigned LoopOpSize = DL.getTypeStoreSize (LoopOpType);
40
40
uint64_t LoopEndCount = CopyLen->getZExtValue () / LoopOpSize;
@@ -59,8 +59,8 @@ void llvm::createMemCpyLoopKnownSize(Instruction *InsertBefore, Value *SrcAddr,
59
59
DstAddr = PLBuilder.CreateBitCast (DstAddr, DstOpType);
60
60
}
61
61
62
- Align PartDstAlign (MinAlign (DstAlign, LoopOpSize));
63
- Align PartSrcAlign (MinAlign (SrcAlign, LoopOpSize));
62
+ Align PartDstAlign (commonAlignment (DstAlign, LoopOpSize));
63
+ Align PartSrcAlign (commonAlignment (SrcAlign, LoopOpSize));
64
64
65
65
IRBuilder<> LoopBuilder (LoopBB);
66
66
PHINode *LoopIndex = LoopBuilder.CreatePHI (TypeOfCopyLen, 2 , " loop-index" );
@@ -92,11 +92,12 @@ void llvm::createMemCpyLoopKnownSize(Instruction *InsertBefore, Value *SrcAddr,
92
92
93
93
SmallVector<Type *, 5 > RemainingOps;
94
94
TTI.getMemcpyLoopResidualLoweringType (RemainingOps, Ctx, RemainingBytes,
95
- SrcAS, DstAS, SrcAlign, DstAlign);
95
+ SrcAS, DstAS, SrcAlign.value (),
96
+ DstAlign.value ());
96
97
97
98
for (auto OpTy : RemainingOps) {
98
- Align PartSrcAlign (MinAlign (SrcAlign, BytesCopied));
99
- Align PartDstAlign (MinAlign (DstAlign, BytesCopied));
99
+ Align PartSrcAlign (commonAlignment (SrcAlign, BytesCopied));
100
+ Align PartDstAlign (commonAlignment (DstAlign, BytesCopied));
100
101
101
102
// Calaculate the new index
102
103
unsigned OperandSize = DL.getTypeStoreSize (OpTy);
@@ -131,8 +132,8 @@ void llvm::createMemCpyLoopKnownSize(Instruction *InsertBefore, Value *SrcAddr,
131
132
132
133
void llvm::createMemCpyLoopUnknownSize (Instruction *InsertBefore,
133
134
Value *SrcAddr, Value *DstAddr,
134
- Value *CopyLen, unsigned SrcAlign,
135
- unsigned DstAlign, bool SrcIsVolatile,
135
+ Value *CopyLen, Align SrcAlign,
136
+ Align DstAlign, bool SrcIsVolatile,
136
137
bool DstIsVolatile,
137
138
const TargetTransformInfo &TTI) {
138
139
BasicBlock *PreLoopBB = InsertBefore->getParent ();
@@ -145,8 +146,8 @@ void llvm::createMemCpyLoopUnknownSize(Instruction *InsertBefore,
145
146
unsigned SrcAS = cast<PointerType>(SrcAddr->getType ())->getAddressSpace ();
146
147
unsigned DstAS = cast<PointerType>(DstAddr->getType ())->getAddressSpace ();
147
148
148
- Type *LoopOpType = TTI.getMemcpyLoopLoweringType (Ctx, CopyLen, SrcAS, DstAS,
149
- SrcAlign, DstAlign);
149
+ Type *LoopOpType = TTI.getMemcpyLoopLoweringType (
150
+ Ctx, CopyLen, SrcAS, DstAS, SrcAlign. value () , DstAlign. value () );
150
151
unsigned LoopOpSize = DL.getTypeStoreSize (LoopOpType);
151
152
152
153
IRBuilder<> PLBuilder (PreLoopBB->getTerminator ());
@@ -175,8 +176,8 @@ void llvm::createMemCpyLoopUnknownSize(Instruction *InsertBefore,
175
176
BasicBlock::Create (Ctx, " loop-memcpy-expansion" , ParentFunc, PostLoopBB);
176
177
IRBuilder<> LoopBuilder (LoopBB);
177
178
178
- Align PartSrcAlign (MinAlign (SrcAlign, LoopOpSize));
179
- Align PartDstAlign (MinAlign (DstAlign, LoopOpSize));
179
+ Align PartSrcAlign (commonAlignment (SrcAlign, LoopOpSize));
180
+ Align PartDstAlign (commonAlignment (DstAlign, LoopOpSize));
180
181
181
182
PHINode *LoopIndex = LoopBuilder.CreatePHI (CopyLenType, 2 , " loop-index" );
182
183
LoopIndex->addIncoming (ConstantInt::get (CopyLenType, 0U ), PreLoopBB);
@@ -288,8 +289,8 @@ void llvm::createMemCpyLoopUnknownSize(Instruction *InsertBefore,
288
289
// return dst;
289
290
// }
290
291
static void createMemMoveLoop (Instruction *InsertBefore, Value *SrcAddr,
291
- Value *DstAddr, Value *CopyLen, unsigned SrcAlign,
292
- unsigned DstAlign, bool SrcIsVolatile,
292
+ Value *DstAddr, Value *CopyLen, Align SrcAlign,
293
+ Align DstAlign, bool SrcIsVolatile,
293
294
bool DstIsVolatile) {
294
295
Type *TypeOfCopyLen = CopyLen->getType ();
295
296
BasicBlock *OrigBB = InsertBefore->getParent ();
@@ -323,8 +324,8 @@ static void createMemMoveLoop(Instruction *InsertBefore, Value *SrcAddr,
323
324
ExitBB->setName (" memmove_done" );
324
325
325
326
unsigned PartSize = DL.getTypeStoreSize (EltTy);
326
- Align PartSrcAlign (MinAlign (SrcAlign, PartSize));
327
- Align PartDstAlign (MinAlign (DstAlign, PartSize));
327
+ Align PartSrcAlign (commonAlignment (SrcAlign, PartSize));
328
+ Align PartDstAlign (commonAlignment (DstAlign, PartSize));
328
329
329
330
// Initial comparison of n == 0 that lets us skip the loops altogether. Shared
330
331
// between both backwards and forward copy clauses.
@@ -375,7 +376,7 @@ static void createMemMoveLoop(Instruction *InsertBefore, Value *SrcAddr,
375
376
}
376
377
377
378
static void createMemSetLoop (Instruction *InsertBefore, Value *DstAddr,
378
- Value *CopyLen, Value *SetValue, unsigned DstAlign,
379
+ Value *CopyLen, Value *SetValue, Align DstAlign,
379
380
bool IsVolatile) {
380
381
Type *TypeOfCopyLen = CopyLen->getType ();
381
382
BasicBlock *OrigBB = InsertBefore->getParent ();
@@ -399,7 +400,7 @@ static void createMemSetLoop(Instruction *InsertBefore, Value *DstAddr,
399
400
OrigBB->getTerminator ()->eraseFromParent ();
400
401
401
402
unsigned PartSize = DL.getTypeStoreSize (SetValue->getType ());
402
- Align PartAlign (MinAlign (DstAlign, PartSize));
403
+ Align PartAlign (commonAlignment (DstAlign, PartSize));
403
404
404
405
IRBuilder<> LoopBuilder (LoopBB);
405
406
PHINode *LoopIndex = LoopBuilder.CreatePHI (TypeOfCopyLen, 0 );
@@ -421,25 +422,27 @@ static void createMemSetLoop(Instruction *InsertBefore, Value *DstAddr,
421
422
void llvm::expandMemCpyAsLoop (MemCpyInst *Memcpy,
422
423
const TargetTransformInfo &TTI) {
423
424
if (ConstantInt *CI = dyn_cast<ConstantInt>(Memcpy->getLength ())) {
424
- createMemCpyLoopKnownSize (/* InsertBefore */ Memcpy,
425
- /* SrcAddr */ Memcpy->getRawSource (),
426
- /* DstAddr */ Memcpy->getRawDest (),
427
- /* CopyLen */ CI,
428
- /* SrcAlign */ Memcpy->getSourceAlignment (),
429
- /* DestAlign */ Memcpy->getDestAlignment (),
430
- /* SrcIsVolatile */ Memcpy->isVolatile (),
431
- /* DstIsVolatile */ Memcpy->isVolatile (),
432
- /* TargetTransformInfo */ TTI);
425
+ createMemCpyLoopKnownSize (
426
+ /* InsertBefore */ Memcpy,
427
+ /* SrcAddr */ Memcpy->getRawSource (),
428
+ /* DstAddr */ Memcpy->getRawDest (),
429
+ /* CopyLen */ CI,
430
+ /* SrcAlign */ Memcpy->getSourceAlign ().valueOrOne (),
431
+ /* DestAlign */ Memcpy->getDestAlign ().valueOrOne (),
432
+ /* SrcIsVolatile */ Memcpy->isVolatile (),
433
+ /* DstIsVolatile */ Memcpy->isVolatile (),
434
+ /* TargetTransformInfo */ TTI);
433
435
} else {
434
- createMemCpyLoopUnknownSize (/* InsertBefore */ Memcpy,
435
- /* SrcAddr */ Memcpy->getRawSource (),
436
- /* DstAddr */ Memcpy->getRawDest (),
437
- /* CopyLen */ Memcpy->getLength (),
438
- /* SrcAlign */ Memcpy->getSourceAlignment (),
439
- /* DestAlign */ Memcpy->getDestAlignment (),
440
- /* SrcIsVolatile */ Memcpy->isVolatile (),
441
- /* DstIsVolatile */ Memcpy->isVolatile (),
442
- /* TargetTransfomrInfo */ TTI);
436
+ createMemCpyLoopUnknownSize (
437
+ /* InsertBefore */ Memcpy,
438
+ /* SrcAddr */ Memcpy->getRawSource (),
439
+ /* DstAddr */ Memcpy->getRawDest (),
440
+ /* CopyLen */ Memcpy->getLength (),
441
+ /* SrcAlign */ Memcpy->getSourceAlign ().valueOrOne (),
442
+ /* DestAlign */ Memcpy->getDestAlign ().valueOrOne (),
443
+ /* SrcIsVolatile */ Memcpy->isVolatile (),
444
+ /* DstIsVolatile */ Memcpy->isVolatile (),
445
+ /* TargetTransfomrInfo */ TTI);
443
446
}
444
447
}
445
448
@@ -448,8 +451,8 @@ void llvm::expandMemMoveAsLoop(MemMoveInst *Memmove) {
448
451
/* SrcAddr */ Memmove->getRawSource (),
449
452
/* DstAddr */ Memmove->getRawDest (),
450
453
/* CopyLen */ Memmove->getLength (),
451
- /* SrcAlign */ Memmove->getSourceAlignment (),
452
- /* DestAlign */ Memmove->getDestAlignment (),
454
+ /* SrcAlign */ Memmove->getSourceAlign (). valueOrOne (),
455
+ /* DestAlign */ Memmove->getDestAlign (). valueOrOne (),
453
456
/* SrcIsVolatile */ Memmove->isVolatile (),
454
457
/* DstIsVolatile */ Memmove->isVolatile ());
455
458
}
@@ -459,6 +462,6 @@ void llvm::expandMemSetAsLoop(MemSetInst *Memset) {
459
462
/* DstAddr */ Memset->getRawDest (),
460
463
/* CopyLen */ Memset->getLength (),
461
464
/* SetValue */ Memset->getValue (),
462
- /* Alignment */ Memset->getDestAlignment (),
465
+ /* Alignment */ Memset->getDestAlign (). valueOrOne (),
463
466
Memset->isVolatile ());
464
467
}
0 commit comments