diff --git a/lib/RemoveExtractValues/RemoveExtractValuesPass.cpp b/lib/RemoveExtractValues/RemoveExtractValuesPass.cpp index 3fedd9632..534d11501 100644 --- a/lib/RemoveExtractValues/RemoveExtractValuesPass.cpp +++ b/lib/RemoveExtractValues/RemoveExtractValuesPass.cpp @@ -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(); - AU.addRequired(); } bool RemoveExtractValues::runOnFunction(llvm::Function &F) { @@ -54,9 +38,6 @@ bool RemoveExtractValues::runOnFunction(llvm::Function &F) { if (ToReplace.empty()) return false; - auto &Cache = getAnalysis().get(); - auto &Model = getAnalysis().get().getReadOnlyModel(); - // Create a pool of functions with the same behavior: we will need a different // function for each different struct OpaqueFunctionsPool 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(I->getAggregateOperand())); - auto *CallReturningAggregate = cast(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(AggregateType); - if (not TheStructType->isLiteral()) - TheStructType->setName(StructName); - I->replaceAllUsesWith(InjectedCall); InjectedCall->copyMetadata(*I); llvm::RecursivelyDeleteTriviallyDeadInstructions(I); diff --git a/tests/unit/llvm_lit_tests/RemoveExtractValues.ll b/tests/unit/llvm_lit_tests/RemoveExtractValues.ll index 7914d97b2..14614626b 100644 --- a/tests/unit/llvm_lit_tests/RemoveExtractValues.ll +++ b/tests/unit/llvm_lit_tests/RemoveExtractValues.ll @@ -7,11 +7,11 @@ ; not optimized away by the O2 pipeline %0 = type { i64, i32, i16, i8} -; CHECK: %_artificial_struct_returned_by__helper_returns_struct = type { i64, i32, i16, i8 } +; CHECK: %0 = type { i64, i32, i16, i8 } ; Function Attrs: noinline optnone declare dso_local %0 @helper_returns_struct() local_unnamed_addr #0 -; CHECK: declare dso_local %_artificial_struct_returned_by__helper_returns_struct @helper_returns_struct() local_unnamed_addr #0 +; CHECK: declare dso_local %0 @helper_returns_struct() local_unnamed_addr #0 ; Function Attrs: noinline optnone declare dso_local %0 @save_i64() local_unnamed_addr #0 @@ -29,10 +29,10 @@ declare dso_local %0 @save_i8() local_unnamed_addr #0 define void @f() local_unnamed_addr #1 { newFuncRoot: %0 = call %0 @helper_returns_struct() - %1 = extractvalue %0 %0, 0 ; CHECK: tail call i64 @{{OpaqueExtractvalue.[0-9]+|OpaqueExtractvalue}}(%_artificial_struct_returned_by__helper_returns_struct %0, i64 0) - %2 = extractvalue %0 %0, 1 ; CHECK-NEXT: tail call i32 @{{OpaqueExtractvalue.[0-9]+|OpaqueExtractvalue}}(%_artificial_struct_returned_by__helper_returns_struct %0, i64 1) - %3 = extractvalue %0 %0, 2 ; CHECK-NEXT: tail call i16 @{{OpaqueExtractvalue.[0-9]+|OpaqueExtractvalue}}(%_artificial_struct_returned_by__helper_returns_struct %0, i64 2) - %4 = extractvalue %0 %0, 3 ; CHECK-NEXT: tail call i8 @{{OpaqueExtractvalue.[0-9]+|OpaqueExtractvalue}}(%_artificial_struct_returned_by__helper_returns_struct %0, i64 3) + %1 = extractvalue %0 %0, 0 ; CHECK: tail call i64 @{{OpaqueExtractvalue.[0-9]+|OpaqueExtractvalue}}(%0 %0, i64 0) + %2 = extractvalue %0 %0, 1 ; CHECK-NEXT: tail call i32 @{{OpaqueExtractvalue.[0-9]+|OpaqueExtractvalue}}(%0 %0, i64 1) + %3 = extractvalue %0 %0, 2 ; CHECK-NEXT: tail call i16 @{{OpaqueExtractvalue.[0-9]+|OpaqueExtractvalue}}(%0 %0, i64 2) + %4 = extractvalue %0 %0, 3 ; CHECK-NEXT: tail call i8 @{{OpaqueExtractvalue.[0-9]+|OpaqueExtractvalue}}(%0 %0, i64 3) call void @save_i64(i64 %1) call void @save_i32(i32 %2) call void @save_i16(i16 %3) @@ -42,12 +42,3 @@ newFuncRoot: attributes #0 = { noinline optnone } attributes #1 = { noreturn } - -; General Metadata -!revng.model = !{!0} - -; Model -!0 = !{!"--- -Architecture: x86_64 -... -"}