26
26
#include " clang/CodeGen/ModuleBuilder.h"
27
27
#include " swift/AST/GenericEnvironment.h"
28
28
#include " swift/SIL/SILType.h"
29
+ #include " swift/Runtime/Config.h"
29
30
#include " llvm/IR/CallSite.h"
30
31
#include " llvm/Support/Compiler.h"
31
32
@@ -108,7 +109,7 @@ static void addInoutParameterAttributes(IRGenModule &IGM,
108
109
109
110
static llvm::CallingConv::ID getFreestandingConvention (IRGenModule &IGM) {
110
111
// TODO: use a custom CC that returns three scalars efficiently
111
- return llvm::CallingConv::Swift ;
112
+ return SWIFT_LLVM_CC (SwiftCC) ;
112
113
}
113
114
114
115
// / Expand the requirements of the given abstract calling convention
@@ -151,33 +152,33 @@ static void addIndirectResultAttributes(IRGenModule &IGM,
151
152
attrs = attrs.addAttributes (IGM.LLVMContext , paramIndex + 1 , resultAttrs);
152
153
}
153
154
154
- static void addSwiftSelfAttributes (IRGenModule &IGM,
155
- llvm::AttributeSet &attrs,
156
- unsigned argIndex) {
155
+ void IRGenModule::addSwiftSelfAttributes (llvm::AttributeSet &attrs,
156
+ unsigned argIndex) {
157
+ if (!UseSwiftCC)
158
+ return ;
157
159
static const llvm::Attribute::AttrKind attrKinds[] = {
158
160
llvm::Attribute::SwiftSelf,
159
161
};
160
162
auto argAttrs =
161
- llvm::AttributeSet::get (IGM. LLVMContext , argIndex + 1 , attrKinds);
162
- attrs = attrs.addAttributes (IGM. LLVMContext , argIndex + 1 , argAttrs);
163
+ llvm::AttributeSet::get (this -> LLVMContext , argIndex + 1 , attrKinds);
164
+ attrs = attrs.addAttributes (this -> LLVMContext , argIndex + 1 , argAttrs);
163
165
}
164
166
165
- static void addSwiftErrorAttributes (IRGenModule &IGM,
166
- llvm::AttributeSet &attrs,
167
- unsigned argIndex) {
167
+ void IRGenModule::addSwiftErrorAttributes (llvm::AttributeSet &attrs,
168
+ unsigned argIndex) {
168
169
// Don't add the swifterror attribute on ABI that don't pass it in a register.
169
170
// We create a shadow stack location of the swifterror parameter for the
170
171
// debugger on such platforms and so we can't mark the parameter with a
171
172
// swifterror attribute.
172
- if (!IGM. IsSwiftErrorInRegister )
173
+ if (!UseSwiftCC || ! this -> IsSwiftErrorInRegister )
173
174
return ;
174
175
175
176
static const llvm::Attribute::AttrKind attrKinds[] = {
176
177
llvm::Attribute::SwiftError,
177
178
};
178
179
auto argAttrs =
179
- llvm::AttributeSet::get (IGM. LLVMContext , argIndex + 1 , attrKinds);
180
- attrs = attrs.addAttributes (IGM. LLVMContext , argIndex + 1 , argAttrs);
180
+ llvm::AttributeSet::get (this -> LLVMContext , argIndex + 1 , attrKinds);
181
+ attrs = attrs.addAttributes (this -> LLVMContext , argIndex + 1 , argAttrs);
181
182
}
182
183
183
184
void irgen::addByvalArgumentAttributes (IRGenModule &IGM,
@@ -939,10 +940,10 @@ llvm::Type *SignatureExpansion::expandExternalSignatureTypes() {
939
940
case clang::ParameterABI::Ordinary:
940
941
break ;
941
942
case clang::ParameterABI::SwiftContext:
942
- addSwiftSelfAttributes (IGM, Attrs, getCurParamIndex ());
943
+ IGM. addSwiftSelfAttributes (Attrs, getCurParamIndex ());
943
944
break ;
944
945
case clang::ParameterABI::SwiftErrorResult:
945
- addSwiftErrorAttributes (IGM, Attrs, getCurParamIndex ());
946
+ IGM. addSwiftErrorAttributes (Attrs, getCurParamIndex ());
946
947
break ;
947
948
case clang::ParameterABI::SwiftIndirectResult:
948
949
addIndirectResultAttributes (IGM, Attrs, getCurParamIndex (),claimSRet ());
@@ -1115,7 +1116,7 @@ void SignatureExpansion::expandParameters() {
1115
1116
auto curLength = ParamIRTypes.size (); (void ) curLength;
1116
1117
1117
1118
if (claimSelf ())
1118
- addSwiftSelfAttributes (IGM, Attrs, curLength);
1119
+ IGM. addSwiftSelfAttributes (Attrs, curLength);
1119
1120
expand (FnType->getSelfParameter ());
1120
1121
assert (ParamIRTypes.size () == curLength + 1 &&
1121
1122
" adding 'self' added unexpected number of parameters" );
@@ -1141,7 +1142,7 @@ void SignatureExpansion::expandParameters() {
1141
1142
};
1142
1143
if (needsContext ()) {
1143
1144
if (claimSelf ())
1144
- addSwiftSelfAttributes (IGM, Attrs, ParamIRTypes.size ());
1145
+ IGM. addSwiftSelfAttributes (Attrs, ParamIRTypes.size ());
1145
1146
ParamIRTypes.push_back (IGM.RefCountedPtrTy );
1146
1147
}
1147
1148
}
@@ -1151,7 +1152,7 @@ void SignatureExpansion::expandParameters() {
1151
1152
// if we set the right attribute.
1152
1153
if (FnType->hasErrorResult ()) {
1153
1154
if (claimError ())
1154
- addSwiftErrorAttributes (IGM, Attrs, ParamIRTypes.size ());
1155
+ IGM. addSwiftErrorAttributes (Attrs, ParamIRTypes.size ());
1155
1156
llvm::Type *errorType = IGM.getStorageType (
1156
1157
getSILFuncConventions ().getSILType (FnType->getErrorResult ()));
1157
1158
ParamIRTypes.push_back (errorType->getPointerTo ());
@@ -1493,7 +1494,7 @@ void CallEmission::setFromCallee() {
1493
1494
assert (LastArgWritten > 0 );
1494
1495
Args[--LastArgWritten] = errorResultSlot.getAddress ();
1495
1496
addAttribute (LastArgWritten + 1 , llvm::Attribute::NoCapture);
1496
- addSwiftErrorAttributes ( IGF.IGM , Attrs, LastArgWritten);
1497
+ IGF.IGM . addSwiftErrorAttributes ( Attrs, LastArgWritten);
1497
1498
1498
1499
// Fill in the context pointer if necessary.
1499
1500
if (!contextPtr) {
@@ -1509,7 +1510,7 @@ void CallEmission::setFromCallee() {
1509
1510
&& " block function should not claimed to have data pointer" );
1510
1511
assert (LastArgWritten > 0 );
1511
1512
Args[--LastArgWritten] = contextPtr;
1512
- addSwiftSelfAttributes ( IGF.IGM , Attrs, LastArgWritten);
1513
+ IGF.IGM . addSwiftSelfAttributes ( Attrs, LastArgWritten);
1513
1514
}
1514
1515
}
1515
1516
0 commit comments