1212// ===----------------------------------------------------------------------===//
1313
1414#include " CIRGenCall.h"
15+ #include " CIRGenConstantEmitter.h"
1516#include " CIRGenFunction.h"
1617#include " CIRGenModule.h"
1718#include " CIRGenValue.h"
@@ -66,6 +67,32 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
6667 return emitLibraryCall (*this , fd, e,
6768 cgm.getBuiltinLibFunction (fd, builtinID));
6869
70+ assert (!cir::MissingFeatures::builtinCallF128 ());
71+
72+ // If the builtin has been declared explicitly with an assembler label,
73+ // disable the specialized emitting below. Ideally we should communicate the
74+ // rename in IR, or at least avoid generating the intrinsic calls that are
75+ // likely to get lowered to the renamed library functions.
76+ unsigned builtinIDIfNoAsmLabel = fd->hasAttr <AsmLabelAttr>() ? 0 : builtinID;
77+
78+ assert (!cir::MissingFeatures::builtinCallMathErrno ());
79+ assert (!cir::MissingFeatures::builtinCall ());
80+
81+ switch (builtinIDIfNoAsmLabel) {
82+ default :
83+ break ;
84+
85+ case Builtin::BI__assume:
86+ case Builtin::BI__builtin_assume: {
87+ if (e->getArg (0 )->HasSideEffects (getContext ()))
88+ return RValue::get (nullptr );
89+
90+ mlir::Value argValue = emitCheckedArgForAssume (e->getArg (0 ));
91+ builder.create <cir::AssumeOp>(getLoc (e->getExprLoc ()), argValue);
92+ return RValue::get (nullptr );
93+ }
94+ }
95+
6996 cgm.errorNYI (e->getSourceRange (), " unimplemented builtin call" );
7097 return getUndefRValue (e->getType ());
7198}
@@ -88,3 +115,14 @@ cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *fd,
88115 mlir::Type type = convertType (fd->getType ());
89116 return getOrCreateCIRFunction (name, type, d, /* forVTable=*/ false );
90117}
118+
119+ mlir::Value CIRGenFunction::emitCheckedArgForAssume (const Expr *e) {
120+ mlir::Value argValue = evaluateExprAsBool (e);
121+ if (!sanOpts.has (SanitizerKind::Builtin))
122+ return argValue;
123+
124+ assert (!cir::MissingFeatures::sanitizers ());
125+ cgm.errorNYI (e->getSourceRange (),
126+ " emitCheckedArgForAssume: sanitizers are NYI" );
127+ return {};
128+ }
0 commit comments