Skip to content

Commit fcec328

Browse files
committed
[Test] Ensourced multidefuse-liveness.
Moved the test next to the code it calls.
1 parent f996371 commit fcec328

File tree

2 files changed

+59
-57
lines changed

2 files changed

+59
-57
lines changed

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,65 @@ bool MultiDefPrunedLiveness::isUserBeforeDef(SILInstruction *user) const {
601601
}
602602
}
603603

604+
namespace swift::test {
605+
// Arguments:
606+
// - the string "defs:"
607+
// - list of live-range defining values or instructions
608+
// - the string "uses:"
609+
// - variadic list of live-range user instructions
610+
// Dumps:
611+
// - the liveness result and boundary
612+
//
613+
// Computes liveness for the specified def nodes by considering only the
614+
// specified uses. The actual uses of the def nodes are ignored.
615+
//
616+
// This is useful for testing non-ssa liveness, for example, of memory
617+
// locations. In that case, the def nodes may be stores and the uses may be
618+
// destroy_addrs.
619+
static FunctionTest MultiDefUseLivenessTest(
620+
"multidefuse-liveness", [](auto &function, auto &arguments, auto &test) {
621+
SmallVector<SILBasicBlock *, 8> discoveredBlocks;
622+
MultiDefPrunedLiveness liveness(&function, &discoveredBlocks);
623+
624+
llvm::outs() << "MultiDef lifetime analysis:\n";
625+
if (arguments.takeString() != "defs:") {
626+
llvm::report_fatal_error(
627+
"test specification expects the 'defs:' label\n");
628+
}
629+
while (true) {
630+
auto argument = arguments.takeArgument();
631+
if (isa<InstructionArgument>(argument)) {
632+
auto *instruction = cast<InstructionArgument>(argument).getValue();
633+
llvm::outs() << " def instruction: " << *instruction;
634+
liveness.initializeDef(instruction);
635+
continue;
636+
}
637+
if (isa<ValueArgument>(argument)) {
638+
SILValue value = cast<ValueArgument>(argument).getValue();
639+
llvm::outs() << " def value: " << value;
640+
liveness.initializeDef(value);
641+
continue;
642+
}
643+
if (cast<StringArgument>(argument).getValue() != "uses:") {
644+
llvm::report_fatal_error(
645+
"test specification expects the 'uses:' label\n");
646+
}
647+
break;
648+
}
649+
while (arguments.hasUntaken()) {
650+
auto *inst = arguments.takeInstruction();
651+
// lifetimeEnding has no effects on liveness, it's only a cache for the
652+
// caller.
653+
liveness.updateForUse(inst, /*lifetimeEnding*/ false);
654+
}
655+
liveness.print(llvm::outs());
656+
657+
PrunedLivenessBoundary boundary;
658+
liveness.computeBoundary(boundary);
659+
boundary.print(llvm::outs());
660+
});
661+
} // end namespace swift::test
662+
604663
void MultiDefPrunedLiveness::findBoundariesInBlock(
605664
SILBasicBlock *block, bool isLiveOut,
606665
PrunedLivenessBoundary &boundary) const {

lib/SILOptimizer/UtilityPasses/TestRunner.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -230,63 +230,6 @@ static FunctionTest TestSpecificationTest(
230230
// MARK: OSSA Lifetime Unit Tests
231231
//===----------------------------------------------------------------------===//
232232

233-
// Arguments:
234-
// - the string "defs:"
235-
// - list of live-range defining values or instructions
236-
// - the string "uses:"
237-
// - variadic list of live-range user instructions
238-
// Dumps:
239-
// - the liveness result and boundary
240-
//
241-
// Computes liveness for the specified def nodes by considering only the
242-
// specified uses. The actual uses of the def nodes are ignored.
243-
//
244-
// This is useful for testing non-ssa liveness, for example, of memory
245-
// locations. In that case, the def nodes may be stores and the uses may be
246-
// destroy_addrs.
247-
static FunctionTest MultiDefUseLivenessTest(
248-
"multidefuse-liveness", [](auto &function, auto &arguments, auto &test) {
249-
SmallVector<SILBasicBlock *, 8> discoveredBlocks;
250-
MultiDefPrunedLiveness liveness(&function, &discoveredBlocks);
251-
252-
llvm::outs() << "MultiDef lifetime analysis:\n";
253-
if (arguments.takeString() != "defs:") {
254-
llvm::report_fatal_error(
255-
"test specification expects the 'defs:' label\n");
256-
}
257-
while (true) {
258-
auto argument = arguments.takeArgument();
259-
if (isa<InstructionArgument>(argument)) {
260-
auto *instruction = cast<InstructionArgument>(argument).getValue();
261-
llvm::outs() << " def instruction: " << *instruction;
262-
liveness.initializeDef(instruction);
263-
continue;
264-
}
265-
if (isa<ValueArgument>(argument)) {
266-
SILValue value = cast<ValueArgument>(argument).getValue();
267-
llvm::outs() << " def value: " << value;
268-
liveness.initializeDef(value);
269-
continue;
270-
}
271-
if (cast<StringArgument>(argument).getValue() != "uses:") {
272-
llvm::report_fatal_error(
273-
"test specification expects the 'uses:' label\n");
274-
}
275-
break;
276-
}
277-
while (arguments.hasUntaken()) {
278-
auto *inst = arguments.takeInstruction();
279-
// lifetimeEnding has no effects on liveness, it's only a cache for the
280-
// caller.
281-
liveness.updateForUse(inst, /*lifetimeEnding*/ false);
282-
}
283-
liveness.print(llvm::outs());
284-
285-
PrunedLivenessBoundary boundary;
286-
liveness.computeBoundary(boundary);
287-
boundary.print(llvm::outs());
288-
});
289-
290233
// Arguments:
291234
// - value: entity whose fields' livenesses are being computed
292235
// - string: "defs:"

0 commit comments

Comments
 (0)