From 8e0c80f26914552e11144bd92dae726b66c3739d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Oct 2019 08:06:44 -0400 Subject: video_core/ast: Supply const accessors for data where applicable Provides const equivalents of data accessors for use within const contexts. --- src/video_core/shader/ast.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/video_core/shader/ast.h') diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index ba234138e..39f500284 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h @@ -48,11 +48,11 @@ public: void Init(ASTNode first, ASTNode parent); - ASTNode GetFirst() { + ASTNode GetFirst() const { return first; } - ASTNode GetLast() { + ASTNode GetLast() const { return last; } @@ -177,6 +177,10 @@ public: return &data; } + const ASTData* GetInnerData() const { + return &data; + } + ASTNode GetNext() const { return next; } @@ -189,6 +193,10 @@ public: return *manager; } + const ASTZipper& GetManager() const { + return *manager; + } + std::optional GetGotoLabel() const { auto inner = std::get_if(&data); if (inner) { -- cgit v1.2.3 From 8eb1398f8d90fb2813f438b9fffac716b6ec51d2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Oct 2019 08:17:32 -0400 Subject: video_core/{ast, expr}: Use std::move where applicable Avoids unnecessary atomic reference count increments and decrements. --- src/video_core/shader/ast.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/video_core/shader/ast.h') diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index 39f500284..aad35c12e 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h @@ -71,20 +71,18 @@ public: class ASTProgram { public: - explicit ASTProgram() = default; ASTZipper nodes{}; }; class ASTIfThen { public: - explicit ASTIfThen(Expr condition) : condition(condition) {} + explicit ASTIfThen(Expr condition) : condition{std::move(condition)} {} Expr condition; ASTZipper nodes{}; }; class ASTIfElse { public: - explicit ASTIfElse() = default; ASTZipper nodes{}; }; @@ -103,7 +101,7 @@ public: class ASTVarSet { public: - explicit ASTVarSet(u32 index, Expr condition) : index{index}, condition{condition} {} + explicit ASTVarSet(u32 index, Expr condition) : index{index}, condition{std::move(condition)} {} u32 index; Expr condition; }; @@ -117,42 +115,45 @@ public: class ASTGoto { public: - explicit ASTGoto(Expr condition, u32 label) : condition{condition}, label{label} {} + explicit ASTGoto(Expr condition, u32 label) : condition{std::move(condition)}, label{label} {} Expr condition; u32 label; }; class ASTDoWhile { public: - explicit ASTDoWhile(Expr condition) : condition(condition) {} + explicit ASTDoWhile(Expr condition) : condition{std::move(condition)} {} Expr condition; ASTZipper nodes{}; }; class ASTReturn { public: - explicit ASTReturn(Expr condition, bool kills) : condition{condition}, kills{kills} {} + explicit ASTReturn(Expr condition, bool kills) + : condition{std::move(condition)}, kills{kills} {} Expr condition; bool kills; }; class ASTBreak { public: - explicit ASTBreak(Expr condition) : condition{condition} {} + explicit ASTBreak(Expr condition) : condition{std::move(condition)} {} Expr condition; }; class ASTBase { public: - explicit ASTBase(ASTNode parent, ASTData data) : parent{parent}, data{data} {} + explicit ASTBase(ASTNode parent, ASTData data) + : data{std::move(data)}, parent{std::move(parent)} {} template static ASTNode Make(ASTNode parent, Args&&... args) { - return std::make_shared(parent, ASTData(U(std::forward(args)...))); + return std::make_shared(std::move(parent), + ASTData(U(std::forward(args)...))); } void SetParent(ASTNode new_parent) { - parent = new_parent; + parent = std::move(new_parent); } ASTNode& GetParent() { @@ -247,7 +248,7 @@ public: void SetGotoCondition(Expr new_condition) { auto inner = std::get_if(&data); if (inner) { - inner->condition = new_condition; + inner->condition = std::move(new_condition); } } @@ -370,9 +371,9 @@ public: private: bool IsBackwardsJump(ASTNode goto_node, ASTNode label_node) const; - bool IndirectlyRelated(ASTNode first, ASTNode second); + bool IndirectlyRelated(const ASTNode& first, const ASTNode& second) const; - bool DirectlyRelated(ASTNode first, ASTNode second); + bool DirectlyRelated(const ASTNode& first, const ASTNode& second) const; void EncloseDoWhile(ASTNode goto_node, ASTNode label); -- cgit v1.2.3 From 43503a69bf730125b380601a919e81ca09afeb74 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Oct 2019 08:40:24 -0400 Subject: video_core/{ast, expr}: Organize forward declaration Keeps them alphabetically sorted for readability. --- src/video_core/shader/ast.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/video_core/shader/ast.h') diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index aad35c12e..6d2dc0895 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h @@ -18,17 +18,17 @@ namespace VideoCommon::Shader { class ASTBase; -class ASTProgram; -class ASTIfThen; -class ASTIfElse; -class ASTBlockEncoded; class ASTBlockDecoded; -class ASTVarSet; +class ASTBlockEncoded; +class ASTBreak; +class ASTDoWhile; class ASTGoto; +class ASTIfElse; +class ASTIfThen; class ASTLabel; -class ASTDoWhile; +class ASTProgram; class ASTReturn; -class ASTBreak; +class ASTVarSet; using ASTData = std::variant; -- cgit v1.2.3 From 3a20d9734fa8996434895bc3d27e4b255ae98bea Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Oct 2019 08:43:44 -0400 Subject: video_core/ast: Default the move constructor and assignment operator This is behaviorally equivalent and also fixes a bug where some members weren't being moved over. --- src/video_core/shader/ast.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/video_core/shader/ast.h') diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index 6d2dc0895..d280ed143 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h @@ -313,8 +313,8 @@ public: ASTManager(const ASTManager& o) = delete; ASTManager& operator=(const ASTManager& other) = delete; - ASTManager(ASTManager&& other) noexcept; - ASTManager& operator=(ASTManager&& other) noexcept; + ASTManager(ASTManager&& other) noexcept = default; + ASTManager& operator=(ASTManager&& other) noexcept = default; void Init(); -- cgit v1.2.3 From 6c41d1cd7eadf1030c02d661d7f360b98f4a8943 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Oct 2019 08:48:15 -0400 Subject: video_core/ast: Make ShowCurrentState() take a string_view instead of std::string Allows the function to be non-allocating in terms of the output string. --- src/video_core/shader/ast.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/video_core/shader/ast.h') diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index d280ed143..5a77c60cb 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h @@ -332,7 +332,7 @@ public: void Decompile(); - void ShowCurrentState(std::string state); + void ShowCurrentState(std::string_view state); void SanityCheck(); -- cgit v1.2.3 From d82b181d445441ce84612c38d748d3d5a6f8854c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Oct 2019 08:50:00 -0400 Subject: video_core/ast: Unindent most of IsFullyDecompiled() by one level --- src/video_core/shader/ast.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/video_core/shader/ast.h') diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index 5a77c60cb..d7bf11821 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h @@ -340,20 +340,20 @@ public: bool IsFullyDecompiled() const { if (full_decompile) { - return gotos.size() == 0; - } else { - for (ASTNode goto_node : gotos) { - auto label_index = goto_node->GetGotoLabel(); - if (!label_index) { - return false; - } - ASTNode glabel = labels[*label_index]; - if (IsBackwardsJump(goto_node, glabel)) { - return false; - } + return gotos.empty(); + } + + for (ASTNode goto_node : gotos) { + auto label_index = goto_node->GetGotoLabel(); + if (!label_index) { + return false; + } + ASTNode glabel = labels[*label_index]; + if (IsBackwardsJump(goto_node, glabel)) { + return false; } - return true; } + return true; } ASTNode GetProgram() const { -- cgit v1.2.3