@@ -406,6 +406,35 @@ MLIRScanner::EmitClangBuiltinCallExpr(clang::CallExpr *expr) {
406
406
llvm::errs () << " val: " << val << " T: " << T << " \n " ;
407
407
assert (0 && " unhandled builtin addressof" );
408
408
}
409
+ case Builtin::BI__builtin_operator_new: {
410
+ mlir::Value count = Visit (*expr->arg_begin ()).getValue (loc, builder);
411
+ count = builder.create <IndexCastOp>(
412
+ loc, mlir::IndexType::get (builder.getContext ()), count);
413
+ auto ty = getMLIRType (expr->getType ());
414
+ mlir::Value alloc;
415
+ if (auto mt = ty.dyn_cast <mlir::MemRefType>()) {
416
+ auto shape = std::vector<int64_t >(mt.getShape ());
417
+ mlir::Value args[1 ] = {count};
418
+ alloc = builder.create <mlir::memref::AllocOp>(loc, mt, args);
419
+ } else {
420
+ auto PT = ty.cast <LLVM::LLVMPointerType>();
421
+ alloc = builder.create <mlir::LLVM::BitcastOp>(
422
+ loc, ty, Glob.CallMalloc (builder, loc, count));
423
+ }
424
+ return make_pair (ValueCategory (alloc, /* isRef*/ false ), true );
425
+ }
426
+ case Builtin::BI__builtin_operator_delete: {
427
+ mlir::Value toDelete = Visit (*expr->arg_begin ()).getValue (loc, builder);
428
+ if (toDelete.getType ().isa <mlir::MemRefType>()) {
429
+ builder.create <mlir::memref::DeallocOp>(loc, toDelete);
430
+ } else {
431
+ mlir::Value args[1 ] = {builder.create <LLVM::BitcastOp>(
432
+ loc, LLVM::LLVMPointerType::get (builder.getI8Type ()), toDelete)};
433
+ builder.create <mlir::LLVM::CallOp>(loc, Glob.GetOrCreateFreeFunction (),
434
+ args);
435
+ }
436
+ return make_pair (nullptr , true );
437
+ }
409
438
default :
410
439
break ;
411
440
}
0 commit comments