[Mesa-dev] [PATCH 01/12] nv50/ir: optimize the use of std::tr1::unordered_set

Ilia Mirkin imirkin at alum.mit.edu
Fri May 15 11:46:56 PDT 2015


Please elaborate why this is necessary. I have, in the past, had
requests to move to the C++11 std::unordered_set -- would that work
for you? I'd be happy with a #if c++11 is available, use
std::unordered_set. Otherwise use std::tr1::unordered_set.

On Fri, May 15, 2015 at 2:42 PM, Chih-Wei Huang <cwhuang at android-x86.org> wrote:
> Instead of using unordered_set<user-defined-type *> directly, the patch
> changes to use unordered_set<void *> and adds a wrapper template class
> to convert the iterators to the expected user-defined type.
>
> This avoid instantiating the template multiple times and make it be
> more compatible with stlport.
>
> Signed-off-by: Chih-Wei Huang <cwhuang at linux.org.tw>
> ---
>  src/gallium/drivers/nouveau/codegen/nv50_ir.h      | 28 +++++++++++++++++++---
>  .../nouveau/codegen/nv50_ir_lowering_nvc0.cpp      |  4 ++--
>  .../nouveau/codegen/nv50_ir_lowering_nvc0.h        |  4 +---
>  src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp |  5 ++--
>  4 files changed, 30 insertions(+), 11 deletions(-)
>
> diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir.h b/src/gallium/drivers/nouveau/codegen/nv50_ir.h
> index 529dcb9..f4d52b7 100644
> --- a/src/gallium/drivers/nouveau/codegen/nv50_ir.h
> +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir.h
> @@ -451,6 +451,28 @@ struct Storage
>  #define NV50_IR_INTERP_OFFSET      (2 << 2)
>  #define NV50_IR_INTERP_SAMPLEID    (3 << 2)
>
> +typedef std::tr1::unordered_set<void *> voidptr_unordered_set;
> +
> +template <typename V>
> +class ptr_unordered_set : public voidptr_unordered_set {
> +  public:
> +    typedef voidptr_unordered_set _base;
> +    typedef _base::iterator _biterator;
> +
> +    class iterator : public _biterator {
> +      public:
> +        iterator(const _biterator & i) : _biterator(i) {}
> +        V *operator*() { return reinterpret_cast<V *>(*_biterator(*this)); }
> +        const V *operator*() const { return reinterpret_cast<const V *>(*_biterator(*this)); }
> +    };
> +    typedef const iterator const_iterator;
> +
> +    iterator begin() { return _base::begin(); }
> +    iterator end() { return _base::end(); }
> +    const_iterator begin() const { return _base::begin(); }
> +    const_iterator end() const { return _base::end(); }
> +};
> +
>  // do we really want this to be a class ?
>  class Modifier
>  {
> @@ -583,10 +605,10 @@ public:
>
>     static inline Value *get(Iterator&);
>
> -   std::tr1::unordered_set<ValueRef *> uses;
> +   ptr_unordered_set<ValueRef> uses;
>     std::list<ValueDef *> defs;
> -   typedef std::tr1::unordered_set<ValueRef *>::iterator UseIterator;
> -   typedef std::tr1::unordered_set<ValueRef *>::const_iterator UseCIterator;
> +   typedef ptr_unordered_set<ValueRef>::iterator UseIterator;
> +   typedef ptr_unordered_set<ValueRef>::const_iterator UseCIterator;
>     typedef std::list<ValueDef *>::iterator DefIterator;
>     typedef std::list<ValueDef *>::const_iterator DefCIterator;
>
> diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.cpp
> index b61f3c4..669d292 100644
> --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.cpp
> +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.cpp
> @@ -224,7 +224,7 @@ NVC0LegalizePostRA::findFirstUses(
>        const Instruction *texi,
>        const Instruction *insn,
>        std::list<TexUse> &uses,
> -      std::tr1::unordered_set<const Instruction *>& visited)
> +      ptr_unordered_set<const Instruction>& visited)
>  {
>     for (int d = 0; insn->defExists(d); ++d) {
>        Value *v = insn->getDef(d);
> @@ -318,7 +318,7 @@ NVC0LegalizePostRA::insertTextureBarriers(Function *fn)
>     if (!uses)
>        return false;
>     for (size_t i = 0; i < texes.size(); ++i) {
> -      std::tr1::unordered_set<const Instruction *> visited;
> +      ptr_unordered_set<const Instruction> visited;
>        findFirstUses(texes[i], texes[i], uses[i], visited);
>     }
>
> diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.h b/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.h
> index 260e101..17b6f6f 100644
> --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.h
> +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.h
> @@ -20,8 +20,6 @@
>   * OTHER DEALINGS IN THE SOFTWARE.
>   */
>
> -#include <tr1/unordered_set>
> -
>  #include "codegen/nv50_ir.h"
>  #include "codegen/nv50_ir_build_util.h"
>
> @@ -73,7 +71,7 @@ private:
>     inline bool insnDominatedBy(const Instruction *, const Instruction *) const;
>     void findFirstUses(const Instruction *tex, const Instruction *def,
>                        std::list<TexUse>&,
> -                      std::tr1::unordered_set<const Instruction *>&);
> +                      ptr_unordered_set<const Instruction>&);
>     void findOverwritingDefs(const Instruction *tex, Instruction *insn,
>                              const BasicBlock *term,
>                              std::list<TexUse>&);
> diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp
> index 898653c..03acba7 100644
> --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp
> +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_ra.cpp
> @@ -25,7 +25,6 @@
>
>  #include <stack>
>  #include <limits>
> -#include <tr1/unordered_set>
>
>  namespace nv50_ir {
>
> @@ -1551,7 +1550,7 @@ SpillCodeInserter::run(const std::list<ValuePair>& lst)
>        // Keep track of which instructions to delete later. Deleting them
>        // inside the loop is unsafe since a single instruction may have
>        // multiple destinations that all need to be spilled (like OP_SPLIT).
> -      std::tr1::unordered_set<Instruction *> to_del;
> +      ptr_unordered_set<Instruction> to_del;
>
>        for (Value::DefIterator d = lval->defs.begin(); d != lval->defs.end();
>             ++d) {
> @@ -1593,7 +1592,7 @@ SpillCodeInserter::run(const std::list<ValuePair>& lst)
>           }
>        }
>
> -      for (std::tr1::unordered_set<Instruction *>::const_iterator it = to_del.begin();
> +      for (ptr_unordered_set<Instruction>::iterator it = to_del.begin();
>             it != to_del.end(); ++it)
>           delete_Instruction(func->getProgram(), *it);
>     }
> --
> 1.9.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list