Skip to content

Commit 1b2842b

Browse files
committed
[Alignment][NFC] CreateMemSet use MaybeAlign
Summary: 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: courbet Subscribers: arsenm, jvesely, nhaehnle, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D71213
1 parent 707e970 commit 1b2842b

File tree

14 files changed

+164
-159
lines changed

14 files changed

+164
-159
lines changed

clang/lib/CodeGen/CGAtomic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
350350
CGF.Builder.CreateMemSet(
351351
addr, llvm::ConstantInt::get(CGF.Int8Ty, 0),
352352
CGF.getContext().toCharUnitsFromBits(AtomicSizeInBits).getQuantity(),
353-
LVal.getAlignment().getQuantity());
353+
LVal.getAlignment().getAsAlign());
354354
return true;
355355
}
356356

clang/lib/CodeGen/CGBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
296296
llvm::CallInst *CreateMemSet(Address Dest, llvm::Value *Value,
297297
llvm::Value *Size, bool IsVolatile = false) {
298298
return CreateMemSet(Dest.getPointer(), Value, Size,
299-
Dest.getAlignment().getQuantity(), IsVolatile);
299+
Dest.getAlignment().getAsAlign(), IsVolatile);
300300
}
301301

302302
using CGBuilderBaseTy::CreatePreserveStructAccessIndex;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ int64_t clamp(int64_t Value, int64_t Low, int64_t High) {
4646
return std::min(High, std::max(Low, Value));
4747
}
4848

49-
static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size, unsigned AlignmentInBytes) {
49+
static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size,
50+
Align AlignmentInBytes) {
5051
ConstantInt *Byte;
5152
switch (CGF.getLangOpts().getTrivialAutoVarInit()) {
5253
case LangOptions::TrivialAutoVarInitKind::Uninitialized:
@@ -2359,12 +2360,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23592360
Value *Size = EmitScalarExpr(E->getArg(0));
23602361
const TargetInfo &TI = getContext().getTargetInfo();
23612362
// The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
2362-
unsigned SuitableAlignmentInBytes =
2363+
const Align SuitableAlignmentInBytes =
23632364
CGM.getContext()
23642365
.toCharUnitsFromBits(TI.getSuitableAlign())
2365-
.getQuantity();
2366+
.getAsAlign();
23662367
AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
2367-
AI->setAlignment(MaybeAlign(SuitableAlignmentInBytes));
2368+
AI->setAlignment(SuitableAlignmentInBytes);
23682369
initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
23692370
return RValue::get(AI);
23702371
}
@@ -2374,10 +2375,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
23742375
Value *AlignmentInBitsValue = EmitScalarExpr(E->getArg(1));
23752376
auto *AlignmentInBitsCI = cast<ConstantInt>(AlignmentInBitsValue);
23762377
unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue();
2377-
unsigned AlignmentInBytes =
2378-
CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getQuantity();
2378+
const Align AlignmentInBytes =
2379+
CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getAsAlign();
23792380
AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
2380-
AI->setAlignment(MaybeAlign(AlignmentInBytes));
2381+
AI->setAlignment(AlignmentInBytes);
23812382
initializeAlloca(*this, AI, Size, AlignmentInBytes);
23822383
return RValue::get(AI);
23832384
}
@@ -12335,7 +12336,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
1233512336
case X86::BI__stosb: {
1233612337
// We treat __stosb as a volatile memset - it may not generate "rep stosb"
1233712338
// instruction, but it will create a memset that won't be optimized away.
12338-
return Builder.CreateMemSet(Ops[0], Ops[1], Ops[2], 1, true);
12339+
return Builder.CreateMemSet(Ops[0], Ops[1], Ops[2], Align::None(), true);
1233912340
}
1234012341
case X86::BI__ud2:
1234112342
// llvm.trap makes a ud2a instruction on x86.

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,15 @@ class IRBuilderBase {
449449
/// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
450450
/// specified, it will be added to the instruction. Likewise with alias.scope
451451
/// and noalias tags.
452-
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
453-
bool isVolatile = false, MDNode *TBAATag = nullptr,
454-
MDNode *ScopeTag = nullptr,
452+
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size,
453+
MaybeAlign Align, bool isVolatile = false,
454+
MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
455455
MDNode *NoAliasTag = nullptr) {
456456
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
457457
TBAATag, ScopeTag, NoAliasTag);
458458
}
459459

460-
CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
460+
CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, MaybeAlign Align,
461461
bool isVolatile = false, MDNode *TBAATag = nullptr,
462462
MDNode *ScopeTag = nullptr,
463463
MDNode *NoAliasTag = nullptr);

llvm/lib/IR/Core.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3442,7 +3442,8 @@ LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
34423442
LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
34433443
LLVMValueRef Val, LLVMValueRef Len,
34443444
unsigned Align) {
3445-
return wrap(unwrap(B)->CreateMemSet(unwrap(Ptr), unwrap(Val), unwrap(Len), Align));
3445+
return wrap(unwrap(B)->CreateMemSet(unwrap(Ptr), unwrap(Val), unwrap(Len),
3446+
MaybeAlign(Align)));
34463447
}
34473448

34483449
LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,

llvm/lib/IR/IRBuilder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ static InvokeInst *createInvokeHelper(Function *Invokee, BasicBlock *NormalDest,
9696
return II;
9797
}
9898

99-
CallInst *IRBuilderBase::
100-
CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
101-
bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
102-
MDNode *NoAliasTag) {
99+
CallInst *IRBuilderBase::CreateMemSet(Value *Ptr, Value *Val, Value *Size,
100+
MaybeAlign Align, bool isVolatile,
101+
MDNode *TBAATag, MDNode *ScopeTag,
102+
MDNode *NoAliasTag) {
103103
Ptr = getCastedInt8PtrValue(Ptr);
104104
Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
105105
Type *Tys[] = { Ptr->getType(), Size->getType() };
@@ -108,8 +108,8 @@ CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
108108

109109
CallInst *CI = createCallHelper(TheFn, Ops, this);
110110

111-
if (Align > 0)
112-
cast<MemSetInst>(CI)->setDestAlignment(Align);
111+
if (Align)
112+
cast<MemSetInst>(CI)->setDestAlignment(Align->value());
113113

114114
// Set the TBAA info if present.
115115
if (TBAATag)

llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,9 @@ bool AMDGPUPromoteAlloca::handleAlloca(AllocaInst &I, bool SufficientLDS) {
898898
}
899899
case Intrinsic::memset: {
900900
MemSetInst *MemSet = cast<MemSetInst>(Intr);
901-
Builder.CreateMemSet(MemSet->getRawDest(), MemSet->getValue(),
902-
MemSet->getLength(), MemSet->getDestAlignment(),
903-
MemSet->isVolatile());
901+
Builder.CreateMemSet(
902+
MemSet->getRawDest(), MemSet->getValue(), MemSet->getLength(),
903+
MaybeAlign(MemSet->getDestAlignment()), MemSet->isVolatile());
904904
Intr->eraseFromParent();
905905
continue;
906906
}

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ bool HWAddressSanitizer::tagAlloca(IRBuilder<> &IRB, AllocaInst *AI,
789789
// llvm.memset right here into either a sequence of stores, or a call to
790790
// hwasan_tag_memory.
791791
if (ShadowSize)
792-
IRB.CreateMemSet(ShadowPtr, JustTag, ShadowSize, /*Align=*/1);
792+
IRB.CreateMemSet(ShadowPtr, JustTag, ShadowSize, Align::None());
793793
if (Size != AlignedSize) {
794794
IRB.CreateStore(
795795
ConstantInt::get(Int8Ty, Size % Mapping.getObjectAlignment()),

0 commit comments

Comments
 (0)