@@ -954,200 +954,140 @@ MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) {
954
954
true );
955
955
}
956
956
957
+ std::vector<mlir::Value> args;
958
+ auto VisitArgs = [&]() {
959
+ assert (args.empty () && " Expecting empty args" );
960
+ for (auto a : expr->arguments ())
961
+ args.push_back (Visit (a).getValue (builder));
962
+ };
957
963
Optional<Value> V = None;
958
964
switch (expr->getBuiltinCallee ()) {
959
965
case Builtin::BIceil: {
960
- std::vector<mlir::Value> args;
961
- for (auto a : expr->arguments ()) {
962
- args.push_back (Visit (a).getValue (builder));
963
- }
966
+ VisitArgs ();
964
967
V = builder.create <math::CeilOp>(loc, args[0 ]);
965
968
} break ;
966
969
case Builtin::BIcos: {
967
- std::vector<mlir::Value> args;
968
- for (auto a : expr->arguments ()) {
969
- args.push_back (Visit (a).getValue (builder));
970
- }
970
+ VisitArgs ();
971
971
V = builder.create <mlir::math::CosOp>(loc, args[0 ]);
972
972
} break ;
973
973
case Builtin::BIexp:
974
974
case Builtin::BIexpf: {
975
- std::vector<mlir::Value> args;
976
- for (auto a : expr->arguments ()) {
977
- args.push_back (Visit (a).getValue (builder));
978
- }
975
+ VisitArgs ();
979
976
V = builder.create <mlir::math::ExpOp>(loc, args[0 ]);
980
977
} break ;
981
978
case Builtin::BIlog: {
982
- std::vector<mlir::Value> args;
983
- for (auto a : expr->arguments ()) {
984
- args.push_back (Visit (a).getValue (builder));
985
- }
979
+ VisitArgs ();
986
980
V = builder.create <mlir::math::LogOp>(loc, args[0 ]);
987
981
} break ;
988
982
case Builtin::BIsin: {
989
- std::vector<mlir::Value> args;
990
- for (auto a : expr->arguments ()) {
991
- args.push_back (Visit (a).getValue (builder));
992
- }
983
+ VisitArgs ();
993
984
V = builder.create <mlir::math::SinOp>(loc, args[0 ]);
994
985
} break ;
995
986
case Builtin::BIsqrt:
996
987
case Builtin::BIsqrtf: {
997
- std::vector<mlir::Value> args;
998
- for (auto a : expr->arguments ()) {
999
- args.push_back (Visit (a).getValue (builder));
1000
- }
988
+ VisitArgs ();
1001
989
V = builder.create <mlir::math::SqrtOp>(loc, args[0 ]);
1002
990
} break ;
1003
991
case Builtin::BI__builtin_atanh:
1004
992
case Builtin::BI__builtin_atanhf:
1005
993
case Builtin::BI__builtin_atanhl: {
1006
- std::vector<mlir::Value> args;
1007
- for (auto a : expr->arguments ()) {
1008
- args.push_back (Visit (a).getValue (builder));
1009
- }
994
+ VisitArgs ();
1010
995
V = builder.create <math::AtanOp>(loc, args[0 ]);
1011
996
} break ;
1012
997
case Builtin::BI__builtin_copysign:
1013
998
case Builtin::BI__builtin_copysignf:
1014
999
case Builtin::BI__builtin_copysignl: {
1015
- std::vector<mlir::Value> args;
1016
- for (auto a : expr->arguments ()) {
1017
- args.push_back (Visit (a).getValue (builder));
1018
- }
1000
+ VisitArgs ();
1019
1001
V = builder.create <LLVM::CopySignOp>(loc, args[0 ], args[1 ]);
1020
1002
} break ;
1021
1003
case Builtin::BI__builtin_exp2:
1022
1004
case Builtin::BI__builtin_exp2f:
1023
1005
case Builtin::BI__builtin_exp2l: {
1024
- std::vector<mlir::Value> args;
1025
- for (auto a : expr->arguments ()) {
1026
- args.push_back (Visit (a).getValue (builder));
1027
- }
1006
+ VisitArgs ();
1028
1007
V = builder.create <math::Exp2Op>(loc, args[0 ]);
1029
1008
} break ;
1030
1009
case Builtin::BI__builtin_expm1:
1031
1010
case Builtin::BI__builtin_expm1f:
1032
1011
case Builtin::BI__builtin_expm1l: {
1033
- std::vector<mlir::Value> args;
1034
- for (auto a : expr->arguments ()) {
1035
- args.push_back (Visit (a).getValue (builder));
1036
- }
1012
+ VisitArgs ();
1037
1013
V = builder.create <math::ExpM1Op>(loc, args[0 ]);
1038
1014
} break ;
1039
1015
case Builtin::BI__builtin_fma:
1040
1016
case Builtin::BI__builtin_fmaf:
1041
1017
case Builtin::BI__builtin_fmal: {
1042
- std::vector<mlir::Value> args;
1043
- for (auto a : expr->arguments ()) {
1044
- args.push_back (Visit (a).getValue (builder));
1045
- }
1018
+ VisitArgs ();
1046
1019
V = builder.create <LLVM::FMAOp>(loc, args[0 ], args[1 ], args[2 ]);
1047
1020
} break ;
1048
1021
case Builtin::BI__builtin_fmax:
1049
1022
case Builtin::BI__builtin_fmaxf:
1050
1023
case Builtin::BI__builtin_fmaxl: {
1051
- std::vector<mlir::Value> args;
1052
- for (auto a : expr->arguments ()) {
1053
- args.push_back (Visit (a).getValue (builder));
1054
- }
1024
+ VisitArgs ();
1055
1025
V = builder.create <LLVM::MaxNumOp>(loc, args[0 ], args[1 ]);
1056
1026
} break ;
1057
1027
case Builtin::BI__builtin_fmin:
1058
1028
case Builtin::BI__builtin_fminf:
1059
1029
case Builtin::BI__builtin_fminl: {
1060
- std::vector<mlir::Value> args;
1061
- for (auto a : expr->arguments ()) {
1062
- args.push_back (Visit (a).getValue (builder));
1063
- }
1030
+ VisitArgs ();
1064
1031
V = builder.create <LLVM::MinNumOp>(loc, args[0 ], args[1 ]);
1065
1032
} break ;
1066
1033
case Builtin::BI__builtin_log1p:
1067
1034
case Builtin::BI__builtin_log1pf:
1068
1035
case Builtin::BI__builtin_log1pl: {
1069
- std::vector<mlir::Value> args;
1070
- for (auto a : expr->arguments ()) {
1071
- args.push_back (Visit (a).getValue (builder));
1072
- }
1036
+ VisitArgs ();
1073
1037
V = builder.create <math::Log1pOp>(loc, args[0 ]);
1074
1038
} break ;
1075
1039
case Builtin::BI__builtin_pow:
1076
1040
case Builtin::BI__builtin_powf:
1077
1041
case Builtin::BI__builtin_powl: {
1078
- std::vector<mlir::Value> args;
1079
- for (auto a : expr->arguments ()) {
1080
- args.push_back (Visit (a).getValue (builder));
1081
- }
1042
+ VisitArgs ();
1082
1043
V = builder.create <math::PowFOp>(loc, args[0 ], args[1 ]);
1083
1044
} break ;
1084
1045
case Builtin::BI__builtin_assume: {
1085
- std::vector<mlir::Value> args;
1086
- for (auto a : expr->arguments ()) {
1087
- args.push_back (Visit (a).getValue (builder));
1088
- }
1046
+ VisitArgs ();
1089
1047
V = builder.create <LLVM::AssumeOp>(loc, args[0 ])->getResult (0 );
1090
1048
} break ;
1091
1049
case Builtin::BI__builtin_isgreater: {
1092
- std::vector<mlir::Value> args;
1093
- for (auto a : expr->arguments ()) {
1094
- args.push_back (Visit (a).getValue (builder));
1095
- }
1050
+ VisitArgs ();
1096
1051
auto postTy =
1097
1052
Glob.getTypes ().getMLIRType (expr->getType ()).cast <mlir::IntegerType>();
1098
1053
V = builder.create <ExtUIOp>(
1099
1054
loc, postTy,
1100
1055
builder.create <CmpFOp>(loc, CmpFPredicate::OGT, args[0 ], args[1 ]));
1101
1056
} break ;
1102
1057
case Builtin::BI__builtin_isgreaterequal: {
1103
- std::vector<mlir::Value> args;
1104
- for (auto a : expr->arguments ()) {
1105
- args.push_back (Visit (a).getValue (builder));
1106
- }
1058
+ VisitArgs ();
1107
1059
auto postTy =
1108
1060
Glob.getTypes ().getMLIRType (expr->getType ()).cast <mlir::IntegerType>();
1109
1061
V = builder.create <ExtUIOp>(
1110
1062
loc, postTy,
1111
1063
builder.create <CmpFOp>(loc, CmpFPredicate::OGE, args[0 ], args[1 ]));
1112
1064
} break ;
1113
1065
case Builtin::BI__builtin_isless: {
1114
- std::vector<mlir::Value> args;
1115
- for (auto a : expr->arguments ()) {
1116
- args.push_back (Visit (a).getValue (builder));
1117
- }
1066
+ VisitArgs ();
1118
1067
auto postTy =
1119
1068
Glob.getTypes ().getMLIRType (expr->getType ()).cast <mlir::IntegerType>();
1120
1069
V = builder.create <ExtUIOp>(
1121
1070
loc, postTy,
1122
1071
builder.create <CmpFOp>(loc, CmpFPredicate::OLT, args[0 ], args[1 ]));
1123
1072
} break ;
1124
1073
case Builtin::BI__builtin_islessequal: {
1125
- std::vector<mlir::Value> args;
1126
- for (auto a : expr->arguments ()) {
1127
- args.push_back (Visit (a).getValue (builder));
1128
- }
1074
+ VisitArgs ();
1129
1075
auto postTy =
1130
1076
Glob.getTypes ().getMLIRType (expr->getType ()).cast <mlir::IntegerType>();
1131
1077
V = builder.create <ExtUIOp>(
1132
1078
loc, postTy,
1133
1079
builder.create <CmpFOp>(loc, CmpFPredicate::OLE, args[0 ], args[1 ]));
1134
1080
} break ;
1135
1081
case Builtin::BI__builtin_islessgreater: {
1136
- std::vector<mlir::Value> args;
1137
- for (auto a : expr->arguments ()) {
1138
- args.push_back (Visit (a).getValue (builder));
1139
- }
1082
+ VisitArgs ();
1140
1083
auto postTy =
1141
1084
Glob.getTypes ().getMLIRType (expr->getType ()).cast <mlir::IntegerType>();
1142
1085
V = builder.create <ExtUIOp>(
1143
1086
loc, postTy,
1144
1087
builder.create <CmpFOp>(loc, CmpFPredicate::ONE, args[0 ], args[1 ]));
1145
1088
} break ;
1146
1089
case Builtin::BI__builtin_isunordered: {
1147
- std::vector<mlir::Value> args;
1148
- for (auto a : expr->arguments ()) {
1149
- args.push_back (Visit (a).getValue (builder));
1150
- }
1090
+ VisitArgs ();
1151
1091
auto postTy =
1152
1092
Glob.getTypes ().getMLIRType (expr->getType ()).cast <mlir::IntegerType>();
1153
1093
V = builder.create <ExtUIOp>(
@@ -1156,21 +1096,15 @@ MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) {
1156
1096
} break ;
1157
1097
case Builtin::BImemmove:
1158
1098
case Builtin::BI__builtin_memmove: {
1159
- std::vector<mlir::Value> args;
1160
- for (auto a : expr->arguments ()) {
1161
- args.push_back (Visit (a).getValue (builder));
1162
- }
1099
+ VisitArgs ();
1163
1100
builder.create <LLVM::MemmoveOp>(
1164
1101
loc, args[0 ], args[1 ], args[2 ],
1165
1102
/* isVolatile*/ builder.create <ConstantIntOp>(loc, false , 1 ));
1166
1103
V = args[0 ];
1167
1104
} break ;
1168
1105
case Builtin::BImemset:
1169
1106
case Builtin::BI__builtin_memset: {
1170
- std::vector<mlir::Value> args;
1171
- for (auto a : expr->arguments ()) {
1172
- args.push_back (Visit (a).getValue (builder));
1173
- }
1107
+ VisitArgs ();
1174
1108
builder.create <LLVM::MemsetOp>(
1175
1109
loc, args[0 ],
1176
1110
builder.create <TruncIOp>(loc, builder.getI8Type (), args[1 ]), args[2 ],
@@ -1179,10 +1113,7 @@ MLIRScanner::EmitBuiltinOps(clang::CallExpr *expr) {
1179
1113
} break ;
1180
1114
case Builtin::BImemcpy:
1181
1115
case Builtin::BI__builtin_memcpy: {
1182
- std::vector<mlir::Value> args;
1183
- for (auto a : expr->arguments ()) {
1184
- args.push_back (Visit (a).getValue (builder));
1185
- }
1116
+ VisitArgs ();
1186
1117
builder.create <LLVM::MemcpyOp>(
1187
1118
loc, args[0 ], args[1 ], args[2 ],
1188
1119
/* isVolatile*/ builder.create <ConstantIntOp>(loc, false , 1 ));
0 commit comments