Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[NFC] Deduped async call emission code.
Previously the same code was used for saving values into the async
context.  Here, that code is extracted into a private method.
  • Loading branch information
nate-chandler committed Oct 7, 2020
1 parent 0a5df67 commit 6e0d894
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/IRGen/GenCall.cpp
Expand Up @@ -1952,6 +1952,12 @@ class AsyncCallEmission final : public CallEmission {
getCallee().getSubstitutions());
}

void saveValue(ElementLayout layout, Explosion &explosion, bool isOutlined) {
Address addr = layout.project(IGF, context, /*offsets*/ llvm::None);
auto &ti = cast<LoadableTypeInfo>(layout.getType());
ti.initialize(IGF, explosion, addr, isOutlined);
}

public:
AsyncCallEmission(IRGenFunction &IGF, llvm::Value *selfValue, Callee &&callee)
: CallEmission(IGF, selfValue, std::move(callee)) {
Expand Down Expand Up @@ -2000,18 +2006,12 @@ class AsyncCallEmission final : public CallEmission {
for (unsigned index = 0, count = layout.getIndirectReturnCount();
index < count; ++index) {
auto fieldLayout = layout.getIndirectReturnLayout(index);
Address fieldAddr =
fieldLayout.project(IGF, context, /*offsets*/ llvm::None);
cast<LoadableTypeInfo>(fieldLayout.getType())
.initialize(IGF, llArgs, fieldAddr, isOutlined);
saveValue(fieldLayout, llArgs, isOutlined);
}
for (unsigned index = 0, count = layout.getArgumentCount(); index < count;
++index) {
auto fieldLayout = layout.getArgumentLayout(index);
Address fieldAddr =
fieldLayout.project(IGF, context, /*offsets*/ llvm::None);
auto &ti = cast<LoadableTypeInfo>(fieldLayout.getType());
ti.initialize(IGF, llArgs, fieldAddr, isOutlined);
saveValue(fieldLayout, llArgs, isOutlined);
}
if (layout.hasBindings()) {
auto bindingLayout = layout.getBindingsLayout();
Expand All @@ -2020,10 +2020,7 @@ class AsyncCallEmission final : public CallEmission {
}
if (selfValue) {
auto fieldLayout = layout.getLocalContextLayout();
Address fieldAddr =
fieldLayout.project(IGF, context, /*offsets*/ llvm::None);
auto &ti = cast<LoadableTypeInfo>(fieldLayout.getType());
ti.initialize(IGF, llArgs, fieldAddr, isOutlined);
saveValue(fieldLayout, llArgs, isOutlined);
}
}
void emitCallToUnmappedExplosion(llvm::CallInst *call, Explosion &out) override {
Expand Down

0 comments on commit 6e0d894

Please sign in to comment.