skia2/include/private/SkSLIRNode.h

64 lines
1.4 KiB
C
Raw Normal View History

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_IRNODE
#define SKSL_IRNODE
#include "include/private/SkSLString.h"
#include "include/private/SkTArray.h"
#include "src/sksl/SkSLLexer.h"
#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"
#include <algorithm>
#include <atomic>
#include <unordered_set>
#include <vector>
namespace SkSL {
class Expression;
class FunctionDeclaration;
class FunctionDefinition;
class Statement;
class Symbol;
class SymbolTable;
class Type;
class Variable;
class VariableReference;
enum class VariableRefKind : int8_t;
enum class VariableStorage : int8_t;
/**
* Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved
* version of the program (all types determined, everything validated), ready for code generation.
*/
class IRNode : public Poolable {
public:
virtual ~IRNode() {}
virtual std::string description() const = 0;
// No copy construction or assignment
IRNode(const IRNode&) = delete;
IRNode& operator=(const IRNode&) = delete;
// line of this element within the program being compiled, for error reporting purposes
int fLine;
protected:
IRNode(int line, int kind)
: fLine(line)
, fKind(kind) {}
int fKind;
};
} // namespace SkSL
#endif