Files
revng-revng/lib/PromoteStackPointer/CleanupStackSizeMarkersPass.cpp
T
Giacomo Vercesi ab125b35b0 Fix License headers
Change company name to "rev.ng Labs Srl" in all license headers
to reflect changed company name and legal status
Add missing license headers to files that didn't have one
2022-04-19 12:17:59 +02:00

57 lines
1.4 KiB
C++

//
// Copyright (c) rev.ng Labs Srl. See LICENSE.md for details.
//
#include "llvm/IR/Instructions.h"
#include "revng/Support/IRHelpers.h"
#include "revng-c/PromoteStackPointer/CleanupStackSizeMarkersPass.h"
#include "revng-c/PromoteStackPointer/InstrumentStackAccessesPass.h"
using namespace llvm;
bool CleanupStackSizeMarkersPass::runOnModule(Module &M) {
SmallVector<CallInst *, 16> CallsToDelete;
SmallVector<Function *, 16> FunctionsToDelete;
for (Function &F : 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 = M.getFunction("stack_size_at_call_site")) {
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");