Skip to content

Commit cab6ec6

Browse files
authored
Merge pull request #11041 from CodaFi/functional-programming
[Gardening] Use 'SGF' in EmitBBArguments
2 parents 879e8e5 + 1c60011 commit cab6ec6

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
7979
/*RetTy*/ ManagedValue>
8080
{
8181
public:
82-
SILGenFunction &gen;
82+
SILGenFunction &SGF;
8383
SILBasicBlock *parent;
8484
SILLocation loc;
8585
bool functionArgs;
8686
ArrayRef<SILParameterInfo> &parameters;
8787

88-
EmitBBArguments(SILGenFunction &gen, SILBasicBlock *parent,
88+
EmitBBArguments(SILGenFunction &sgf, SILBasicBlock *parent,
8989
SILLocation l, bool functionArgs,
9090
ArrayRef<SILParameterInfo> &parameters)
91-
: gen(gen), parent(parent), loc(l), functionArgs(functionArgs),
91+
: SGF(sgf), parent(parent), loc(l), functionArgs(functionArgs),
9292
parameters(parameters) {}
9393

9494
ManagedValue getManagedValue(SILValue arg, CanType t,
@@ -105,7 +105,7 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
105105
// An unowned parameter is passed at +0, like guaranteed, but it isn't
106106
// kept alive by the caller, so we need to retain and manage it
107107
// regardless.
108-
return gen.emitManagedRetain(loc, arg);
108+
return SGF.emitManagedRetain(loc, arg);
109109

110110
case ParameterConvention::Indirect_Inout:
111111
case ParameterConvention::Indirect_InoutAliasable:
@@ -117,20 +117,20 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
117117
case ParameterConvention::Indirect_In_Constant:
118118
// An owned or 'in' parameter is passed in at +1. We can claim ownership
119119
// of the parameter and clean it up when it goes out of scope.
120-
return gen.emitManagedRValueWithCleanup(arg);
120+
return SGF.emitManagedRValueWithCleanup(arg);
121121
}
122122
llvm_unreachable("bad parameter convention");
123123
}
124124

125125
ManagedValue visitType(CanType t) {
126-
auto argType = gen.getLoweredType(t);
126+
auto argType = SGF.getLoweredType(t);
127127
// Pop the next parameter info.
128128
auto parameterInfo = parameters.front();
129129
parameters = parameters.slice(1);
130130
assert(
131131
argType
132132
== parent->getParent()->mapTypeIntoContext(
133-
gen.getSILType(parameterInfo))
133+
SGF.getSILType(parameterInfo))
134134
&& "argument does not have same type as specified by parameter info");
135135

136136
SILValue arg =
@@ -148,16 +148,16 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
148148
&& isa<FunctionType>(objectType)
149149
&& cast<FunctionType>(objectType)->getRepresentation()
150150
== FunctionType::Representation::Block) {
151-
SILValue blockCopy = gen.B.createCopyBlock(loc, mv.getValue());
152-
mv = gen.emitManagedRValueWithCleanup(blockCopy);
151+
SILValue blockCopy = SGF.B.createCopyBlock(loc, mv.getValue());
152+
mv = SGF.emitManagedRValueWithCleanup(blockCopy);
153153
}
154154
return mv;
155155
}
156156

157157
ManagedValue visitTupleType(CanTupleType t) {
158158
SmallVector<ManagedValue, 4> elements;
159159

160-
auto &tl = gen.getTypeLowering(t);
160+
auto &tl = SGF.getTypeLowering(t);
161161
bool canBeGuaranteed = tl.isLoadable();
162162

163163
// Collect the exploded elements.
@@ -170,7 +170,7 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
170170
elements.push_back(elt);
171171
}
172172

173-
if (tl.isLoadable() || !gen.silConv.useLoweredAddresses()) {
173+
if (tl.isLoadable() || !SGF.silConv.useLoweredAddresses()) {
174174
SmallVector<SILValue, 4> elementValues;
175175
if (canBeGuaranteed) {
176176
// If all of the elements were guaranteed, we can form a guaranteed tuple.
@@ -180,32 +180,32 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
180180
// Otherwise, we need to move or copy values into a +1 tuple.
181181
for (auto element : elements) {
182182
SILValue value = element.hasCleanup()
183-
? element.forward(gen)
184-
: element.copyUnmanaged(gen, loc).forward(gen);
183+
? element.forward(SGF)
184+
: element.copyUnmanaged(SGF, loc).forward(SGF);
185185
elementValues.push_back(value);
186186
}
187187
}
188-
auto tupleValue = gen.B.createTuple(loc, tl.getLoweredType(),
188+
auto tupleValue = SGF.B.createTuple(loc, tl.getLoweredType(),
189189
elementValues);
190190
return canBeGuaranteed
191191
? ManagedValue::forUnmanaged(tupleValue)
192-
: gen.emitManagedRValueWithCleanup(tupleValue);
192+
: SGF.emitManagedRValueWithCleanup(tupleValue);
193193
} else {
194194
// If the type is address-only, we need to move or copy the elements into
195195
// a tuple in memory.
196196
// TODO: It would be a bit more efficient to use a preallocated buffer
197197
// in this case.
198-
auto buffer = gen.emitTemporaryAllocation(loc, tl.getLoweredType());
198+
auto buffer = SGF.emitTemporaryAllocation(loc, tl.getLoweredType());
199199
for (auto i : indices(elements)) {
200200
auto element = elements[i];
201-
auto elementBuffer = gen.B.createTupleElementAddr(loc, buffer,
201+
auto elementBuffer = SGF.B.createTupleElementAddr(loc, buffer,
202202
i, element.getType().getAddressType());
203203
if (element.hasCleanup())
204-
element.forwardInto(gen, loc, elementBuffer);
204+
element.forwardInto(SGF, loc, elementBuffer);
205205
else
206-
element.copyInto(gen, elementBuffer, loc);
206+
element.copyInto(SGF, elementBuffer, loc);
207207
}
208-
return gen.emitManagedRValueWithCleanup(buffer);
208+
return SGF.emitManagedRValueWithCleanup(buffer);
209209
}
210210
}
211211
};

0 commit comments

Comments
 (0)