Mesa (main): aco: Use std::vector for the underlying container of std::stack

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 1 09:57:11 UTC 2021


Module: Mesa
Branch: main
Commit: 0812d440c7f6adbfe215f0373e241a7b65469415
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0812d440c7f6adbfe215f0373e241a7b65469415

Author: Tony Wasserka <tony.wasserka at gmx.de>
Date:   Sat Jul 10 12:20:56 2021 +0200

aco: Use std::vector for the underlying container of std::stack

By default, std::stack uses std::deque to allocate its elements, which has
poor cache efficiency. std::vector makes appending elements more expensive
(due to potential reallocations), but in the changed contexts the element
count should always be low anyway.

Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11925>

---

 src/amd/compiler/aco_insert_NOPs.cpp           | 2 +-
 src/amd/compiler/aco_insert_waitcnt.cpp        | 2 +-
 src/amd/compiler/aco_instruction_selection.cpp | 2 +-
 src/amd/compiler/aco_spill.cpp                 | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/amd/compiler/aco_insert_NOPs.cpp b/src/amd/compiler/aco_insert_NOPs.cpp
index 361411d05e5..5dd1c7183e8 100644
--- a/src/amd/compiler/aco_insert_NOPs.cpp
+++ b/src/amd/compiler/aco_insert_NOPs.cpp
@@ -847,7 +847,7 @@ void
 mitigate_hazards(Program* program)
 {
    std::vector<Ctx> all_ctx(program->blocks.size());
-   std::stack<unsigned> loop_header_indices;
+   std::stack<unsigned, std::vector<unsigned>> loop_header_indices;
 
    for (unsigned i = 0; i < program->blocks.size(); i++) {
       Block& block = program->blocks[i];
diff --git a/src/amd/compiler/aco_insert_waitcnt.cpp b/src/amd/compiler/aco_insert_waitcnt.cpp
index d7fc87c126d..cb6c2a60804 100644
--- a/src/amd/compiler/aco_insert_waitcnt.cpp
+++ b/src/amd/compiler/aco_insert_waitcnt.cpp
@@ -767,7 +767,7 @@ insert_wait_states(Program* program)
    std::vector<wait_ctx> in_ctx(program->blocks.size(), wait_ctx(program));
    std::vector<wait_ctx> out_ctx(program->blocks.size(), wait_ctx(program));
 
-   std::stack<unsigned> loop_header_indices;
+   std::stack<unsigned, std::vector<unsigned>> loop_header_indices;
    unsigned loop_progress = 0;
 
    for (unsigned i = 0; i < program->blocks.size();) {
diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp
index bd81c50083c..d4fd9794fdc 100644
--- a/src/amd/compiler/aco_instruction_selection.cpp
+++ b/src/amd/compiler/aco_instruction_selection.cpp
@@ -11811,7 +11811,7 @@ select_gs_copy_shader(Program* program, struct nir_shader* gs_shader, ac_shader_
    Temp vtx_offset = bld.vop2(aco_opcode::v_lshlrev_b32, bld.def(v1), Operand::c32(2u),
                               get_arg(&ctx, ctx.args->ac.vertex_id));
 
-   std::stack<if_context> if_contexts;
+   std::stack<if_context, std::vector<if_context>> if_contexts;
 
    for (unsigned stream = 0; stream < 4; stream++) {
       if (stream_id.isConstant() && stream != stream_id.constantValue())
diff --git a/src/amd/compiler/aco_spill.cpp b/src/amd/compiler/aco_spill.cpp
index dc1d3bc34f7..7dfbc03006b 100644
--- a/src/amd/compiler/aco_spill.cpp
+++ b/src/amd/compiler/aco_spill.cpp
@@ -56,7 +56,7 @@ struct spill_ctx {
    std::vector<std::map<Temp, uint32_t>> spills_entry;
    std::vector<std::map<Temp, uint32_t>> spills_exit;
    std::vector<bool> processed;
-   std::stack<Block*> loop_header;
+   std::stack<Block*, std::vector<Block*>> loop_header;
    std::vector<std::map<Temp, std::pair<uint32_t, uint32_t>>> next_use_distances_start;
    std::vector<std::map<Temp, std::pair<uint32_t, uint32_t>>> next_use_distances_end;
    std::vector<std::pair<RegClass, std::unordered_set<uint32_t>>> interferences;



More information about the mesa-commit mailing list