Skip to content

Commit 573c417

Browse files
Merge pull request #61656 from nate-chandler/test/20221020/1
[Test] Added a few conveniences.
2 parents 1ebcd13 + 8397a21 commit 573c417

File tree

5 files changed

+250
-40
lines changed

5 files changed

+250
-40
lines changed

docs/SIL.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,15 +3949,19 @@ The following types of test arguments are supported:
39493949
- function: @function <-- the current function
39503950
@function[uint] <-- function at index ``uint``
39513951
@function[name] <-- function named ``name``
3952-
- block: @block <-- the first block
3952+
- block: @block <-- the block containing the test_specification instruction
3953+
@block[+uint] <-- the block ``uint`` blocks after the containing block
3954+
@block[-uint] <-- the block ``uint`` blocks before the containing block
39533955
@block[uint] <-- the block at index ``uint``
39543956
@{function}.{block} <-- the indicated block in the indicated function
39553957
Example: @function[foo].block[2]
39563958
- trace: @trace <-- the first ``debug_value [trace]`` in the current function
39573959
@trace[uint] <-- the ``debug_value [trace]`` at index ``uint``
39583960
@{function}.{trace} <-- the indicated trace in the indicated function
39593961
Example: @function[bar].trace
3960-
- instruction: @instruction <-- the first instruction
3962+
- instruction: @instruction <-- the instruction after* the test_specification instruction
3963+
@instruction[+uint] <-- the instruction ``uint`` instructions after* the test_specification instruction
3964+
@instruction[-uint] <-- the instruction ``uint`` instructions before* the test_specification instruction
39613965
@instruction[uint] <-- the instruction at index ``uint``
39623966
@{function}.{instruction} <-- the indicated instruction in the indicated function
39633967
Example: @function[baz].instruction[19]
@@ -3969,6 +3973,11 @@ The following types of test arguments are supported:
39693973
Example: @block[19].instruction[2].operand[3]
39703974
Example: @function[2].instruction.operand
39713975

3976+
* Not counting instructions that are deleted when processing functions for tests.
3977+
The following instructions currently are deleted:
3978+
test_specification
3979+
debug_value [trace]
3980+
39723981

39733982
Profiling
39743983
~~~~~~~~~

include/swift/SILOptimizer/Utils/ParseTestSpecification.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_SIL_PARSETESTSPECIFICATION
1919

2020
#include "swift/Basic/TaggedUnion.h"
21+
#include "swift/SIL/SILInstruction.h"
2122
#include "swift/SIL/SILValue.h"
2223
#include "llvm/ADT/StringRef.h"
2324

@@ -140,7 +141,13 @@ struct Arguments {
140141
return cast<UIntArgument>(takeArgument()).getValue();
141142
}
142143
SILValue takeValue() {
143-
return cast<ValueArgument>(takeArgument()).getValue();
144+
auto argument = takeArgument();
145+
if (isa<InstructionArgument>(argument)) {
146+
auto *instruction = cast<InstructionArgument>(argument).getValue();
147+
auto *svi = cast<SingleValueInstruction>(instruction);
148+
return svi;
149+
}
150+
return cast<ValueArgument>(argument).getValue();
144151
}
145152
Operand *takeOperand() {
146153
return cast<OperandArgument>(takeArgument()).getValue();
@@ -156,17 +163,32 @@ struct Arguments {
156163
}
157164
};
158165

166+
/// The specification for a test which has not yet been parsed.
167+
struct UnparsedSpecification {
168+
/// The string which specifies the test.
169+
///
170+
/// Not a StringRef because the TestSpecificationInst whose payload is of
171+
/// interest gets deleted.
172+
std::string string;
173+
/// The next non-debug instruction.
174+
///
175+
/// Provides an "anchor" for the specification. Contextual arguments
176+
/// (@instruction, @block, @function) can be parsed in terms of this anchor.
177+
SILInstruction *context;
178+
};
179+
159180
/// Finds and deletes each test_specification instruction in \p function and
160181
/// appends its string payload to the provided vector.
161-
void getTestSpecifications(SILFunction *function,
162-
SmallVectorImpl<std::string> &specifications);
182+
void getTestSpecifications(
183+
SILFunction *function,
184+
SmallVectorImpl<UnparsedSpecification> &specifications);
163185

164186
/// Given the string \p specification operand of a test_specification
165187
/// instruction from \p function, parse the arguments which it refers to into
166188
/// \p arguments and the component strings into \p argumentStrings.
167189
void parseTestArgumentsFromSpecification(
168-
SILFunction *function, StringRef specification, Arguments &arguments,
169-
SmallVectorImpl<StringRef> &argumentStrings);
190+
SILFunction *function, UnparsedSpecification const &specification,
191+
Arguments &arguments, SmallVectorImpl<StringRef> &argumentStrings);
170192

171193
} // namespace test
172194
} // namespace swift

0 commit comments

Comments
 (0)