/src/skia/src/sksl/ir/SkSLExpressionStatement.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2021 Google LLC |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #include "src/sksl/SkSLContext.h" |
9 | | #include "src/sksl/SkSLProgramSettings.h" |
10 | | #include "src/sksl/ir/SkSLExpressionStatement.h" |
11 | | #include "src/sksl/ir/SkSLNop.h" |
12 | | |
13 | | namespace SkSL { |
14 | | |
15 | | std::unique_ptr<Statement> ExpressionStatement::Make(const Context& context, |
16 | 726k | std::unique_ptr<Expression> expr) { |
17 | 726k | if (context.fConfig->fSettings.fOptimize) { |
18 | | // Expression-statements without any side effect can be replaced with a Nop. |
19 | 726k | if (!expr->hasSideEffects()) { |
20 | 218k | return Nop::Make(); |
21 | 218k | } |
22 | 508k | } |
23 | | |
24 | 508k | return std::make_unique<ExpressionStatement>(std::move(expr)); |
25 | 508k | } |
26 | | |
27 | | } // namespace SkSL |