Stoorx added a comment.

I've looked through usages of `getClobbers` again, and found that in each case 
the result if the function is casted to `std::string`.

  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGStmt.cpp
  
  std::string Constraints = "=r,*Z,~{memory}";
    std::string MachineClobbers =
        static_cast<std::string>(CGF.getTarget().getClobbers());
    if (!MachineClobbers.empty()) {
      Constraints += ',';
      Constraints += MachineClobbers;
    }

I think we can 'make two deals with one shot' if we would:

- Make `std::string_view` as a return type of `getClobbers` (by value, since 
the `std::string_view` is 'TriviallyCopyable')
- (Maybe) Make private static field of `std::string` type for actual clobber 
value (or `std::string_view` type since it can be constexpr-constructed)
- Return the value of this field from `getClobbers`
- Change type of MachineClobbers (in usages, see example above) variable to 
`std::string_view` since it actually used for read-only access. (We do not need 
to construct `std::string` and destruct it almost immediately)

As a result we get:

- More robust usage of `getClobbers` (a bit ridiculous but...)
- Zero unnecessary allocations

(Also: I've discovered that `llvm::StringRef` is exact the same thing as 
`std::string_view`. I think of it so much :^) )


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148799/new/

https://reviews.llvm.org/D148799

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to