Skip to content

Commit af5cd31

Browse files
committed
[Test] Added test for SILCombiner::processInst.
1 parent 6deba02 commit af5cd31

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,36 @@ void SILCombiner::processInstruction(SILInstruction *I,
510510
Builder.getTrackingList()->clear();
511511
}
512512

513+
namespace swift::test {
514+
struct SILCombinerProcessInstruction {
515+
void operator()(SILCombiner &combiner, SILInstruction *inst,
516+
SILCombineCanonicalize &canonicalizer, bool &madeChange) {
517+
combiner.processInstruction(inst, canonicalizer, madeChange);
518+
}
519+
};
520+
// Arguments:
521+
// - instruction: the instruction to be processed
522+
// - bool: remove cond_fails
523+
// - bool: enable lifetime canonicalization
524+
// Dumps:
525+
// - the function after the processing is attempted
526+
static FunctionTest SILCombineProcessInstruction(
527+
"sil_combine_process_instruction",
528+
[](auto &function, auto &arguments, auto &test) {
529+
auto inst = arguments.takeInstruction();
530+
auto removeCondFails = arguments.takeBool();
531+
auto enableCopyPropagation = arguments.takeBool();
532+
SILCombiner combiner(test.getPass(), removeCondFails,
533+
enableCopyPropagation);
534+
SILCombineCanonicalize canonicalizer(combiner.Worklist,
535+
*test.getDeadEndBlocks());
536+
bool madeChange = false;
537+
SILCombinerProcessInstruction()(combiner, inst, canonicalizer,
538+
madeChange);
539+
function.dump();
540+
});
541+
} // end namespace swift::test
542+
513543
namespace swift::test {
514544
// Arguments:
515545
// - instruction: the instruction to be visited

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
namespace swift {
4848

4949
class AliasAnalysis;
50+
class SILCombineCanonicalize;
51+
namespace test {
52+
struct SILCombinerProcessInstruction;
53+
}
5054

5155
/// This is a class which maintains the state of the combiner and simplifies
5256
/// many operations such as removing/adding instructions and syncing them with
@@ -415,6 +419,8 @@ class SILCombiner :
415419
void processInstruction(SILInstruction *instruction,
416420
SILCombineCanonicalize &scCanonicalize,
417421
bool &MadeChange);
422+
friend test::SILCombinerProcessInstruction;
423+
418424
/// Add reachable code to the worklist. Meant to be used when starting to
419425
/// process a new function.
420426
void addReachableCodeToWorklist(SILBasicBlock *BB);

0 commit comments

Comments
 (0)