Skip to content

Commit 36a3a14

Browse files
committed
Move the LoadOperation abstraction to InstructionUtils.h
This is a fundamental abstraction over loads. It was in OwnershipOptUtils because load_borrow happens to be restricted by OSSA. Passes should not include OwnershipOptUtils just because they work with loads. (cherry picked from commit 91c4efe)
1 parent 8397fbd commit 36a3a14

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

include/swift/SIL/InstructionUtils.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,58 @@ RuntimeEffect getRuntimeEffect(SILInstruction *inst, SILType &impactType);
152152
void findClosuresForFunctionValue(SILValue V,
153153
TinyPtrVector<PartialApplyInst *> &results);
154154

155+
/// An abstraction over LoadInst/LoadBorrowInst so one can handle both types of
156+
/// load using common code.
157+
struct LoadOperation {
158+
llvm::PointerUnion<LoadInst *, LoadBorrowInst *> value;
159+
160+
LoadOperation() : value() {}
161+
LoadOperation(SILInstruction *input) : value(nullptr) {
162+
if (auto *li = dyn_cast<LoadInst>(input)) {
163+
value = li;
164+
return;
165+
}
166+
167+
if (auto *lbi = dyn_cast<LoadBorrowInst>(input)) {
168+
value = lbi;
169+
return;
170+
}
171+
}
172+
173+
explicit operator bool() const { return !value.isNull(); }
174+
175+
SingleValueInstruction *getLoadInst() const {
176+
if (value.is<LoadInst *>())
177+
return value.get<LoadInst *>();
178+
return value.get<LoadBorrowInst *>();
179+
}
180+
181+
SingleValueInstruction *operator*() const { return getLoadInst(); }
182+
183+
const SingleValueInstruction *operator->() const { return getLoadInst(); }
184+
185+
SingleValueInstruction *operator->() { return getLoadInst(); }
186+
187+
SILValue getOperand() const {
188+
if (value.is<LoadInst *>())
189+
return value.get<LoadInst *>()->getOperand();
190+
return value.get<LoadBorrowInst *>()->getOperand();
191+
}
192+
193+
/// Return the ownership qualifier of the underlying load if we have a load or
194+
/// None if we have a load_borrow.
195+
///
196+
/// TODO: Rather than use an optional here, we should include an invalid
197+
/// representation in LoadOwnershipQualifier.
198+
Optional<LoadOwnershipQualifier> getOwnershipQualifier() const {
199+
if (auto *lbi = value.dyn_cast<LoadBorrowInst *>()) {
200+
return None;
201+
}
202+
203+
return value.get<LoadInst *>()->getOwnershipQualifier();
204+
}
205+
};
206+
155207
/// Given a polymorphic builtin \p bi that may be generic and thus have in/out
156208
/// params, stash all of the information needed for either specializing while
157209
/// inlining or propagating the type in constant propagation.

include/swift/SILOptimizer/Utils/OwnershipOptUtils.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -356,58 +356,6 @@ class OwnershipReplaceSingleUseHelper {
356356
}
357357
};
358358

359-
/// An abstraction over LoadInst/LoadBorrowInst so one can handle both types of
360-
/// load using common code.
361-
struct LoadOperation {
362-
llvm::PointerUnion<LoadInst *, LoadBorrowInst *> value;
363-
364-
LoadOperation() : value() {}
365-
LoadOperation(SILInstruction *input) : value(nullptr) {
366-
if (auto *li = dyn_cast<LoadInst>(input)) {
367-
value = li;
368-
return;
369-
}
370-
371-
if (auto *lbi = dyn_cast<LoadBorrowInst>(input)) {
372-
value = lbi;
373-
return;
374-
}
375-
}
376-
377-
explicit operator bool() const { return !value.isNull(); }
378-
379-
SingleValueInstruction *getLoadInst() const {
380-
if (value.is<LoadInst *>())
381-
return value.get<LoadInst *>();
382-
return value.get<LoadBorrowInst *>();
383-
}
384-
385-
SingleValueInstruction *operator*() const { return getLoadInst(); }
386-
387-
const SingleValueInstruction *operator->() const { return getLoadInst(); }
388-
389-
SingleValueInstruction *operator->() { return getLoadInst(); }
390-
391-
SILValue getOperand() const {
392-
if (value.is<LoadInst *>())
393-
return value.get<LoadInst *>()->getOperand();
394-
return value.get<LoadBorrowInst *>()->getOperand();
395-
}
396-
397-
/// Return the ownership qualifier of the underlying load if we have a load or
398-
/// None if we have a load_borrow.
399-
///
400-
/// TODO: Rather than use an optional here, we should include an invalid
401-
/// representation in LoadOwnershipQualifier.
402-
Optional<LoadOwnershipQualifier> getOwnershipQualifier() const {
403-
if (auto *lbi = value.dyn_cast<LoadBorrowInst *>()) {
404-
return None;
405-
}
406-
407-
return value.get<LoadInst *>()->getOwnershipQualifier();
408-
}
409-
};
410-
411359
/// Extend the store_borrow \p sbi's scope such that it encloses \p newUsers.
412360
bool extendStoreBorrow(StoreBorrowInst *sbi,
413361
SmallVectorImpl<Operand *> &newUses,

0 commit comments

Comments
 (0)