10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
// /
13
+ // / \file
14
+ // /
13
15
// / Eager Specializer
14
16
// / -----------------
15
17
// /
25
27
// /
26
28
// / TODO: We have not determined whether to support inexact type checks. It
27
29
// / will be a tradeoff between utility of the attribute vs. cost of the check.
30
+ // /
31
+ // ===----------------------------------------------------------------------===//
28
32
29
33
#define DEBUG_TYPE " eager-specializer"
34
+
30
35
#include " swift/AST/GenericEnvironment.h"
31
36
#include " swift/AST/Type.h"
32
37
#include " swift/SIL/SILFunction.h"
36
41
#include " llvm/Support/Debug.h"
37
42
38
43
using namespace swift ;
39
- using llvm::dbgs;
40
44
41
45
// Temporary flag.
42
46
llvm::cl::opt<bool > EagerSpecializeFlag (
@@ -650,7 +654,8 @@ emitArgumentConversion(SmallVectorImpl<SILValue> &CallArgs) {
650
654
unsigned ArgIdx = OrigArg->getIndex ();
651
655
652
656
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 ()));
654
659
655
660
if (!substConv.useLoweredAddresses ()) {
656
661
CallArgs.push_back (CastArg);
@@ -710,16 +715,15 @@ static SILFunction *eagerSpecialize(SILOptFunctionBuilder &FuncBuilder,
710
715
SILFunction *GenericFunc,
711
716
const SILSpecializeAttr &SA,
712
717
const ReabstractionInfo &ReInfo) {
713
- LLVM_DEBUG (dbgs () << " Specializing " << GenericFunc->getName () << " \n " );
718
+ LLVM_DEBUG (llvm:: dbgs () << " Specializing " << GenericFunc->getName () << " \n " );
714
719
715
720
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 " );
723
727
724
728
GenericFuncSpecializer
725
729
FuncSpecializer (FuncBuilder, GenericFunc,
@@ -728,7 +732,7 @@ static SILFunction *eagerSpecialize(SILOptFunctionBuilder &FuncBuilder,
728
732
729
733
SILFunction *NewFunc = FuncSpecializer.trySpecialization ();
730
734
if (!NewFunc)
731
- LLVM_DEBUG (dbgs () << " Failed. Cannot specialize function.\n " );
735
+ LLVM_DEBUG (llvm:: dbgs () << " Failed. Cannot specialize function.\n " );
732
736
return NewFunc;
733
737
}
734
738
@@ -744,11 +748,12 @@ void EagerSpecializerTransform::run() {
744
748
// TODO: we should support ownership here but first we'll have to support
745
749
// ownership in GenericFuncSpecializer.
746
750
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 " );
750
754
continue ;
751
755
}
756
+
752
757
// Only specialize functions in their home module.
753
758
if (F.isExternalDeclaration () || F.isAvailableExternally ())
754
759
continue ;
@@ -786,11 +791,13 @@ void EagerSpecializerTransform::run() {
786
791
EagerDispatch (&F, ReInfo).emitDispatchTo (NewFunc);
787
792
}
788
793
});
794
+
789
795
// Invalidate everything since we delete calls as well as add new
790
796
// calls and branches.
791
797
if (Changed) {
792
798
invalidateAnalysis (&F, SILAnalysis::InvalidationKind::Everything);
793
799
}
800
+
794
801
// As specializations are created, the attributes should be removed.
795
802
F.clearSpecializeAttrs ();
796
803
}
0 commit comments