15
15
16
16
#include " mlir/IR/Builders.h"
17
17
#include " mlir/IR/Location.h"
18
+ #include " mlir/Support/LLVM.h"
18
19
#include " clang/AST/ExprCXX.h"
19
20
#include " clang/AST/Stmt.h"
20
21
#include " clang/AST/StmtOpenACC.h"
@@ -24,16 +25,13 @@ using namespace clang;
24
25
using namespace clang ::CIRGen;
25
26
using namespace cir ;
26
27
27
- Address CIRGenFunction::emitCompoundStmtWithoutScope (const CompoundStmt &s,
28
- Address *lastValue,
29
- AggValueSlot slot) {
28
+ mlir::LogicalResult CIRGenFunction::emitCompoundStmtWithoutScope (
29
+ const CompoundStmt &s, Address *lastValue, AggValueSlot slot) {
30
30
const Stmt *exprResult = s.getStmtExprResult ();
31
31
assert ((!lastValue || (lastValue && exprResult)) &&
32
32
" If lastValue is not null then the CompoundStmt must have a "
33
33
" StmtExprResult" );
34
34
35
- Address retAlloca = Address::invalid ();
36
-
37
35
for (Stmt *curStmt : s.body ()) {
38
36
// We have to special case labels here. They are statements, but when put
39
37
// at the end of a statement expression, they yield the value of their
@@ -44,7 +42,7 @@ Address CIRGenFunction::emitCompoundStmtWithoutScope(const CompoundStmt &s,
44
42
while (!isa<Expr>(exprResult)) {
45
43
if (const auto *ls = dyn_cast<LabelStmt>(exprResult)) {
46
44
if (emitLabel (*ls->getDecl ()).failed ())
47
- return Address::invalid ();
45
+ return mlir::failure ();
48
46
exprResult = ls->getSubStmt ();
49
47
} else if (const auto *as = dyn_cast<AttributedStmt>(exprResult)) {
50
48
// FIXME: Update this if we ever have attributes that affect the
@@ -68,18 +66,16 @@ Address CIRGenFunction::emitCompoundStmtWithoutScope(const CompoundStmt &s,
68
66
}
69
67
} else {
70
68
if (emitStmt (curStmt, /* useCurrentScope=*/ false ).failed ())
71
- return Address::invalid ();
69
+ return mlir::failure ();
72
70
}
73
71
}
74
72
75
- return retAlloca ;
73
+ return mlir::success () ;
76
74
}
77
75
78
- Address CIRGenFunction::emitCompoundStmt (const CompoundStmt &s,
79
- Address *lastValue,
80
- AggValueSlot slot) {
81
- Address retAlloca = Address::invalid ();
82
-
76
+ mlir::LogicalResult CIRGenFunction::emitCompoundStmt (const CompoundStmt &s,
77
+ Address *lastValue,
78
+ AggValueSlot slot) {
83
79
// Add local scope to track new declared variables.
84
80
SymTableScopeTy varScope (symbolTable);
85
81
mlir::Location scopeLoc = getLoc (s.getSourceRange ());
@@ -88,14 +84,10 @@ Address CIRGenFunction::emitCompoundStmt(const CompoundStmt &s,
88
84
scopeLoc, [&](mlir::OpBuilder &b, mlir::Type &type, mlir::Location loc) {
89
85
scopeInsPt = b.saveInsertionPoint ();
90
86
});
91
- {
92
- mlir::OpBuilder::InsertionGuard guard (builder);
93
- builder.restoreInsertionPoint (scopeInsPt);
94
- LexicalScope lexScope (*this , scopeLoc, builder.getInsertionBlock ());
95
- retAlloca = emitCompoundStmtWithoutScope (s, lastValue, slot);
96
- }
97
-
98
- return retAlloca;
87
+ mlir::OpBuilder::InsertionGuard guard (builder);
88
+ builder.restoreInsertionPoint (scopeInsPt);
89
+ LexicalScope lexScope (*this , scopeLoc, builder.getInsertionBlock ());
90
+ return emitCompoundStmtWithoutScope (s, lastValue, slot);
99
91
}
100
92
101
93
void CIRGenFunction::emitStopPoint (const Stmt *s) {
@@ -297,10 +289,8 @@ mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const Stmt *s,
297
289
return emitDeclStmt (cast<DeclStmt>(*s));
298
290
case Stmt::CompoundStmtClass:
299
291
if (useCurrentScope)
300
- emitCompoundStmtWithoutScope (cast<CompoundStmt>(*s));
301
- else
302
- emitCompoundStmt (cast<CompoundStmt>(*s));
303
- break ;
292
+ return emitCompoundStmtWithoutScope (cast<CompoundStmt>(*s));
293
+ return emitCompoundStmt (cast<CompoundStmt>(*s));
304
294
case Stmt::ContinueStmtClass:
305
295
return emitContinueStmt (cast<ContinueStmt>(*s));
306
296
0 commit comments