1010//
1111// ===----------------------------------------------------------------------===//
1212// /
13+ // / \file
14+ // /
1315// / Eager Specializer
1416// / -----------------
1517// /
2527// /
2628// / TODO: We have not determined whether to support inexact type checks. It
2729// / will be a tradeoff between utility of the attribute vs. cost of the check.
30+ // /
31+ // ===----------------------------------------------------------------------===//
2832
2933#define DEBUG_TYPE " eager-specializer"
34+
3035#include " swift/AST/GenericEnvironment.h"
3136#include " swift/AST/Type.h"
3237#include " swift/SIL/SILFunction.h"
3641#include " llvm/Support/Debug.h"
3742
3843using namespace swift ;
39- using llvm::dbgs;
4044
4145// Temporary flag.
4246llvm::cl::opt<bool > EagerSpecializeFlag (
@@ -650,7 +654,8 @@ emitArgumentConversion(SmallVectorImpl<SILValue> &CallArgs) {
650654 unsigned ArgIdx = OrigArg->getIndex ();
651655
652656 auto CastArg = emitArgumentCast (SubstitutedType, OrigArg, ArgIdx);
653- LLVM_DEBUG (dbgs () << " Cast generic arg: " ; CastArg->print (dbgs ()));
657+ LLVM_DEBUG (llvm::dbgs () << " Cast generic arg: " ;
658+ CastArg->print (llvm::dbgs ()));
654659
655660 if (!substConv.useLoweredAddresses ()) {
656661 CallArgs.push_back (CastArg);
@@ -710,16 +715,15 @@ static SILFunction *eagerSpecialize(SILOptFunctionBuilder &FuncBuilder,
710715 SILFunction *GenericFunc,
711716 const SILSpecializeAttr &SA,
712717 const ReabstractionInfo &ReInfo) {
713- LLVM_DEBUG (dbgs () << " Specializing " << GenericFunc->getName () << " \n " );
718+ LLVM_DEBUG (llvm:: dbgs () << " Specializing " << GenericFunc->getName () << " \n " );
714719
715720 LLVM_DEBUG (auto FT = GenericFunc->getLoweredFunctionType ();
716- dbgs () << " Generic Sig:" ;
717- dbgs ().indent (2 ); FT->getInvocationGenericSignature ()->print (dbgs ());
718- dbgs () << " Generic Env:" ;
719- dbgs ().indent (2 );
720- GenericFunc->getGenericEnvironment ()->dump (dbgs ());
721- dbgs () << " Specialize Attr:" ;
722- SA.print (dbgs ()); dbgs () << " \n " );
721+ llvm::dbgs () << " Generic Sig:" ; llvm::dbgs ().indent (2 );
722+ FT->getInvocationGenericSignature ()->print (llvm::dbgs ());
723+ llvm::dbgs () << " Generic Env:" ; llvm::dbgs ().indent (2 );
724+ GenericFunc->getGenericEnvironment ()->dump (llvm::dbgs ());
725+ llvm::dbgs () << " Specialize Attr:" ; SA.print (llvm::dbgs ());
726+ llvm::dbgs () << " \n " );
723727
724728 GenericFuncSpecializer
725729 FuncSpecializer (FuncBuilder, GenericFunc,
@@ -728,7 +732,7 @@ static SILFunction *eagerSpecialize(SILOptFunctionBuilder &FuncBuilder,
728732
729733 SILFunction *NewFunc = FuncSpecializer.trySpecialization ();
730734 if (!NewFunc)
731- LLVM_DEBUG (dbgs () << " Failed. Cannot specialize function.\n " );
735+ LLVM_DEBUG (llvm:: dbgs () << " Failed. Cannot specialize function.\n " );
732736 return NewFunc;
733737}
734738
@@ -744,11 +748,12 @@ void EagerSpecializerTransform::run() {
744748 // TODO: we should support ownership here but first we'll have to support
745749 // ownership in GenericFuncSpecializer.
746750 if (!F.shouldOptimize () || F.hasOwnership ()) {
747- LLVM_DEBUG (dbgs () << " Cannot specialize function " << F.getName ()
748- << " because it has ownership or is marked to be "
749- " excluded from optimizations.\n " );
751+ LLVM_DEBUG (llvm:: dbgs () << " Cannot specialize function " << F.getName ()
752+ << " because it has ownership or is marked to be "
753+ " excluded from optimizations.\n " );
750754 continue ;
751755 }
756+
752757 // Only specialize functions in their home module.
753758 if (F.isExternalDeclaration () || F.isAvailableExternally ())
754759 continue ;
@@ -786,11 +791,13 @@ void EagerSpecializerTransform::run() {
786791 EagerDispatch (&F, ReInfo).emitDispatchTo (NewFunc);
787792 }
788793 });
794+
789795 // Invalidate everything since we delete calls as well as add new
790796 // calls and branches.
791797 if (Changed) {
792798 invalidateAnalysis (&F, SILAnalysis::InvalidationKind::Everything);
793799 }
800+
794801 // As specializations are created, the attributes should be removed.
795802 F.clearSpecializeAttrs ();
796803 }
0 commit comments