1818#include " clang/AST/CharUnits.h"
1919#include " clang/AST/Decl.h"
2020#include " clang/AST/Expr.h"
21+ #include " clang/AST/ExprCXX.h"
2122#include " clang/CIR/Dialect/IR/CIRDialect.h"
2223#include " clang/CIR/MissingFeatures.h"
2324
@@ -479,18 +480,10 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) {
479480mlir::LogicalResult CIRGenFunction::emitIfOnBoolExpr (const Expr *cond,
480481 const Stmt *thenS,
481482 const Stmt *elseS) {
482- // Attempt to be more accurate as possible with IfOp location, generate
483- // one fused location that has either 2 or 4 total locations, depending
484- // on else's availability.
485- auto getStmtLoc = [this ](const Stmt &s) {
486- return mlir::FusedLoc::get (&getMLIRContext (),
487- {getLoc (s.getSourceRange ().getBegin ()),
488- getLoc (s.getSourceRange ().getEnd ())});
489- };
490- mlir::Location thenLoc = getStmtLoc (*thenS);
483+ mlir::Location thenLoc = getLoc (thenS->getSourceRange ());
491484 std::optional<mlir::Location> elseLoc;
492485 if (elseS)
493- elseLoc = getStmtLoc (* elseS);
486+ elseLoc = getLoc ( elseS-> getSourceRange () );
494487
495488 mlir::LogicalResult resThen = mlir::success (), resElse = mlir::success ();
496489 emitIfOnBoolExpr (
@@ -518,7 +511,9 @@ cir::IfOp CIRGenFunction::emitIfOnBoolExpr(
518511 const clang::Expr *cond, BuilderCallbackRef thenBuilder,
519512 mlir::Location thenLoc, BuilderCallbackRef elseBuilder,
520513 std::optional<mlir::Location> elseLoc) {
521-
514+ // Attempt to be as accurate as possible with IfOp location, generate
515+ // one fused location that has either 2 or 4 total locations, depending
516+ // on else's availability.
522517 SmallVector<mlir::Location, 2 > ifLocs{thenLoc};
523518 if (elseLoc)
524519 ifLocs.push_back (*elseLoc);
@@ -531,44 +526,34 @@ cir::IfOp CIRGenFunction::emitIfOnBoolExpr(
531526 /* elseBuilder=*/ elseBuilder);
532527}
533528
534- // / TODO(cir): PGO data
535529// / TODO(cir): see EmitBranchOnBoolExpr for extra ideas).
536530mlir::Value CIRGenFunction::emitOpOnBoolExpr (mlir::Location loc,
537531 const Expr *cond) {
538- // TODO(CIR): scoped ApplyDebugLocation DL(*this, Cond );
539- // TODO(CIR): __builtin_unpredictable and profile counts?
532+ assert (! cir::MissingFeatures::pgoUse () );
533+ assert (! cir::MissingFeatures::generateDebugInfo ());
540534 cond = cond->IgnoreParens ();
541535
542- // if (const BinaryOperator *CondBOp = dyn_cast<BinaryOperator>(cond)) {
543- // llvm_unreachable("binaryoperator ifstmt NYI");
544- // }
545-
546- if (const UnaryOperator *CondUOp = dyn_cast<UnaryOperator>(cond)) {
547- // In LLVM the condition is reversed here for efficient codegen.
548- // This should be done in CIR prior to LLVM lowering, if we do now
549- // we can make CIR based diagnostics misleading.
550- // cir.ternary(!x, t, f) -> cir.ternary(x, f, t)
551- assert (!cir::MissingFeatures::shouldReverseUnaryCondOnBoolExpr ());
552- }
536+ // In LLVM the condition is reversed here for efficient codegen.
537+ // This should be done in CIR prior to LLVM lowering, if we do now
538+ // we can make CIR based diagnostics misleading.
539+ // cir.ternary(!x, t, f) -> cir.ternary(x, f, t)
540+ assert (!cir::MissingFeatures::shouldReverseUnaryCondOnBoolExpr ());
553541
554- if (const ConditionalOperator *CondOp = dyn_cast <ConditionalOperator>(cond)) {
542+ if (isa <ConditionalOperator>(cond)) {
555543
556544 cgm.errorNYI (cond->getExprLoc (), " Ternary NYI" );
557545 assert (!cir::MissingFeatures::ternaryOp ());
558546 return createDummyValue (loc, cond->getType ());
559547 }
560548
561- // if (const CXXThrowExpr *Throw = dyn_cast <CXXThrowExpr>(cond)) {
562- // llvm_unreachable ("NYI");
563- // }
549+ if (isa <CXXThrowExpr>(cond)) {
550+ cgm. errorNYI (" NYI" );
551+ }
564552
565553 // If the branch has a condition wrapped by __builtin_unpredictable,
566554 // create metadata that specifies that the branch is unpredictable.
567555 // Don't bother if not optimizing because that metadata would not be used.
568- auto *Call = dyn_cast<CallExpr>(cond->IgnoreImpCasts ());
569- if (Call && cgm.getCodeGenOpts ().OptimizationLevel != 0 ) {
570- assert (!cir::MissingFeatures::insertBuiltinUnpredictable ());
571- }
556+ assert (!cir::MissingFeatures::insertBuiltinUnpredictable ());
572557
573558 // Emit the code with the fully general case.
574559 return evaluateExprAsBool (cond);
0 commit comments