Files
revng-revng/lib/PromoteStackPointer/CleanupStackSizeMarkersPass.cpp
Alessandro Di Federico f8bd4c3bac Move around some files in preparation for libtcg
* Make the following private headers public:
  * Lift/CPUStateAccessAnalysisPass.h
  * Lift/CSVOffsets.h
  * Lift/PTCDump.h
  * Lift/VariableManager.h
* Move from revngSupport to revngLift:
  * IRAnnotators.{h,cpp}
  * SelfReferencingDbgAnnotationWriter.{h,cpp}
* Move from revngSupport to revngModel:
  * FunctionTags.{h,cpp}
  * ProgramCounterHandler.{h,cpp}
* Move from revngSupport to revngRecompile:
  * OriginalAssemblyAnnotationWriter.{h,cpp}
2025-10-24 15:34:11 +02:00

57 lines
1.5 KiB
C++

//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/IR/Instructions.h"
#include "revng/Model/FunctionTags.h"
#include "revng/PromoteStackPointer/CleanupStackSizeMarkersPass.h"
#include "revng/PromoteStackPointer/InstrumentStackAccessesPass.h"
#include "revng/Support/IRHelpers.h"
using namespace llvm;
bool CleanupStackSizeMarkersPass::runOnModule(Module &M) {
SmallVector<CallInst *, 16> CallsToDelete;
SmallVector<Function *, 16> FunctionsToDelete;
for (Function &F : FunctionTags::StackOffsetMarker.functions(&M)) {
for (User *U : F.users()) {
auto *Call = cast<CallInst>(U);
Call->replaceAllUsesWith(Call->getArgOperand(0));
CallsToDelete.push_back(Call);
}
FunctionsToDelete.push_back(&F);
}
if (auto *SSACS = getIRHelper("stack_size_at_call_site", M)) {
for (User *U : SSACS->users()) {
auto *Call = cast<CallInst>(U);
CallsToDelete.push_back(Call);
}
FunctionsToDelete.push_back(SSACS);
}
for (CallInst *Call : CallsToDelete) {
eraseFromParent(Call);
}
for (Function *F : FunctionsToDelete) {
eraseFromParent(F);
}
return CallsToDelete.size() + FunctionsToDelete.size() != 0;
}
void CleanupStackSizeMarkersPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
}
char CleanupStackSizeMarkersPass::ID = 0;
using RegisterCSSM = RegisterPass<CleanupStackSizeMarkersPass>;
static RegisterCSSM R("cleanup-stack-size-markers",
"Cleanup Stack Size Markers Pass");