Skip to content

Commit ab3265d

Browse files
committed
Add test utilities to print ownership and sil-triviality
1 parent 77e30d2 commit ab3265d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/SIL/IR/SILType.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/SIL/AbstractionPattern.h"
2323
#include "swift/SIL/SILFunctionConventions.h"
2424
#include "swift/SIL/SILModule.h"
25+
#include "swift/SIL/Test.h"
2526
#include "swift/SIL/TypeLowering.h"
2627
#include <tuple>
2728

@@ -1287,3 +1288,21 @@ SILType SILType::removingMoveOnlyWrapperToBoxedType(const SILFunction *fn) {
12871288
bool SILType::isSendable(SILFunction *fn) const {
12881289
return getASTType()->isSendableType();
12891290
}
1291+
1292+
namespace swift::test {
1293+
// Arguments:
1294+
// - SILValue: value
1295+
// Dumps:
1296+
// - message
1297+
static FunctionTest IsSILTrivial("is-sil-trivial", [](auto &function,
1298+
auto &arguments,
1299+
auto &test) {
1300+
SILValue value = arguments.takeValue();
1301+
llvm::outs() << value;
1302+
if (value->getType().isTrivial(value->getFunction())) {
1303+
llvm::outs() << " is trivial\n";
1304+
} else {
1305+
llvm::outs() << " is not trivial\n";
1306+
}
1307+
});
1308+
} // end namespace swift::test

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/SIL/SILVisitor.h"
1413
#include "swift/SIL/SILBuiltinVisitor.h"
1514
#include "swift/SIL/SILModule.h"
15+
#include "swift/SIL/SILVisitor.h"
16+
#include "swift/SIL/Test.h"
1617

1718
using namespace swift;
1819

@@ -690,3 +691,17 @@ ValueOwnershipKind ValueBase::getOwnershipKind() const {
690691
assert(result && "Returned ownership kind invalid on values");
691692
return result;
692693
}
694+
695+
namespace swift::test {
696+
// Arguments:
697+
// - SILValue: value
698+
// Dumps:
699+
// - message
700+
static FunctionTest GetOwnershipKind("get-ownership-kind", [](auto &function,
701+
auto &arguments,
702+
auto &test) {
703+
SILValue value = arguments.takeValue();
704+
llvm::outs() << value;
705+
llvm::outs() << "OwnershipKind: " << value->getOwnershipKind() << "\n";
706+
});
707+
} // end namespace swift::test

0 commit comments

Comments
 (0)