6868#include " swift/Basic/TaggedUnion.h"
6969#include " swift/SIL/SILArgumentArrayRef.h"
7070#include " swift/SIL/SILBasicBlock.h"
71+ #include " swift/SIL/SILBridging.h"
7172#include " swift/SIL/SILFunction.h"
7273#include " swift/SIL/SILInstruction.h"
7374#include " swift/SILOptimizer/PassManager/Passes.h"
@@ -224,6 +225,17 @@ struct DumpFunction : UnitTest {
224225 void invoke (Arguments &arguments) override { getFunction ()->dump (); }
225226};
226227
228+ // Arguments: NONE
229+ // Dumps: the index of the self argument of the current function
230+ struct FunctionGetSelfArgumentIndex : UnitTest {
231+ FunctionGetSelfArgumentIndex (UnitTestRunner *pass) : UnitTest(pass) {}
232+ void invoke (Arguments &arguments) override {
233+ auto index =
234+ SILFunction_getSelfArgumentIndex (BridgedFunction{getFunction ()});
235+ llvm::errs () << " self argument index = " << index << " \n " ;
236+ }
237+ };
238+
227239// / [new_tests] Add the new UnitTest subclass above this line.
228240
229241class UnitTestRunner : public SILFunctionTransform {
@@ -238,10 +250,9 @@ class UnitTestRunner : public SILFunctionTransform {
238250 llvm::errs () << components[index];
239251 if (index != size - 1 ) {
240252 llvm::errs () << " , " ;
241- } else {
242- llvm::errs () << " \n " ;
243253 }
244254 }
255+ llvm::errs () << " \n " ;
245256 }
246257
247258 template <typename Doit>
@@ -260,6 +271,8 @@ class UnitTestRunner : public SILFunctionTransform {
260271 CanonicalizeOSSALifetimeTest)
261272 ADD_UNIT_TEST_SUBCLASS (" visit-adjacent-reborrows-of-phi" ,
262273 VisitAdjacentReborrowsOfPhiTest)
274+ ADD_UNIT_TEST_SUBCLASS (" function-get-self-argument-index" ,
275+ FunctionGetSelfArgumentIndex)
263276 // / [new_tests] Add the new mapping from string to subclass above this line.
264277
265278#undef ADD_UNIT_TEST_SUBCLASS
0 commit comments