@@ -186,6 +186,36 @@ static mlir::Type wrapAllocaResultType(mlir::Type intype) {
186186 return fir::ReferenceType::get (intype);
187187}
188188
189+ llvm::SmallVector<mlir::MemorySlot> fir::AllocaOp::getPromotableSlots () {
190+ // TODO: support promotion of dynamic allocas
191+ if (isDynamic ())
192+ return {};
193+
194+ return {mlir::MemorySlot{getResult (), getAllocatedType ()}};
195+ }
196+
197+ mlir::Value fir::AllocaOp::getDefaultValue (const mlir::MemorySlot &slot,
198+ mlir::OpBuilder &builder) {
199+ return fir::UndefOp::create (builder, getLoc (), slot.elemType );
200+ }
201+
202+ void fir::AllocaOp::handleBlockArgument (const mlir::MemorySlot &slot,
203+ mlir::BlockArgument argument,
204+ mlir::OpBuilder &builder) {}
205+
206+ std::optional<mlir::PromotableAllocationOpInterface>
207+ fir::AllocaOp::handlePromotionComplete (const mlir::MemorySlot &slot,
208+ mlir::Value defaultValue,
209+ mlir::OpBuilder &builder) {
210+ if (defaultValue && defaultValue.use_empty ()) {
211+ assert (mlir::isa<fir::UndefOp>(defaultValue.getDefiningOp ()) &&
212+ " Expected undef op to be the default value" );
213+ defaultValue.getDefiningOp ()->erase ();
214+ }
215+ this ->erase ();
216+ return std::nullopt ;
217+ }
218+
189219mlir::Type fir::AllocaOp::getAllocatedType () {
190220 return mlir::cast<fir::ReferenceType>(getType ()).getEleTy ();
191221}
@@ -2861,6 +2891,39 @@ llvm::SmallVector<mlir::Attribute> fir::LenParamIndexOp::getAttributes() {
28612891// LoadOp
28622892// ===----------------------------------------------------------------------===//
28632893
2894+ bool fir::LoadOp::loadsFrom (const mlir::MemorySlot &slot) {
2895+ return getMemref () == slot.ptr ;
2896+ }
2897+
2898+ bool fir::LoadOp::storesTo (const mlir::MemorySlot &slot) { return false ; }
2899+
2900+ mlir::Value fir::LoadOp::getStored (const mlir::MemorySlot &slot,
2901+ mlir::OpBuilder &builder,
2902+ mlir::Value reachingDef,
2903+ const mlir::DataLayout &dataLayout) {
2904+ return mlir::Value ();
2905+ }
2906+
2907+ bool fir::LoadOp::canUsesBeRemoved (
2908+ const mlir::MemorySlot &slot,
2909+ const SmallPtrSetImpl<mlir::OpOperand *> &blockingUses,
2910+ mlir::SmallVectorImpl<mlir::OpOperand *> &newBlockingUses,
2911+ const mlir::DataLayout &dataLayout) {
2912+ if (blockingUses.size () != 1 )
2913+ return false ;
2914+ mlir::Value blockingUse = (*blockingUses.begin ())->get ();
2915+ return blockingUse == slot.ptr && getMemref () == slot.ptr ;
2916+ }
2917+
2918+ mlir::DeletionKind fir::LoadOp::removeBlockingUses (
2919+ const mlir::MemorySlot &slot,
2920+ const SmallPtrSetImpl<mlir::OpOperand *> &blockingUses,
2921+ mlir::OpBuilder &builder, mlir::Value reachingDefinition,
2922+ const mlir::DataLayout &dataLayout) {
2923+ getResult ().replaceAllUsesWith (reachingDefinition);
2924+ return mlir::DeletionKind::Delete;
2925+ }
2926+
28642927void fir::LoadOp::build (mlir::OpBuilder &builder, mlir::OperationState &result,
28652928 mlir::Value refVal) {
28662929 if (!refVal) {
@@ -4256,6 +4319,39 @@ llvm::LogicalResult fir::SliceOp::verify() {
42564319// StoreOp
42574320// ===----------------------------------------------------------------------===//
42584321
4322+ bool fir::StoreOp::loadsFrom (const mlir::MemorySlot &slot) { return false ; }
4323+
4324+ bool fir::StoreOp::storesTo (const mlir::MemorySlot &slot) {
4325+ return getMemref () == slot.ptr ;
4326+ }
4327+
4328+ mlir::Value fir::StoreOp::getStored (const mlir::MemorySlot &slot,
4329+ mlir::OpBuilder &builder,
4330+ mlir::Value reachingDef,
4331+ const mlir::DataLayout &dataLayout) {
4332+ return getValue ();
4333+ }
4334+
4335+ bool fir::StoreOp::canUsesBeRemoved (
4336+ const mlir::MemorySlot &slot,
4337+ const SmallPtrSetImpl<mlir::OpOperand *> &blockingUses,
4338+ mlir::SmallVectorImpl<mlir::OpOperand *> &newBlockingUses,
4339+ const mlir::DataLayout &dataLayout) {
4340+ if (blockingUses.size () != 1 )
4341+ return false ;
4342+ mlir::Value blockingUse = (*blockingUses.begin ())->get ();
4343+ return blockingUse == slot.ptr && getMemref () == slot.ptr &&
4344+ getValue () != slot.ptr ;
4345+ }
4346+
4347+ mlir::DeletionKind fir::StoreOp::removeBlockingUses (
4348+ const mlir::MemorySlot &slot,
4349+ const SmallPtrSetImpl<mlir::OpOperand *> &blockingUses,
4350+ mlir::OpBuilder &builder, mlir::Value reachingDefinition,
4351+ const mlir::DataLayout &dataLayout) {
4352+ return mlir::DeletionKind::Delete;
4353+ }
4354+
42594355mlir::Type fir::StoreOp::elementType (mlir::Type refType) {
42604356 return fir::dyn_cast_ptrEleTy (refType);
42614357}
0 commit comments