Skip to content

Commit f12ac4c

Browse files
committed
SIL: add two utility functions to AccessPath
1 parent 74b7341 commit f12ac4c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/swift/SIL/MemAccessUtils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ class AccessPath {
821821
/// access, thus not within an access scope.
822822
static AccessPath computeInScope(SILValue address);
823823

824+
/// Creates an AccessPass, which identifies the first tail-element of the
825+
/// object \p rootReference.
826+
static AccessPath forTailStorage(SILValue rootReference);
827+
824828
// Encode a dynamic index_addr as an UnknownOffset.
825829
static constexpr int UnknownOffset = std::numeric_limits<int>::min() >> 1;
826830

@@ -984,6 +988,12 @@ class AccessPath {
984988
SILFunction *function,
985989
unsigned useLimit = std::numeric_limits<unsigned>::max()) const;
986990

991+
/// Returns a new AccessPass, identical to this AccessPath, except that the
992+
/// offset is replaced with \p newOffset.
993+
AccessPath withOffset(int newOffset) const {
994+
return AccessPath(storage, pathNode, newOffset);
995+
}
996+
987997
void printPath(raw_ostream &os) const;
988998
void print(raw_ostream &os) const;
989999
void dump() const;

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,13 @@ AccessedStorage AccessedStorage::computeInScope(SILValue sourceAddress) {
763763
// MARK: AccessPath
764764
//===----------------------------------------------------------------------===//
765765

766+
AccessPath AccessPath::forTailStorage(SILValue rootReference) {
767+
return AccessPath(
768+
AccessedStorage::forClass(rootReference, AccessedStorage::TailIndex),
769+
PathNode(rootReference->getModule()->getIndexTrieRoot()),
770+
/*offset*/ 0);
771+
}
772+
766773
bool AccessPath::contains(AccessPath subPath) const {
767774
if (!isValid() || !subPath.isValid()) {
768775
return false;

0 commit comments

Comments
 (0)