llvm.org GIT mirror llvm / 8b6d26e
[Alignment][NFC] Convert LoadInst 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/D69302 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375498 91177308-0d34-0410-b5e6-96231b3b80d8 Guillaume Chatelet 1 year, 1 day ago
10 changed file(s) with 39 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
183183 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
184184 BasicBlock *InsertAtEnd);
185185 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
186 unsigned Align, Instruction *InsertBefore = nullptr);
186 MaybeAlign Align, Instruction *InsertBefore = nullptr);
187187 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
188 unsigned Align, BasicBlock *InsertAtEnd);
188 MaybeAlign Align, BasicBlock *InsertAtEnd);
189189 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
190 unsigned Align, AtomicOrdering Order,
190 MaybeAlign Align, AtomicOrdering Order,
191191 SyncScope::ID SSID = SyncScope::System,
192192 Instruction *InsertBefore = nullptr);
193193 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
194 unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
194 MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,
195195 BasicBlock *InsertAtEnd);
196196
197197 // Deprecated [opaque pointer types]
210210 BasicBlock *InsertAtEnd)
211211 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
212212 isVolatile, InsertAtEnd) {}
213 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
213 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, MaybeAlign Align,
214214 Instruction *InsertBefore = nullptr)
215215 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
216216 isVolatile, Align, InsertBefore) {}
217 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
217 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, MaybeAlign Align,
218218 BasicBlock *InsertAtEnd)
219219 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
220220 isVolatile, Align, InsertAtEnd) {}
221 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
221 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, MaybeAlign Align,
222222 AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System,
223223 Instruction *InsertBefore = nullptr)
224224 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
225225 isVolatile, Align, Order, SSID, InsertBefore) {}
226 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
226 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, MaybeAlign Align,
227227 AtomicOrdering Order, SyncScope::ID SSID, BasicBlock *InsertAtEnd)
228228 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
229229 isVolatile, Align, Order, SSID, InsertAtEnd) {}
69686968 return Error(ExplicitTypeLoc,
69696969 "explicit pointee type doesn't match operand's pointee type");
69706970
6971 Inst = new LoadInst(Ty, Val, "", isVolatile,
6972 Alignment ? Alignment->value() : 0, Ordering, SSID);
6971 Inst = new LoadInst(Ty, Val, "", isVolatile, Alignment, Ordering, SSID);
69736972 return AteExtraComma ? InstExtraComma : InstNormal;
69746973 }
69756974
47914791 MaybeAlign Align;
47924792 if (Error Err = parseAlignmentValue(Record[OpNum], Align))
47934793 return Err;
4794 I = new LoadInst(Ty, Op, "", Record[OpNum + 1],
4795 Align ? Align->value() : 0);
4794 I = new LoadInst(Ty, Op, "", Record[OpNum + 1], Align);
47964795 InstructionList.push_back(I);
47974796 break;
47984797 }
48294828 MaybeAlign Align;
48304829 if (Error Err = parseAlignmentValue(Record[OpNum], Align))
48314830 return Err;
4832 I = new LoadInst(Ty, Op, "", Record[OpNum + 1],
4833 Align ? Align->value() : 0, Ordering, SSID);
4831 I = new LoadInst(Ty, Op, "", Record[OpNum + 1], Align, Ordering, SSID);
48344832 InstructionList.push_back(I);
48354833 break;
48364834 }
12951295
12961296 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
12971297 Instruction *InsertBef)
1298 : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertBef) {}
1298 : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/None, InsertBef) {}
12991299
13001300 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
13011301 BasicBlock *InsertAE)
1302 : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {}
1302 : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/None, InsertAE) {}
13031303
13041304 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1305 unsigned Align, Instruction *InsertBef)
1305 MaybeAlign Align, Instruction *InsertBef)
13061306 : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
13071307 SyncScope::System, InsertBef) {}
13081308
13091309 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1310 unsigned Align, BasicBlock *InsertAE)
1310 MaybeAlign Align, BasicBlock *InsertAE)
13111311 : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
13121312 SyncScope::System, InsertAE) {}
13131313
13141314 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1315 unsigned Align, AtomicOrdering Order,
1316 SyncScope::ID SSID, Instruction *InsertBef)
1315 MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,
1316 Instruction *InsertBef)
13171317 : UnaryInstruction(Ty, Load, Ptr, InsertBef) {
13181318 assert(Ty == cast(Ptr->getType())->getElementType());
13191319 setVolatile(isVolatile);
13241324 }
13251325
13261326 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1327 unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
1327 MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,
13281328 BasicBlock *InsertAE)
13291329 : UnaryInstruction(Ty, Load, Ptr, InsertAE) {
13301330 assert(Ty == cast(Ptr->getType())->getElementType());
13311331 setVolatile(isVolatile);
1332 setAlignment(MaybeAlign(Align));
1332 setAlignment(Align);
13331333 setAtomic(Order, SSID);
13341334 AssertOK();
13351335 setName(Name);
41394139
41404140 LoadInst *LoadInst::cloneImpl() const {
41414141 return new LoadInst(getType(), getOperand(0), Twine(), isVolatile(),
4142 getAlignment(), getOrdering(), getSyncScopeID());
4142 MaybeAlign(getAlignment()), getOrdering(),
4143 getSyncScopeID());
41434144 }
41444145
41454146 StoreInst *StoreInst::cloneImpl() const {
908908 // Replace the cmp X, 0 with a use of the bool value.
909909 // Sink the load to where the compare was, if atomic rules allow us to.
910910 Value *LV = new LoadInst(InitBool->getValueType(), InitBool,
911 InitBool->getName() + ".val", false, 0,
911 InitBool->getName() + ".val", false, None,
912912 LI->getOrdering(), LI->getSyncScopeID(),
913913 LI->isUnordered() ? (Instruction *)ICI : LI);
914914 InitBoolUsed = true;
17151715 assert(LI->getOperand(0) == GV && "Not a copy!");
17161716 // Insert a new load, to preserve the saved value.
17171717 StoreVal = new LoadInst(NewGV->getValueType(), NewGV,
1718 LI->getName() + ".b", false, 0,
1718 LI->getName() + ".b", false, None,
17191719 LI->getOrdering(), LI->getSyncScopeID(), LI);
17201720 } else {
17211721 assert((isa(StoredVal) || isa(StoredVal)) &&
17311731 } else {
17321732 // Change the load into a load of bool then a select.
17331733 LoadInst *LI = cast(UI);
1734 LoadInst *NLI =
1735 new LoadInst(NewGV->getValueType(), NewGV, LI->getName() + ".b",
1736 false, 0, LI->getOrdering(), LI->getSyncScopeID(), LI);
1734 LoadInst *NLI = new LoadInst(NewGV->getValueType(), NewGV,
1735 LI->getName() + ".b", false, None,
1736 LI->getOrdering(), LI->getSyncScopeID(), LI);
17371737 Instruction *NSI;
17381738 if (IsOneZero)
17391739 NSI = new ZExtInst(NLI, LI->getType(), "", LI);
23412341 // Turn PPC VSX loads into normal loads.
23422342 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
23432343 PointerType::getUnqual(II->getType()));
2344 return new LoadInst(II->getType(), Ptr, Twine(""), false, 1);
2344 return new LoadInst(II->getType(), Ptr, Twine(""), false, Align::None());
23452345 }
23462346 case Intrinsic::ppc_altivec_stvx:
23472347 case Intrinsic::ppc_altivec_stvxl:
541541 // visitLoadInst will propagate an alignment onto the load when TD is around,
542542 // and if TD isn't around, we can't handle the mixed case.
543543 bool isVolatile = FirstLI->isVolatile();
544 unsigned LoadAlignment = FirstLI->getAlignment();
544 MaybeAlign LoadAlignment(FirstLI->getAlignment());
545545 unsigned LoadAddrSpace = FirstLI->getPointerAddressSpace();
546546
547547 // We can't sink the load if the loaded value could be modified between the
573573
574574 // If some of the loads have an alignment specified but not all of them,
575575 // we can't do the transformation.
576 if ((LoadAlignment != 0) != (LI->getAlignment() != 0))
577 return nullptr;
578
579 LoadAlignment = std::min(LoadAlignment, LI->getAlignment());
576 if ((LoadAlignment.hasValue()) != (LI->getAlignment() != 0))
577 return nullptr;
578
579 LoadAlignment = std::min(LoadAlignment, MaybeAlign(LI->getAlignment()));
580580
581581 // If the PHI is of volatile loads and the load block has multiple
582582 // successors, sinking it would remove a load of the volatile value from
12401240 BasicBlock *UnavailablePred = PredLoad.first;
12411241 Value *LoadPtr = PredLoad.second;
12421242
1243 auto *NewLoad =
1244 new LoadInst(LI->getType(), LoadPtr, LI->getName() + ".pre",
1245 LI->isVolatile(), LI->getAlignment(), LI->getOrdering(),
1246 LI->getSyncScopeID(), UnavailablePred->getTerminator());
1243 auto *NewLoad = new LoadInst(
1244 LI->getType(), LoadPtr, LI->getName() + ".pre", LI->isVolatile(),
1245 MaybeAlign(LI->getAlignment()), LI->getOrdering(), LI->getSyncScopeID(),
1246 UnavailablePred->getTerminator());
12471247 NewLoad->setDebugLoc(LI->getDebugLoc());
12481248
12491249 // Transfer the old load's AA tags to the new load.
14701470 "Can't handle critical edge here!");
14711471 LoadInst *NewVal = new LoadInst(
14721472 LoadI->getType(), LoadedPtr->DoPHITranslation(LoadBB, UnavailablePred),
1473 LoadI->getName() + ".pr", false, LoadI->getAlignment(),
1473 LoadI->getName() + ".pr", false, MaybeAlign(LoadI->getAlignment()),
14741474 LoadI->getOrdering(), LoadI->getSyncScopeID(),
14751475 UnavailablePred->getTerminator());
14761476 NewVal->setDebugLoc(LoadI->getDebugLoc());
434434 PH->getTerminator());
435435 Value *Initial = new LoadInst(
436436 Cand.Load->getType(), InitialPtr, "load_initial",
437 /* isVolatile */ false, Cand.Load->getAlignment(), PH->getTerminator());
437 /* isVolatile */ false, MaybeAlign(Cand.Load->getAlignment()),
438 PH->getTerminator());
438439
439440 PHINode *PHI = PHINode::Create(Initial->getType(), 2, "store_forwarded",
440441 &L->getHeader()->front());