Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bf66ffb

Browse files
Ethan NicholasSkia Commit-Bot
Ethan Nicholas
authored and
Skia Commit-Bot
committed
Reland "Revert "moved BinaryExpression's data into IRNode""
This reverts commit 1d3e0e0. Reason for revert: possibly causing https://task-scheduler.skia.org/task/F1DoniJAddPuEkH9ETTE Original change's description: > Revert "Revert "moved BinaryExpression's data into IRNode"" > > This reverts commit b61c3a9. > > Change-Id: I4689e1f4977fab3233ff492cee06fbc301b5c689 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317386 > Reviewed-by: John Stiles <[email protected]> > Commit-Queue: Ethan Nicholas <[email protected]> [email protected],[email protected],[email protected] # Not skipping CQ checks because this is a reland. Change-Id: Id0f3f211f09fbf31b626c648ed141fc6154a450c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317395 Reviewed-by: Ethan Nicholas <[email protected]> Commit-Queue: Ethan Nicholas <[email protected]>
1 parent 72664be commit bf66ffb

16 files changed

+208
-372
lines changed

gn/sksl.gni

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ skia_sksl_sources = [
6868
"$_src/sksl/ir/SkSLFunctionCall.h",
6969
"$_src/sksl/ir/SkSLFunctionDefinition.h",
7070
"$_src/sksl/ir/SkSLFunctionReference.h",
71-
"$_src/sksl/ir/SkSLIRNode.cpp",
7271
"$_src/sksl/ir/SkSLIRNode.h",
7372
"$_src/sksl/ir/SkSLIfStatement.h",
7473
"$_src/sksl/ir/SkSLIndexExpression.h",

src/sksl/SkSLASTNode.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
#include "src/sksl/SkSLString.h"
1313
#include "src/sksl/ir/SkSLModifiers.h"
1414

15-
#include <algorithm>
1615
#include <vector>
1716

1817
namespace SkSL {
1918

19+
// std::max isn't constexpr in some compilers
20+
static constexpr size_t Max(size_t a, size_t b) {
21+
return a > b ? a : b;
22+
}
23+
2024
/**
2125
* Represents a node in the abstract syntax tree (AST). The AST is based directly on the parse tree;
2226
* it is a parsed-but-not-yet-analyzed version of the program.
@@ -263,18 +267,18 @@ struct ASTNode {
263267
};
264268

265269
struct NodeData {
266-
char fBytes[std::max(sizeof(Token),
267-
std::max(sizeof(StringFragment),
268-
std::max(sizeof(bool),
269-
std::max(sizeof(SKSL_INT),
270-
std::max(sizeof(SKSL_FLOAT),
271-
std::max(sizeof(Modifiers),
272-
std::max(sizeof(TypeData),
273-
std::max(sizeof(FunctionData),
274-
std::max(sizeof(ParameterData),
275-
std::max(sizeof(VarData),
276-
std::max(sizeof(InterfaceBlockData),
277-
sizeof(SectionData))))))))))))];
270+
char fBytes[Max(sizeof(Token),
271+
Max(sizeof(StringFragment),
272+
Max(sizeof(bool),
273+
Max(sizeof(SKSL_INT),
274+
Max(sizeof(SKSL_FLOAT),
275+
Max(sizeof(Modifiers),
276+
Max(sizeof(TypeData),
277+
Max(sizeof(FunctionData),
278+
Max(sizeof(ParameterData),
279+
Max(sizeof(VarData),
280+
Max(sizeof(InterfaceBlockData),
281+
sizeof(SectionData))))))))))))];
278282

279283
enum class Kind {
280284
kToken,

src/sksl/SkSLAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ bool ProgramVisitor::visitExpression(const Expression& e) {
266266
return false;
267267
case Expression::Kind::kBinary: {
268268
const BinaryExpression& b = e.as<BinaryExpression>();
269-
return this->visitExpression(b.left()) || this->visitExpression(b.right()); }
269+
return this->visitExpression(*b.fLeft) || this->visitExpression(*b.fRight); }
270270
case Expression::Kind::kConstructor: {
271271
const Constructor& c = e.as<Constructor>();
272272
for (const auto& arg : c.fArguments) {

src/sksl/SkSLByteCodeGenerator.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -681,29 +681,28 @@ void ByteCodeGenerator::writeTypedInstruction(const Type& type,
681681
}
682682

683683
bool ByteCodeGenerator::writeBinaryExpression(const BinaryExpression& b, bool discard) {
684-
const Expression& left = b.left();
685-
const Expression& right = b.right();
686-
Token::Kind op = b.getOperator();
687-
if (op == Token::Kind::TK_EQ) {
688-
std::unique_ptr<LValue> lvalue = this->getLValue(left);
689-
this->writeExpression(right);
684+
if (b.fOperator == Token::Kind::TK_EQ) {
685+
std::unique_ptr<LValue> lvalue = this->getLValue(*b.fLeft);
686+
this->writeExpression(*b.fRight);
690687
lvalue->store(discard);
691688
discard = false;
692689
return discard;
693690
}
694-
const Type& lType = left.type();
695-
const Type& rType = right.type();
691+
const Type& lType = b.fLeft->type();
692+
const Type& rType = b.fRight->type();
696693
bool lVecOrMtx = (lType.typeKind() == Type::TypeKind::kVector ||
697694
lType.typeKind() == Type::TypeKind::kMatrix);
698695
bool rVecOrMtx = (rType.typeKind() == Type::TypeKind::kVector ||
699696
rType.typeKind() == Type::TypeKind::kMatrix);
697+
Token::Kind op;
700698
std::unique_ptr<LValue> lvalue;
701-
if (Compiler::IsAssignment(op)) {
702-
lvalue = this->getLValue(left);
699+
if (Compiler::IsAssignment(b.fOperator)) {
700+
lvalue = this->getLValue(*b.fLeft);
703701
lvalue->load();
704-
op = Compiler::RemoveAssignment(op);
702+
op = Compiler::RemoveAssignment(b.fOperator);
705703
} else {
706-
this->writeExpression(left);
704+
this->writeExpression(*b.fLeft);
705+
op = b.fOperator;
707706
if (!lVecOrMtx && rVecOrMtx) {
708707
for (int i = SlotCount(rType); i > 1; --i) {
709708
this->write(ByteCodeInstruction::kDup, 1);
@@ -719,7 +718,7 @@ bool ByteCodeGenerator::writeBinaryExpression(const BinaryExpression& b, bool di
719718
this->write(ByteCodeInstruction::kMaskPush);
720719
this->write(ByteCodeInstruction::kBranchIfAllFalse);
721720
DeferredLocation falseLocation(this);
722-
this->writeExpression(right);
721+
this->writeExpression(*b.fRight);
723722
this->write(ByteCodeInstruction::kAndB, 1);
724723
falseLocation.set();
725724
this->write(ByteCodeInstruction::kMaskPop);
@@ -732,7 +731,7 @@ bool ByteCodeGenerator::writeBinaryExpression(const BinaryExpression& b, bool di
732731
this->write(ByteCodeInstruction::kMaskPush);
733732
this->write(ByteCodeInstruction::kBranchIfAllFalse);
734733
DeferredLocation falseLocation(this);
735-
this->writeExpression(right);
734+
this->writeExpression(*b.fRight);
736735
this->write(ByteCodeInstruction::kOrB, 1);
737736
falseLocation.set();
738737
this->write(ByteCodeInstruction::kMaskPop);
@@ -742,13 +741,13 @@ bool ByteCodeGenerator::writeBinaryExpression(const BinaryExpression& b, bool di
742741
case Token::Kind::TK_SHR: {
743742
SkASSERT(count == 1 && (tc == SkSL::TypeCategory::kSigned ||
744743
tc == SkSL::TypeCategory::kUnsigned));
745-
if (!right.isCompileTimeConstant()) {
746-
fErrors.error(right.fOffset, "Shift amounts must be constant");
744+
if (!b.fRight->isCompileTimeConstant()) {
745+
fErrors.error(b.fRight->fOffset, "Shift amounts must be constant");
747746
return false;
748747
}
749-
int64_t shift = right.getConstantInt();
748+
int64_t shift = b.fRight->getConstantInt();
750749
if (shift < 0 || shift > 31) {
751-
fErrors.error(right.fOffset, "Shift amount out of range");
750+
fErrors.error(b.fRight->fOffset, "Shift amount out of range");
752751
return false;
753752
}
754753

@@ -766,7 +765,7 @@ bool ByteCodeGenerator::writeBinaryExpression(const BinaryExpression& b, bool di
766765
default:
767766
break;
768767
}
769-
this->writeExpression(right);
768+
this->writeExpression(*b.fRight);
770769
if (lVecOrMtx && !rVecOrMtx) {
771770
for (int i = SlotCount(lType); i > 1; --i) {
772771
this->write(ByteCodeInstruction::kDup, 1);

src/sksl/SkSLCFGGenerator.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ bool BasicBlock::tryRemoveExpression(std::vector<BasicBlock::Node>::iterator* it
166166
switch (expr->kind()) {
167167
case Expression::Kind::kBinary: {
168168
BinaryExpression& b = expr->as<BinaryExpression>();
169-
if (b.getOperator() == Token::Kind::TK_EQ) {
170-
if (!this->tryRemoveLValueBefore(iter, &b.left())) {
169+
if (b.fOperator == Token::Kind::TK_EQ) {
170+
if (!this->tryRemoveLValueBefore(iter, b.fLeft.get())) {
171171
return false;
172172
}
173-
} else if (!this->tryRemoveExpressionBefore(iter, &b.left())) {
173+
} else if (!this->tryRemoveExpressionBefore(iter, b.fLeft.get())) {
174174
return false;
175175
}
176-
if (!this->tryRemoveExpressionBefore(iter, &b.right())) {
176+
if (!this->tryRemoveExpressionBefore(iter, b.fRight.get())) {
177177
return false;
178178
}
179179
SkASSERT((*iter)->expression()->get() == expr);
@@ -267,12 +267,11 @@ bool BasicBlock::tryInsertExpression(std::vector<BasicBlock::Node>::iterator* it
267267
switch ((*expr)->kind()) {
268268
case Expression::Kind::kBinary: {
269269
BinaryExpression& b = expr->get()->as<BinaryExpression>();
270-
if (!this->tryInsertExpression(iter, &b.rightPointer())) {
270+
if (!this->tryInsertExpression(iter, &b.fRight)) {
271271
return false;
272272
}
273-
274273
++(*iter);
275-
if (!this->tryInsertExpression(iter, &b.leftPointer())) {
274+
if (!this->tryInsertExpression(iter, &b.fLeft)) {
276275
return false;
277276
}
278277
++(*iter);
@@ -320,17 +319,16 @@ void CFGGenerator::addExpression(CFG& cfg, std::unique_ptr<Expression>* e, bool
320319
switch ((*e)->kind()) {
321320
case Expression::Kind::kBinary: {
322321
BinaryExpression& b = e->get()->as<BinaryExpression>();
323-
Token::Kind op = b.getOperator();
324-
switch (op) {
322+
switch (b.fOperator) {
325323
case Token::Kind::TK_LOGICALAND: // fall through
326324
case Token::Kind::TK_LOGICALOR: {
327325
// this isn't as precise as it could be -- we don't bother to track that if we
328326
// early exit from a logical and/or, we know which branch of an 'if' we're going
329327
// to hit -- but it won't make much difference in practice.
330-
this->addExpression(cfg, &b.leftPointer(), constantPropagate);
328+
this->addExpression(cfg, &b.fLeft, constantPropagate);
331329
BlockId start = cfg.fCurrent;
332330
cfg.newBlock();
333-
this->addExpression(cfg, &b.rightPointer(), constantPropagate);
331+
this->addExpression(cfg, &b.fRight, constantPropagate);
334332
cfg.newBlock();
335333
cfg.addExit(start, cfg.fCurrent);
336334
cfg.fBlocks[cfg.fCurrent].fNodes.push_back({
@@ -342,8 +340,8 @@ void CFGGenerator::addExpression(CFG& cfg, std::unique_ptr<Expression>* e, bool
342340
break;
343341
}
344342
case Token::Kind::TK_EQ: {
345-
this->addExpression(cfg, &b.rightPointer(), constantPropagate);
346-
this->addLValue(cfg, &b.leftPointer());
343+
this->addExpression(cfg, &b.fRight, constantPropagate);
344+
this->addLValue(cfg, &b.fLeft);
347345
cfg.fBlocks[cfg.fCurrent].fNodes.push_back({
348346
BasicBlock::Node::kExpression_Kind,
349347
constantPropagate,
@@ -353,8 +351,8 @@ void CFGGenerator::addExpression(CFG& cfg, std::unique_ptr<Expression>* e, bool
353351
break;
354352
}
355353
default:
356-
this->addExpression(cfg, &b.leftPointer(), !Compiler::IsAssignment(op));
357-
this->addExpression(cfg, &b.rightPointer(), constantPropagate);
354+
this->addExpression(cfg, &b.fLeft, !Compiler::IsAssignment(b.fOperator));
355+
this->addExpression(cfg, &b.fRight, constantPropagate);
358356
cfg.fBlocks[cfg.fCurrent].fNodes.push_back({
359357
BasicBlock::Node::kExpression_Kind,
360358
constantPropagate,

src/sksl/SkSLCPPCodeGenerator.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,45 +70,42 @@ String CPPCodeGenerator::getTypeName(const Type& type) {
7070

7171
void CPPCodeGenerator::writeBinaryExpression(const BinaryExpression& b,
7272
Precedence parentPrecedence) {
73-
const Expression& left = b.left();
74-
const Expression& right = b.right();
75-
Token::Kind op = b.getOperator();
76-
if (op == Token::Kind::TK_PERCENT) {
73+
if (b.fOperator == Token::Kind::TK_PERCENT) {
7774
// need to use "%%" instead of "%" b/c the code will be inside of a printf
78-
Precedence precedence = GetBinaryPrecedence(op);
75+
Precedence precedence = GetBinaryPrecedence(b.fOperator);
7976
if (precedence >= parentPrecedence) {
8077
this->write("(");
8178
}
82-
this->writeExpression(left, precedence);
79+
this->writeExpression(*b.fLeft, precedence);
8380
this->write(" %% ");
84-
this->writeExpression(right, precedence);
81+
this->writeExpression(*b.fRight, precedence);
8582
if (precedence >= parentPrecedence) {
8683
this->write(")");
8784
}
88-
} else if (left.kind() == Expression::Kind::kNullLiteral ||
89-
right.kind() == Expression::Kind::kNullLiteral) {
85+
} else if (b.fLeft->kind() == Expression::Kind::kNullLiteral ||
86+
b.fRight->kind() == Expression::Kind::kNullLiteral) {
9087
const Variable* var;
91-
if (left.kind() != Expression::Kind::kNullLiteral) {
92-
var = &left.as<VariableReference>().fVariable;
88+
if (b.fLeft->kind() != Expression::Kind::kNullLiteral) {
89+
var = &b.fLeft->as<VariableReference>().fVariable;
9390
} else {
94-
var = &right.as<VariableReference>().fVariable;
91+
var = &b.fRight->as<VariableReference>().fVariable;
9592
}
9693
SkASSERT(var->type().typeKind() == Type::TypeKind::kNullable &&
9794
var->type().componentType() == *fContext.fFragmentProcessor_Type);
9895
this->write("%s");
99-
const char* prefix = "";
100-
switch (op) {
96+
const char* op = "";
97+
switch (b.fOperator) {
10198
case Token::Kind::TK_EQEQ:
102-
prefix = "!";
99+
op = "!";
103100
break;
104101
case Token::Kind::TK_NEQ:
105-
prefix = "";
102+
op = "";
106103
break;
107104
default:
108105
SkASSERT(false);
109106
}
110107
int childIndex = this->getChildFPIndex(*var);
111-
fFormatArgs.push_back(String(prefix) + "_outer.childProcessor(" + to_string(childIndex) +
108+
fFormatArgs.push_back(String(op) + "_outer.childProcessor(" + to_string(childIndex) +
112109
") ? \"true\" : \"false\"");
113110
} else {
114111
INHERITED::writeBinaryExpression(b, parentPrecedence);

0 commit comments

Comments
 (0)