Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm-project
Submodule llvm-project updated 2174 files
1 change: 1 addition & 0 deletions tools/mlir-clang/Lib/CGStmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ ValueCategory MLIRScanner::VisitForStmt(clang::ForStmt *fors) {
loops.push_back(lctx);
Visit(fors->getBody());
if (auto s = fors->getInc()) {
IfScope scope(*this);
Visit(s);
}
loops.pop_back();
Expand Down
33 changes: 33 additions & 0 deletions tools/mlir-clang/Lib/clang-mlir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,39 @@ ValueCategory MLIRScanner::VisitInitListExpr(clang::InitListExpr *expr) {
return ValueCategory(op, true);
}

ValueCategory MLIRScanner::VisitCXXStdInitializerListExpr(
clang::CXXStdInitializerListExpr *expr) {

auto ArrayPtr = Visit(expr->getSubExpr());

const ConstantArrayType *ArrayType =
Glob.CGM.getContext().getAsConstantArrayType(
expr->getSubExpr()->getType());
assert(ArrayType && "std::initializer_list constructed from non-array");

// FIXME: Perform the checks on the field types in SemaInit.
RecordDecl *Record = expr->getType()->castAs<RecordType>()->getDecl();
auto Field = Record->field_begin();

mlir::Type subType = getMLIRType(expr->getType());

mlir::Value res = builder.create<LLVM::UndefOp>(loc, subType);

ArrayPtr = CommonArrayToPointer(ArrayPtr);

res = builder.create<LLVM::InsertValueOp>(loc, res.getType(), res,
ArrayPtr.getValue(builder),
builder.getI64ArrayAttr(0));
Field++;
auto iTy = getMLIRType(Field->getType()).cast<mlir::IntegerType>();
res = builder.create<LLVM::InsertValueOp>(
loc, res.getType(), res,
builder.create<arith::ConstantIntOp>(
loc, ArrayType->getSize().getZExtValue(), iTy.getWidth()),
builder.getI64ArrayAttr(1));
return ValueCategory(res, /*isRef*/ false);
}

ValueCategory
MLIRScanner::VisitArrayInitIndexExpr(clang::ArrayInitIndexExpr *expr) {
assert(arrayinit.size());
Expand Down
2 changes: 2 additions & 0 deletions tools/mlir-clang/Lib/clang-mlir.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ class MLIRScanner : public StmtVisitor<MLIRScanner, ValueCategory> {
mlir::Attribute InitializeValueByInitListExpr(mlir::Value toInit,
clang::Expr *expr);
ValueCategory VisitInitListExpr(clang::InitListExpr *expr);
ValueCategory
VisitCXXStdInitializerListExpr(clang::CXXStdInitializerListExpr *expr);

ValueCategory VisitArrayInitLoop(clang::ArrayInitLoopExpr *expr,
ValueCategory tostore);
Expand Down
2 changes: 2 additions & 0 deletions tools/mlir-clang/Test/Verification/combif.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: mlir-clang %s --function=* -S | FileCheck %s

// XFAIL: *
// TODO handle negation on if combine
// TODO remove unused cyclic phi

void use(float);
Expand Down
33 changes: 33 additions & 0 deletions tools/mlir-clang/Test/Verification/loopinc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: mlir-clang %s --function=test -S | FileCheck %s

unsigned int test() {
int divisor = 1;
unsigned int shift; // Shift amounts.

for (shift = 0; 1; shift++) if ((1U << shift) >= divisor) break;

// should always return 0
return shift;
}

// CHECK: func @test() -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32
// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32
// CHECK-NEXT: %true = arith.constant true
// CHECK-NEXT: %0 = scf.while (%arg0 = %c0_i32, %arg1 = %true) : (i32, i1) -> i32 {
// CHECK-NEXT: scf.condition(%arg1) %arg0 : i32
// CHECK-NEXT: } do {
// CHECK-NEXT: ^bb0(%arg0: i32):
// CHECK-NEXT: %1 = arith.shli %c1_i32, %arg0 : i32
// CHECK-NEXT: %2 = arith.cmpi uge, %1, %c1_i32 : i32
// CHECK-NEXT: %3 = arith.cmpi ult, %1, %c1_i32 : i32
// CHECK-NEXT: %4 = scf.if %2 -> (i32) {
// CHECK-NEXT: scf.yield %arg0 : i32
// CHECK-NEXT: } else {
// CHECK-NEXT: %5 = arith.addi %arg0, %c1_i32 : i32
// CHECK-NEXT: scf.yield %5 : i32
// CHECK-NEXT: }
// CHECK-NEXT: scf.yield %4, %3 : i32, i1
// CHECK-NEXT: }
// CHECK-NEXT: return %0 : i32
// CHECK-NEXT: }