mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
RemoveExtraValues: simplify the pass
Simplification includes dropping dependencies onto `FunctionMetadataCachePass` and `LoadModelWrapperPass`, as well as removing "StructName" logic outright.
This commit is contained in:
committed by
Pietro Fezzardi
parent
5da851fcd5
commit
6adee367ee
@@ -2,28 +2,14 @@
|
||||
// Copyright rev.ng Labs Srl. See LICENSE.md for details.
|
||||
//
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/Type.h"
|
||||
#include "llvm/Transforms/Utils/Local.h"
|
||||
|
||||
#include "revng/EarlyFunctionAnalysis/FunctionMetadataCache.h"
|
||||
#include "revng/Model/IRHelpers.h"
|
||||
#include "revng/Model/LoadModelPass.h"
|
||||
#include "revng/Support/Assert.h"
|
||||
#include "revng/Support/FunctionTags.h"
|
||||
#include "revng/Support/IRHelpers.h"
|
||||
#include "revng/Support/OpaqueFunctionsPool.h"
|
||||
|
||||
#include "revng-c/RemoveExtractValues/RemoveExtractValuesPass.h"
|
||||
#include "revng-c/Support/FunctionTags.h"
|
||||
#include "revng-c/Support/PTMLC.h"
|
||||
#include "revng-c/TypeNames/LLVMTypeNames.h"
|
||||
#include "revng-c/TypeNames/ModelTypeNames.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
@@ -37,8 +23,6 @@ static Reg X("remove-extractvalues",
|
||||
|
||||
void RemoveExtractValues::getAnalysisUsage(llvm::AnalysisUsage &AU) const {
|
||||
AU.setPreservesAll();
|
||||
AU.addRequired<LoadModelWrapperPass>();
|
||||
AU.addRequired<FunctionMetadataCachePass>();
|
||||
}
|
||||
|
||||
bool RemoveExtractValues::runOnFunction(llvm::Function &F) {
|
||||
@@ -54,9 +38,6 @@ bool RemoveExtractValues::runOnFunction(llvm::Function &F) {
|
||||
if (ToReplace.empty())
|
||||
return false;
|
||||
|
||||
auto &Cache = getAnalysis<FunctionMetadataCachePass>().get();
|
||||
auto &Model = getAnalysis<LoadModelWrapperPass>().get().getReadOnlyModel();
|
||||
|
||||
// Create a pool of functions with the same behavior: we will need a different
|
||||
// function for each different struct
|
||||
OpaqueFunctionsPool<TypePair> OpaqueEVPool(F.getParent(),
|
||||
@@ -86,28 +67,6 @@ bool RemoveExtractValues::runOnFunction(llvm::Function &F) {
|
||||
// Emit a call to the new function
|
||||
CallInst *InjectedCall = Builder.CreateCall(ExtractValueFunction,
|
||||
ArgValues);
|
||||
using PTMLCBuilder = ptml::PTMLCBuilder;
|
||||
PTMLCBuilder B(/*GeneratePlainC*/ true);
|
||||
std::string StructName;
|
||||
revng_assert(isa<CallInst>(I->getAggregateOperand()));
|
||||
auto *CallReturningAggregate = cast<CallInst>(I->getAggregateOperand());
|
||||
if (isCallToIsolatedFunction(CallReturningAggregate)) {
|
||||
auto Prototype = Cache.getCallSitePrototype(*Model,
|
||||
CallReturningAggregate);
|
||||
revng_assert(Prototype.get());
|
||||
StructName = std::string(getReturnTypeName(*Prototype.get(), B, false));
|
||||
} else {
|
||||
// If it is not a isolated function, it must be a helper function.
|
||||
auto CalledFunction = CallReturningAggregate->getCalledFunction();
|
||||
revng_assert(CalledFunction);
|
||||
StructName = getReturnTypeLocationDefinition(CalledFunction, B);
|
||||
}
|
||||
|
||||
auto AggregateType = I->getAggregateOperand()->getType();
|
||||
auto *TheStructType = llvm::cast<llvm::StructType>(AggregateType);
|
||||
if (not TheStructType->isLiteral())
|
||||
TheStructType->setName(StructName);
|
||||
|
||||
I->replaceAllUsesWith(InjectedCall);
|
||||
InjectedCall->copyMetadata(*I);
|
||||
llvm::RecursivelyDeleteTriviallyDeadInstructions(I);
|
||||
|
||||
Reference in New Issue
Block a user