[PATCH] D135296: [llvm][NFC] Consolidate equivalent function type parsing code into single function
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 5 11:14:42 PDT 2022
leonardchan created this revision.
leonardchan added reviewers: phosek, MaskRay.
leonardchan added a project: LLVM.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
leonardchan requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135296
Files:
llvm/lib/AsmParser/LLParser.cpp
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -6398,6 +6439,25 @@
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<ParamInfo, 16> &ArgList, FunctionType *&FuncTy) {
+ FuncTy = dyn_cast<FunctionType>(RetType);
+ if (!FuncTy) {
+ // Pull out the types of all of the arguments...
+ std::vector<Type*> 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
@@ -6431,18 +6491,9 @@
// 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<FunctionType>(RetType);
- if (!Ty) {
- // Pull out the types of all of the arguments...
- std::vector<Type*> 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;
@@ -6757,18 +6808,9 @@
// 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<FunctionType>(RetType);
- if (!Ty) {
- // Pull out the types of all of the arguments...
- std::vector<Type *> 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;
@@ -7162,18 +7204,9 @@
// 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<FunctionType>(RetType);
- if (!Ty) {
- // Pull out the types of all of the arguments...
- std::vector<Type*> 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135296.465475.patch
Type: text/x-patch
Size: 3738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221005/14bb849f/attachment.bin>
More information about the llvm-commits
mailing list