================
@@ -1799,6 +1870,162 @@ mlir::Value
ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
cgf.cgm.UInt64Ty, e->EvaluateKnownConstInt(cgf.getContext())));
}
+/// Return true if the specified expression is cheap enough and
side-effect-free
+/// enough to evaluate unconditionally instead of conditionally. This is used
+/// to convert control flow into selects in some cases.
+/// TODO(cir): can be shared with LLVM codegen.
+static bool isCheapEnoughToEvaluateUnconditionally(const Expr *e,
+ CIRGenFunction &cgf) {
+ // Anything that is an integer or floating point constant is fine.
+ return e->IgnoreParens()->isEvaluatable(cgf.getContext());
+
+ // Even non-volatile automatic variables can't be evaluated unconditionally.
+ // Referencing a thread_local may cause non-trivial initialization work to
+ // occur. If we're inside a lambda and one of the variables is from the scope
+ // outside the lambda, that function may have returned already. Reading its
+ // locals is a bad idea. Also, these reads may introduce races there didn't
+ // exist in the source-level program.
+}
+
+mlir::Value ScalarExprEmitter::VisitAbstractConditionalOperator(
+ const AbstractConditionalOperator *e) {
+ CIRGenBuilderTy &builder = cgf.getBuilder();
+ mlir::Location loc = cgf.getLoc(e->getSourceRange());
+ ignoreResultAssign = false;
+
+ // Bind the common expression if necessary.
+ CIRGenFunction::OpaqueValueMapping binding(cgf, e);
----------------
andykaylor wrote:
This doesn't seem to be necessary yet. As far as I can tell, we'll need this
when we add handling for OpaqueValueExprClass but not until then.
https://github.com/llvm/llvm-project/pull/138156
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits