@@ -256,12 +256,6 @@ void MLIRScanner::init(mlir::FuncOp function, const FunctionDecl *fd) {
256
256
llvm::errs () << " warning, destructor not fully handled yet\n " ;
257
257
}
258
258
259
- Stmt *stmt = fd->getBody ();
260
- assert (stmt);
261
- if (ShowAST) {
262
- stmt->dump ();
263
- }
264
-
265
259
auto i1Ty = builder.getIntegerType (1 );
266
260
auto type = mlir::MemRefType::get ({}, i1Ty, {}, 0 );
267
261
auto truev = builder.create <ConstantIntOp>(loc, true , 1 );
@@ -279,6 +273,51 @@ void MLIRScanner::init(mlir::FuncOp function, const FunctionDecl *fd) {
279
273
returnVal, std::vector<mlir::Value>({}));
280
274
}
281
275
}
276
+
277
+ if (auto D = dyn_cast<CXXMethodDecl>(fd)) {
278
+ // ClangAST incorrectly does not contain the correct definition
279
+ // of a union move operation and as such we _must_ emit a memcpy
280
+ // for a defaulted union copy or move.
281
+ if (D->getParent ()->isUnion () && D->isDefaulted ()) {
282
+ mlir::Value V = ThisVal.val ;
283
+ assert (V);
284
+ if (auto MT = V.getType ().dyn_cast <MemRefType>()) {
285
+ V = builder.create <polygeist::Pointer2MemrefOp>(
286
+ loc, LLVM::LLVMPointerType::get (MT.getElementType ()), V);
287
+ }
288
+ mlir::Value src = function.getArgument (1 );
289
+ if (auto MT = src.getType ().dyn_cast <MemRefType>()) {
290
+ src = builder.create <polygeist::Pointer2MemrefOp>(
291
+ loc, LLVM::LLVMPointerType::get (MT.getElementType ()), src);
292
+ }
293
+ mlir::Value typeSize = builder.create <polygeist::TypeSizeOp>(
294
+ loc, builder.getIndexType (),
295
+ mlir::TypeAttr::get (
296
+ V.getType ().cast <LLVM::LLVMPointerType>().getElementType ()));
297
+ typeSize = builder.create <arith::IndexCastOp>(loc, builder.getI64Type (),
298
+ typeSize);
299
+ V = builder.create <LLVM::BitcastOp>(
300
+ loc,
301
+ LLVM::LLVMPointerType::get (
302
+ builder.getI8Type (),
303
+ V.getType ().cast <LLVM::LLVMPointerType>().getAddressSpace ()),
304
+ V);
305
+ src = builder.create <LLVM::BitcastOp>(
306
+ loc,
307
+ LLVM::LLVMPointerType::get (
308
+ builder.getI8Type (),
309
+ src.getType ().cast <LLVM::LLVMPointerType>().getAddressSpace ()),
310
+ src);
311
+ mlir::Value volatileCpy = builder.create <ConstantIntOp>(loc, false , 1 );
312
+ builder.create <LLVM::MemcpyOp>(loc, V, src, typeSize, volatileCpy);
313
+ }
314
+ }
315
+
316
+ Stmt *stmt = fd->getBody ();
317
+ assert (stmt);
318
+ if (ShowAST) {
319
+ stmt->dump ();
320
+ }
282
321
Visit (stmt);
283
322
284
323
if (function.getFunctionType ().getResults ().size ()) {
@@ -3206,13 +3245,19 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass(
3206
3245
Glob.CGM .getContext ().getLValueReferenceType (QualType (BaseType, 0 )));
3207
3246
3208
3247
size_t fnum;
3248
+ bool subIndex = true ;
3209
3249
3210
3250
if (isLLVMStructABI (RD, /* ST*/ nullptr )) {
3211
3251
auto &layout = Glob.CGM .getTypes ().getCGRecordLayout (RD);
3212
3252
if (std::get<1 >(tup))
3213
3253
fnum = layout.getVirtualBaseIndex (BaseDecl);
3214
- else
3215
- fnum = layout.getNonVirtualBaseLLVMFieldNo (BaseDecl);
3254
+ else {
3255
+ if (!layout.hasNonVirtualBaseLLVMField (BaseDecl)) {
3256
+ subIndex = false ;
3257
+ } else {
3258
+ fnum = layout.getNonVirtualBaseLLVMFieldNo (BaseDecl);
3259
+ }
3260
+ }
3216
3261
} else {
3217
3262
assert (!std::get<1 >(tup) && " Should not see virtual bases here!" );
3218
3263
fnum = 0 ;
@@ -3228,31 +3273,34 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass(
3228
3273
assert (found);
3229
3274
}
3230
3275
3231
- if (auto mt = value.getType ().dyn_cast <MemRefType>()) {
3232
- auto shape = std::vector<int64_t >(mt.getShape ());
3233
- shape.erase (shape.begin ());
3234
- auto mt0 = mlir::MemRefType::get (shape, mt.getElementType (),
3235
- MemRefLayoutAttrInterface (),
3236
- mt.getMemorySpace ());
3237
- value = builder.create <polygeist::SubIndexOp>(loc, mt0, value,
3238
- getConstantIndex (fnum));
3239
- } else {
3240
- mlir::Value idx[] = {builder.create <arith::ConstantIntOp>(loc, 0 , 32 ),
3241
- builder.create <arith::ConstantIntOp>(loc, fnum, 32 )};
3242
- auto PT = value.getType ().cast <LLVM::LLVMPointerType>();
3243
- mlir::Type ET;
3244
- if (auto ST =
3245
- PT.getElementType ().dyn_cast <mlir::LLVM::LLVMStructType>()) {
3246
- ET = ST.getBody ()[fnum];
3276
+ if (subIndex) {
3277
+ if (auto mt = value.getType ().dyn_cast <MemRefType>()) {
3278
+ auto shape = std::vector<int64_t >(mt.getShape ());
3279
+ shape.erase (shape.begin ());
3280
+ auto mt0 = mlir::MemRefType::get (shape, mt.getElementType (),
3281
+ MemRefLayoutAttrInterface (),
3282
+ mt.getMemorySpace ());
3283
+ value = builder.create <polygeist::SubIndexOp>(loc, mt0, value,
3284
+ getConstantIndex (fnum));
3247
3285
} else {
3248
- ET = PT.getElementType ()
3249
- .cast <mlir::LLVM::LLVMArrayType>()
3250
- .getElementType ();
3251
- }
3286
+ mlir::Value idx[] = {
3287
+ builder.create <arith::ConstantIntOp>(loc, 0 , 32 ),
3288
+ builder.create <arith::ConstantIntOp>(loc, fnum, 32 )};
3289
+ auto PT = value.getType ().cast <LLVM::LLVMPointerType>();
3290
+ mlir::Type ET;
3291
+ if (auto ST =
3292
+ PT.getElementType ().dyn_cast <mlir::LLVM::LLVMStructType>()) {
3293
+ ET = ST.getBody ()[fnum];
3294
+ } else {
3295
+ ET = PT.getElementType ()
3296
+ .cast <mlir::LLVM::LLVMArrayType>()
3297
+ .getElementType ();
3298
+ }
3252
3299
3253
- value = builder.create <LLVM::GEPOp>(
3254
- loc, LLVM::LLVMPointerType::get (ET, PT.getAddressSpace ()), value,
3255
- idx);
3300
+ value = builder.create <LLVM::GEPOp>(
3301
+ loc, LLVM::LLVMPointerType::get (ET, PT.getAddressSpace ()), value,
3302
+ idx);
3303
+ }
3256
3304
}
3257
3305
3258
3306
auto pt = nt.dyn_cast <mlir::LLVM::LLVMPointerType>();
0 commit comments