Skip to content

Commit a730387

Browse files
committed
[Test] Sorted alphabetically.
1 parent ca2601d commit a730387

File tree

1 file changed

+140
-133
lines changed

1 file changed

+140
-133
lines changed

lib/SILOptimizer/UtilityPasses/UnitTestRunner.cpp

Lines changed: 140 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@
5656
// [new_tests] TESTING MORE FUNCTIONALITY:
5757
//
5858
// 1) Add a new UnitTest subclass.
59+
// - In the section "Unit Tests Subclasses" section ordered alphabetically.
5960
// - Add a constructor: NewTest(UnitTestRunner *pass) : UnitTest(pass) {}
6061
// - Implement invoke: void invoke(test::Arguments &arguments) override {...}
6162
// - Call the take{TYPE} methods to get the arguments you need.
6263
// - Call your function with those arguments.
6364
// 2) Add a new ADD_UNIT_TEST_SUBCLASS line.
65+
// - Ordered alphabetically.
6466
//
6567
//===----------------------------------------------------------------------===//
6668

@@ -157,6 +159,130 @@ class UnitTestRunner : public SILFunctionTransform {
157159
friend class UnitTest;
158160
};
159161

162+
//===----------------------------------------------------------------------===//
163+
// MARK: Unit Test Subclasses {{
164+
//===----------------------------------------------------------------------===//
165+
166+
// Arguments:
167+
// - bool: pruneDebug
168+
// - bool: maximizeLifetimes
169+
// - SILValue: value to canonicalize
170+
// Dumps:
171+
// - function after value canonicalization
172+
struct CanonicalizeOSSALifetimeTest : UnitTest {
173+
CanonicalizeOSSALifetimeTest(UnitTestRunner *pass) : UnitTest(pass) {}
174+
void invoke(Arguments &arguments) override {
175+
auto *accessBlockAnalysis = getAnalysis<NonLocalAccessBlockAnalysis>();
176+
auto *dominanceAnalysis = getAnalysis<DominanceAnalysis>();
177+
DominanceInfo *domTree = dominanceAnalysis->get(getFunction());
178+
auto pruneDebug = arguments.takeBool();
179+
auto maximizeLifetimes = arguments.takeBool();
180+
InstructionDeleter deleter;
181+
CanonicalizeOSSALifetime canonicalizer(pruneDebug, maximizeLifetimes, accessBlockAnalysis,
182+
domTree, deleter);
183+
auto value = arguments.takeValue();
184+
canonicalizer.canonicalizeValueLifetime(value);
185+
getFunction()->dump();
186+
}
187+
};
188+
189+
// Arguments: NONE
190+
// Dumps:
191+
// - the function
192+
struct DumpFunction : UnitTest {
193+
DumpFunction(UnitTestRunner *pass) : UnitTest(pass) {}
194+
void invoke(Arguments &arguments) override { getFunction()->dump(); }
195+
};
196+
197+
// Arguments: NONE
198+
// Dumps: the index of the self argument of the current function
199+
struct FunctionGetSelfArgumentIndex : UnitTest {
200+
FunctionGetSelfArgumentIndex(UnitTestRunner *pass) : UnitTest(pass) {}
201+
void invoke(Arguments &arguments) override {
202+
auto index =
203+
SILFunction_getSelfArgumentIndex(BridgedFunction{getFunction()});
204+
llvm::errs() << "self argument index = " << index << "\n";
205+
}
206+
};
207+
208+
// Arguments:
209+
// - instruction
210+
// Dumps:
211+
// - instruction
212+
// - whether it's a deinit barrier
213+
struct IsDeinitBarrierTest : UnitTest {
214+
IsDeinitBarrierTest(UnitTestRunner *pass) : UnitTest(pass) {}
215+
void invoke(Arguments &arguments) override {
216+
auto *instruction = arguments.takeInstruction();
217+
auto *analysis = getAnalysis<BasicCalleeAnalysis>();
218+
auto isBarrier = isDeinitBarrier(instruction, analysis);
219+
instruction->dump();
220+
auto *boolString = isBarrier ? "true" : "false";
221+
llvm::errs() << boolString << "\n";
222+
}
223+
};
224+
225+
// Arguments:
226+
// - variadic list of - instruction: a last user
227+
// Dumps:
228+
// - the insertion points
229+
struct PrunedLivenessBoundaryWithListOfLastUsersInsertionPointsTest : UnitTest {
230+
PrunedLivenessBoundaryWithListOfLastUsersInsertionPointsTest(
231+
UnitTestRunner *pass)
232+
: UnitTest(pass) {}
233+
void invoke(Arguments &arguments) override {
234+
PrunedLivenessBoundary boundary;
235+
while (arguments.hasUntaken()) {
236+
boundary.lastUsers.push_back(arguments.takeInstruction());
237+
}
238+
boundary.visitInsertionPoints(
239+
[](SILBasicBlock::iterator point) { point->dump(); });
240+
}
241+
};
242+
243+
struct ShrinkBorrowScopeTest : UnitTest {
244+
ShrinkBorrowScopeTest(UnitTestRunner *pass) : UnitTest(pass) {}
245+
void invoke(Arguments &arguments) override {
246+
auto instruction = arguments.takeValue();
247+
auto expected = arguments.takeBool();
248+
auto *bbi = cast<BeginBorrowInst>(instruction);
249+
auto *analysis = getAnalysis<BasicCalleeAnalysis>();
250+
SmallVector<CopyValueInst *, 4> modifiedCopyValueInsts;
251+
InstructionDeleter deleter(
252+
InstModCallbacks().onDelete([&](auto *instruction) {
253+
llvm::errs() << "DELETED:\n";
254+
instruction->dump();
255+
}));
256+
auto shrunk =
257+
shrinkBorrowScope(*bbi, deleter, analysis, modifiedCopyValueInsts);
258+
unsigned index = 0;
259+
for (auto *cvi : modifiedCopyValueInsts) {
260+
auto expectedCopy = arguments.takeValue();
261+
llvm::errs() << "rewritten copy " << index << ":\n";
262+
llvm::errs() << "expected:\n";
263+
expectedCopy->print(llvm::errs());
264+
llvm::errs() << "got:\n";
265+
cvi->dump();
266+
assert(cvi == expectedCopy);
267+
++index;
268+
}
269+
assert(expected == shrunk && "didn't shrink expectedly!?");
270+
}
271+
};
272+
273+
struct SimplifyCFGCanonicalizeSwitchEnum : UnitTest {
274+
SimplifyCFGCanonicalizeSwitchEnum(UnitTestRunner *pass) : UnitTest(pass) {}
275+
void invoke(Arguments &arguments) override {
276+
auto *passToRun = cast<SILFunctionTransform>(createSimplifyCFG());
277+
passToRun->injectPassManager(getPass()->getPassManager());
278+
passToRun->injectFunction(getFunction());
279+
SimplifyCFG(*getFunction(), *passToRun, /*VerifyAll=*/false,
280+
/*EnableJumpThread=*/false)
281+
.canonicalizeSwitchEnums();
282+
}
283+
};
284+
285+
160286
// Arguments:
161287
// - string: list of characters, each of which specifies subsequent arguments
162288
// - A: (block) argument
@@ -238,29 +364,6 @@ struct TestSpecificationTest : UnitTest {
238364
}
239365
};
240366

241-
// Arguments:
242-
// - bool: pruneDebug
243-
// - bool: maximizeLifetimes
244-
// - SILValue: value to canonicalize
245-
// Dumps:
246-
// - function after value canonicalization
247-
struct CanonicalizeOSSALifetimeTest : UnitTest {
248-
CanonicalizeOSSALifetimeTest(UnitTestRunner *pass) : UnitTest(pass) {}
249-
void invoke(Arguments &arguments) override {
250-
auto *accessBlockAnalysis = getAnalysis<NonLocalAccessBlockAnalysis>();
251-
auto *dominanceAnalysis = getAnalysis<DominanceAnalysis>();
252-
DominanceInfo *domTree = dominanceAnalysis->get(getFunction());
253-
auto pruneDebug = arguments.takeBool();
254-
auto maximizeLifetimes = arguments.takeBool();
255-
InstructionDeleter deleter;
256-
CanonicalizeOSSALifetime canonicalizer(pruneDebug, maximizeLifetimes, accessBlockAnalysis,
257-
domTree, deleter);
258-
auto value = arguments.takeValue();
259-
canonicalizer.canonicalizeValueLifetime(value);
260-
getFunction()->dump();
261-
}
262-
};
263-
264367
// Arguments:
265368
// - SILValue: phi
266369
// Dumps:
@@ -278,103 +381,12 @@ struct VisitAdjacentReborrowsOfPhiTest : UnitTest {
278381
}
279382
};
280383

281-
// Arguments:
282-
// - variadic list of - instruction: a last user
283-
// Dumps:
284-
// - the insertion points
285-
struct PrunedLivenessBoundaryWithListOfLastUsersInsertionPointsTest : UnitTest {
286-
PrunedLivenessBoundaryWithListOfLastUsersInsertionPointsTest(
287-
UnitTestRunner *pass)
288-
: UnitTest(pass) {}
289-
void invoke(Arguments &arguments) override {
290-
PrunedLivenessBoundary boundary;
291-
while (arguments.hasUntaken()) {
292-
boundary.lastUsers.push_back(arguments.takeInstruction());
293-
}
294-
boundary.visitInsertionPoints(
295-
[](SILBasicBlock::iterator point) { point->dump(); });
296-
}
297-
};
298-
299-
// Arguments: NONE
300-
// Dumps:
301-
// - the function
302-
struct DumpFunction : UnitTest {
303-
DumpFunction(UnitTestRunner *pass) : UnitTest(pass) {}
304-
void invoke(Arguments &arguments) override { getFunction()->dump(); }
305-
};
306-
307-
struct SimplifyCFGCanonicalizeSwitchEnum : UnitTest {
308-
SimplifyCFGCanonicalizeSwitchEnum(UnitTestRunner *pass) : UnitTest(pass) {}
309-
void invoke(Arguments &arguments) override {
310-
auto *passToRun = cast<SILFunctionTransform>(createSimplifyCFG());
311-
passToRun->injectPassManager(getPass()->getPassManager());
312-
passToRun->injectFunction(getFunction());
313-
SimplifyCFG(*getFunction(), *passToRun, /*VerifyAll=*/false,
314-
/*EnableJumpThread=*/false)
315-
.canonicalizeSwitchEnums();
316-
}
317-
};
318-
319-
// Arguments: NONE
320-
// Dumps: the index of the self argument of the current function
321-
struct FunctionGetSelfArgumentIndex : UnitTest {
322-
FunctionGetSelfArgumentIndex(UnitTestRunner *pass) : UnitTest(pass) {}
323-
void invoke(Arguments &arguments) override {
324-
auto index =
325-
SILFunction_getSelfArgumentIndex(BridgedFunction{getFunction()});
326-
llvm::errs() << "self argument index = " << index << "\n";
327-
}
328-
};
329-
330-
// Arguments:
331-
// - instruction
332-
// Dumps:
333-
// - instruction
334-
// - whether it's a deinit barrier
335-
struct IsDeinitBarrierTest : UnitTest {
336-
IsDeinitBarrierTest(UnitTestRunner *pass) : UnitTest(pass) {}
337-
void invoke(Arguments &arguments) override {
338-
auto *instruction = arguments.takeInstruction();
339-
auto *analysis = getAnalysis<BasicCalleeAnalysis>();
340-
auto isBarrier = isDeinitBarrier(instruction, analysis);
341-
instruction->dump();
342-
auto *boolString = isBarrier ? "true" : "false";
343-
llvm::errs() << boolString << "\n";
344-
}
345-
};
346-
347-
struct ShrinkBorrowScopeTest : UnitTest {
348-
ShrinkBorrowScopeTest(UnitTestRunner *pass) : UnitTest(pass) {}
349-
void invoke(Arguments &arguments) override {
350-
auto instruction = arguments.takeValue();
351-
auto expected = arguments.takeBool();
352-
auto *bbi = cast<BeginBorrowInst>(instruction);
353-
auto *analysis = getAnalysis<BasicCalleeAnalysis>();
354-
SmallVector<CopyValueInst *, 4> modifiedCopyValueInsts;
355-
InstructionDeleter deleter(
356-
InstModCallbacks().onDelete([&](auto *instruction) {
357-
llvm::errs() << "DELETED:\n";
358-
instruction->dump();
359-
}));
360-
auto shrunk =
361-
shrinkBorrowScope(*bbi, deleter, analysis, modifiedCopyValueInsts);
362-
unsigned index = 0;
363-
for (auto *cvi : modifiedCopyValueInsts) {
364-
auto expectedCopy = arguments.takeValue();
365-
llvm::errs() << "rewritten copy " << index << ":\n";
366-
llvm::errs() << "expected:\n";
367-
expectedCopy->print(llvm::errs());
368-
llvm::errs() << "got:\n";
369-
cvi->dump();
370-
assert(cvi == expectedCopy);
371-
++index;
372-
}
373-
assert(expected == shrunk && "didn't shrink expectedly!?");
374-
}
375-
};
384+
/// [new_tests] Add the new UnitTest subclass above this line.
385+
/// Please sort alphabetically by to help reduce merge conflicts.
376386

377-
/// [new_tests] Add the new UnitTest subclass above this line.
387+
//===----------------------------------------------------------------------===//
388+
// MARK: Unit Test Subclasses }}
389+
//===----------------------------------------------------------------------===//
378390

379391
template <typename Doit>
380392
void UnitTestRunner::withTest(StringRef name, Doit doit) {
@@ -385,23 +397,18 @@ void UnitTestRunner::withTest(StringRef name, Doit doit) {
385397
return; \
386398
}
387399

400+
ADD_UNIT_TEST_SUBCLASS("canonicalize-ossa-lifetime", CanonicalizeOSSALifetimeTest)
388401
ADD_UNIT_TEST_SUBCLASS("dump-function", DumpFunction)
389-
390-
ADD_UNIT_TEST_SUBCLASS("test-specification-parsing", TestSpecificationTest)
391-
ADD_UNIT_TEST_SUBCLASS("canonicalize-ossa-lifetime",
392-
CanonicalizeOSSALifetimeTest)
393-
ADD_UNIT_TEST_SUBCLASS("visit-adjacent-reborrows-of-phi",
394-
VisitAdjacentReborrowsOfPhiTest)
395-
ADD_UNIT_TEST_SUBCLASS("function-get-self-argument-index",
396-
FunctionGetSelfArgumentIndex)
397-
ADD_UNIT_TEST_SUBCLASS(
398-
"pruned-liveness-boundary-with-list-of-last-users-insertion-points",
399-
PrunedLivenessBoundaryWithListOfLastUsersInsertionPointsTest)
400-
ADD_UNIT_TEST_SUBCLASS("shrink-borrow-scope", ShrinkBorrowScopeTest)
402+
ADD_UNIT_TEST_SUBCLASS("function-get-self-argument-index", FunctionGetSelfArgumentIndex)
401403
ADD_UNIT_TEST_SUBCLASS("is-deinit-barrier", IsDeinitBarrierTest)
402-
ADD_UNIT_TEST_SUBCLASS("simplify-cfg-canonicalize-switch-enum",
403-
SimplifyCFGCanonicalizeSwitchEnum)
404+
ADD_UNIT_TEST_SUBCLASS("pruned-liveness-boundary-with-list-of-last-users-insertion-points", PrunedLivenessBoundaryWithListOfLastUsersInsertionPointsTest)
405+
ADD_UNIT_TEST_SUBCLASS("shrink-borrow-scope", ShrinkBorrowScopeTest)
406+
ADD_UNIT_TEST_SUBCLASS("simplify-cfg-canonicalize-switch-enum", SimplifyCFGCanonicalizeSwitchEnum)
407+
ADD_UNIT_TEST_SUBCLASS("test-specification-parsing", TestSpecificationTest)
408+
ADD_UNIT_TEST_SUBCLASS("visit-adjacent-reborrows-of-phi", VisitAdjacentReborrowsOfPhiTest)
404409
/// [new_tests] Add the new mapping from string to subclass above this line.
410+
/// Please sort alphabetically by name to help reduce merge
411+
/// conflicts.
405412

406413
#undef ADD_UNIT_TEST_SUBCLASS
407414
}

0 commit comments

Comments
 (0)