Skip to content

Commit

Permalink
[NFC] Made indexing on AsyncContextLayout private.
Browse files Browse the repository at this point in the history
Previously the methods for getting the index into the layout were public
and were being used to directly access the underlying buffer.  Here,
that abstraction leakage is fixed and field access is forced to go
through the appropriate methods.
  • Loading branch information
nate-chandler committed Oct 6, 2020
1 parent 72051ef commit b90cab6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
56 changes: 27 additions & 29 deletions lib/IRGen/GenCall.h
Expand Up @@ -109,26 +109,42 @@ namespace irgen {
NecessaryBindings bindings;
SmallVector<ArgumentInfo, 4> argumentInfos;

unsigned getErrorIndex() { return (unsigned)FixedIndex::Error; }
unsigned getFirstIndirectReturnIndex() {
return getErrorIndex() + getErrorCount();
}
unsigned getLocalContextIndex() {
assert(hasLocalContext());
return getFirstIndirectReturnIndex() + getIndirectReturnCount();
}
unsigned getIndexAfterLocalContext() {
return getFirstIndirectReturnIndex() + getIndirectReturnCount() +
(hasLocalContext() ? 1 : 0);
}
unsigned getBindingsIndex() {
assert(hasBindings());
return getIndexAfterLocalContext();
}
unsigned getFirstArgumentIndex() {
return getIndexAfterLocalContext() + (hasBindings() ? 1 : 0);
}
unsigned getIndexAfterArguments() {
return getFirstArgumentIndex() + getArgumentCount();
}
unsigned getFirstDirectReturnIndex() { return getIndexAfterArguments(); }

public:
bool canHaveError() { return canHaveValidError; }
unsigned getErrorIndex() { return (unsigned)FixedIndex::Error; }
ElementLayout getErrorLayout() { return getElement(getErrorIndex()); }
unsigned getErrorCount() { return (unsigned)FixedCount::Error; }
SILType getErrorType() { return errorType; }

unsigned getFirstIndirectReturnIndex() {
return getErrorIndex() + getErrorCount();
}
ElementLayout getIndirectReturnLayout(unsigned index) {
return getElement(getFirstIndirectReturnIndex() + index);
}
unsigned getIndirectReturnCount() { return indirectReturnInfos.size(); }

bool hasLocalContext() { return (bool)localContextInfo; }
unsigned getLocalContextIndex() {
assert(hasLocalContext());
return getFirstIndirectReturnIndex() + getIndirectReturnCount();
}
ElementLayout getLocalContextLayout() {
assert(hasLocalContext());
return getElement(getLocalContextIndex());
Expand All @@ -141,48 +157,30 @@ namespace irgen {
assert(hasLocalContext());
return localContextInfo->type;
}
unsigned getIndexAfterLocalContext() {
return getFirstIndirectReturnIndex() + getIndirectReturnCount() +
(hasLocalContext() ? 1 : 0);
}

bool hasBindings() const { return !bindings.empty(); }
unsigned getBindingsIndex() {
assert(hasBindings());
return getIndexAfterLocalContext();
}
ElementLayout getBindingsLayout() {
assert(hasBindings());
return getElement(getBindingsIndex());
}
ParameterConvention getBindingsConvention() {
return ParameterConvention::Direct_Unowned;
}
const NecessaryBindings &getBindings() const { return bindings; }

unsigned getFirstArgumentIndex() {
return getIndexAfterLocalContext() + (hasBindings() ? 1 : 0);
}
ElementLayout getArgumentLayout(unsigned index) {
return getElement(getFirstArgumentIndex() + index);
}
ParameterConvention getArgumentConvention(unsigned index) {
return argumentInfos[index].convention;
}
SILType getArgumentType(unsigned index) {
return argumentInfos[index].type;
}
// Returns the type of a parameter of the substituted function using the
// indexing of the function parameters, *not* the indexing of
// AsyncContextLayout.
SILType getParameterType(unsigned index) {
SILFunctionConventions origConv(substitutedType, IGF.getSILModule());
return origConv.getSILArgumentType(
index, IGF.IGM.getMaximalTypeExpansionContext());
}
unsigned getArgumentCount() { return argumentInfos.size(); }
unsigned getIndexAfterArguments() {
return getFirstArgumentIndex() + getArgumentCount();
}

unsigned getFirstDirectReturnIndex() { return getIndexAfterArguments(); }
unsigned getDirectReturnCount() { return directReturnInfos.size(); }
ElementLayout getDirectReturnLayout(unsigned index) {
return getElement(getFirstDirectReturnIndex() + index);
Expand Down
13 changes: 4 additions & 9 deletions lib/IRGen/IRGenSIL.cpp
Expand Up @@ -1261,9 +1261,7 @@ class AsyncNativeCCEntryPointArgumentEmission final
}
llvm::Value *getIndirectResult(unsigned index) override {
Address dataAddr = layout.emitCastTo(IGF, context);
unsigned baseIndirectReturnIndex = layout.getFirstIndirectReturnIndex();
unsigned elementIndex = baseIndirectReturnIndex + index;
auto &fieldLayout = layout.getElement(elementIndex);
auto fieldLayout = layout.getIndirectReturnLayout(index);
Address fieldAddr =
fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
return IGF.Builder.CreateLoad(fieldAddr);
Expand Down Expand Up @@ -3101,16 +3099,13 @@ static void emitReturnInst(IRGenSILFunction &IGF,
auto layout = getAsyncContextLayout(IGF);

Address dataAddr = layout.emitCastTo(IGF, context);
unsigned index = layout.getFirstDirectReturnIndex();
for (auto r :
IGF.CurSILFn->getLoweredFunctionType()->getDirectFormalResults()) {
(void)r;
auto &fieldLayout = layout.getElement(index);
for (unsigned index = 0, count = layout.getDirectReturnCount();
index < count; ++index) {
auto fieldLayout = layout.getDirectReturnLayout(index);
Address fieldAddr =
fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None);
cast<LoadableTypeInfo>(fieldLayout.getType())
.initialize(IGF, result, fieldAddr, /*isOutlined*/ false);
++index;
}
IGF.Builder.CreateRetVoid();
} else {
Expand Down

0 comments on commit b90cab6

Please sign in to comment.