@@ -305,13 +305,14 @@ static void addDereferenceableAttributeToBuilder(IRGenModule &IGM,
305
305
static void addIndirectValueParameterAttributes (IRGenModule &IGM,
306
306
llvm::AttributeList &attrs,
307
307
const TypeInfo &ti,
308
- unsigned argIndex) {
308
+ unsigned argIndex,
309
+ bool addressable) {
309
310
llvm::AttrBuilder b (IGM.getLLVMContext ());
310
311
// Value parameter pointers can't alias or be captured.
311
312
b.addAttribute (llvm::Attribute::NoAlias);
312
313
// Bitwise takable value types are guaranteed not to capture
313
314
// a pointer into itself.
314
- if (ti.isBitwiseTakable (ResilienceExpansion::Maximal))
315
+ if (!addressable && ti.isBitwiseTakable (ResilienceExpansion::Maximal))
315
316
b.addAttribute (llvm::Attribute::NoCapture);
316
317
// The parameter must reference dereferenceable memory of the type.
317
318
addDereferenceableAttributeToBuilder (IGM, b, ti);
@@ -340,7 +341,7 @@ static void addPackParameterAttributes(IRGenModule &IGM,
340
341
static void addInoutParameterAttributes (IRGenModule &IGM, SILType paramSILType,
341
342
llvm::AttributeList &attrs,
342
343
const TypeInfo &ti, unsigned argIndex,
343
- bool aliasable) {
344
+ bool aliasable, bool addressable ) {
344
345
llvm::AttrBuilder b (IGM.getLLVMContext ());
345
346
// Thanks to exclusivity checking, it is not possible to alias inouts except
346
347
// those that are inout_aliasable.
@@ -351,7 +352,7 @@ static void addInoutParameterAttributes(IRGenModule &IGM, SILType paramSILType,
351
352
}
352
353
// Bitwise takable value types are guaranteed not to capture
353
354
// a pointer into itself.
354
- if (ti.isBitwiseTakable (ResilienceExpansion::Maximal))
355
+ if (!addressable && ti.isBitwiseTakable (ResilienceExpansion::Maximal))
355
356
b.addAttribute (llvm::Attribute::NoCapture);
356
357
// The inout must reference dereferenceable memory of the type.
357
358
addDereferenceableAttributeToBuilder (IGM, b, ti);
@@ -600,9 +601,11 @@ namespace {
600
601
Signature getSignature ();
601
602
602
603
private:
603
- const TypeInfo &expand (SILParameterInfo param );
604
+ const TypeInfo &expand (unsigned paramIdx );
604
605
llvm::Type *addIndirectResult (SILType resultType, bool useInReg = false );
605
606
607
+ bool isAddressableParam (unsigned paramIdx);
608
+
606
609
SILFunctionConventions getSILFuncConventions () const {
607
610
return SILFunctionConventions (FnType, IGM.getSILModule ());
608
611
}
@@ -1781,24 +1784,27 @@ static ArrayRef<llvm::Type *> expandScalarOrStructTypeToArray(llvm::Type *&ty) {
1781
1784
return expandedTys;
1782
1785
}
1783
1786
1784
- const TypeInfo &SignatureExpansion::expand (SILParameterInfo param) {
1787
+ const TypeInfo &SignatureExpansion::expand (unsigned paramIdx) {
1788
+ auto param = FnType->getParameters ()[paramIdx];
1785
1789
auto paramSILType = getSILFuncConventions ().getSILType (
1786
1790
param, IGM.getMaximalTypeExpansionContext ());
1787
1791
auto &ti = IGM.getTypeInfo (paramSILType);
1788
1792
switch (auto conv = param.getConvention ()) {
1789
1793
case ParameterConvention::Indirect_In:
1790
1794
case ParameterConvention::Indirect_In_Guaranteed:
1791
1795
case ParameterConvention::Indirect_In_CXX:
1792
- addIndirectValueParameterAttributes (IGM, Attrs, ti, ParamIRTypes.size ());
1796
+ addIndirectValueParameterAttributes (IGM, Attrs, ti, ParamIRTypes.size (),
1797
+ isAddressableParam (paramIdx));
1793
1798
addPointerParameter (IGM.getStorageType (getSILFuncConventions ().getSILType (
1794
1799
param, IGM.getMaximalTypeExpansionContext ())));
1795
1800
return ti;
1796
1801
1797
1802
case ParameterConvention::Indirect_Inout:
1798
1803
case ParameterConvention::Indirect_InoutAliasable:
1799
1804
addInoutParameterAttributes (
1800
- IGM, paramSILType, Attrs, ti, ParamIRTypes.size (),
1801
- conv == ParameterConvention::Indirect_InoutAliasable);
1805
+ IGM, paramSILType, Attrs, ti, ParamIRTypes.size (),
1806
+ conv == ParameterConvention::Indirect_InoutAliasable,
1807
+ isAddressableParam (paramIdx));
1802
1808
addPointerParameter (IGM.getStorageType (getSILFuncConventions ().getSILType (
1803
1809
param, IGM.getMaximalTypeExpansionContext ())));
1804
1810
return ti;
@@ -1822,7 +1828,8 @@ const TypeInfo &SignatureExpansion::expand(SILParameterInfo param) {
1822
1828
auto &nativeSchema = ti.nativeParameterValueSchema (IGM);
1823
1829
if (nativeSchema.requiresIndirect ()) {
1824
1830
addIndirectValueParameterAttributes (IGM, Attrs, ti,
1825
- ParamIRTypes.size ());
1831
+ ParamIRTypes.size (),
1832
+ /* addressable*/ false );
1826
1833
ParamIRTypes.push_back (ti.getStorageType ()->getPointerTo ());
1827
1834
return ti;
1828
1835
}
@@ -1842,6 +1849,13 @@ const TypeInfo &SignatureExpansion::expand(SILParameterInfo param) {
1842
1849
llvm_unreachable (" bad parameter convention" );
1843
1850
}
1844
1851
1852
+ bool SignatureExpansion::isAddressableParam (unsigned paramIdx) {
1853
+ return FnType->isAddressable (paramIdx, IGM.IRGen .SIL ,
1854
+ IGM.getGenericEnvironment (),
1855
+ IGM.getSILTypes (),
1856
+ IGM.getMaximalTypeExpansionContext ());
1857
+ }
1858
+
1845
1859
// / Does the given function type have a self parameter that should be
1846
1860
// / given the special treatment for self parameters?
1847
1861
// /
@@ -1887,7 +1901,6 @@ static void addParamInfo(SignatureExpansionABIDetails *details,
1887
1901
}
1888
1902
1889
1903
void SignatureExpansion::expandKeyPathAccessorParameters () {
1890
- auto params = FnType->getParameters ();
1891
1904
unsigned numArgsToExpand;
1892
1905
SmallVector<llvm::Type *, 4 > tailParams;
1893
1906
@@ -1933,7 +1946,7 @@ void SignatureExpansion::expandKeyPathAccessorParameters() {
1933
1946
llvm_unreachable (" non keypath accessor convention" );
1934
1947
}
1935
1948
for (unsigned i = 0 ; i < numArgsToExpand; i++) {
1936
- expand (params[i] );
1949
+ expand (i );
1937
1950
}
1938
1951
for (auto tailParam : tailParams) {
1939
1952
ParamIRTypes.push_back (tailParam);
@@ -1987,9 +2000,9 @@ void SignatureExpansion::expandParameters(
1987
2000
params = params.drop_back ();
1988
2001
}
1989
2002
1990
- for (auto param : params) {
1991
- const TypeInfo &ti = expand (param );
1992
- addParamInfo (recordedABIDetails, ti, param .getConvention ());
2003
+ for (auto pair : enumerate( params) ) {
2004
+ const TypeInfo &ti = expand (pair. index () );
2005
+ addParamInfo (recordedABIDetails, ti, pair. value () .getConvention ());
1993
2006
}
1994
2007
if (recordedABIDetails && FnType->hasSelfParam () && !hasSelfContext)
1995
2008
recordedABIDetails->parameters .back ().isSelf = true ;
@@ -2015,7 +2028,7 @@ void SignatureExpansion::expandParameters(
2015
2028
2016
2029
if (claimSelf ())
2017
2030
IGM.addSwiftSelfAttributes (Attrs, curLength);
2018
- expand (FnType->getSelfParameter ());
2031
+ expand (FnType->getSelfParameterIndex ());
2019
2032
if (recordedABIDetails)
2020
2033
recordedABIDetails->hasTrailingSelfParam = true ;
2021
2034
assert (ParamIRTypes.size () == curLength + 1 &&
@@ -2260,8 +2273,8 @@ void SignatureExpansion::expandAsyncEntryType() {
2260
2273
params = params.drop_back ();
2261
2274
}
2262
2275
2263
- for (auto param : params) {
2264
- expand (param );
2276
+ for (unsigned i : range ( params. size ()) ) {
2277
+ expand (i );
2265
2278
}
2266
2279
2267
2280
// Next, the generic signature.
@@ -2279,7 +2292,7 @@ void SignatureExpansion::expandAsyncEntryType() {
2279
2292
if (hasSelfContext) {
2280
2293
auto curLength = ParamIRTypes.size ();
2281
2294
(void )curLength;
2282
- expand (FnType->getSelfParameter ());
2295
+ expand (FnType->getSelfParameterIndex ());
2283
2296
assert (ParamIRTypes.size () == curLength + 1 &&
2284
2297
" adding 'self' added unexpected number of parameters" );
2285
2298
if (claimSelf ())
0 commit comments