@@ -60,24 +60,23 @@ static RValue emitBuiltinBitOp(CIRGenFunction &cgf, const CallExpr *e,
6060RValue CIRGenFunction::emitBuiltinExpr (const GlobalDecl &gd, unsigned builtinID,
6161 const CallExpr *e,
6262 ReturnValueSlot returnValue) {
63+ mlir::Location loc = getLoc (e->getSourceRange ());
64+
6365 // See if we can constant fold this builtin. If so, don't emit it at all.
6466 // TODO: Extend this handling to all builtin calls that we can constant-fold.
6567 Expr::EvalResult result;
6668 if (e->isPRValue () && e->EvaluateAsRValue (result, cgm.getASTContext ()) &&
6769 !result.hasSideEffects ()) {
68- if (result.Val .isInt ()) {
69- return RValue::get (builder.getConstInt (getLoc (e->getSourceRange ()),
70- result.Val .getInt ()));
71- }
70+ if (result.Val .isInt ())
71+ return RValue::get (builder.getConstInt (loc, result.Val .getInt ()));
7272 if (result.Val .isFloat ()) {
7373 // Note: we are using result type of CallExpr to determine the type of
7474 // the constant. Classic codegen uses the result value to determine the
7575 // type. We feel it should be Ok to use expression type because it is
7676 // hard to imagine a builtin function evaluates to a value that
7777 // over/underflows its own defined type.
7878 mlir::Type type = convertType (e->getType ());
79- return RValue::get (builder.getConstFP (getLoc (e->getExprLoc ()), type,
80- result.Val .getFloat ()));
79+ return RValue::get (builder.getConstFP (loc, type, result.Val .getFloat ()));
8180 }
8281 }
8382
@@ -94,8 +93,6 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
9493 assert (!cir::MissingFeatures::builtinCallMathErrno ());
9594 assert (!cir::MissingFeatures::builtinCall ());
9695
97- mlir::Location loc = getLoc (e->getExprLoc ());
98-
9996 switch (builtinIDIfNoAsmLabel) {
10097 default :
10198 break ;
@@ -200,11 +197,28 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
200197 probability);
201198 }
202199
203- auto result = builder.create <cir::ExpectOp>(getLoc (e->getSourceRange ()),
204- argValue.getType (), argValue,
205- expectedValue, probAttr);
200+ auto result = builder.create <cir::ExpectOp>(
201+ loc, argValue.getType (), argValue, expectedValue, probAttr);
206202 return RValue::get (result);
207203 }
204+
205+ case Builtin::BI__builtin_bswap16:
206+ case Builtin::BI__builtin_bswap32:
207+ case Builtin::BI__builtin_bswap64:
208+ case Builtin::BI_byteswap_ushort:
209+ case Builtin::BI_byteswap_ulong:
210+ case Builtin::BI_byteswap_uint64: {
211+ mlir::Value arg = emitScalarExpr (e->getArg (0 ));
212+ return RValue::get (builder.create <cir::ByteSwapOp>(loc, arg));
213+ }
214+
215+ case Builtin::BI__builtin_bitreverse8:
216+ case Builtin::BI__builtin_bitreverse16:
217+ case Builtin::BI__builtin_bitreverse32:
218+ case Builtin::BI__builtin_bitreverse64: {
219+ mlir::Value arg = emitScalarExpr (e->getArg (0 ));
220+ return RValue::get (builder.create <cir::BitReverseOp>(loc, arg));
221+ }
208222 }
209223
210224 // If this is an alias for a lib function (e.g. __builtin_sin), emit
0 commit comments