Skip to content

Commit 531c116

Browse files
committed
Resubmit "[Alignment][NFC] Deprecate CreateMemCpy/CreateMemMove"
Summary: This is a resubmit of D71473. This patch introduces a set of functions to enable deprecation of IRBuilder functions without breaking out of tree clients. Functions will be deprecated one by one and as in tree code is cleaned up. This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: aaron.ballman, courbet Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71547
1 parent 531c711 commit 531c116

19 files changed

+200
-146
lines changed

llvm/include/llvm/IR/Argument.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ class Argument final : public Value {
7676
bool hasByValOrInAllocaAttr() const;
7777

7878
/// If this is a byval or inalloca argument, return its alignment.
79+
/// FIXME: Remove this function once transition to Align is over.
80+
/// Use getParamAlign() instead.
7981
unsigned getParamAlignment() const;
8082

83+
/// If this is a byval or inalloca argument, return its alignment.
84+
MaybeAlign getParamAlign() const;
85+
8186
/// If this is a byval argument, return its type.
8287
Type *getParamByValType() const;
8388

llvm/include/llvm/IR/Function.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,18 @@ class Function : public GlobalObject, public ilist_node<Function> {
435435
void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes);
436436

437437
/// Extract the alignment for a call or parameter (0=unknown).
438+
/// FIXME: Remove this function once transition to Align is over.
439+
/// Use getParamAlign() instead.
438440
unsigned getParamAlignment(unsigned ArgNo) const {
439-
if (const auto MA = AttributeSets.getParamAlignment(ArgNo))
441+
if (const auto MA = getParamAlign(ArgNo))
440442
return MA->value();
441443
return 0;
442444
}
443445

446+
MaybeAlign getParamAlign(unsigned ArgNo) const {
447+
return AttributeSets.getParamAlignment(ArgNo);
448+
}
449+
444450
/// Extract the byval type for a parameter.
445451
Type *getParamByValType(unsigned ArgNo) const {
446452
Type *Ty = AttributeSets.getParamByValType(ArgNo);

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,14 @@ class IRBuilderBase {
493493
/// and noalias tags.
494494
/// FIXME: Remove this function once transition to Align is over.
495495
/// Use the version that takes MaybeAlign instead of this one.
496-
CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
497-
unsigned SrcAlign, uint64_t Size,
498-
bool isVolatile = false, MDNode *TBAATag = nullptr,
499-
MDNode *TBAAStructTag = nullptr,
500-
MDNode *ScopeTag = nullptr,
501-
MDNode *NoAliasTag = nullptr) {
496+
LLVM_ATTRIBUTE_DEPRECATED(
497+
CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
498+
unsigned SrcAlign, uint64_t Size,
499+
bool isVolatile = false, MDNode *TBAATag = nullptr,
500+
MDNode *TBAAStructTag = nullptr,
501+
MDNode *ScopeTag = nullptr,
502+
MDNode *NoAliasTag = nullptr),
503+
"Use the version that takes MaybeAlign instead") {
502504
return CreateMemCpy(Dst, MaybeAlign(DstAlign), Src, MaybeAlign(SrcAlign),
503505
getInt64(Size), isVolatile, TBAATag, TBAAStructTag,
504506
ScopeTag, NoAliasTag);
@@ -517,12 +519,14 @@ class IRBuilderBase {
517519

518520
/// FIXME: Remove this function once transition to Align is over.
519521
/// Use the version that takes MaybeAlign instead of this one.
520-
CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
521-
unsigned SrcAlign, Value *Size,
522-
bool isVolatile = false, MDNode *TBAATag = nullptr,
523-
MDNode *TBAAStructTag = nullptr,
524-
MDNode *ScopeTag = nullptr,
525-
MDNode *NoAliasTag = nullptr);
522+
LLVM_ATTRIBUTE_DEPRECATED(
523+
CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
524+
unsigned SrcAlign, Value *Size,
525+
bool isVolatile = false, MDNode *TBAATag = nullptr,
526+
MDNode *TBAAStructTag = nullptr,
527+
MDNode *ScopeTag = nullptr,
528+
MDNode *NoAliasTag = nullptr),
529+
"Use the version that takes MaybeAlign instead");
526530
CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
527531
MaybeAlign SrcAlign, Value *Size,
528532
bool isVolatile = false, MDNode *TBAATag = nullptr,
@@ -562,12 +566,15 @@ class IRBuilderBase {
562566
/// and noalias tags.
563567
/// FIXME: Remove this function once transition to Align is over.
564568
/// Use the version that takes MaybeAlign instead of this one.
565-
CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
566-
uint64_t Size, bool isVolatile = false,
567-
MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
568-
MDNode *NoAliasTag = nullptr) {
569-
return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size), isVolatile,
570-
TBAATag, ScopeTag, NoAliasTag);
569+
LLVM_ATTRIBUTE_DEPRECATED(
570+
CallInst *CreateMemMove(
571+
Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
572+
uint64_t Size, bool isVolatile = false, MDNode *TBAATag = nullptr,
573+
MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr),
574+
"Use the version that takes MaybeAlign") {
575+
return CreateMemMove(Dst, MaybeAlign(DstAlign), Src, MaybeAlign(SrcAlign),
576+
getInt64(Size), isVolatile, TBAATag, ScopeTag,
577+
NoAliasTag);
571578
}
572579
CallInst *CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src,
573580
MaybeAlign SrcAlign, uint64_t Size,
@@ -579,11 +586,12 @@ class IRBuilderBase {
579586
}
580587
/// FIXME: Remove this function once transition to Align is over.
581588
/// Use the version that takes MaybeAlign instead of this one.
582-
CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src,
583-
unsigned SrcAlign, Value *Size,
584-
bool isVolatile = false, MDNode *TBAATag = nullptr,
585-
MDNode *ScopeTag = nullptr,
586-
MDNode *NoAliasTag = nullptr) {
589+
LLVM_ATTRIBUTE_DEPRECATED(
590+
CallInst *CreateMemMove(
591+
Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
592+
Value *Size, bool isVolatile = false, MDNode *TBAATag = nullptr,
593+
MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr),
594+
"Use the version that takes MaybeAlign") {
587595
return CreateMemMove(Dst, MaybeAlign(DstAlign), Src, MaybeAlign(SrcAlign),
588596
Size, isVolatile, TBAATag, ScopeTag, NoAliasTag);
589597
}

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,19 +1585,31 @@ class CallBase : public Instruction {
15851585
}
15861586

15871587
/// Extract the alignment of the return value.
1588+
/// FIXME: Remove this function once transition to Align is over.
1589+
/// Use getRetAlign() instead.
15881590
unsigned getRetAlignment() const {
15891591
if (const auto MA = Attrs.getRetAlignment())
15901592
return MA->value();
15911593
return 0;
15921594
}
15931595

1596+
/// Extract the alignment of the return value.
1597+
MaybeAlign getRetAlign() const { return Attrs.getRetAlignment(); }
1598+
15941599
/// Extract the alignment for a call or parameter (0=unknown).
1600+
/// FIXME: Remove this function once transition to Align is over.
1601+
/// Use getParamAlign() instead.
15951602
unsigned getParamAlignment(unsigned ArgNo) const {
15961603
if (const auto MA = Attrs.getParamAlignment(ArgNo))
15971604
return MA->value();
15981605
return 0;
15991606
}
16001607

1608+
/// Extract the alignment for a call or parameter (0=unknown).
1609+
MaybeAlign getParamAlign(unsigned ArgNo) const {
1610+
return Attrs.getParamAlignment(ArgNo);
1611+
}
1612+
16011613
/// Extract the byval type for a call or parameter.
16021614
Type *getParamByValType(unsigned ArgNo) const {
16031615
Type *Ty = Attrs.getParamByValType(ArgNo);

llvm/include/llvm/IR/Instructions.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,20 @@ class LoadInst : public UnaryInstruction {
239239
}
240240

241241
/// Return the alignment of the access that is being performed.
242+
/// FIXME: Remove this function once transition to Align is over.
243+
/// Use getAlign() instead.
242244
unsigned getAlignment() const {
243-
if (const auto MA =
244-
decodeMaybeAlign((getSubclassDataFromInstruction() >> 1) & 31))
245+
if (const auto MA = getAlign())
245246
return MA->value();
246247
return 0;
247248
}
248249

249-
void setAlignment(MaybeAlign Align);
250+
/// Return the alignment of the access that is being performed.
251+
MaybeAlign getAlign() const {
252+
return decodeMaybeAlign((getSubclassDataFromInstruction() >> 1) & 31);
253+
}
254+
255+
void setAlignment(MaybeAlign Alignment);
250256

251257
/// Returns the ordering constraint of this load instruction.
252258
AtomicOrdering getOrdering() const {
@@ -365,14 +371,19 @@ class StoreInst : public Instruction {
365371
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
366372

367373
/// Return the alignment of the access that is being performed
374+
/// FIXME: Remove this function once transition to Align is over.
375+
/// Use getAlign() instead.
368376
unsigned getAlignment() const {
369-
if (const auto MA =
370-
decodeMaybeAlign((getSubclassDataFromInstruction() >> 1) & 31))
377+
if (const auto MA = getAlign())
371378
return MA->value();
372379
return 0;
373380
}
374381

375-
void setAlignment(MaybeAlign Align);
382+
MaybeAlign getAlign() const {
383+
return decodeMaybeAlign((getSubclassDataFromInstruction() >> 1) & 31);
384+
}
385+
386+
void setAlignment(MaybeAlign Alignment);
376387

377388
/// Returns the ordering constraint of this store instruction.
378389
AtomicOrdering getOrdering() const {

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ namespace llvm {
348348
return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
349349
}
350350

351+
/// FIXME: Remove this function once transition to Align is over.
352+
/// Use getDestAlign() instead.
351353
unsigned getDestAlignment() const { return getParamAlignment(ARG_DEST); }
354+
MaybeAlign getDestAlign() const { return getParamAlign(ARG_DEST); }
352355

353356
/// Set the specified arguments of the instruction.
354357
void setDest(Value *Ptr) {
@@ -406,10 +409,16 @@ namespace llvm {
406409
return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
407410
}
408411

412+
/// FIXME: Remove this function once transition to Align is over.
413+
/// Use getSourceAlign() instead.
409414
unsigned getSourceAlignment() const {
410415
return BaseCL::getParamAlignment(ARG_SOURCE);
411416
}
412417

418+
MaybeAlign getSourceAlign() const {
419+
return BaseCL::getParamAlign(ARG_SOURCE);
420+
}
421+
413422
void setSource(Value *Ptr) {
414423
assert(getRawSource()->getType() == Ptr->getType() &&
415424
"setSource called with pointer of wrong type!");

llvm/lib/CodeGen/SafeStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
563563

564564
for (Argument *Arg : ByValArguments) {
565565
unsigned Offset = SSL.getObjectOffset(Arg);
566-
unsigned Align = SSL.getObjectAlignment(Arg);
566+
MaybeAlign Align(SSL.getObjectAlignment(Arg));
567567
Type *Ty = Arg->getType()->getPointerElementType();
568568

569569
uint64_t Size = DL.getTypeStoreSize(Ty);
@@ -580,7 +580,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
580580
DIExpression::ApplyOffset, -Offset);
581581
Arg->replaceAllUsesWith(NewArg);
582582
IRB.SetInsertPoint(cast<Instruction>(NewArg)->getNextNode());
583-
IRB.CreateMemCpy(Off, Align, Arg, Arg->getParamAlignment(), Size);
583+
IRB.CreateMemCpy(Off, Align, Arg, Arg->getParamAlign(), Size);
584584
}
585585

586586
// Allocate space for every unsafe static AllocaInst on the unsafe stack.

llvm/lib/IR/Core.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,17 +3450,17 @@ LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,
34503450
LLVMValueRef Dst, unsigned DstAlign,
34513451
LLVMValueRef Src, unsigned SrcAlign,
34523452
LLVMValueRef Size) {
3453-
return wrap(unwrap(B)->CreateMemCpy(unwrap(Dst), DstAlign,
3454-
unwrap(Src), SrcAlign,
3453+
return wrap(unwrap(B)->CreateMemCpy(unwrap(Dst), MaybeAlign(DstAlign),
3454+
unwrap(Src), MaybeAlign(SrcAlign),
34553455
unwrap(Size)));
34563456
}
34573457

34583458
LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B,
34593459
LLVMValueRef Dst, unsigned DstAlign,
34603460
LLVMValueRef Src, unsigned SrcAlign,
34613461
LLVMValueRef Size) {
3462-
return wrap(unwrap(B)->CreateMemMove(unwrap(Dst), DstAlign,
3463-
unwrap(Src), SrcAlign,
3462+
return wrap(unwrap(B)->CreateMemMove(unwrap(Dst), MaybeAlign(DstAlign),
3463+
unwrap(Src), MaybeAlign(SrcAlign),
34643464
unwrap(Size)));
34653465
}
34663466

llvm/lib/IR/Function.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ unsigned Argument::getParamAlignment() const {
126126
return getParent()->getParamAlignment(getArgNo());
127127
}
128128

129+
MaybeAlign Argument::getParamAlign() const {
130+
assert(getType()->isPointerTy() && "Only pointers have alignments");
131+
return getParent()->getParamAlign(getArgNo());
132+
}
133+
129134
Type *Argument::getParamByValType() const {
130135
assert(getType()->isPointerTy() && "Only pointers have byval types");
131136
return getParent()->getParamByValType(getArgNo());

llvm/lib/IR/Instructions.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,11 +1342,7 @@ void LoadInst::setAlignment(MaybeAlign Align) {
13421342
"Alignment is greater than MaximumAlignment!");
13431343
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) |
13441344
(encode(Align) << 1));
1345-
if (Align)
1346-
assert(getAlignment() == Align->value() &&
1347-
"Alignment representation error!");
1348-
else
1349-
assert(getAlignment() == 0 && "Alignment representation error!");
1345+
assert(getAlign() == Align && "Alignment representation error!");
13501346
}
13511347

13521348
//===----------------------------------------------------------------------===//
@@ -1416,16 +1412,12 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
14161412
AssertOK();
14171413
}
14181414

1419-
void StoreInst::setAlignment(MaybeAlign Align) {
1420-
assert((!Align || *Align <= MaximumAlignment) &&
1415+
void StoreInst::setAlignment(MaybeAlign Alignment) {
1416+
assert((!Alignment || *Alignment <= MaximumAlignment) &&
14211417
"Alignment is greater than MaximumAlignment!");
14221418
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) |
1423-
(encode(Align) << 1));
1424-
if (Align)
1425-
assert(getAlignment() == Align->value() &&
1426-
"Alignment representation error!");
1427-
else
1428-
assert(getAlignment() == 0 && "Alignment representation error!");
1419+
(encode(Alignment) << 1));
1420+
assert(getAlign() == Alignment && "Alignment representation error!");
14291421
}
14301422

14311423
//===----------------------------------------------------------------------===//

llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,16 +884,16 @@ bool AMDGPUPromoteAlloca::handleAlloca(AllocaInst &I, bool SufficientLDS) {
884884
continue;
885885
case Intrinsic::memcpy: {
886886
MemCpyInst *MemCpy = cast<MemCpyInst>(Intr);
887-
Builder.CreateMemCpy(MemCpy->getRawDest(), MemCpy->getDestAlignment(),
888-
MemCpy->getRawSource(), MemCpy->getSourceAlignment(),
887+
Builder.CreateMemCpy(MemCpy->getRawDest(), MemCpy->getDestAlign(),
888+
MemCpy->getRawSource(), MemCpy->getSourceAlign(),
889889
MemCpy->getLength(), MemCpy->isVolatile());
890890
Intr->eraseFromParent();
891891
continue;
892892
}
893893
case Intrinsic::memmove: {
894894
MemMoveInst *MemMove = cast<MemMoveInst>(Intr);
895-
Builder.CreateMemMove(MemMove->getRawDest(), MemMove->getDestAlignment(),
896-
MemMove->getRawSource(), MemMove->getSourceAlignment(),
895+
Builder.CreateMemMove(MemMove->getRawDest(), MemMove->getDestAlign(),
896+
MemMove->getRawSource(), MemMove->getSourceAlign(),
897897
MemMove->getLength(), MemMove->isVolatile());
898898
Intr->eraseFromParent();
899899
continue;

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,14 +2275,12 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
22752275
: CondBuilder.CreateBitCast(LoadBasePtr, Int32PtrTy);
22762276
NewCall = CondBuilder.CreateCall(Fn, {Op0, Op1, NumWords});
22772277
} else {
2278-
NewCall = CondBuilder.CreateMemMove(StoreBasePtr, SI->getAlignment(),
2279-
LoadBasePtr, LI->getAlignment(),
2280-
NumBytes);
2278+
NewCall = CondBuilder.CreateMemMove(
2279+
StoreBasePtr, SI->getAlign(), LoadBasePtr, LI->getAlign(), NumBytes);
22812280
}
22822281
} else {
2283-
NewCall = Builder.CreateMemCpy(StoreBasePtr, SI->getAlignment(),
2284-
LoadBasePtr, LI->getAlignment(),
2285-
NumBytes);
2282+
NewCall = Builder.CreateMemCpy(StoreBasePtr, SI->getAlign(), LoadBasePtr,
2283+
LI->getAlign(), NumBytes);
22862284
// Okay, the memcpy has been formed. Zap the original store and
22872285
// anything that feeds into it.
22882286
RecursivelyDeleteTriviallyDeadInstructions(SI, TLI);

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,15 +2901,14 @@ void FunctionStackPoisoner::copyArgsPassedByValToAllocas() {
29012901
for (Argument &Arg : F.args()) {
29022902
if (Arg.hasByValAttr()) {
29032903
Type *Ty = Arg.getType()->getPointerElementType();
2904-
unsigned Alignment = Arg.getParamAlignment();
2905-
if (Alignment == 0)
2906-
Alignment = DL.getABITypeAlignment(Ty);
2904+
const Align Alignment =
2905+
DL.getValueOrABITypeAlignment(Arg.getParamAlign(), Ty);
29072906

29082907
AllocaInst *AI = IRB.CreateAlloca(
29092908
Ty, nullptr,
29102909
(Arg.hasName() ? Arg.getName() : "Arg" + Twine(Arg.getArgNo())) +
29112910
".byval");
2912-
AI->setAlignment(Align(Alignment));
2911+
AI->setAlignment(Alignment);
29132912
Arg.replaceAllUsesWith(AI);
29142913

29152914
uint64_t AllocSize = DL.getTypeAllocSize(Ty);

0 commit comments

Comments
 (0)