Skip to content

Commit 182cdc6

Browse files
committed
results of scope op forwarded
1 parent 8176d88 commit 182cdc6

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,10 @@ class CIRScopeOpFlattening : public mlir::OpRewritePattern<cir::ScopeOp> {
135135
// Split the current block before the ScopeOp to create the inlining
136136
// point.
137137
auto *currentBlock = rewriter.getInsertionBlock();
138-
auto *remainingOpsBlock =
138+
mlir::Block *continueBlock =
139139
rewriter.splitBlock(currentBlock, rewriter.getInsertionPoint());
140-
mlir::Block *continueBlock;
141-
if (scopeOp.getNumResults() == 0)
142-
continueBlock = remainingOpsBlock;
143-
else
144-
llvm_unreachable("NYI");
140+
if (scopeOp.getNumResults() > 0)
141+
continueBlock->addArguments(scopeOp.getResultTypes(), loc);
145142

146143
// Inline body region.
147144
auto *beforeBody = &scopeOp.getRegion().front();

clang/test/CIR/CodeGen/fullexpr.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir-flat %s -o %t.cir.flat
4+
// RUN: FileCheck --check-prefix=FLAT --input-file=%t.cir.flat %s
5+
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -o - %s \
6+
// RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll
7+
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
38

49
int go(int const& val);
510

@@ -18,3 +23,31 @@ int go1() {
1823
// CHECK-NEXT: cir.yield %[[#RValTmp]] : !s32i
1924
// CHECK-NEXT: }
2025
// CHECK-NEXT: cir.store %[[#RVal]], %[[#XAddr]] : !s32i, !cir.ptr<!s32i>
26+
27+
// FLAT: cir.func @_Z3go1v() -> !s32i
28+
// FLAT: %[[#TmpAddr:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["ref.tmp0", init] {alignment = 4 : i64}
29+
// FLAT: %[[#XAddr:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {alignment = 4 : i64}
30+
// FLAT: cir.br ^[[before_body:.*]]{{ loc.*}}
31+
// FLAT-NEXT: ^[[before_body]]: // pred: ^bb0
32+
// FLAT-NEXT: %[[#One:]] = cir.const #cir.int<1> : !s32i
33+
// FLAT-NEXT: cir.store %[[#One]], %[[#TmpAddr]] : !s32i, !cir.ptr<!s32i>
34+
// FLAT-NEXT: %[[#RValTmp:]] = cir.call @_Z2goRKi(%[[#TmpAddr]]) : (!cir.ptr<!s32i>) -> !s32i
35+
// FLAT-NEXT: cir.br ^[[continue_block:.*]](%[[#RValTmp]] : !s32i) {{loc.*}}
36+
// FLAT-NEXT: ^[[continue_block]](%[[#BlkArgRval:]]: !s32i {{loc.*}}): // pred: ^[[before_body]]
37+
// FLAT-NEXT: cir.store %[[#BlkArgRval]], %[[#XAddr]] : !s32i, !cir.ptr<!s32i>
38+
39+
// LLVM-LABEL: @_Z3go1v()
40+
// LLVM-NEXT: %[[#TmpAddr:]] = alloca i32, i64 1, align 4
41+
// LLVM: br label %[[before_body:[0-9]+]]
42+
// LLVM: [[before_body]]:
43+
// LLVM-NEXT: store i32 1, ptr %[[#TmpAddr]], align 4
44+
// LLVM-NEXT: %[[#RValTmp:]] = call i32 @_Z2goRKi(ptr %[[#TmpAddr]])
45+
// LLVM-NEXT: br label %[[continue_block:[0-9]+]]
46+
47+
// LLVM: [[continue_block]]:
48+
// LLVM-NEXT: [[PHI:%.*]] = phi i32 [ %[[#RValTmp]], %[[before_body]] ]
49+
// LLVM: store i32 [[PHI]], ptr [[TMP0:%.*]], align 4
50+
// LLVM: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
51+
// LLVM: store i32 [[TMP1]], ptr [[TMP2:%.*]], align 4
52+
// LLVM: [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4
53+
// LLVM: ret i32 [[TMP3]]

0 commit comments

Comments
 (0)