Skip to content

Commit 30d779e

Browse files
committed
[Test] Added sil_combine_instruction.
1 parent cad0761 commit 30d779e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/SIL/DebugUtils.h"
2626
#include "swift/SIL/SILBuilder.h"
2727
#include "swift/SIL/SILVisitor.h"
28+
#include "swift/SIL/Test.h"
2829
#include "swift/SILOptimizer/Analysis/AliasAnalysis.h"
2930
#include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
3031
#include "swift/SILOptimizer/Analysis/NonLocalAccessBlockAnalysis.h"
@@ -498,6 +499,29 @@ bool SILCombiner::doOneIteration(SILFunction &F, unsigned Iteration) {
498499
return MadeChange;
499500
}
500501

502+
namespace swift::test {
503+
// Arguments:
504+
// - instruction: the instruction to be canonicalized
505+
// Dumps:
506+
// - the function after the canonicalization is attempted
507+
static FunctionTest SILCombineCanonicalizeInstruction(
508+
"sil_combine_instruction", [](auto &function, auto &arguments, auto &test) {
509+
SILCombiner combiner(test.getPass(), false, false);
510+
auto inst = arguments.takeInstruction();
511+
combiner.Builder.setInsertionPoint(inst);
512+
auto *result = combiner.visit(inst);
513+
if (result) {
514+
combiner.Worklist.replaceInstructionWithInstruction(inst, result
515+
#ifndef NDEBUG
516+
,
517+
""
518+
#endif
519+
);
520+
}
521+
function.dump();
522+
});
523+
} // end namespace swift::test
524+
501525
bool SILCombiner::runOnFunction(SILFunction &F) {
502526
clear();
503527

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ class SILCombiner :
7272
/// lifetimes in OSSA.
7373
NonLocalAccessBlockAnalysis *NLABA;
7474

75+
public:
7576
/// Worklist containing all of the instructions primed for simplification.
7677
SmallSILInstructionWorklist<256> Worklist;
7778

79+
private:
7880
/// Utility for dead code removal.
7981
InstructionDeleter deleter;
8082

@@ -102,10 +104,12 @@ class SILCombiner :
102104
// The tracking list is used by `Builder` for newly added
103105
// instructions, which we will periodically move to our worklist.
104106
llvm::SmallVector<SILInstruction *, 64> TrackingList;
105-
107+
108+
public:
106109
/// Builder used to insert instructions.
107110
SILBuilder Builder;
108111

112+
private:
109113
SILOptFunctionBuilder FuncBuilder;
110114

111115
/// Cast optimizer

0 commit comments

Comments
 (0)