Skip to content

Commit 9ce8bb3

Browse files
committed
Add a new abstraction FixedStorageSemanticsCall
1 parent 3fe1029 commit 9ce8bb3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

include/swift/SIL/InstWrappers.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SIL_WRAPPERTYPES_H
1414
#define SWIFT_SIL_WRAPPERTYPES_H
1515

16+
#include "swift/SIL/SILFunction.h"
1617
#include "swift/SIL/SILInstruction.h"
1718

1819
namespace swift {
@@ -361,6 +362,43 @@ class ForwardingOperation {
361362
// operation.
362363
bool visitForwardedValues(function_ref<bool(SILValue)> visitor);
363364
};
365+
366+
enum class FixedStorageSemanticsCallKind { None, CheckIndex, GetCount };
367+
368+
struct FixedStorageSemanticsCall {
369+
ApplyInst *apply = nullptr;
370+
FixedStorageSemanticsCallKind kind = FixedStorageSemanticsCallKind::None;
371+
372+
FixedStorageSemanticsCall(SILInstruction *input) {
373+
auto *applyInst = dyn_cast<ApplyInst>(input);
374+
if (!applyInst) {
375+
return;
376+
}
377+
auto *callee = applyInst->getReferencedFunctionOrNull();
378+
if (!callee) {
379+
return;
380+
}
381+
for (auto &attr : callee->getSemanticsAttrs()) {
382+
if (attr == "fixed_storage.check_index") {
383+
apply = applyInst;
384+
kind = FixedStorageSemanticsCallKind::CheckIndex;
385+
break;
386+
} else if (attr == "fixed_storage.get_count") {
387+
apply = applyInst;
388+
kind = FixedStorageSemanticsCallKind::GetCount;
389+
break;
390+
}
391+
}
392+
}
393+
394+
FixedStorageSemanticsCallKind getKind() const { return kind; }
395+
explicit operator bool() const { return apply != nullptr; }
396+
const ApplyInst *operator->() const { return apply; }
397+
ApplyInst *operator->() { return apply; }
398+
};
399+
400+
bool isFixedStorageSemanticsCallKind(SILFunction *function);
401+
364402
} // end namespace swift
365403

366404
#endif

lib/SIL/Utils/InstWrappers.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,13 @@ bool ForwardingOperation::visitForwardedValues(
9999
return visitor(args[0]);
100100
});
101101
}
102+
103+
bool swift::isFixedStorageSemanticsCallKind(SILFunction *function) {
104+
for (auto &attr : function->getSemanticsAttrs()) {
105+
if (attr == "fixed_storage.check_index" ||
106+
attr == "fixed_storage.get_count") {
107+
return true;
108+
}
109+
}
110+
return false;
111+
}

0 commit comments

Comments
 (0)