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.elemType));
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)
77 if (getIsVolatile() || getMemOrder().has_value())
80 Value blockingUse = (*blockingUses.begin())->get();
81 return blockingUse == slot.ptr && getAddr() == slot.ptr &&
85DeletionKind cir::LoadOp::removeBlockingUses(
86 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
87 OpBuilder &builder,
Value reachingDefinition,
88 const DataLayout &dataLayout) {
89 getResult().replaceAllUsesWith(reachingDefinition);
90 return DeletionKind::Delete;
97bool cir::StoreOp::loadsFrom(
const MemorySlot &slot) {
return false; }
99bool cir::StoreOp::storesTo(
const MemorySlot &slot) {
100 return getAddr() == slot.ptr;
103Value cir::StoreOp::getStored(
const MemorySlot &slot, OpBuilder &builder,
104 Value reachingDef,
const DataLayout &dataLayout) {
108bool cir::StoreOp::canUsesBeRemoved(
109 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
110 SmallVectorImpl<OpOperand *> &newBlockingUses,
111 const DataLayout &dataLayout) {
112 if (blockingUses.size() != 1)
116 if (getIsVolatile() || getMemOrder().has_value())
119 Value blockingUse = (*blockingUses.begin())->get();
120 return blockingUse == slot.ptr && getAddr() == slot.ptr &&
121 getValue() != slot.ptr && slot.elemType == getValue().getType();
124DeletionKind cir::StoreOp::removeBlockingUses(
125 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
126 OpBuilder &builder,
Value reachingDefinition,
127 const DataLayout &dataLayout) {
128 return DeletionKind::Delete;
135bool cir::CopyOp::loadsFrom(
const MemorySlot &slot) {
136 return getSrc() == slot.ptr;
139bool cir::CopyOp::storesTo(
const MemorySlot &slot) {
140 return getDst() == slot.ptr;
143Value cir::CopyOp::getStored(
const MemorySlot &slot, OpBuilder &builder,
144 Value reachingDef,
const DataLayout &dataLayout) {
145 return cir::LoadOp::create(builder, getLoc(), slot.elemType, getSrc());
148DeletionKind cir::CopyOp::removeBlockingUses(
149 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
150 OpBuilder &builder, mlir::Value reachingDefinition,
151 const DataLayout &dataLayout) {
153 cir::StoreOp::create(builder, getLoc(), reachingDefinition, getDst(),
157 cir::SyncScopeKindAttr(),
158 cir::MemOrderAttr());
159 return DeletionKind::Delete;
162bool cir::CopyOp::canUsesBeRemoved(
163 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
164 SmallVectorImpl<OpOperand *> &newBlockingUses,
165 const DataLayout &dataLayout) {
166 if (getDst() == getSrc())
169 return getCopySizeInBytes(dataLayout) ==
170 dataLayout.getTypeSize(slot.elemType);
177bool cir::CastOp::canUsesBeRemoved(
178 const SmallPtrSetImpl<OpOperand *> &blockingUses,
179 SmallVectorImpl<OpOperand *> &newBlockingUses,
180 const DataLayout &dataLayout) {
181 if (
getKind() == cir::CastKind::bitcast)
186DeletionKind cir::CastOp::removeBlockingUses(
187 const SmallPtrSetImpl<OpOperand *> &blockingUses, OpBuilder &builder) {
188 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)