From 4f6477a615d18dac6cc3aa0d3fb946191f8168c9 Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Wed, 5 Oct 2022 18:40:50 +0000 Subject: [PATCH] [llvm][NFC] Consolidate equivalent function type parsing code into single function Differential Revision: https://reviews.llvm.org/D135296 --- llvm/lib/AsmParser/LLParser.cpp | 64 ++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 1b072f8..99c369c 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -6414,6 +6414,25 @@ bool LLParser::parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS) { return false; } +// If RetType is a non-function pointer type, then this is the short syntax +// for the call, which means that RetType is just the return type. Infer the +// rest of the function argument types from the arguments that are present. +static bool resolveFunctionType(Type *RetType, const SmallVector &ArgList, FunctionType *&FuncTy) { + FuncTy = dyn_cast(RetType); + if (!FuncTy) { + // Pull out the types of all of the arguments... + std::vector ParamTypes; + for (unsigned i = 0, e = ArgList.size(); i != e; ++i) + ParamTypes.push_back(ArgList[i].V->getType()); + + if (!FunctionType::isValidReturnType(RetType)) + return error(RetTypeLoc, "Invalid result type for LLVM function"); + + FuncTy = FunctionType::get(RetType, ParamTypes, false); + } + return false; +} + /// parseInvoke /// ::= 'invoke' OptionalCallingConv OptionalAttrs Type Value ParamList /// OptionalAttrs 'to' TypeAndValue 'unwind' TypeAndValue @@ -6447,18 +6466,9 @@ bool LLParser::parseInvoke(Instruction *&Inst, PerFunctionState &PFS) { // If RetType is a non-function pointer type, then this is the short syntax // for the call, which means that RetType is just the return type. Infer the // rest of the function argument types from the arguments that are present. - FunctionType *Ty = dyn_cast(RetType); - if (!Ty) { - // Pull out the types of all of the arguments... - std::vector ParamTypes; - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) - ParamTypes.push_back(ArgList[i].V->getType()); - - if (!FunctionType::isValidReturnType(RetType)) - return error(RetTypeLoc, "Invalid result type for LLVM function"); - - Ty = FunctionType::get(RetType, ParamTypes, false); - } + FunctionType *Ty; + if (resolveFunctionType(RetType, ArgList, Ty)) + return true; CalleeID.FTy = Ty; @@ -6773,18 +6783,9 @@ bool LLParser::parseCallBr(Instruction *&Inst, PerFunctionState &PFS) { // If RetType is a non-function pointer type, then this is the short syntax // for the call, which means that RetType is just the return type. Infer the // rest of the function argument types from the arguments that are present. - FunctionType *Ty = dyn_cast(RetType); - if (!Ty) { - // Pull out the types of all of the arguments... - std::vector ParamTypes; - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) - ParamTypes.push_back(ArgList[i].V->getType()); - - if (!FunctionType::isValidReturnType(RetType)) - return error(RetTypeLoc, "Invalid result type for LLVM function"); - - Ty = FunctionType::get(RetType, ParamTypes, false); - } + FunctionType *Ty; + if (resolveFunctionType(RetType, ArgList, Ty)) + return true; CalleeID.FTy = Ty; @@ -7178,18 +7179,9 @@ bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS, // If RetType is a non-function pointer type, then this is the short syntax // for the call, which means that RetType is just the return type. Infer the // rest of the function argument types from the arguments that are present. - FunctionType *Ty = dyn_cast(RetType); - if (!Ty) { - // Pull out the types of all of the arguments... - std::vector ParamTypes; - for (unsigned i = 0, e = ArgList.size(); i != e; ++i) - ParamTypes.push_back(ArgList[i].V->getType()); - - if (!FunctionType::isValidReturnType(RetType)) - return error(RetTypeLoc, "Invalid result type for LLVM function"); - - Ty = FunctionType::get(RetType, ParamTypes, false); - } + FunctionType *Ty; + if (resolveFunctionType(RetType, ArgList, Ty)) + return true; CalleeID.FTy = Ty; -- 2.7.4