[PATCH] D27145: Add "RPRED" mechanism for relocation predicates. (5% speedup for `ld.lld -O0`)

Sean Silva via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 27 15:29:46 PST 2016


silvas added a comment.

In https://reviews.llvm.org/D27145#606205, @ruiu wrote:

> It is a legitimate concern that the new code is harder to read, especially when compared to the original simple-minded one.


I don't think it actually is so bad. These predicates are rarely modified and usually have a larger semantic meaning like `needsPlt` or `refersToGotEntry`. I don't think that most people reading this code actually look at the specific set of RelExpr's being checked very often.

> I wonder if a table lookup will work here. A RelExpr is a small integer, so we can do something like this
> 
>   static bool refersToGotEntry(RelExpr Expr) {
>     return RefersToGotEntry[static_cast<int>(Expr)];
>   }
>    
> 
> where RefersToGotEntry is defined as
> 
>   bool RefersToGotEntry[R_MAX] = {
>     .R_GOT = true, .R_GOT_OFF = true, .R_MIPS_GOT_LOCAL_PAGE = true, ...
>   }

If you want I can try an approach like that. However, the syntax you have there isn't possible in C++. It would probably end up looking something like:

  RelExprPredicateTable RefersToGotEntry([](RelExpr Expr) {
    return Expr == R_GOT || Expr == R_GOT_OFF || Expr == R_MIPS_GOT_LOCAL_PAGE ||
           Expr == R_MIPS_GOT_OFF || Expr == R_MIPS_GOT_OFF32 ||
           Expr == R_MIPS_TLSGD || Expr == R_MIPS_TLSLD ||
           Expr == R_GOT_PAGE_PC || Expr == R_GOT_PC || Expr == R_GOT_FROM_END ||
           Expr == R_TLSGD || Expr == R_TLSGD_PC || Expr == R_TLSDESC ||
           Expr == R_TLSDESC_PAGE;
  });

The code for RelExprPredicateTable would be some annoying constexpr metaprogramming that calls the lambda on each possible RelExpr value to build the table (and then we have to worry about which compilers support the necessary C++ features to do it; if not all of them do, then it may not be possible or it may have to be done in an ugly way). I'm not sure that would actually be that much more readable.

Do you want me to try it?

Also, it may not be as fast (hard to beat a single AND), but that will have to be measured.


https://reviews.llvm.org/D27145





More information about the llvm-commits mailing list