From cb8aa3d92986795bf07cb78c2fb741b60e3addb4 Mon Sep 17 00:00:00 2001 From: Alessandro Di Federico Date: Thu, 5 Oct 2023 18:44:07 +0200 Subject: [PATCH] Adopt .prototype() Also adopt `QualifiedType::getFunctionType` where appropriate in order to unwrap typedefs. --- lib/Backend/DecompileFunction.cpp | 2 +- lib/DataLayoutAnalysis/Backend/DLAUpdateModelTypes.cpp | 5 ++++- .../Frontend/DLACreateInterProceduralTypes.cpp | 2 +- lib/HeadersGeneration/ModelToHeader.cpp | 2 +- lib/IRCanonicalization/MakeModelGEPPass.cpp | 5 +++-- lib/IRCanonicalization/PrepareLLVMIRForMLIR.cpp | 2 +- lib/InitModelTypes/InitModelTypes.cpp | 2 +- lib/PromoteStackPointer/DetectStackSizePass.cpp | 2 +- lib/RemoveLiftingArtifacts/PromoteInitCSVToUndef.cpp | 7 ++++--- lib/Support/ModelHelpers.cpp | 6 +++--- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/Backend/DecompileFunction.cpp b/lib/Backend/DecompileFunction.cpp index f74757c59..f7e8e4fb8 100644 --- a/lib/Backend/DecompileFunction.cpp +++ b/lib/Backend/DecompileFunction.cpp @@ -353,7 +353,7 @@ public: Model(Model), LLVMFunction(LLVMFunction), ModelFunction(*llvmToModelFunction(Model, LLVMFunction)), - ParentPrototype(*ModelFunction.Prototype().getConst()), + ParentPrototype(*ModelFunction.prototype(Model).getConst()), GHAST(GHAST), TopScopeVariables(TopScopeVariables), TypeMap(initModelTypes(Cache, diff --git a/lib/DataLayoutAnalysis/Backend/DLAUpdateModelTypes.cpp b/lib/DataLayoutAnalysis/Backend/DLAUpdateModelTypes.cpp index 33818b3f0..f0d2c4791 100644 --- a/lib/DataLayoutAnalysis/Backend/DLAUpdateModelTypes.cpp +++ b/lib/DataLayoutAnalysis/Backend/DLAUpdateModelTypes.cpp @@ -657,7 +657,10 @@ bool dla::updateFuncSignatures(const llvm::Module &M, if (not ModelFunc) continue; - Type *ModelPrototype = ModelFunc->Prototype().get(); + TypePath WrappedPrototypePath = ModelFunc->prototype(*Model); + using model::QualifiedType; + auto PrototypePath = QualifiedType::getFunctionType(WrappedPrototypePath); + Type *ModelPrototype = PrototypePath->get(); revng_log(Log, "Updating prototype of function " << LLVMFunc.getNameOrAsOperand()); diff --git a/lib/DataLayoutAnalysis/Frontend/DLACreateInterProceduralTypes.cpp b/lib/DataLayoutAnalysis/Frontend/DLACreateInterProceduralTypes.cpp index ad62fe811..ba11bea18 100644 --- a/lib/DataLayoutAnalysis/Frontend/DLACreateInterProceduralTypes.cpp +++ b/lib/DataLayoutAnalysis/Frontend/DLACreateInterProceduralTypes.cpp @@ -56,7 +56,7 @@ bool TSBuilder::createInterproceduralTypes(llvm::Module &M, auto It = Model.ImportedDynamicFunctions().find(SymbolName.str()); revng_assert(It != Model.ImportedDynamicFunctions().end()); const model::DynamicFunction &DF = *It; - const auto &TTR = getPrototype(Model, DF); + const auto &TTR = DF.prototype(Model); revng_assert(TTR.isValid()); Prototype = TTR.getConst(); } diff --git a/lib/HeadersGeneration/ModelToHeader.cpp b/lib/HeadersGeneration/ModelToHeader.cpp index d5c1ab995..7ef070525 100644 --- a/lib/HeadersGeneration/ModelToHeader.cpp +++ b/lib/HeadersGeneration/ModelToHeader.cpp @@ -225,7 +225,7 @@ bool dumpModelToHeader(const model::Binary &Model, if (Options.FunctionsToOmit.contains(MF.Entry())) continue; - const model::Type *FT = MF.Prototype().get(); + const model::Type *FT = MF.prototype(Model).get(); if (Options.TypesToOmit.contains(FT)) continue; diff --git a/lib/IRCanonicalization/MakeModelGEPPass.cpp b/lib/IRCanonicalization/MakeModelGEPPass.cpp index 1c1b05168..2d4a7f7ff 100644 --- a/lib/IRCanonicalization/MakeModelGEPPass.cpp +++ b/lib/IRCanonicalization/MakeModelGEPPass.cpp @@ -1723,7 +1723,7 @@ getAccessedTypeOnIR(FunctionMetadataCache &Cache, const model::Function *MF = llvmToModelFunction(Model, *ReturningF); revng_assert(MF); - const auto Layout = abi::FunctionType::Layout::make(MF->Prototype()); + const auto Layout = abi::FunctionType::Layout::make(MF->prototype(Model)); bool HasNoReturnValues = (Layout.ReturnValues.empty() and not Layout.returnsAggregateType()); @@ -1790,7 +1790,8 @@ getAccessedTypeOnIR(FunctionMetadataCache &Cache, unsigned ArgNum = Call->getArgOperandNo(&U); const model::Function *CalledFType = llvmToModelFunction(Model, *CalledF); - const model::Type *CalledPrototype = CalledFType->Prototype().getConst(); + const model::Type *CalledPrototype = CalledFType->prototype(Model) + .getConst(); if (auto *RFT = dyn_cast(CalledPrototype)) { revng_log(ModelGEPLog, "Has RawFunctionType prototype."); diff --git a/lib/IRCanonicalization/PrepareLLVMIRForMLIR.cpp b/lib/IRCanonicalization/PrepareLLVMIRForMLIR.cpp index 538d98727..0517df776 100644 --- a/lib/IRCanonicalization/PrepareLLVMIRForMLIR.cpp +++ b/lib/IRCanonicalization/PrepareLLVMIRForMLIR.cpp @@ -164,7 +164,7 @@ static void adjustAnonymousStructs(Module &M, const model::Binary &Model) { llvm::StringRef SymbolName = F.getName().drop_front(strlen("dynamic_")); auto It = Model.ImportedDynamicFunctions().find(SymbolName.str()); revng_assert(It != Model.ImportedDynamicFunctions().end()); - const auto &TTR = getPrototype(Model, *It); + const auto &TTR = It->prototype(Model); revng_assert(TTR.isValid()); Prototype = TTR.getConst(); } diff --git a/lib/InitModelTypes/InitModelTypes.cpp b/lib/InitModelTypes/InitModelTypes.cpp index 092649a0a..53b4da41f 100644 --- a/lib/InitModelTypes/InitModelTypes.cpp +++ b/lib/InitModelTypes/InitModelTypes.cpp @@ -324,7 +324,7 @@ ModelTypesMap initModelTypes(FunctionMetadataCache &Cache, bool PointersOnly) { ModelTypesMap TypeMap; - const model::Type *Prototype = ModelF->Prototype().getConst(); + const model::Type *Prototype = ModelF->prototype(Model).getConst(); revng_assert(Prototype); addArgumentsTypes(F, Prototype, Model, TypeMap, PointersOnly); diff --git a/lib/PromoteStackPointer/DetectStackSizePass.cpp b/lib/PromoteStackPointer/DetectStackSizePass.cpp index b62984621..2f797c580 100644 --- a/lib/PromoteStackPointer/DetectStackSizePass.cpp +++ b/lib/PromoteStackPointer/DetectStackSizePass.cpp @@ -151,7 +151,7 @@ void DetectStackSize::collectStackBounds(FunctionMetadataCache &Cache, // frame/arguments bool NeedsStackFrame = ModelFunction.StackFrameType().empty(); bool NeedsStackArguments = false; - model::Type *Prototype = ModelFunction.Prototype().get(); + model::Type *Prototype = ModelFunction.prototype(*Binary).get(); RawFunctionType *RawPrototype = nullptr; if ((RawPrototype = dyn_cast(Prototype))) { revng_assert(RawPrototype->StackArgumentsType().Qualifiers().empty()); diff --git a/lib/RemoveLiftingArtifacts/PromoteInitCSVToUndef.cpp b/lib/RemoveLiftingArtifacts/PromoteInitCSVToUndef.cpp index 4d9eec313..520da3fcb 100644 --- a/lib/RemoveLiftingArtifacts/PromoteInitCSVToUndef.cpp +++ b/lib/RemoveLiftingArtifacts/PromoteInitCSVToUndef.cpp @@ -18,12 +18,13 @@ using namespace llvm; static bool undefPreservedRegistersInitialization(Function &F, - const model::Function &ModelFunction) { + const model::Function &ModelFunction, + const model::Binary &Binary) { bool Changed = false; QuickMetadata QMD(F.getParent()->getContext()); using abi::FunctionType::Layout; - auto Layout = Layout::make(*ModelFunction.Prototype().get()); + auto Layout = Layout::make(*ModelFunction.prototype(Binary).get()); for (auto &BB : F) { auto It = BB.begin(); @@ -74,7 +75,7 @@ public: const model::Binary &Binary = *ModelWrapper.getReadOnlyModel(); MetaAddress Entry = getMetaAddressMetadata(&F, "revng.function.entry"); auto &ModelFunction = Binary.Functions().at(Entry); - return undefPreservedRegistersInitialization(F, ModelFunction); + return undefPreservedRegistersInitialization(F, ModelFunction, Binary); } return false; diff --git a/lib/Support/ModelHelpers.cpp b/lib/Support/ModelHelpers.cpp index 065cc096a..27101a514 100644 --- a/lib/Support/ModelHelpers.cpp +++ b/lib/Support/ModelHelpers.cpp @@ -440,7 +440,7 @@ getStrongModelInfo(FunctionMetadataCache &Cache, // RawFunctionTypes that return multiple values, therefore they have // the same type as the parent function's return type revng_assert(Call->getFunction()->getReturnType() == Call->getType()); - ReturnTypes = handleReturnValue(ParentFunc()->Prototype(), Model); + ReturnTypes = handleReturnValue(ParentFunc()->prototype(Model), Model); } else if (FTags.contains(FunctionTags::SegmentRef)) { const auto &[StartAddress, @@ -562,14 +562,14 @@ getExpectedModelType(FunctionMetadataCache &Cache, revng_assert(Call->getFunction()->getReturnType() == Call->getType()); llvm::SmallVector ReturnTypes; - ReturnTypes = handleReturnValue(ParentFunc()->Prototype(), Model); + ReturnTypes = handleReturnValue(ParentFunc()->prototype(Model), Model); return { ReturnTypes[ArgOperandIdx] }; } else if (FTags.contains(FunctionTags::BinaryNot)) { return { llvmIntToModelType(Call->getType(), Model) }; } } } else if (auto *Ret = dyn_cast(User)) { - return handleReturnValue(ParentFunc()->Prototype(), Model); + return handleReturnValue(ParentFunc()->prototype(Model), Model); } else if (auto *BinaryOp = dyn_cast(User)) { using namespace model::PrimitiveTypeKind; auto Opcode = BinaryOp->getOpcode();