Skip to content

Commit 1a2af60

Browse files
committed
[NFC] SILGen: Extracted emitBuiltinStore.
In preparation to reuse the code for a different sort of store.
1 parent 923bf1f commit 1a2af60

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,35 +206,40 @@ static ManagedValue emitBuiltinDestroy(SILGenFunction &SGF,
206206
return ManagedValue::forObjectRValueWithoutOwnership(SGF.emitEmptyTuple(loc));
207207
}
208208

209-
static ManagedValue emitBuiltinAssign(SILGenFunction &SGF,
210-
SILLocation loc,
211-
SubstitutionMap substitutions,
212-
ArrayRef<ManagedValue> args,
213-
SGFContext C) {
214-
assert(args.size() >= 2 && "assign should have two arguments");
209+
static ManagedValue emitBuiltinStore(SILGenFunction &SGF, SILLocation loc,
210+
SubstitutionMap substitutions,
211+
ArrayRef<ManagedValue> args, SGFContext C,
212+
bool isStrict, bool isInvariant,
213+
llvm::MaybeAlign alignment) {
214+
assert(args.size() >= 2 && "should have two arguments");
215215
assert(substitutions.getReplacementTypes().size() == 1 &&
216-
"assign should have a single substitution");
216+
"should have a single substitution");
217217

218218
// The substitution determines the type of the thing we're destroying.
219-
CanType assignFormalType =
220-
substitutions.getReplacementTypes()[0]->getCanonicalType();
221-
SILType assignType = SGF.getLoweredType(assignFormalType);
222-
219+
CanType formalTy = substitutions.getReplacementTypes()[0]->getCanonicalType();
220+
SILType loweredTy = SGF.getLoweredType(formalTy);
221+
223222
// Convert the destination pointer argument to a SIL address.
224-
SILValue addr = SGF.B.createPointerToAddress(loc,
225-
args.back().getUnmanagedValue(),
226-
assignType.getAddressType(),
227-
/*isStrict*/ true,
228-
/*isInvariant*/ false);
229-
230-
// Build the value to be assigned, reconstructing tuples if needed.
231-
auto src = RValue(SGF, args.slice(0, args.size() - 1), assignFormalType);
232-
223+
SILValue addr = SGF.B.createPointerToAddress(
224+
loc, args.back().getUnmanagedValue(), loweredTy.getAddressType(),
225+
isStrict, isInvariant, alignment);
226+
227+
// Build the value to be stored, reconstructing tuples if needed.
228+
auto src = RValue(SGF, args.slice(0, args.size() - 1), formalTy);
229+
233230
std::move(src).ensurePlusOne(SGF, loc).assignInto(SGF, loc, addr);
234231

235232
return ManagedValue::forObjectRValueWithoutOwnership(SGF.emitEmptyTuple(loc));
236233
}
237234

235+
static ManagedValue emitBuiltinAssign(SILGenFunction &SGF, SILLocation loc,
236+
SubstitutionMap substitutions,
237+
ArrayRef<ManagedValue> args,
238+
SGFContext C) {
239+
return emitBuiltinStore(SGF, loc, substitutions, args, C, /*isStrict=*/true,
240+
/*isInvariant=*/false, llvm::MaybeAlign());
241+
}
242+
238243
/// Emit Builtin.initialize by evaluating the operand directly into
239244
/// the address.
240245
static ManagedValue emitBuiltinInit(SILGenFunction &SGF,

0 commit comments

Comments
 (0)