7676#include " swift/AST/DiagnosticsSIL.h"
7777#include " swift/AST/Expr.h"
7878#include " swift/AST/Module.h"
79+ #include " swift/AST/SemanticAttrs.h"
7980#include " swift/AST/SubstitutionMap.h"
8081#include " swift/Basic/OptimizationMode.h"
81- #include " swift/AST/SemanticAttrs.h"
8282#include " swift/Demangling/Demangle.h"
8383#include " swift/Demangling/Demangler.h"
84+ #include " swift/SIL/BasicBlockBits.h"
8485#include " swift/SIL/BasicBlockUtils.h"
8586#include " swift/SIL/CFG.h"
8687#include " swift/SIL/InstructionUtils.h"
9394#include " swift/SIL/SILLocation.h"
9495#include " swift/SIL/SILModule.h"
9596#include " swift/SIL/TypeLowering.h"
96- #include " swift/SIL/BasicBlockBits.h"
9797#include " swift/SILOptimizer/PassManager/Passes.h"
9898#include " swift/SILOptimizer/PassManager/Transforms.h"
9999#include " swift/SILOptimizer/Utils/CFGOptUtils.h"
100+ #include " swift/SILOptimizer/Utils/CompileTimeInterpolationUtils.h"
100101#include " swift/SILOptimizer/Utils/ConstExpr.h"
101102#include " swift/SILOptimizer/Utils/InstructionDeleter.h"
102103#include " swift/SILOptimizer/Utils/SILInliner.h"
@@ -245,38 +246,6 @@ static bool isIntegerOrBoolType(SILType silType, ASTContext &astContext) {
245246 return nominalDecl && isStdlibIntegerOrBoolDecl (nominalDecl, astContext);
246247}
247248
248- // / Decide if the given instruction (which could possibly be a call) should
249- // / be constant evaluated.
250- // /
251- // / \returns true iff the given instruction is not a call or if it is, it calls
252- // / a known constant-evaluable function such as string append etc., or calls
253- // / a function annotate as "constant_evaluable".
254- static bool shouldAttemptEvaluation (SILInstruction *inst) {
255- auto *apply = dyn_cast<ApplyInst>(inst);
256- if (!apply)
257- return true ;
258- SILFunction *calleeFun = apply->getCalleeFunction ();
259- if (!calleeFun)
260- return false ;
261- return isConstantEvaluable (calleeFun);
262- }
263-
264- // / Skip or evaluate the given instruction based on the evaluation policy and
265- // / handle errors. The policy is to evaluate all non-apply instructions as well
266- // / as apply instructions that are marked as "constant_evaluable".
267- static std::pair<Optional<SILBasicBlock::iterator>, Optional<SymbolicValue>>
268- evaluateOrSkip (ConstExprStepEvaluator &stepEval,
269- SILBasicBlock::iterator instI) {
270- SILInstruction *inst = &(*instI);
271-
272- // Note that skipping a call conservatively approximates its effects on the
273- // interpreter state.
274- if (shouldAttemptEvaluation (inst)) {
275- return stepEval.tryEvaluateOrElseMakeEffectsNonConstant (instI);
276- }
277- return stepEval.skipByMakingEffectsNonConstant (instI);
278- }
279-
280249// / Return true iff the given value is a stdlib Int or Bool and it not a direct
281250// / construction of Int or Bool.
282251static bool isFoldableIntOrBool (SILValue value, ASTContext &astContext) {
@@ -818,31 +787,6 @@ static SILValue emitCodeForSymbolicValue(SymbolicValue symVal,
818787 }
819788}
820789
821- // / Given a SILValue \p value, compute the set of transitive users of the value
822- // / (excluding value itself) by following the use-def chain starting at value.
823- // / Note that this function does not follow use-def chains though branches.
824- static void getTransitiveUsers (SILValue value,
825- SmallVectorImpl<SILInstruction *> &users) {
826- // Collect the instructions that are data dependent on the value using a
827- // fix point iteration.
828- SmallPtrSet<SILInstruction *, 16 > visitedUsers;
829- SmallVector<SILValue, 16 > worklist;
830- worklist.push_back (value);
831-
832- while (!worklist.empty ()) {
833- SILValue currVal = worklist.pop_back_val ();
834- for (Operand *use : currVal->getUses ()) {
835- SILInstruction *user = use->getUser ();
836- if (visitedUsers.count (user))
837- continue ;
838- visitedUsers.insert (user);
839- llvm::copy (user->getResults (), std::back_inserter (worklist));
840- }
841- }
842- // At this point, visitedUsers have all the transitive, data-dependent uses.
843- users.append (visitedUsers.begin (), visitedUsers.end ());
844- }
845-
846790// / Collect the end points of the instructions that are data dependent on \c
847791// / value. A instruction is data dependent on \c value if its result may
848792// / transitively depends on \c value. Note that data dependencies through
@@ -853,7 +797,7 @@ static void getTransitiveUsers(SILValue value,
853797// / \param endUsers buffer for storing the found end points of the data
854798// / dependence chain.
855799static void
856- getEndPointsOfDataDependentChain (SILValue value, SILFunction *fun,
800+ getEndPointsOfDataDependentChain (SingleValueInstruction * value, SILFunction *fun,
857801 SmallVectorImpl<SILInstruction *> &endUsers) {
858802 assert (!value->getType ().isAddress ());
859803
0 commit comments