Handle Label & goto
This commit is contained in:
parent
56c878e72d
commit
016acada4e
|
@ -306,6 +306,37 @@ ValueCategory MLIRScanner::VisitContinueStmt(clang::ContinueStmt *stmt) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
ValueCategory MLIRScanner::VisitLabelStmt(clang::LabelStmt *stmt) {
|
||||
auto toadd = builder.getInsertionBlock()->getParent();
|
||||
Block *labelB;
|
||||
auto found = labels.find(stmt);
|
||||
if (found != labels.end()) {
|
||||
labelB = found->second;
|
||||
} else {
|
||||
labelB = new Block();
|
||||
labels[stmt] = labelB;
|
||||
}
|
||||
toadd->getBlocks().push_back(labelB);
|
||||
builder.create<mlir::BranchOp>(loc, labelB);
|
||||
builder.setInsertionPointToStart(labelB);
|
||||
Visit(stmt->getSubStmt());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ValueCategory MLIRScanner::VisitGotoStmt(clang::GotoStmt *stmt) {
|
||||
auto labelstmt = stmt->getLabel()->getStmt();
|
||||
Block *labelB;
|
||||
auto found = labels.find(labelstmt);
|
||||
if (found != labels.end()) {
|
||||
labelB = found->second;
|
||||
} else {
|
||||
labelB = new Block();
|
||||
labels[labelstmt] = labelB;
|
||||
}
|
||||
builder.create<mlir::BranchOp>(loc, labelB);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ValueCategory MLIRScanner::VisitReturnStmt(clang::ReturnStmt *stmt) {
|
||||
IfScope scope(*this);
|
||||
bool isArrayReturn = false;
|
||||
|
|
|
@ -309,6 +309,10 @@ public:
|
|||
|
||||
ValueCategory VisitReturnStmt(clang::ReturnStmt *stmt);
|
||||
|
||||
std::map<LabelStmt *, Block *> labels;
|
||||
ValueCategory VisitLabelStmt(clang::LabelStmt *stmt);
|
||||
ValueCategory VisitGotoStmt(clang::GotoStmt *stmt);
|
||||
|
||||
ValueCategory VisitStmtExpr(clang::StmtExpr *stmt);
|
||||
|
||||
ValueCategory VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr *expr);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// RUN: mlir-clang %s --function=* -S | FileCheck %s
|
||||
|
||||
int fir (int d_i[1000], int idx[1000] ) {
|
||||
int i;
|
||||
int tmp=0;
|
||||
|
||||
for_loop:
|
||||
for (i=0;i<1000;i++) {
|
||||
tmp += idx [i] * d_i[999-i];
|
||||
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// CHECK: func @fir(%arg0: memref<?xi32>, %arg1: memref<?xi32>) -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
|
||||
// CHECK-NEXT: %c1 = arith.constant 1 : index
|
||||
// CHECK-NEXT: %c0 = arith.constant 0 : index
|
||||
// CHECK-NEXT: %c1000 = arith.constant 1000 : index
|
||||
// CHECK-NEXT: %c999 = arith.constant 999 : index
|
||||
// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32
|
||||
// CHECK-NEXT: %0:2 = scf.for %arg2 = %c0 to %c1000 step %c1 iter_args(%arg3 = %c0_i32, %arg4 = %c0_i32) -> (i32, i32) {
|
||||
// CHECK-NEXT: %1 = memref.load %arg1[%arg2] : memref<?xi32>
|
||||
// CHECK-NEXT: %2 = arith.subi %c999, %arg2 : index
|
||||
// CHECK-NEXT: %3 = memref.load %arg0[%2] : memref<?xi32>
|
||||
// CHECK-NEXT: %4 = arith.muli %1, %3 : i32
|
||||
// CHECK-NEXT: %5 = arith.addi %arg3, %4 : i32
|
||||
// CHECK-NEXT: scf.yield %5, %5 : i32, i32
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: return %0#1 : i32
|
||||
// CHECK-NEXT: }
|
Loading…
Reference in New Issue