Skip to content

Commit a682866

Browse files
committed
Address code review comments
1 parent 49898be commit a682866

File tree

7 files changed

+28
-78
lines changed

7 files changed

+28
-78
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -389,25 +389,6 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
389389
return createCallOp(loc, callee, cir::VoidType(), operands, attrs);
390390
}
391391

392-
cir::CallOp createTryCallOp(
393-
mlir::Location loc, mlir::SymbolRefAttr callee = mlir::SymbolRefAttr(),
394-
mlir::Type returnType = cir::VoidType(),
395-
mlir::ValueRange operands = mlir::ValueRange(),
396-
[[maybe_unused]] cir::SideEffect sideEffect = cir::SideEffect::All) {
397-
assert(!cir::MissingFeatures::opCallCallConv());
398-
assert(!cir::MissingFeatures::opCallSideEffect());
399-
return createCallOp(loc, callee, returnType, operands);
400-
}
401-
402-
cir::CallOp createTryCallOp(
403-
mlir::Location loc, cir::FuncOp callee, mlir::ValueRange operands,
404-
[[maybe_unused]] cir::SideEffect sideEffect = cir::SideEffect::All) {
405-
assert(!cir::MissingFeatures::opCallCallConv());
406-
assert(!cir::MissingFeatures::opCallSideEffect());
407-
return createTryCallOp(loc, mlir::SymbolRefAttr::get(callee),
408-
callee.getFunctionType().getReturnType(), operands);
409-
}
410-
411392
//===--------------------------------------------------------------------===//
412393
// Cast/Conversion Operators
413394
//===--------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,11 @@ emitCallLikeOp(CIRGenFunction &cgf, mlir::Location callLoc,
472472
assert(!cir::MissingFeatures::opCallSurroundingTry());
473473

474474
if (isInvoke) {
475-
// This call can throw, few options:
476-
// - If this call does not have an associated cir.try, use the
477-
// one provided by InvokeDest,
478-
// - User written try/catch clauses require calls to handle
479-
// exceptions under cir.try.
475+
// This call may throw and requires catch and/or cleanup handling.
476+
// If this call does not appear within the `try` region of an existing
477+
// TryOp, we must create a synthetic TryOp to contain the call. This
478+
// happens when a call that may throw appears within a cleanup
479+
// scope.
480480

481481
// In OG, we build the landing pad for this scope. In CIR, we emit a
482482
// synthetic cir.try because this didn't come from code generating from a
@@ -501,7 +501,7 @@ emitCallLikeOp(CIRGenFunction &cgf, mlir::Location callLoc,
501501
}
502502

503503
callOpWithExceptions =
504-
builder.createTryCallOp(callLoc, directFuncOp, cirCallArgs);
504+
builder.createCallOp(callLoc, directFuncOp, cirCallArgs);
505505

506506
(void)cgf.getInvokeDest(tryOp);
507507

clang/lib/CIR/CodeGen/CIRGenCleanup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void EHScopeStack::popCleanup() {
188188
}
189189
}
190190

191-
bool EHScopeStack::requiresLandingPad() const {
191+
bool EHScopeStack::requiresCatchOrCleanup() const {
192192
for (stable_iterator si = getInnermostEHScope(); si != stable_end();) {
193193
// TODO(cir): Skip lifetime markers.
194194
assert(!cir::MissingFeatures::emitLifetimeMarkers());

clang/lib/CIR/CodeGen/CIRGenCleanup.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class EHScope {
3838
};
3939
enum { NumCommonBits = 3 };
4040

41-
bool isScopeMayThrow;
41+
bool scopeMayThrow;
4242

4343
protected:
4444
class CatchBitFields {
@@ -94,10 +94,10 @@ class EHScope {
9494
// Traditional LLVM codegen also checks for `!block->use_empty()`, but
9595
// in CIRGen the block content is not important, just used as a way to
9696
// signal `hasEHBranches`.
97-
return isScopeMayThrow;
97+
return scopeMayThrow;
9898
}
9999

100-
void setMayThrow(bool mayThrow) { isScopeMayThrow = mayThrow; }
100+
void setMayThrow(bool mayThrow) { scopeMayThrow = mayThrow; }
101101

102102
EHScopeStack::stable_iterator getEnclosingEHScope() const {
103103
return enclosingEHScope;

clang/lib/CIR/CodeGen/CIRGenException.cpp

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -355,33 +355,6 @@ void CIRGenFunction::enterCXXTryStmt(const CXXTryStmt &s, cir::TryOp tryOp,
355355
}
356356
}
357357

358-
/// Emit the structure of the dispatch block for the given catch scope.
359-
/// It is an invariant that the dispatch block already exists.
360-
static void emitCatchDispatchBlock(CIRGenFunction &cgf,
361-
EHCatchScope &catchScope, cir::TryOp tryOp) {
362-
if (EHPersonality::get(cgf).isWasmPersonality()) {
363-
cgf.cgm.errorNYI("emitCatchDispatchBlock: WASM personality");
364-
return;
365-
}
366-
367-
if (EHPersonality::get(cgf).usesFuncletPads()) {
368-
cgf.cgm.errorNYI("emitCatchDispatchBlock: usesFuncletPads");
369-
return;
370-
}
371-
372-
assert(catchScope.mayThrow() &&
373-
"Expected catchScope that may throw exception");
374-
375-
// If there's only a single catch-all, getEHDispatchBlock returned
376-
// that catch-all as the dispatch block.
377-
if (catchScope.getNumHandlers() == 1 &&
378-
catchScope.getHandler(0).isCatchAll()) {
379-
return;
380-
}
381-
382-
cgf.cgm.errorNYI("emitCatchDispatchBlock: non-catch all handler");
383-
}
384-
385358
void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
386359
unsigned numHandlers = s.getNumHandlers();
387360
EHCatchScope &catchScope = cast<EHCatchScope>(*ehStack.begin());
@@ -410,9 +383,6 @@ void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
410383
return;
411384
}
412385

413-
// Emit the structure of the EH dispatch for this catch.
414-
emitCatchDispatchBlock(*this, catchScope, tryOp);
415-
416386
// Copy the handler blocks off before we pop the EH stack. Emitting
417387
// the handlers might scribble on this memory.
418388
SmallVector<EHCatchScope::Handler, 8> handlers(
@@ -490,8 +460,8 @@ void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
490460
assert(!cir::MissingFeatures::incrementProfileCounter());
491461
}
492462

493-
mlir::Operation *CIRGenFunction::emitLandingPad(cir::TryOp tryOp) {
494-
assert(ehStack.requiresLandingPad());
463+
mlir::Operation *CIRGenFunction::populateCatchHandlers(cir::TryOp tryOp) {
464+
assert(ehStack.requiresCatchOrCleanup());
495465
assert(!cgm.getLangOpts().IgnoreExceptions &&
496466
"LandingPad should not be emitted when -fignore-exceptions are in "
497467
"effect.");
@@ -551,17 +521,17 @@ mlir::Operation *CIRGenFunction::emitLandingPad(cir::TryOp tryOp) {
551521
if (handler.isCatchAll()) {
552522
assert(!hasCatchAll);
553523
hasCatchAll = true;
554-
goto done;
524+
break;
555525
}
556526

557527
cgm.errorNYI("emitLandingPad: non catch-all");
558528
return {};
559529
}
560530

561-
goto done;
531+
if (hasCatchAll)
532+
break;
562533
}
563534

564-
done:
565535
if (hasCatchAll) {
566536
handlerAttrs.push_back(cir::CatchAllAttr::get(&getMLIRContext()));
567537
} else {
@@ -576,20 +546,19 @@ mlir::Operation *CIRGenFunction::emitLandingPad(cir::TryOp tryOp) {
576546

577547
// In traditional LLVM codegen. this tells the backend how to generate the
578548
// landing pad by generating a branch to the dispatch block. In CIR,
579-
// getEHDispatchBlock is used to populate blocks for later filing during
549+
// this is used to populate blocks for later filing during
580550
// cleanup handling.
581-
(void)getEHDispatchBlock(ehStack.getInnermostEHScope(), tryOp);
551+
(void)populateEHCatchRegions(ehStack.getInnermostEHScope(), tryOp);
582552

583553
return tryOp;
584554
}
585555

586556
// Differently from LLVM traditional codegen, there are no dispatch blocks
587557
// to look at given cir.try_call does not jump to blocks like invoke does.
588-
// However, we keep this around since other parts of CIRGen use
589-
// getCachedEHDispatchBlock to infer state.
558+
// However.
590559
mlir::Block *
591-
CIRGenFunction::getEHDispatchBlock(EHScopeStack::stable_iterator scope,
592-
cir::TryOp tryOp) {
560+
CIRGenFunction::populateEHCatchRegions(EHScopeStack::stable_iterator scope,
561+
cir::TryOp tryOp) {
593562
if (EHPersonality::get(*this).usesFuncletPads()) {
594563
cgm.errorNYI("getEHDispatchBlock: usesFuncletPads");
595564
return {};
@@ -648,7 +617,7 @@ CIRGenFunction::getEHDispatchBlock(EHScopeStack::stable_iterator scope,
648617
}
649618

650619
bool CIRGenFunction::isInvokeDest() {
651-
if (!ehStack.requiresLandingPad())
620+
if (!ehStack.requiresCatchOrCleanup())
652621
return false;
653622

654623
// If exceptions are disabled/ignored and SEH is not in use, then there is no
@@ -669,7 +638,7 @@ bool CIRGenFunction::isInvokeDest() {
669638
}
670639

671640
mlir::Operation *CIRGenFunction::getInvokeDestImpl(cir::TryOp tryOp) {
672-
assert(ehStack.requiresLandingPad());
641+
assert(ehStack.requiresCatchOrCleanup());
673642
assert(!ehStack.empty());
674643

675644
// TODO(cir): add personality function
@@ -681,7 +650,7 @@ mlir::Operation *CIRGenFunction::getInvokeDestImpl(cir::TryOp tryOp) {
681650
if (personality.usesFuncletPads()) {
682651
cgm.errorNYI("getInvokeDestImpl: usesFuncletPads");
683652
} else {
684-
lp = emitLandingPad(tryOp);
653+
lp = populateCatchHandlers(tryOp);
685654
}
686655

687656
return lp;

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,16 +916,16 @@ class CIRGenFunction : public CIRGenTypeCache {
916916
return false;
917917
}
918918

919-
mlir::Block *getEHDispatchBlock(EHScopeStack::stable_iterator scope,
920-
cir::TryOp tryOp);
919+
mlir::Block *populateEHCatchRegions(EHScopeStack::stable_iterator scope,
920+
cir::TryOp tryOp);
921921

922922
/// The cleanup depth enclosing all the cleanups associated with the
923923
/// parameters.
924924
EHScopeStack::stable_iterator prologueCleanupDepth;
925925

926926
mlir::Operation *getInvokeDestImpl(cir::TryOp tryOp);
927927
mlir::Operation *getInvokeDest(cir::TryOp tryOp) {
928-
if (!ehStack.requiresLandingPad())
928+
if (!ehStack.requiresCatchOrCleanup())
929929
return nullptr;
930930
// Return the respective cir.try, this can be used to compute
931931
// any other relevant information.
@@ -1604,7 +1604,7 @@ class CIRGenFunction : public CIRGenTypeCache {
16041604
void emitLambdaDelegatingInvokeBody(const CXXMethodDecl *md);
16051605
void emitLambdaStaticInvokeBody(const CXXMethodDecl *md);
16061606

1607-
mlir::Operation *emitLandingPad(cir::TryOp tryOp);
1607+
mlir::Operation *populateCatchHandlers(cir::TryOp tryOp);
16081608

16091609
mlir::LogicalResult emitIfStmt(const clang::IfStmt &s);
16101610

clang/lib/CIR/CodeGen/EHScopeStack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class EHScopeStack {
217217
/// Determines whether the exception-scopes stack is empty.
218218
bool empty() const { return startOfData == endOfBuffer; }
219219

220-
bool requiresLandingPad() const;
220+
bool requiresCatchOrCleanup() const;
221221

222222
/// Determines whether there are any normal cleanups on the stack.
223223
bool hasNormalCleanups() const {

0 commit comments

Comments
 (0)