[gcc r17-3005] RISC-V: Return implied_exts by const reference
Ma Jin via Gcc-cvs <[email protected]> Thu, 6 Aug 2026 06:51:03 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:487ed3d78a7725304da0d67b557c5dee093bf384 commit r17-3005-g487ed3d78a7725304da0d67b557c5dee093bf384 Author: Jin Ma <[email protected]> Date: Wed Jul 22 15:49:51 2026 +0800 RISC-V: Return implied_exts by const reference riscv_ext_info_t::implied_exts() returns its std::vector member by value, but all three callers (check_implied_ext, handle_combine_ext, riscv_minimal_hwprobe_feature_bits) only iterate over the result and never need ownership. Every invocation therefore copies the entire implied-extension vector. During option parsing this runs once per compiled source file; at -O0 the optimisation passes are skipped so option-parsing overhead dominates, causing a 6.7% compile-time regression on CSIBE -O0 benchmarks. Return a const reference instead. The underlying m_implied_exts member lives in a static global map entry and outlives every caller, so no dangling-reference risk exists. gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_ext_info_t::implied_exts): Return const reference instead of by-value copy. Signed-off-by: Jin Ma <[email protected]> Diff: --- gcc/common/config/riscv/riscv-common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 2d56ba59f0e4..6bbbacab8df4 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -135,7 +135,7 @@ public: /* Return true if any change. */ bool apply_implied_ext (riscv_subset_list *subset_list) const; - const std::vector<riscv_implied_info_t> implied_exts () const + const std::vector<riscv_implied_info_t> &implied_exts () const { return m_implied_exts; }