Skip to content

Commit 3e325c3

Browse files
authored
Add Try/catch (#193)
* Add Try * Fix placement new
1 parent 326e0ee commit 3e325c3

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

tools/mlir-clang/Lib/CGStmt.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,12 @@ ValueCategory MLIRScanner::VisitGotoStmt(clang::GotoStmt *stmt) {
978978
return nullptr;
979979
}
980980

981+
ValueCategory MLIRScanner::VisitCXXTryStmt(clang::CXXTryStmt *stmt) {
982+
llvm::errs() << "warning, not performing catches for try: ";
983+
stmt->dump();
984+
return Visit(stmt->getTryBlock());
985+
}
986+
981987
ValueCategory MLIRScanner::VisitReturnStmt(clang::ReturnStmt *stmt) {
982988
IfScope scope(*this);
983989
bool isArrayReturn = false;

tools/mlir-clang/Lib/clang-mlir.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,23 @@ ValueCategory MLIRScanner::VisitCXXNewExpr(clang::CXXNewExpr *expr) {
11071107

11081108
mlir::Value alloc;
11091109
mlir::Value arrayCons;
1110-
if (auto mt = ty.dyn_cast<mlir::MemRefType>()) {
1110+
if (!expr->placement_arguments().empty()) {
1111+
mlir::Value val = Visit(*expr->placement_arg_begin()).getValue(builder);
1112+
if (auto mt = ty.dyn_cast<mlir::MemRefType>()) {
1113+
arrayCons = alloc =
1114+
builder.create<polygeist::Pointer2MemrefOp>(loc, mt, val);
1115+
} else {
1116+
arrayCons = alloc = builder.create<mlir::LLVM::BitcastOp>(loc, ty, val);
1117+
auto PT = ty.cast<LLVM::LLVMPointerType>();
1118+
if (expr->isArray())
1119+
arrayCons = builder.create<mlir::LLVM::BitcastOp>(
1120+
loc,
1121+
LLVM::LLVMPointerType::get(
1122+
LLVM::LLVMArrayType::get(PT.getElementType(), 0),
1123+
PT.getAddressSpace()),
1124+
alloc);
1125+
}
1126+
} else if (auto mt = ty.dyn_cast<mlir::MemRefType>()) {
11111127
auto shape = std::vector<int64_t>(mt.getShape());
11121128
mlir::Value args[1] = {count};
11131129
arrayCons = alloc = builder.create<mlir::memref::AllocOp>(loc, mt, args);
@@ -1116,7 +1132,7 @@ ValueCategory MLIRScanner::VisitCXXNewExpr(clang::CXXNewExpr *expr) {
11161132
auto typeSize = getTypeSize(expr->getAllocatedType());
11171133
mlir::Value args[1] = {builder.create<arith::MulIOp>(loc, typeSize, count)};
11181134
args[0] = builder.create<IndexCastOp>(loc, i64, args[0]);
1119-
alloc = builder.create<mlir::LLVM::BitcastOp>(
1135+
arrayCons = alloc = builder.create<mlir::LLVM::BitcastOp>(
11201136
loc, ty,
11211137
builder
11221138
.create<mlir::LLVM::CallOp>(loc, Glob.GetOrCreateMallocFunction(),

tools/mlir-clang/Lib/clang-mlir.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ class MLIRScanner : public StmtVisitor<MLIRScanner, ValueCategory> {
249249

250250
ValueCategory VisitCXXTypeidExpr(clang::CXXTypeidExpr *expr);
251251

252+
ValueCategory VisitCXXTryStmt(clang::CXXTryStmt *stmt);
253+
252254
ValueCategory VisitStringLiteral(clang::StringLiteral *expr);
253255

254256
ValueCategory VisitParenExpr(clang::ParenExpr *expr);

0 commit comments

Comments
 (0)