33
33
#include " llvm/ADT/TypeSwitch.h"
34
34
#include " llvm/Support/ErrorHandling.h"
35
35
#include " llvm/Support/MathExtras.h"
36
- #include < cassert>
37
36
#include < optional>
38
37
39
38
using cir::MissingFeatures;
@@ -43,16 +42,13 @@ using cir::MissingFeatures;
43
42
// ===----------------------------------------------------------------------===//
44
43
45
44
static mlir::ParseResult
46
- parseFuncType (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> &returnTypes,
47
- llvm::SmallVector<mlir::Type> ¶ms, bool &isVarArg);
48
-
49
- static void printFuncType (mlir::AsmPrinter &p,
50
- mlir::ArrayRef<mlir::Type> returnTypes,
51
- mlir::ArrayRef<mlir::Type> params, bool isVarArg);
45
+ parseFuncTypeArgs (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> ¶ms,
46
+ bool &isVarArg);
47
+ static void printFuncTypeArgs (mlir::AsmPrinter &p,
48
+ mlir::ArrayRef<mlir::Type> params, bool isVarArg);
52
49
53
50
static mlir::ParseResult parsePointerAddrSpace (mlir::AsmParser &p,
54
51
mlir::Attribute &addrSpaceAttr);
55
-
56
52
static void printPointerAddrSpace (mlir::AsmPrinter &p,
57
53
mlir::Attribute addrSpaceAttr);
58
54
@@ -817,46 +813,9 @@ FuncType FuncType::clone(TypeRange inputs, TypeRange results) const {
817
813
return get (llvm::to_vector (inputs), results[0 ], isVarArg ());
818
814
}
819
815
820
- // A special parser is needed for function returning void to consume the "!void"
821
- // returned type in the case there is no alias defined.
822
- static mlir::ParseResult
823
- parseFuncTypeReturn (mlir::AsmParser &p,
824
- llvm::SmallVector<mlir::Type> &returnTypes) {
825
- if (p.parseOptionalExclamationKeyword (" !void" ).succeeded ())
826
- // !void means no return type.
827
- return p.parseLParen ();
828
- if (succeeded (p.parseOptionalLParen ()))
829
- // If we have already a '(', the function has no return type
830
- return mlir::success ();
831
-
832
- mlir::Type type;
833
- auto result = p.parseOptionalType (type);
834
- if (!result.has_value ())
835
- return mlir::failure ();
836
- if (failed (*result) || isa<cir::VoidType>(type))
837
- // No return type specified.
838
- return p.parseLParen ();
839
- // Otherwise use the actual type.
840
- returnTypes.push_back (type);
841
- return p.parseLParen ();
842
- }
843
-
844
- // A special pretty-printer for function returning void to emit a "!void"
845
- // returned type. Note that there is no real type used here since it does not
846
- // appear in the IR and thus the alias might not be defined and cannot be
847
- // referred to. This is why this is a pure syntactic-sugar string which is used.
848
- static void printFuncTypeReturn (mlir::AsmPrinter &p,
849
- mlir::ArrayRef<mlir::Type> returnTypes) {
850
- if (returnTypes.empty ())
851
- // Pretty-print no return type as "!void"
852
- p << " !void " ;
853
- else
854
- p << returnTypes << ' ' ;
855
- }
856
-
857
- static mlir::ParseResult
858
- parseFuncTypeArgs (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> ¶ms,
859
- bool &isVarArg) {
816
+ mlir::ParseResult parseFuncTypeArgs (mlir::AsmParser &p,
817
+ llvm::SmallVector<mlir::Type> ¶ms,
818
+ bool &isVarArg) {
860
819
isVarArg = false ;
861
820
// `(` `)`
862
821
if (succeeded (p.parseOptionalRParen ()))
@@ -886,10 +845,8 @@ parseFuncTypeArgs(mlir::AsmParser &p, llvm::SmallVector<mlir::Type> ¶ms,
886
845
return p.parseRParen ();
887
846
}
888
847
889
- static void printFuncTypeArgs (mlir::AsmPrinter &p,
890
- mlir::ArrayRef<mlir::Type> params,
891
- bool isVarArg) {
892
- p << ' (' ;
848
+ void printFuncTypeArgs (mlir::AsmPrinter &p, mlir::ArrayRef<mlir::Type> params,
849
+ bool isVarArg) {
893
850
llvm::interleaveComma (params, p,
894
851
[&p](mlir::Type type) { p.printType (type); });
895
852
if (isVarArg) {
@@ -900,37 +857,11 @@ static void printFuncTypeArgs(mlir::AsmPrinter &p,
900
857
p << ' )' ;
901
858
}
902
859
903
- static mlir::ParseResult
904
- parseFuncType (mlir::AsmParser &p, llvm::SmallVector<mlir::Type> &returnTypes,
905
- llvm::SmallVector<mlir::Type> ¶ms, bool &isVarArg) {
906
- if (failed (parseFuncTypeReturn (p, returnTypes)))
907
- return failure ();
908
- return parseFuncTypeArgs (p, params, isVarArg);
909
- }
910
-
911
- static void printFuncType (mlir::AsmPrinter &p,
912
- mlir::ArrayRef<mlir::Type> returnTypes,
913
- mlir::ArrayRef<mlir::Type> params, bool isVarArg) {
914
- printFuncTypeReturn (p, returnTypes);
915
- printFuncTypeArgs (p, params, isVarArg);
860
+ llvm::ArrayRef<mlir::Type> FuncType::getReturnTypes () const {
861
+ return static_cast <detail::FuncTypeStorage *>(getImpl ())->returnType ;
916
862
}
917
863
918
- // Return the actual return type or an explicit !cir.void if the function does
919
- // not return anything
920
- mlir::Type FuncType::getReturnType () const {
921
- if (isVoid ())
922
- return cir::VoidType::get (getContext ());
923
- return static_cast <detail::FuncTypeStorage *>(getImpl ())->returnTypes .front ();
924
- }
925
-
926
- bool FuncType::isVoid () const {
927
- auto rt = static_cast <detail::FuncTypeStorage *>(getImpl ())->returnTypes ;
928
- assert (rt.empty () ||
929
- !mlir::isa<cir::VoidType>(rt.front ()) &&
930
- " The return type for a function returning void should be empty "
931
- " instead of a real !cir.void" );
932
- return rt.empty ();
933
- }
864
+ bool FuncType::isVoid () const { return mlir::isa<VoidType>(getReturnType ()); }
934
865
935
866
// ===----------------------------------------------------------------------===//
936
867
// MethodType Definitions
0 commit comments