Skip to content

Commit 22df319

Browse files
committed
[Test] Ensourced fieldsensitive-multidefuse...
-liverange. Moved the test next to the code it calls.
1 parent 0c17600 commit 22df319

File tree

2 files changed

+84
-86
lines changed

2 files changed

+84
-86
lines changed

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/SIL/SILBuilder.h"
2323
#include "swift/SIL/SILInstruction.h"
2424
#include "swift/SIL/ScopedAddressUtils.h"
25+
#include "swift/SIL/Test.h"
2526
#include "llvm/ADT/SmallBitVector.h"
2627
#include "llvm/ADT/SmallVector.h"
2728
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -836,6 +837,89 @@ void FieldSensitivePrunedLiveRange<LivenessWithDefs>::computeBoundary(
836837
}
837838
}
838839

840+
namespace swift::test {
841+
// Arguments:
842+
// - value: entity whose fields' livenesses are being computed
843+
// - string: "defs:"
844+
// - variadic list of triples consisting of
845+
// - value: a live-range defining value
846+
// - int: the beginning of the range of fields defined by the value
847+
// - int: the end of the range of the fields defined by the value
848+
// - the string "uses:"
849+
// - variadic list of quadruples consisting of
850+
// - instruction: a live-range user
851+
// - bool: whether the user is lifetime-ending
852+
// - int: the beginning of the range of fields used by the instruction
853+
// - int: the end of the range of fields used by the instruction
854+
// Dumps:
855+
// - the liveness result and boundary
856+
//
857+
// Computes liveness for the specified def nodes by considering the
858+
// specified uses. The actual uses of the def nodes are ignored.
859+
//
860+
// This is useful for testing non-ssa liveness, for example, of memory
861+
// locations. In that case, the def nodes may be stores and the uses may be
862+
// destroy_addrs.
863+
static FunctionTest FieldSensitiveMultiDefUseLiveRangeTest(
864+
"fieldsensitive-multidefuse-liverange",
865+
[](auto &function, auto &arguments, auto &test) {
866+
SmallVector<SILBasicBlock *, 8> discoveredBlocks;
867+
auto value = arguments.takeValue();
868+
FieldSensitiveMultiDefPrunedLiveRange liveness(&function, value,
869+
&discoveredBlocks);
870+
871+
llvm::outs() << "FieldSensitive MultiDef lifetime analysis:\n";
872+
if (arguments.takeString() != "defs:") {
873+
llvm::report_fatal_error(
874+
"test specification expects the 'defs:' label\n");
875+
}
876+
while (true) {
877+
auto argument = arguments.takeArgument();
878+
if (isa<StringArgument>(argument)) {
879+
if (cast<StringArgument>(argument).getValue() != "uses:") {
880+
llvm::report_fatal_error(
881+
"test specification expects the 'uses:' label\n");
882+
}
883+
break;
884+
}
885+
auto begin = arguments.takeUInt();
886+
auto end = arguments.takeUInt();
887+
TypeTreeLeafTypeRange range(begin, end);
888+
if (isa<InstructionArgument>(argument)) {
889+
auto *instruction = cast<InstructionArgument>(argument).getValue();
890+
llvm::outs() << " def in range [" << begin << ", " << end
891+
<< ") instruction: " << *instruction;
892+
liveness.initializeDef(instruction, range);
893+
continue;
894+
}
895+
if (isa<ValueArgument>(argument)) {
896+
SILValue value = cast<ValueArgument>(argument).getValue();
897+
llvm::outs() << " def in range [" << begin << ", " << end
898+
<< ") value: " << value;
899+
liveness.initializeDef(value, range);
900+
continue;
901+
}
902+
llvm::report_fatal_error(
903+
"test specification expects the 'uses:' label\n");
904+
}
905+
liveness.finishedInitializationOfDefs();
906+
while (arguments.hasUntaken()) {
907+
auto *inst = arguments.takeInstruction();
908+
auto lifetimeEnding = arguments.takeBool();
909+
auto begin = arguments.takeUInt();
910+
auto end = arguments.takeUInt();
911+
TypeTreeLeafTypeRange range(begin, end);
912+
liveness.updateForUse(inst, range, lifetimeEnding);
913+
}
914+
liveness.print(llvm::errs());
915+
916+
FieldSensitivePrunedLivenessBoundary boundary(
917+
liveness.getNumSubElements());
918+
liveness.computeBoundary(boundary);
919+
boundary.print(llvm::errs());
920+
});
921+
} // end namespace swift::test
922+
839923
bool FieldSensitiveMultiDefPrunedLiveRange::isUserBeforeDef(
840924
SILInstruction *user, unsigned element) const {
841925
auto *block = user->getParent();

lib/SILOptimizer/UtilityPasses/TestRunner.cpp

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -225,92 +225,6 @@ static FunctionTest TestSpecificationTest(
225225
}
226226
}
227227
});
228-
229-
//===----------------------------------------------------------------------===//
230-
// MARK: OSSA Lifetime Unit Tests
231-
//===----------------------------------------------------------------------===//
232-
233-
// Arguments:
234-
// - value: entity whose fields' livenesses are being computed
235-
// - string: "defs:"
236-
// - variadic list of triples consisting of
237-
// - value: a live-range defining value
238-
// - int: the beginning of the range of fields defined by the value
239-
// - int: the end of the range of the fields defined by the value
240-
// - the string "uses:"
241-
// - variadic list of quadruples consisting of
242-
// - instruction: a live-range user
243-
// - bool: whether the user is lifetime-ending
244-
// - int: the beginning of the range of fields used by the instruction
245-
// - int: the end of the range of fields used by the instruction
246-
// Dumps:
247-
// - the liveness result and boundary
248-
//
249-
// Computes liveness for the specified def nodes by considering the
250-
// specified uses. The actual uses of the def nodes are ignored.
251-
//
252-
// This is useful for testing non-ssa liveness, for example, of memory
253-
// locations. In that case, the def nodes may be stores and the uses may be
254-
// destroy_addrs.
255-
static FunctionTest FieldSensitiveMultiDefUseLiveRangeTest(
256-
"fieldsensitive-multidefuse-liverange",
257-
[](auto &function, auto &arguments, auto &test) {
258-
SmallVector<SILBasicBlock *, 8> discoveredBlocks;
259-
auto value = arguments.takeValue();
260-
FieldSensitiveMultiDefPrunedLiveRange liveness(&function, value,
261-
&discoveredBlocks);
262-
263-
llvm::outs() << "FieldSensitive MultiDef lifetime analysis:\n";
264-
if (arguments.takeString() != "defs:") {
265-
llvm::report_fatal_error(
266-
"test specification expects the 'defs:' label\n");
267-
}
268-
while (true) {
269-
auto argument = arguments.takeArgument();
270-
if (isa<StringArgument>(argument)) {
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-
auto begin = arguments.takeUInt();
278-
auto end = arguments.takeUInt();
279-
TypeTreeLeafTypeRange range(begin, end);
280-
if (isa<InstructionArgument>(argument)) {
281-
auto *instruction = cast<InstructionArgument>(argument).getValue();
282-
llvm::outs() << " def in range [" << begin << ", " << end
283-
<< ") instruction: " << *instruction;
284-
liveness.initializeDef(instruction, range);
285-
continue;
286-
}
287-
if (isa<ValueArgument>(argument)) {
288-
SILValue value = cast<ValueArgument>(argument).getValue();
289-
llvm::outs() << " def in range [" << begin << ", " << end
290-
<< ") value: " << value;
291-
liveness.initializeDef(value, range);
292-
continue;
293-
}
294-
llvm::report_fatal_error(
295-
"test specification expects the 'uses:' label\n");
296-
}
297-
liveness.finishedInitializationOfDefs();
298-
while (arguments.hasUntaken()) {
299-
auto *inst = arguments.takeInstruction();
300-
auto lifetimeEnding = arguments.takeBool();
301-
auto begin = arguments.takeUInt();
302-
auto end = arguments.takeUInt();
303-
TypeTreeLeafTypeRange range(begin, end);
304-
liveness.updateForUse(inst, range, lifetimeEnding);
305-
}
306-
liveness.print(llvm::errs());
307-
308-
FieldSensitivePrunedLivenessBoundary boundary(
309-
liveness.getNumSubElements());
310-
liveness.computeBoundary(boundary);
311-
boundary.print(llvm::errs());
312-
});
313-
314228
} // namespace swift::test
315229

316230
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)