Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 31ec98d

Browse files
committed
[Alignment][NFC] Convert StoreInst to 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: hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69303 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375499 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8b6d26e commit 31ec98d

File tree

8 files changed

+39
-46
lines changed

8 files changed

+39
-46
lines changed

Diff for: include/llvm/IR/Instructions.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,15 @@ class StoreInst : public Instruction {
337337
StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
338338
Instruction *InsertBefore = nullptr);
339339
StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
340-
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
341-
unsigned Align, Instruction *InsertBefore = nullptr);
342-
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
343-
unsigned Align, BasicBlock *InsertAtEnd);
344-
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
345-
unsigned Align, AtomicOrdering Order,
346-
SyncScope::ID SSID = SyncScope::System,
340+
StoreInst(Value *Val, Value *Ptr, bool isVolatile, MaybeAlign Align,
347341
Instruction *InsertBefore = nullptr);
348-
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
349-
unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
342+
StoreInst(Value *Val, Value *Ptr, bool isVolatile, MaybeAlign Align,
350343
BasicBlock *InsertAtEnd);
344+
StoreInst(Value *Val, Value *Ptr, bool isVolatile, MaybeAlign Align,
345+
AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System,
346+
Instruction *InsertBefore = nullptr);
347+
StoreInst(Value *Val, Value *Ptr, bool isVolatile, MaybeAlign Align,
348+
AtomicOrdering Order, SyncScope::ID SSID, BasicBlock *InsertAtEnd);
351349

352350
// allocate space for exactly two operands
353351
void *operator new(size_t s) {

Diff for: lib/AsmParser/LLParser.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -7016,8 +7016,7 @@ int LLParser::ParseStore(Instruction *&Inst, PerFunctionState &PFS) {
70167016
Ordering == AtomicOrdering::AcquireRelease)
70177017
return Error(Loc, "atomic store cannot use Acquire ordering");
70187018

7019-
Inst = new StoreInst(Val, Ptr, isVolatile, Alignment ? Alignment->value() : 0,
7020-
Ordering, SSID);
7019+
Inst = new StoreInst(Val, Ptr, isVolatile, Alignment, Ordering, SSID);
70217020
return AteExtraComma ? InstExtraComma : InstNormal;
70227021
}
70237022

Diff for: lib/Bitcode/Reader/BitcodeReader.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -4851,8 +4851,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
48514851
MaybeAlign Align;
48524852
if (Error Err = parseAlignmentValue(Record[OpNum], Align))
48534853
return Err;
4854-
I = new StoreInst(Val, Ptr, Record[OpNum + 1],
4855-
Align ? Align->value() : 0);
4854+
I = new StoreInst(Val, Ptr, Record[OpNum + 1], Align);
48564855
InstructionList.push_back(I);
48574856
break;
48584857
}
@@ -4885,8 +4884,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
48854884
MaybeAlign Align;
48864885
if (Error Err = parseAlignmentValue(Record[OpNum], Align))
48874886
return Err;
4888-
I = new StoreInst(Val, Ptr, Record[OpNum + 1], Align ? Align->value() : 0,
4889-
Ordering, SSID);
4887+
I = new StoreInst(Val, Ptr, Record[OpNum + 1], Align, Ordering, SSID);
48904888
InstructionList.push_back(I);
48914889
break;
48924890
}

Diff for: lib/IR/Instructions.cpp

+18-22
Original file line numberDiff line numberDiff line change
@@ -1371,50 +1371,46 @@ StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)
13711371

13721372
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
13731373
Instruction *InsertBefore)
1374-
: StoreInst(val, addr, isVolatile, /*Align=*/0, InsertBefore) {}
1374+
: StoreInst(val, addr, isVolatile, /*Align=*/None, InsertBefore) {}
13751375

13761376
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
13771377
BasicBlock *InsertAtEnd)
1378-
: StoreInst(val, addr, isVolatile, /*Align=*/0, InsertAtEnd) {}
1378+
: StoreInst(val, addr, isVolatile, /*Align=*/None, InsertAtEnd) {}
13791379

1380-
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, unsigned Align,
1380+
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
13811381
Instruction *InsertBefore)
13821382
: StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
13831383
SyncScope::System, InsertBefore) {}
13841384

1385-
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, unsigned Align,
1385+
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
13861386
BasicBlock *InsertAtEnd)
13871387
: StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
13881388
SyncScope::System, InsertAtEnd) {}
13891389

1390-
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
1391-
unsigned Align, AtomicOrdering Order,
1392-
SyncScope::ID SSID,
1390+
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
1391+
AtomicOrdering Order, SyncScope::ID SSID,
13931392
Instruction *InsertBefore)
1394-
: Instruction(Type::getVoidTy(val->getContext()), Store,
1395-
OperandTraits<StoreInst>::op_begin(this),
1396-
OperandTraits<StoreInst>::operands(this),
1397-
InsertBefore) {
1393+
: Instruction(Type::getVoidTy(val->getContext()), Store,
1394+
OperandTraits<StoreInst>::op_begin(this),
1395+
OperandTraits<StoreInst>::operands(this), InsertBefore) {
13981396
Op<0>() = val;
13991397
Op<1>() = addr;
14001398
setVolatile(isVolatile);
1401-
setAlignment(MaybeAlign(Align));
1399+
setAlignment(Align);
14021400
setAtomic(Order, SSID);
14031401
AssertOK();
14041402
}
14051403

1406-
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
1407-
unsigned Align, AtomicOrdering Order,
1408-
SyncScope::ID SSID,
1404+
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,
1405+
AtomicOrdering Order, SyncScope::ID SSID,
14091406
BasicBlock *InsertAtEnd)
1410-
: Instruction(Type::getVoidTy(val->getContext()), Store,
1411-
OperandTraits<StoreInst>::op_begin(this),
1412-
OperandTraits<StoreInst>::operands(this),
1413-
InsertAtEnd) {
1407+
: Instruction(Type::getVoidTy(val->getContext()), Store,
1408+
OperandTraits<StoreInst>::op_begin(this),
1409+
OperandTraits<StoreInst>::operands(this), InsertAtEnd) {
14141410
Op<0>() = val;
14151411
Op<1>() = addr;
14161412
setVolatile(isVolatile);
1417-
setAlignment(MaybeAlign(Align));
1413+
setAlignment(Align);
14181414
setAtomic(Order, SSID);
14191415
AssertOK();
14201416
}
@@ -4146,8 +4142,8 @@ LoadInst *LoadInst::cloneImpl() const {
41464142

41474143
StoreInst *StoreInst::cloneImpl() const {
41484144
return new StoreInst(getOperand(0), getOperand(1), isVolatile(),
4149-
getAlignment(), getOrdering(), getSyncScopeID());
4150-
4145+
MaybeAlign(getAlignment()), getOrdering(),
4146+
getSyncScopeID());
41514147
}
41524148

41534149
AtomicCmpXchgInst *AtomicCmpXchgInst::cloneImpl() const {

Diff for: lib/Transforms/IPO/GlobalOpt.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,8 @@ OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, CallInst *CI, Type *AllocTy,
891891
while (!GV->use_empty()) {
892892
if (StoreInst *SI = dyn_cast<StoreInst>(GV->user_back())) {
893893
// The global is initialized when the store to it occurs.
894-
new StoreInst(ConstantInt::getTrue(GV->getContext()), InitBool, false, 0,
895-
SI->getOrdering(), SI->getSyncScopeID(), SI);
894+
new StoreInst(ConstantInt::getTrue(GV->getContext()), InitBool, false,
895+
None, SI->getOrdering(), SI->getSyncScopeID(), SI);
896896
SI->eraseFromParent();
897897
continue;
898898
}
@@ -1726,7 +1726,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
17261726
}
17271727
}
17281728
StoreInst *NSI =
1729-
new StoreInst(StoreVal, NewGV, false, 0, SI->getOrdering(),
1729+
new StoreInst(StoreVal, NewGV, false, None, SI->getOrdering(),
17301730
SI->getSyncScopeID(), SI);
17311731
NSI->setDebugLoc(SI->getDebugLoc());
17321732
} else {

Diff for: lib/Transforms/InstCombine/InstCombineCalls.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,8 @@ Instruction *InstCombiner::simplifyMaskedStore(IntrinsicInst &II) {
10851085
// If the mask is all ones, this is a plain vector store of the 1st argument.
10861086
if (ConstMask->isAllOnesValue()) {
10871087
Value *StorePtr = II.getArgOperand(1);
1088-
unsigned Alignment = cast<ConstantInt>(II.getArgOperand(2))->getZExtValue();
1088+
MaybeAlign Alignment(
1089+
cast<ConstantInt>(II.getArgOperand(2))->getZExtValue());
10891090
return new StoreInst(II.getArgOperand(0), StorePtr, false, Alignment);
10901091
}
10911092

@@ -2360,7 +2361,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
23602361
// Turn PPC VSX stores into normal stores.
23612362
Type *OpPtrTy = PointerType::getUnqual(II->getArgOperand(0)->getType());
23622363
Value *Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2363-
return new StoreInst(II->getArgOperand(0), Ptr, false, 1);
2364+
return new StoreInst(II->getArgOperand(0), Ptr, false, Align::None());
23642365
}
23652366
case Intrinsic::ppc_qpx_qvlfs:
23662367
// Turn PPC QPX qvlfs -> load if the pointer is known aligned.

Diff for: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,8 @@ bool InstCombiner::mergeStoreIntoSuccessor(StoreInst &SI) {
15791579

15801580
// Advance to a place where it is safe to insert the new store and insert it.
15811581
BBI = DestBB->getFirstInsertionPt();
1582-
StoreInst *NewSI = new StoreInst(MergedVal, SI.getOperand(1),
1583-
SI.isVolatile(), SI.getAlignment(),
1582+
StoreInst *NewSI = new StoreInst(MergedVal, SI.getOperand(1), SI.isVolatile(),
1583+
MaybeAlign(SI.getAlignment()),
15841584
SI.getOrdering(), SI.getSyncScopeID());
15851585
InsertNewInstBefore(NewSI, *BBI);
15861586
NewSI->setDebugLoc(MergedLoc);

Diff for: lib/Transforms/Scalar/DeadStoreElimination.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,9 @@ static bool eliminateDeadStores(BasicBlock &BB, AliasAnalysis *AA,
12541254

12551255
auto *SI = new StoreInst(
12561256
ConstantInt::get(Earlier->getValueOperand()->getType(), Merged),
1257-
Earlier->getPointerOperand(), false, Earlier->getAlignment(),
1258-
Earlier->getOrdering(), Earlier->getSyncScopeID(), DepWrite);
1257+
Earlier->getPointerOperand(), false,
1258+
MaybeAlign(Earlier->getAlignment()), Earlier->getOrdering(),
1259+
Earlier->getSyncScopeID(), DepWrite);
12591260

12601261
unsigned MDToKeep[] = {LLVMContext::MD_dbg, LLVMContext::MD_tbaa,
12611262
LLVMContext::MD_alias_scope,

0 commit comments

Comments
 (0)