|
34 | 34 | #include "swift/SILOptimizer/Utils/CFGOptUtils.h"
|
35 | 35 | #include "swift/SILOptimizer/Utils/ConstantFolding.h"
|
36 | 36 | #include "swift/SILOptimizer/Utils/Devirtualize.h"
|
| 37 | +#include "swift/SILOptimizer/Utils/Generics.h" |
37 | 38 | #include "swift/SILOptimizer/Utils/InstOptUtils.h"
|
38 | 39 | #include "swift/SILOptimizer/Utils/OptimizerStatsUtils.h"
|
39 | 40 | #include "swift/SILOptimizer/Utils/SILInliner.h"
|
@@ -1740,6 +1741,38 @@ swift::SILVTable * BridgedPassContext::specializeVTableForType(BridgedType type,
|
1740 | 1741 | invocation->getTransform());
|
1741 | 1742 | }
|
1742 | 1743 |
|
| 1744 | +OptionalBridgedFunction BridgedPassContext::specializeFunction(BridgedFunction function, |
| 1745 | + BridgedSubstitutionMap substitutions) const { |
| 1746 | + swift::SILModule *mod = invocation->getPassManager()->getModule(); |
| 1747 | + SILFunction *origFunc = function.getFunction(); |
| 1748 | + SubstitutionMap subs = substitutions.unbridged(); |
| 1749 | + ReabstractionInfo ReInfo(mod->getSwiftModule(), mod->isWholeModule(), |
| 1750 | + ApplySite(), origFunc, subs, IsNotSerialized, |
| 1751 | + /*ConvertIndirectToDirect=*/true, |
| 1752 | + /*dropMetatypeArgs=*/false); |
| 1753 | + |
| 1754 | + if (!ReInfo.canBeSpecialized()) { |
| 1755 | + return {nullptr}; |
| 1756 | + } |
| 1757 | + |
| 1758 | + SILOptFunctionBuilder FunctionBuilder(*invocation->getTransform()); |
| 1759 | + |
| 1760 | + GenericFuncSpecializer FuncSpecializer(FunctionBuilder, origFunc, subs, |
| 1761 | + ReInfo, /*isMandatory=*/true); |
| 1762 | + SILFunction *SpecializedF = FuncSpecializer.lookupSpecialization(); |
| 1763 | + if (!SpecializedF) SpecializedF = FuncSpecializer.tryCreateSpecialization(); |
| 1764 | + if (!SpecializedF || SpecializedF->getLoweredFunctionType()->hasError()) { |
| 1765 | + return {nullptr}; |
| 1766 | + } |
| 1767 | + return {SpecializedF}; |
| 1768 | +} |
| 1769 | + |
| 1770 | +void BridgedPassContext::deserializeAllCallees(BridgedFunction function, bool deserializeAll) const { |
| 1771 | + swift::SILModule *mod = invocation->getPassManager()->getModule(); |
| 1772 | + mod->linkFunction(function.getFunction(), deserializeAll ? SILModule::LinkingMode::LinkAll : |
| 1773 | + SILModule::LinkingMode::LinkNormal); |
| 1774 | +} |
| 1775 | + |
1743 | 1776 | bool BridgedPassContext::specializeClassMethodInst(BridgedInstruction cm) const {
|
1744 | 1777 | return ::specializeClassMethodInst(cm.getAs<ClassMethodInst>());
|
1745 | 1778 | }
|
|
0 commit comments