Update the IRGenerator's referenced intrinsics to use unordered_set.

There's no ordering between elements that we need to maintain, so
there's no reason to use a collection that maintains an ordering.

Change-Id: I9ab5626dd048dd79cfcec2ec7a21b0685f46662a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309484
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2020-08-11 18:05:39 -04:00 committed by Skia Commit-Bot
parent 079455c739
commit b8e010c856
5 changed files with 25 additions and 23 deletions

View File

@ -8,6 +8,7 @@
#include "src/sksl/SkSLCompiler.h"
#include <memory>
#include <unordered_set>
#include "src/sksl/SkSLByteCodeGenerator.h"
#include "src/sksl/SkSLCFGGenerator.h"

View File

@ -826,8 +826,10 @@ private:
T* fContainer;
};
template <typename T> AutoClear(T* c) -> AutoClear<T>;
void IRGenerator::convertFunction(const ASTNode& f) {
AutoClear<std::set<const FunctionDeclaration*>> clear(&fReferencedIntrinsics);
AutoClear clear(&fReferencedIntrinsics);
auto iter = f.begin();
const Type* returnType = this->convertType(*(iter++));
if (!returnType) {
@ -1030,11 +1032,8 @@ void IRGenerator::convertFunction(const ASTNode& f) {
if (Program::kVertex_Kind == fKind && fd.fName == "main" && fRTAdjust) {
body->fStatements.insert(body->fStatements.end(), this->getNormalizeSkPositionCode());
}
std::unique_ptr<FunctionDefinition> result(new FunctionDefinition(
f.fOffset,
*decl,
std::move(body),
std::move(fReferencedIntrinsics)));
auto result = std::make_unique<FunctionDefinition>(f.fOffset, *decl, std::move(body),
std::move(fReferencedIntrinsics));
decl->fDefinition = result.get();
result->fSource = &f;
fProgramElements->push_back(std::move(result));

View File

@ -10,6 +10,7 @@
#include <map>
#include <unordered_map>
#include <unordered_set>
#include "src/sksl/SkSLASTFile.h"
#include "src/sksl/SkSLASTNode.h"
@ -179,7 +180,7 @@ private:
// Symbols which have definitions in the include files. The bool tells us whether this
// intrinsic has been included already.
std::map<String, std::pair<std::unique_ptr<ProgramElement>, bool>>* fIntrinsics = nullptr;
std::set<const FunctionDeclaration*> fReferencedIntrinsics;
std::unordered_set<const FunctionDeclaration*> fReferencedIntrinsics;
int fLoopLevel;
int fSwitchLevel;
ErrorReporter& fErrors;

View File

@ -8,6 +8,8 @@
#include "src/sksl/SkSLRehydrator.h"
#include <memory>
#include <unordered_set>
#include "src/sksl/ir/SkSLBinaryExpression.h"
#include "src/sksl/ir/SkSLBreakStatement.h"
#include "src/sksl/ir/SkSLContinueStatement.h"
@ -278,7 +280,7 @@ std::unique_ptr<ProgramElement> Rehydrator::element() {
const FunctionDeclaration* decl = this->symbolRef<FunctionDeclaration>(
Symbol::kFunctionDeclaration_Kind);
std::unique_ptr<Statement> body = this->statement();
std::set<const FunctionDeclaration*> refs;
std::unordered_set<const FunctionDeclaration*> refs;
uint8_t refCount = this->readU8();
for (int i = 0; i < refCount; ++i) {
refs.insert(this->symbolRef<FunctionDeclaration>(

View File

@ -12,7 +12,7 @@
#include "src/sksl/ir/SkSLFunctionDeclaration.h"
#include "src/sksl/ir/SkSLProgramElement.h"
#include <set>
#include <unordered_set>
namespace SkSL {
@ -22,24 +22,23 @@ struct ASTNode;
* A function definition (a declaration plus an associated block of code).
*/
struct FunctionDefinition : public ProgramElement {
FunctionDefinition(int offset, const FunctionDeclaration& declaration,
FunctionDefinition(int offset,
const FunctionDeclaration& declaration,
std::unique_ptr<Statement> body,
std::set<const FunctionDeclaration*> referencedIntrinsics =
std::set<const FunctionDeclaration*>())
: INHERITED(offset, kFunction_Kind)
, fDeclaration(declaration)
, fBody(std::move(body))
, fReferencedIntrinsics(referencedIntrinsics) {}
std::unordered_set<const FunctionDeclaration*> referencedIntrinsics = {})
: INHERITED(offset, kFunction_Kind)
, fDeclaration(declaration)
, fBody(std::move(body))
, fReferencedIntrinsics(std::move(referencedIntrinsics)) {}
bool canBeInlined() const {
static const int INLINE_THRESHOLD = 50; // chosen arbitrarily, feel free to adjust
static constexpr int INLINE_THRESHOLD = 50; // chosen arbitrarily, feel free to adjust
return fBody->nodeCount() < INLINE_THRESHOLD;
}
std::unique_ptr<ProgramElement> clone() const override {
return std::unique_ptr<ProgramElement>(new FunctionDefinition(fOffset, fDeclaration,
fBody->clone(),
fReferencedIntrinsics));
return std::make_unique<FunctionDefinition>(fOffset, fDeclaration,
fBody->clone(), fReferencedIntrinsics);
}
String description() const override {
@ -48,9 +47,9 @@ struct FunctionDefinition : public ProgramElement {
const FunctionDeclaration& fDeclaration;
std::unique_ptr<Statement> fBody;
// we track intrinsic functions we reference so that we can ensure that all of them end up
// copied into the final output
std::set<const FunctionDeclaration*> fReferencedIntrinsics;
// We track intrinsic functions we reference so that we can ensure that all of them end up
// copied into the final output.
std::unordered_set<const FunctionDeclaration*> fReferencedIntrinsics;
// This pointer may be null, and even when non-null is not guaranteed to remain valid for the
// entire lifespan of this object. The parse tree's lifespan is normally controlled by
// IRGenerator, so the IRGenerator being destroyed or being used to compile another file will