2016-07-01 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2017-03-31 17:56:23 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
#ifndef SKSL_IRNODE
|
|
|
|
#define SKSL_IRNODE
|
|
|
|
|
2021-03-04 19:30:25 +00:00
|
|
|
#include "include/private/SkSLString.h"
|
2020-10-13 15:14:08 +00:00
|
|
|
#include "include/private/SkTArray.h"
|
2020-09-22 19:05:37 +00:00
|
|
|
#include "src/sksl/SkSLASTNode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/sksl/SkSLLexer.h"
|
2020-10-07 20:42:04 +00:00
|
|
|
#include "src/sksl/SkSLModifiersPool.h"
|
Reland "Create a basic IRNode pooling system."
This is a reland of e16eca95f5c08c2bdf72cc0b04af62a1071afd8d
This fixes the no-op (iOS) implementation of CreatePoolOnThread.
Original change's description:
> Create a basic IRNode pooling system.
>
> Allocations are redirected by overriding `operator new` and `operator
> delete` on the IRNode class. This allows us to use our existing
> `unique_ptr` and `make_unique` calls as-is. The Pool class is simple;
> it holds a fixed number of nodes and recycles them as they are returned.
>
> A fixed pool size of 2000 nodes was chosen. That is large enough to hold
> the contents of `sksl_large` during compilation, but it can be
> overflowed by very large shaders, or if multiple programs are converted
> at the same time. Exhausting the pool is not a problem; if this happens,
> additional nodes will be allocated via the system allocator as usual.
> More elaborate schemes are possible but might not add a lot of value.
>
> Thread safety is accomplished by placing the pool in a `thread_local`
> static during a Program's creation and destruction; the pool is freed
> when the program is destroyed. One important consequence of this
> strategy is that a program must free every node that it allocated during
> its creation, or else the node will be leaked. In debug, leaking a node
> will be detected and causes a DEBUGFAIL. In release, the pool will be
> freed despite having a live node in it, and if that node is later freed,
> that pointer will be passed to the system `free` (which is likely to
> cause a crash).
>
> In this CL, iOS does not support pooling, since support for
> `thread_local` was only added on iOS 9. This is fixed in the followup
> CL, http://review.skia.org/328837, which uses pthread keys on iOS.
>
> Nanobench shows ~15% improvement:
> (last week) http://screen/5CNBhTaZApcDA8h
> (today) http://screen/8ti5Rymvf6LUs8i
>
> Change-Id: I559de73606ee1be54e5eae7f82129dc928a63e3c
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/326876
> Commit-Queue: John Stiles <johnstiles@google.com>
> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
Change-Id: I8623a574a7e92332ff00b83982497863c8953929
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/329171
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-10-22 15:09:15 +00:00
|
|
|
#include "src/sksl/SkSLPool.h"
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2020-09-25 18:31:59 +00:00
|
|
|
#include <algorithm>
|
2020-10-08 18:52:24 +00:00
|
|
|
#include <atomic>
|
2020-10-14 17:33:18 +00:00
|
|
|
#include <unordered_set>
|
2020-09-22 19:05:37 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
namespace SkSL {
|
|
|
|
|
2020-10-08 09:28:32 +00:00
|
|
|
class Expression;
|
2020-10-08 15:45:44 +00:00
|
|
|
class FunctionDeclaration;
|
2020-10-26 19:06:46 +00:00
|
|
|
class FunctionDefinition;
|
2020-10-08 09:28:32 +00:00
|
|
|
class Statement;
|
2020-10-06 20:14:37 +00:00
|
|
|
class Symbol;
|
2020-09-25 18:31:59 +00:00
|
|
|
class SymbolTable;
|
2020-09-11 16:27:26 +00:00
|
|
|
class Type;
|
2020-10-07 20:42:04 +00:00
|
|
|
class Variable;
|
2020-10-08 10:46:27 +00:00
|
|
|
class VariableReference;
|
2020-10-09 14:43:45 +00:00
|
|
|
enum class VariableRefKind : int8_t;
|
|
|
|
enum class VariableStorage : int8_t;
|
2020-09-11 16:27:26 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
/**
|
2017-03-31 17:56:23 +00:00
|
|
|
* Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved
|
2016-07-01 15:22:01 +00:00
|
|
|
* version of the program (all types determined, everything validated), ready for code generation.
|
|
|
|
*/
|
2021-02-02 00:08:45 +00:00
|
|
|
class IRNode : public Poolable {
|
2020-09-11 16:27:26 +00:00
|
|
|
public:
|
2020-10-30 14:29:12 +00:00
|
|
|
virtual ~IRNode() {}
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2017-03-31 17:56:23 +00:00
|
|
|
virtual String description() const = 0;
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2020-10-30 14:29:12 +00:00
|
|
|
// No copy construction or assignment
|
|
|
|
IRNode(const IRNode&) = delete;
|
|
|
|
IRNode& operator=(const IRNode&) = delete;
|
|
|
|
|
2017-09-11 20:50:14 +00:00
|
|
|
// character offset of this element within the program being compiled, for error reporting
|
|
|
|
// purposes
|
2017-09-18 18:10:39 +00:00
|
|
|
int fOffset;
|
2020-09-08 14:22:09 +00:00
|
|
|
|
|
|
|
protected:
|
2020-10-30 14:29:12 +00:00
|
|
|
IRNode(int offset, int kind)
|
|
|
|
: fOffset(offset)
|
|
|
|
, fKind(kind) {}
|
2020-10-08 10:46:27 +00:00
|
|
|
|
2020-09-08 14:22:09 +00:00
|
|
|
int fKind;
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace SkSL
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
#endif
|