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 builder.create<cir::ConstantOp>(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)
75 Value blockingUse = (*blockingUses.begin())->get();
76 return blockingUse == slot.ptr && getAddr() == slot.ptr &&
80DeletionKind cir::LoadOp::removeBlockingUses(
81 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
82 OpBuilder &builder,
Value reachingDefinition,
83 const DataLayout &dataLayout) {
84 getResult().replaceAllUsesWith(reachingDefinition);
85 return DeletionKind::Delete;
92bool cir::StoreOp::loadsFrom(
const MemorySlot &slot) {
return false; }
94bool cir::StoreOp::storesTo(
const MemorySlot &slot) {
95 return getAddr() == slot.ptr;
98Value cir::StoreOp::getStored(
const MemorySlot &slot, OpBuilder &builder,
99 Value reachingDef,
const DataLayout &dataLayout) {
103bool cir::StoreOp::canUsesBeRemoved(
104 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
105 SmallVectorImpl<OpOperand *> &newBlockingUses,
106 const DataLayout &dataLayout) {
107 if (blockingUses.size() != 1)
109 Value blockingUse = (*blockingUses.begin())->get();
110 return blockingUse == slot.ptr && getAddr() == slot.ptr &&
111 getValue() != slot.ptr && slot.elemType == getValue().getType();
114DeletionKind cir::StoreOp::removeBlockingUses(
115 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
116 OpBuilder &builder,
Value reachingDefinition,
117 const DataLayout &dataLayout) {
118 return DeletionKind::Delete;
125bool cir::CopyOp::loadsFrom(
const MemorySlot &slot) {
126 return getSrc() == slot.ptr;
129bool cir::CopyOp::storesTo(
const MemorySlot &slot) {
130 return getDst() == slot.ptr;
133Value cir::CopyOp::getStored(
const MemorySlot &slot, OpBuilder &builder,
134 Value reachingDef,
const DataLayout &dataLayout) {
135 return cir::LoadOp::create(builder, getLoc(), slot.elemType, getSrc());
138DeletionKind cir::CopyOp::removeBlockingUses(
139 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
140 OpBuilder &builder, mlir::Value reachingDefinition,
141 const DataLayout &dataLayout) {
143 cir::StoreOp::create(builder, getLoc(), reachingDefinition, getDst(),
146 cir::MemOrderAttr());
147 return DeletionKind::Delete;
150bool cir::CopyOp::canUsesBeRemoved(
151 const MemorySlot &slot,
const SmallPtrSetImpl<OpOperand *> &blockingUses,
152 SmallVectorImpl<OpOperand *> &newBlockingUses,
153 const DataLayout &dataLayout) {
154 if (getDst() == getSrc())
157 return getLength(dataLayout) == dataLayout.getTypeSize(slot.elemType);
164bool cir::CastOp::canUsesBeRemoved(
165 const SmallPtrSetImpl<OpOperand *> &blockingUses,
166 SmallVectorImpl<OpOperand *> &newBlockingUses,
167 const DataLayout &dataLayout) {
168 if (
getKind() == cir::CastKind::bitcast)
173DeletionKind cir::CastOp::removeBlockingUses(
174 const SmallPtrSetImpl<OpOperand *> &blockingUses, OpBuilder &builder) {
175 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)