Skip to content

Commit 91c4efe

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.
1 parent f00a33b commit 91c4efe

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
@@ -349,58 +349,6 @@ class OwnershipReplaceSingleUseHelper {
349349
}
350350
};
351351

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

0 commit comments

Comments
 (0)