diff --git a/lib/seadsa/Graph.cc b/lib/seadsa/Graph.cc index 2d9ded30..d3fede2e 100644 --- a/lib/seadsa/Graph.cc +++ b/lib/seadsa/Graph.cc @@ -219,7 +219,8 @@ void Node::addAccessedType(unsigned off, llvm::Type *type) { tmp.push_back({o + i * sz, elementTy}); workList.insert(workList.end(), tmp.rbegin(), tmp.rend()); - } else if (const FixedVectorType *vty = dyn_cast(t)) { + } else if (const FixedVectorType *vty = + dyn_cast(t)) { uint64_t sz = vty->getElementType()->getPrimitiveSizeInBits() / 8; WorkList tmp; const size_t numElements(vty->getNumElements()); @@ -398,9 +399,8 @@ const Cell &Node::getLink(Field _f) const { assert(!FieldType::IsNotTypeAware()); assert(!f.hasOmniType()); Field omni = f.mkOmniField(); - if (m_links.count(omni)) return *m_links.at(omni); - - assert(false); // unreachable + assert(m_links.count(omni)); + return *m_links.at(omni); } void Node::setLink(const Field _f, const Cell &c) { @@ -463,7 +463,8 @@ void Node::addLink(Field _f, const Cell &c) { m_links = std::move(new_links); // -- recreate links that have been removed by adding them through a cell - // -- pointing to the current node. The cell takes care of resolving forwarding + // -- pointing to the current node. The cell takes care of resolving + // forwarding Cell cc(*this, 0); for (auto &kv : saved_links) { cc.addLink(kv.first, *kv.second); diff --git a/lib/seadsa/RemovePtrToInt.cc b/lib/seadsa/RemovePtrToInt.cc index f99e718e..f00fe0aa 100644 --- a/lib/seadsa/RemovePtrToInt.cc +++ b/lib/seadsa/RemovePtrToInt.cc @@ -168,13 +168,14 @@ static bool visitStoreInst(StoreInst *SI, Function &F, const DataLayout &DL, class PointerPromoter : public InstVisitor { Type *m_ty; SmallPtrSetImpl &m_toRemove; - DenseMap &m_toReplace; + DenseMap &m_toReplace; // -- to break cycles in PHINodes SmallPtrSet m_visited; public: - PointerPromoter(SmallPtrSetImpl &toRemove, DenseMap &toReplace) - : m_ty(nullptr), m_toRemove(toRemove), m_toReplace(toReplace) {} + PointerPromoter(SmallPtrSetImpl &toRemove, + DenseMap &toReplace) + : m_ty(nullptr), m_toRemove(toRemove), m_toReplace(toReplace) {} Value *visitInstruction(Instruction &I) { return nullptr; } @@ -227,8 +228,9 @@ class PointerPromoter : public InstVisitor { IRBuilder<> IRB(&I); ptr = IRB.CreateBitCast(ptr, IRB.getInt8PtrTy()); - auto *gep = IRB.CreateGEP(ptr->getType()->getScalarType()->getPointerElementType(), - ptr, {I.getOperand(1)}); + auto *gep = + IRB.CreateGEP(ptr->getType()->getScalarType()->getPointerElementType(), + ptr, I.getOperand(1)); return IRB.CreateBitCast(gep, m_ty); } @@ -270,7 +272,7 @@ class PointerPromoter : public InstVisitor { m_toRemove.insert(SI); } else if (isa(u)) { /* skip */; - } else { + } else { // -- if there is an interesting user, schedule it to be replaced if (!p2i) { IRB.SetInsertPoint(&I); @@ -303,12 +305,11 @@ class PointerPromoter : public InstVisitor { } }; -static bool -visitIntToPtrInst(IntToPtrInst *I2P, Function &F, const DataLayout &DL, - DominatorTree &DT, - SmallDenseMap &NewPhis, - SmallPtrSetImpl &MaybeUnusedInsts, - DenseMap &RenameMap) { +static bool visitIntToPtrInst(IntToPtrInst *I2P, Function &F, + const DataLayout &DL, DominatorTree &DT, + SmallDenseMap &NewPhis, + SmallPtrSetImpl &MaybeUnusedInsts, + DenseMap &RenameMap) { assert(I2P); auto *IntVal = I2P->getOperand(0); @@ -413,7 +414,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) { auto &DT = getAnalysis().getDomTree(); SmallPtrSet StoresToErase; SmallPtrSet MaybeUnusedInsts; - DenseMap RenameMap; + DenseMap RenameMap; SmallDenseMap NewPhis; for (auto &BB : F) { @@ -429,7 +430,8 @@ bool RemovePtrToInt::runOnFunction(Function &F) { } if (auto *I2P = dyn_cast(&I)) { - Changed |= visitIntToPtrInst(I2P, F, DL, DT, NewPhis, MaybeUnusedInsts, RenameMap); + Changed |= visitIntToPtrInst(I2P, F, DL, DT, NewPhis, MaybeUnusedInsts, + RenameMap); continue; } } @@ -442,7 +444,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) { llvm::make_filter_range(MaybeUnusedInsts, [](Instruction *I) { return isInstructionTriviallyDead(I); })); - + // TODO: RecursivelyDeleteTriviallyDeadInstructions takes a vector of // WeakTrackingVH since LLVM 11, which implies that `MaybeUnusedInsts` should // be a vector of WeakTrackingVH as well. See comment: @@ -451,11 +453,10 @@ bool RemovePtrToInt::runOnFunction(Function &F) { // removed before this call. So it should be safe to keep its original type // and map it to WeakTrackingVH as the following code does. SmallVector TriviallyDeadHandles; - for (auto i : TriviallyDeadInstructions) - TriviallyDeadHandles.emplace_back(WeakTrackingVH(i)); - - RecursivelyDeleteTriviallyDeadInstructions(TriviallyDeadHandles); + for (auto i : TriviallyDeadInstructions) + TriviallyDeadHandles.emplace_back(WeakTrackingVH(i)); + RecursivelyDeleteTriviallyDeadInstructions(TriviallyDeadHandles); for (auto kv : RenameMap) { kv.first->replaceAllUsesWith(kv.second); @@ -464,9 +465,7 @@ bool RemovePtrToInt::runOnFunction(Function &F) { DOG(llvm::errs() << "\n~~~~~~~ End of RP2I on " << F.getName() << " ~~~~~ \n"; llvm::errs().flush()); - if (Changed) { - assert(!llvm::verifyFunction(F, &llvm::errs())); - } + if (Changed) { assert(!llvm::verifyFunction(F, &llvm::errs())); } // llvm::errs() << F << "\n"; return Changed;