Files
revng-revng/lib/BasicAnalyses/EmptyNewPC.cpp
T
Alessandro Di Federico 2bd8c468bc Introduce empty-newpc pass
`empty-newpc` is a simple pass suppose to provide an empty body for
the `newpc` function, allowing further optimization pass to take out
all its calls.
2019-03-06 10:31:23 +01:00

30 lines
860 B
C++

/// \file EmptyNewPC.cpp
/// \brief A simple pass to given an empty body to the `newpc` function so that
/// it can be optimized away.
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
// LLVM includes
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
// Local libraries includes
#include "revng/BasicAnalyses/EmptyNewPC.h"
#include "revng/Support/IRHelpers.h"
using namespace llvm;
char EmptyNewPC::ID = 0;
using Register = RegisterPass<EmptyNewPC>;
static Register X("empty-newpc", "Create an empty newpc function", true, true);
bool EmptyNewPC::runOnModule(llvm::Module &M) {
LLVMContext &Context = getContext(&M);
Function *NewPCFunction = M.getFunction("newpc");
NewPCFunction->deleteBody();
ReturnInst::Create(Context, BasicBlock::Create(Context, "", NewPCFunction));
return false;
}