20 SmallVectorImpl<OpOperand *> &newBlockingUses) {
21 for (
Value result : op->getResults())
22 for (OpOperand &use : result.getUses())
23 newBlockingUses.push_back(&use);
32 return {MemorySlot{getResult(), getAllocaType()}};
35Value cir::AllocaOp::getDefaultValue(
const MemorySlot &slot,
37 return cir::ConstantOp::create(builder, getLoc(),
38 cir::UndefAttr::get(slot.valueType));
41void cir::AllocaOp::handleBlockArgument(
const MemorySlot &slot,
42 BlockArgument argument,
43 OpBuilder &builder) {}
45std::optional<PromotableAllocationOpInterface>
46cir::AllocaOp::handlePromotionComplete(
const MemorySlot &slot,
47 Value defaultValue, OpBuilder &builder) {
48 if (defaultValue && defaultValue.use_empty())
49 defaultValue.getDefiningOp()->erase();
58bool cir::LoadOp::loadsFrom(
const MemorySlot &slot) {
59 return getAddr() == slot.ptr;
62bool cir::LoadOp::storesTo(
const MemorySlot &slot) {
return false; }
64Value cir::LoadOp::getStored(
const MemorySlot &slot, OpBuilder &builder,
65 Value reachingDef,
const DataLayout &dataLayout) {
66 llvm_unreachable(
"getStored should not be called on LoadOp");
69bool cir::LoadOp::canUsesBeRemoved(
70 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
71 SmallVectorImpl<OpOperand *> &newBlockingUses,
72 const DataLayout &dataLayout) {
73 if (blockingUses.size() != 1)
76 if (isVolatileOrAtomic())
79 Value blockingUse = (*blockingUses.begin())->get();
80 return blockingUse == slot.ptr && getAddr() == slot.ptr &&
84DeletionKind cir::LoadOp::removeBlockingUses(
85 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
86 OpBuilder &builder,
Value reachingDefinition,
87 const DataLayout &dataLayout) {
88 getResult().replaceAllUsesWith(reachingDefinition);
89 return DeletionKind::Delete;
96bool cir::StoreOp::loadsFrom(
const MemorySlot &slot) {
return false; }
98bool cir::StoreOp::storesTo(
const MemorySlot &slot) {
99 return getAddr() == slot.ptr;
102Value cir::StoreOp::getStored(
const MemorySlot &slot, OpBuilder &builder,
103 Value reachingDef,
const DataLayout &dataLayout) {
107bool cir::StoreOp::canUsesBeRemoved(
108 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
109 SmallVectorImpl<OpOperand *> &newBlockingUses,
110 const DataLayout &dataLayout) {
111 if (blockingUses.size() != 1)
114 if (isVolatileOrAtomic())
117 Value blockingUse = (*blockingUses.begin())->get();
118 return blockingUse == slot.ptr && getAddr() == slot.ptr &&
119 getValue() != slot.ptr && slot.valueType == getValue().getType();
122DeletionKind cir::StoreOp::removeBlockingUses(
123 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
124 OpBuilder &builder,
Value reachingDefinition,
125 const DataLayout &dataLayout) {
126 return DeletionKind::Delete;
133bool cir::CopyOp::loadsFrom(
const MemorySlot &slot) {
134 return getSrc() == slot.ptr;
137bool cir::CopyOp::storesTo(
const MemorySlot &slot) {
138 return getDst() == slot.ptr;
141Value cir::CopyOp::getStored(
const MemorySlot &slot, OpBuilder &builder,
142 Value reachingDef,
const DataLayout &dataLayout) {
143 return cir::LoadOp::create(builder, getLoc(), slot.valueType, getSrc());
146DeletionKind cir::CopyOp::removeBlockingUses(
147 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
148 OpBuilder &builder, mlir::Value reachingDefinition,
149 const DataLayout &dataLayout) {
151 cir::StoreOp::create(builder, getLoc(), reachingDefinition, getDst(),
155 cir::SyncScopeKindAttr(),
156 cir::MemOrderAttr());
157 return DeletionKind::Delete;
160bool cir::CopyOp::canUsesBeRemoved(
161 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
162 SmallVectorImpl<OpOperand *> &newBlockingUses,
163 const DataLayout &dataLayout) {
164 if (getDst() == getSrc())
167 return getCopySizeInBytes(dataLayout) ==
168 dataLayout.getTypeSize(slot.valueType);
175bool cir::MatrixColumnMajorLoadOp::loadsFrom(
const MemorySlot &slot) {
176 return getValue() == slot.ptr;
179bool cir::MatrixColumnMajorLoadOp::storesTo(
const MemorySlot &slot) {
183Value cir::MatrixColumnMajorLoadOp::getStored(
const MemorySlot &slot,
186 const DataLayout &dataLayout) {
187 llvm_unreachable(
"getStored should not be called on MatrixColumnMajorLoadOp");
190bool cir::MatrixColumnMajorLoadOp::canUsesBeRemoved(
191 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
192 SmallVectorImpl<OpOperand *> &newBlockingUses,
193 const DataLayout &dataLayout) {
194 if (blockingUses.size() != 1)
201 Value blockingUse = (*blockingUses.begin())->get();
202 return blockingUse == slot.ptr && getValue() == slot.ptr &&
206DeletionKind cir::MatrixColumnMajorLoadOp::removeBlockingUses(
207 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
208 OpBuilder &builder,
Value reachingDefinition,
209 const DataLayout &dataLayout) {
210 getResult().replaceAllUsesWith(reachingDefinition);
211 return DeletionKind::Delete;
218bool cir::MatrixColumnMajorStoreOp::loadsFrom(
const MemorySlot &slot) {
222bool cir::MatrixColumnMajorStoreOp::storesTo(
const MemorySlot &slot) {
223 return getValue() == slot.ptr;
226Value cir::MatrixColumnMajorStoreOp::getStored(
const MemorySlot &slot,
229 const DataLayout &dataLayout) {
233bool cir::MatrixColumnMajorStoreOp::canUsesBeRemoved(
234 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
235 SmallVectorImpl<OpOperand *> &newBlockingUses,
236 const DataLayout &dataLayout) {
237 if (blockingUses.size() != 1)
244 Value blockingUse = (*blockingUses.begin())->get();
245 return blockingUse == slot.ptr && getValue() == slot.ptr &&
246 getValue() != slot.ptr && slot.valueType == getValue().getType();
249DeletionKind cir::MatrixColumnMajorStoreOp::removeBlockingUses(
250 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
251 OpBuilder &builder,
Value reachingDefinition,
252 const DataLayout &dataLayout) {
253 return DeletionKind::Delete;
260bool cir::CastOp::canUsesBeRemoved(
261 const SmallPtrSetImpl<OpOperand *> &blockingUses,
262 SmallVectorImpl<OpOperand *> &newBlockingUses,
263 const DataLayout &dataLayout) {
264 if (
getKind() == cir::CastKind::bitcast)
269DeletionKind cir::CastOp::removeBlockingUses(
270 const SmallPtrSetImpl<OpOperand *> &blockingUses, OpBuilder &builder) {
271 return DeletionKind::Delete;
static bool forwardToUsers(Operation *op, SmallVectorImpl< OpOperand * > &newBlockingUses)
Conditions the deletion of the operation to the removal of all its uses.
static Decl::Kind getKind(const Decl *D)