@@ -168,13 +168,14 @@ static bool visitStoreInst(StoreInst *SI, Function &F, const DataLayout &DL,
168168class PointerPromoter : public InstVisitor <PointerPromoter, Value *> {
169169 Type *m_ty;
170170 SmallPtrSetImpl<Instruction *> &m_toRemove;
171- DenseMap<Value*, Value*> &m_toReplace;
171+ DenseMap<Value *, Value *> &m_toReplace;
172172 // -- to break cycles in PHINodes
173173 SmallPtrSet<Instruction *, 16 > m_visited;
174174
175175public:
176- PointerPromoter (SmallPtrSetImpl<Instruction *> &toRemove, DenseMap<Value*, Value*> &toReplace)
177- : m_ty(nullptr ), m_toRemove(toRemove), m_toReplace(toReplace) {}
176+ PointerPromoter (SmallPtrSetImpl<Instruction *> &toRemove,
177+ DenseMap<Value *, Value *> &toReplace)
178+ : m_ty(nullptr ), m_toRemove(toRemove), m_toReplace(toReplace) {}
178179
179180 Value *visitInstruction (Instruction &I) { return nullptr ; }
180181
@@ -227,8 +228,9 @@ class PointerPromoter : public InstVisitor<PointerPromoter, Value *> {
227228 IRBuilder<> IRB (&I);
228229
229230 ptr = IRB.CreateBitCast (ptr, IRB.getInt8PtrTy ());
230- auto *gep = IRB.CreateGEP (ptr->getType ()->getScalarType ()->getPointerElementType (),
231- ptr, {I.getOperand (1 )});
231+ auto *gep =
232+ IRB.CreateGEP (ptr->getType ()->getScalarType ()->getPointerElementType (),
233+ ptr, I.getOperand (1 ));
232234 return IRB.CreateBitCast (gep, m_ty);
233235 }
234236
@@ -270,7 +272,7 @@ class PointerPromoter : public InstVisitor<PointerPromoter, Value *> {
270272 m_toRemove.insert (SI);
271273 } else if (isa<IntToPtrInst>(u)) {
272274 /* skip */ ;
273- } else {
275+ } else {
274276 // -- if there is an interesting user, schedule it to be replaced
275277 if (!p2i) {
276278 IRB.SetInsertPoint (&I);
@@ -303,12 +305,11 @@ class PointerPromoter : public InstVisitor<PointerPromoter, Value *> {
303305 }
304306};
305307
306- static bool
307- visitIntToPtrInst (IntToPtrInst *I2P, Function &F, const DataLayout &DL,
308- DominatorTree &DT,
309- SmallDenseMap<PHINode *, PHINode *> &NewPhis,
310- SmallPtrSetImpl<Instruction *> &MaybeUnusedInsts,
311- DenseMap<Value*, Value*> &RenameMap) {
308+ static bool visitIntToPtrInst (IntToPtrInst *I2P, Function &F,
309+ const DataLayout &DL, DominatorTree &DT,
310+ SmallDenseMap<PHINode *, PHINode *> &NewPhis,
311+ SmallPtrSetImpl<Instruction *> &MaybeUnusedInsts,
312+ DenseMap<Value *, Value *> &RenameMap) {
312313 assert (I2P);
313314
314315 auto *IntVal = I2P->getOperand (0 );
@@ -413,7 +414,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
413414 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree ();
414415 SmallPtrSet<StoreInst *, 8 > StoresToErase;
415416 SmallPtrSet<Instruction *, 16 > MaybeUnusedInsts;
416- DenseMap<Value*, Value*> RenameMap;
417+ DenseMap<Value *, Value *> RenameMap;
417418 SmallDenseMap<PHINode *, PHINode *> NewPhis;
418419
419420 for (auto &BB : F) {
@@ -429,7 +430,8 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
429430 }
430431
431432 if (auto *I2P = dyn_cast<IntToPtrInst>(&I)) {
432- Changed |= visitIntToPtrInst (I2P, F, DL, DT, NewPhis, MaybeUnusedInsts, RenameMap);
433+ Changed |= visitIntToPtrInst (I2P, F, DL, DT, NewPhis, MaybeUnusedInsts,
434+ RenameMap);
433435 continue ;
434436 }
435437 }
@@ -442,7 +444,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
442444 llvm::make_filter_range (MaybeUnusedInsts, [](Instruction *I) {
443445 return isInstructionTriviallyDead (I);
444446 }));
445-
447+
446448 // TODO: RecursivelyDeleteTriviallyDeadInstructions takes a vector of
447449 // WeakTrackingVH since LLVM 11, which implies that `MaybeUnusedInsts` should
448450 // be a vector of WeakTrackingVH as well. See comment:
@@ -451,11 +453,10 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
451453 // removed before this call. So it should be safe to keep its original type
452454 // and map it to WeakTrackingVH as the following code does.
453455 SmallVector<WeakTrackingVH, 16 > TriviallyDeadHandles;
454- for (auto i : TriviallyDeadInstructions)
455- TriviallyDeadHandles.emplace_back (WeakTrackingVH (i));
456-
457- RecursivelyDeleteTriviallyDeadInstructions (TriviallyDeadHandles);
456+ for (auto i : TriviallyDeadInstructions)
457+ TriviallyDeadHandles.emplace_back (WeakTrackingVH (i));
458458
459+ RecursivelyDeleteTriviallyDeadInstructions (TriviallyDeadHandles);
459460
460461 for (auto kv : RenameMap) {
461462 kv.first ->replaceAllUsesWith (kv.second );
@@ -464,9 +465,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) {
464465 DOG (llvm::errs () << " \n ~~~~~~~ End of RP2I on " << F.getName () << " ~~~~~ \n " ;
465466 llvm::errs ().flush ());
466467
467- if (Changed) {
468- assert (!llvm::verifyFunction (F, &llvm::errs ()));
469- }
468+ if (Changed) { assert (!llvm::verifyFunction (F, &llvm::errs ())); }
470469
471470 // llvm::errs() << F << "\n";
472471 return Changed;
0 commit comments