Skip to content

Commit

Permalink
Merge pull request #23650 from slavapestov/kill-scalar-prepared-argum…
Browse files Browse the repository at this point in the history
…ents

SILGen: Kill "scalar" PreparedArguments
  • Loading branch information
slavapestov authored Mar 29, 2019
2 parents e7aee37 + 1417647 commit a823e48
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 381 deletions.
3 changes: 2 additions & 1 deletion lib/SILGen/ASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class ASTVisitor : public swift::ASTVisitor<ImplClass,
}

ExprRetTy visitVarargExpansionExpr(VarargExpansionExpr *E, Args... AA) {
llvm_unreachable("vararg expansion should not appear in this position");
return static_cast<ImplClass*>(this)->visit(E->getSubExpr(),
std::forward<Args>(AA)...);
}

ExprRetTy visitIdentityExpr(IdentityExpr *E, Args...AA) {
Expand Down
37 changes: 19 additions & 18 deletions lib/SILGen/ArgumentSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ RValue &ArgumentSource::peekRValue() & {
return Storage.get<RValueStorage>(StoredKind).Value;
}

bool ArgumentSource::isShuffle() const {
switch (StoredKind) {
case Kind::Invalid:
llvm_unreachable("argument source is invalid");
case Kind::RValue:
case Kind::LValue:
return false;
case Kind::Expr:
return isa<ArgumentShuffleExpr>(asKnownExpr());
}
llvm_unreachable("bad kind");
}

RValue ArgumentSource::getAsRValue(SILGenFunction &SGF, SGFContext C) && {
switch (StoredKind) {
case Kind::Invalid:
Expand Down Expand Up @@ -261,17 +248,30 @@ void ArgumentSource::dump(raw_ostream &out, unsigned indent) const {
llvm_unreachable("bad kind");
}

void PreparedArguments::emplaceEmptyArgumentList(SILGenFunction &SGF) {
emplace({}, /*scalar*/ false);
assert(isValid());
PreparedArguments::PreparedArguments(
ArrayRef<AnyFunctionType::Param> params,
Expr *arg) : PreparedArguments(params) {
if (isa<ArgumentShuffleExpr>(arg)) {
IsScalar = true;
addArbitrary(arg);
} else if (auto *PE = dyn_cast<ParenExpr>(arg))
addArbitrary(PE->getSubExpr());
else if (auto *TE = dyn_cast<TupleExpr>(arg)) {
for (auto *elt : TE->getElements())
addArbitrary(elt);
} else {
// FIXME: All ApplyExprs should have a ParenExpr or TupleExpr as their argument
addArbitrary(arg);
}
}

PreparedArguments
PreparedArguments::copy(SILGenFunction &SGF, SILLocation loc) const {
if (isNull()) return PreparedArguments();

assert(isValid());
PreparedArguments result(getParams(), isScalar());
PreparedArguments result(getParams());
result.IsScalar = isScalar();
for (auto &elt : Arguments) {
assert(elt.isRValue());
result.add(elt.getKnownRValueLocation(),
Expand Down Expand Up @@ -319,7 +319,8 @@ PreparedArguments PreparedArguments::copyForDiagnostics() const {
return PreparedArguments();

assert(isValid());
PreparedArguments result(getParams(), isScalar());
PreparedArguments result(getParams());
result.IsScalar = isScalar();
for (auto &arg : Arguments) {
result.Arguments.push_back(arg.copyForDiagnostics());
}
Expand Down
19 changes: 8 additions & 11 deletions lib/SILGen/ArgumentSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ class ArgumentSource {
AbstractionPattern origFormalType,
SILType expectedType = SILType()) &&;

/// Whether this argument source is an ArgumentShuffleExpr.
bool isShuffle() const;

bool isObviouslyEqual(const ArgumentSource &other) const;

ArgumentSource copyForDiagnostics() const;
Expand All @@ -268,11 +265,14 @@ class PreparedArguments {
unsigned IsNull : 1;
public:
PreparedArguments() : IsScalar(false), IsNull(true) {}
PreparedArguments(ArrayRef<AnyFunctionType::Param> params, bool isScalar)
: IsNull(true) {
emplace(params, isScalar);
explicit PreparedArguments(ArrayRef<AnyFunctionType::Param> params)
: IsScalar(false), IsNull(true) {
emplace(params);
}

// Decompse an argument list expression.
PreparedArguments(ArrayRef<AnyFunctionType::Param> params, Expr *arg);

// Move-only.
PreparedArguments(const PreparedArguments &) = delete;
PreparedArguments &operator=(const PreparedArguments &) = delete;
Expand Down Expand Up @@ -320,16 +320,13 @@ class PreparedArguments {
}

/// Emplace a (probably incomplete) argument list.
void emplace(ArrayRef<AnyFunctionType::Param> params, bool isScalar) {
void emplace(ArrayRef<AnyFunctionType::Param> params) {
assert(isNull());
Params.append(params.begin(), params.end());
IsScalar = isScalar;
IsScalar = false;
IsNull = false;
}

/// Emplace an empty argument list.
void emplaceEmptyArgumentList(SILGenFunction &SGF);

/// Add an emitted r-value argument to this argument list.
void add(SILLocation loc, RValue &&arg) {
assert(!isNull());
Expand Down
Loading

0 comments on commit a823e48

Please sign in to comment.