@@ -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
@@ -101,8 +100,6 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
101100 assert (!cir::MissingFeatures::builtinCallMathErrno ());
102101 assert (!cir::MissingFeatures::builtinCall ());
103102
104- mlir::Location loc = getLoc (e->getExprLoc ());
105-
106103 switch (builtinIDIfNoAsmLabel) {
107104 default :
108105 break ;
@@ -185,11 +182,28 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
185182 probability);
186183 }
187184
188- auto result = builder.create <cir::ExpectOp>(getLoc (e->getSourceRange ()),
189- argValue.getType (), argValue,
190- expectedValue, probAttr);
185+ auto result = builder.create <cir::ExpectOp>(
186+ loc, argValue.getType (), argValue, expectedValue, probAttr);
191187 return RValue::get (result);
192188 }
189+
190+ case Builtin::BI__builtin_bswap16:
191+ case Builtin::BI__builtin_bswap32:
192+ case Builtin::BI__builtin_bswap64:
193+ case Builtin::BI_byteswap_ushort:
194+ case Builtin::BI_byteswap_ulong:
195+ case Builtin::BI_byteswap_uint64: {
196+ mlir::Value arg = emitScalarExpr (e->getArg (0 ));
197+ return RValue::get (builder.create <cir::ByteSwapOp>(loc, arg));
198+ }
199+
200+ case Builtin::BI__builtin_bitreverse8:
201+ case Builtin::BI__builtin_bitreverse16:
202+ case Builtin::BI__builtin_bitreverse32:
203+ case Builtin::BI__builtin_bitreverse64: {
204+ mlir::Value arg = emitScalarExpr (e->getArg (0 ));
205+ return RValue::get (builder.create <cir::BitReverseOp>(loc, arg));
206+ }
193207 }
194208
195209 cgm.errorNYI (e->getSourceRange (), " unimplemented builtin call" );
0 commit comments