Skip to content

Commit 0a5df67

Browse files
committed
[NFC] Deduped async entry point emission code.
Previously the same code was used for loading values from the async context. Here, that same code is extracted into a private method.
1 parent 7d74a86 commit 0a5df67

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,14 @@ class AsyncNativeCCEntryPointArgumentEmission final
12071207
/*const*/ AsyncContextLayout layout;
12081208
const Address dataAddr;
12091209

1210+
llvm::Value *loadValue(ElementLayout layout) {
1211+
Address addr = layout.project(IGF, dataAddr, /*offsets*/ llvm::None);
1212+
auto &ti = cast<LoadableTypeInfo>(layout.getType());
1213+
Explosion explosion;
1214+
ti.loadAsTake(IGF, addr, explosion);
1215+
return explosion.claimNext();
1216+
}
1217+
12101218
public:
12111219
AsyncNativeCCEntryPointArgumentEmission(IRGenSILFunction &IGF,
12121220
SILBasicBlock &entry,
@@ -1222,22 +1230,15 @@ class AsyncNativeCCEntryPointArgumentEmission final
12221230
}
12231231
llvm::Value *getContext() override {
12241232
auto contextLayout = layout.getLocalContextLayout();
1225-
Address addr = contextLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
1226-
auto &ti = cast<LoadableTypeInfo>(contextLayout.getType());
1227-
Explosion explosion;
1228-
ti.loadAsTake(IGF, addr, explosion);
1229-
return explosion.claimNext();
1233+
return loadValue(contextLayout);
12301234
}
12311235
Explosion getArgumentExplosion(unsigned index, unsigned size) override {
12321236
assert(size > 0);
12331237
Explosion result;
12341238
for (unsigned i = index, end = index + size; i < end; ++i) {
12351239
auto argumentLayout = layout.getArgumentLayout(i);
1236-
auto addr = argumentLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
1237-
auto &ti = cast<LoadableTypeInfo>(argumentLayout.getType());
1238-
Explosion explosion;
1239-
ti.loadAsTake(IGF, addr, explosion);
1240-
result.add(explosion.claimAll());
1240+
auto *value = loadValue(argumentLayout);
1241+
result.add(value);
12411242
}
12421243
return result;
12431244
}
@@ -1249,30 +1250,15 @@ class AsyncNativeCCEntryPointArgumentEmission final
12491250
}
12501251
llvm::Value *getIndirectResult(unsigned index) override {
12511252
auto fieldLayout = layout.getIndirectReturnLayout(index);
1252-
Address fieldAddr =
1253-
fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
1254-
auto &ti = cast<LoadableTypeInfo>(fieldLayout.getType());
1255-
Explosion explosion;
1256-
ti.loadAsTake(IGF, fieldAddr, explosion);
1257-
return explosion.claimNext();
1253+
return loadValue(fieldLayout);
12581254
};
12591255
llvm::Value *getSelfWitnessTable() override {
12601256
auto fieldLayout = layout.getSelfWitnessTableLayout();
1261-
Address fieldAddr =
1262-
fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
1263-
auto &ti = cast<LoadableTypeInfo>(fieldLayout.getType());
1264-
Explosion explosion;
1265-
ti.loadAsTake(IGF, fieldAddr, explosion);
1266-
return explosion.claimNext();
1257+
return loadValue(fieldLayout);
12671258
}
12681259
llvm::Value *getSelfMetadata() override {
12691260
auto fieldLayout = layout.getSelfMetadataLayout();
1270-
Address fieldAddr =
1271-
fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
1272-
auto &ti = cast<LoadableTypeInfo>(fieldLayout.getType());
1273-
Explosion explosion;
1274-
ti.loadAsTake(IGF, fieldAddr, explosion);
1275-
return explosion.claimNext();
1261+
return loadValue(fieldLayout);
12761262
}
12771263
llvm::Value *getCoroutineBuffer() override {
12781264
llvm_unreachable("unimplemented");

0 commit comments

Comments
 (0)