================
@@ -426,28 +444,36 @@ emitStructFieldArgs(mlir::OpBuilder &builder,
mlir::Location loc,
mlir::Value structVal, cir::RecordType recTy,
SmallVectorImpl<mlir::Value> &newArgs,
SmallVectorImpl<cir::LoadOp> &replacedWholeLoads) {
- cir::LoadOp wholeLoad = structVal.getDefiningOp<cir::LoadOp>();
- cir::AllocaOp srcAlloca;
- if (wholeLoad && !wholeLoad.getIsVolatile() && !wholeLoad.getMemOrder())
- srcAlloca = wholeLoad.getAddr().getDefiningOp<cir::AllocaOp>();
+ WholeRecordSource src = getWholeRecordSource(structVal);
- if (srcAlloca) {
+ if (src.alloca) {
mlir::OpBuilder::InsertionGuard guard(builder);
- builder.setInsertionPoint(wholeLoad);
+ builder.setInsertionPoint(src.load);
for (auto [f, fieldTy] : llvm::enumerate(recTy.getMembers())) {
mlir::Type fieldPtrTy = cir::PointerType::get(fieldTy);
mlir::Value fieldPtr = cir::GetMemberOp::create(
- builder, loc, fieldPtrTy, srcAlloca, /*name=*/"", /*index=*/f);
+ builder, loc, fieldPtrTy, src.alloca, /*name=*/"", /*index=*/f);
newArgs.push_back(cir::LoadOp::create(builder, loc, fieldPtr));
}
- replacedWholeLoads.push_back(wholeLoad);
+ replacedWholeLoads.push_back(src.load);
} else {
for (unsigned f = 0; f < recTy.getNumElements(); ++f)
newArgs.push_back(
cir::ExtractMemberOp::create(builder, loc, structVal, f));
}
}
+/// Erase the whole-record loads a call-site rewrite read around, once the
+/// original call (their remaining user) is gone. A single load can feed
+/// several operands (e.g. after CSE merges identical loads), so dedupe before
+/// erasing to avoid touching a freed op twice.
+static void eraseDeadWholeRecordLoads(ArrayRef<cir::LoadOp> loads) {
+ SmallPtrSet<mlir::Operation *, 4> erased;
+ for (cir::LoadOp wholeLoad : loads)
+ if (erased.insert(wholeLoad).second && wholeLoad.use_empty())
----------------
erichkeane wrote:
Is it not weird to add to 'erased' even if the use list is empty? Also, is
`use_empty` cheaper enough we should be checking that first?
https://github.com/llvm/llvm-project/pull/216499
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits