Commit d38f84ac authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[codegen] Simplify definition of signatures

Liftoff defines many signatures of fixed size. This is currently done by
defining a fixed-size array on the stack, and then using this in the
signature definition. This is cumbersome and hard to read, since the
array contains return types and parameter types, and only the signature
definition separates the two. But also the order of those two sizes in
the signature is non-obvious and easy to get wrong.

This CL introduces a helper to define fixed-size signatures in a
"builder style", i.e. parameters and return types can be added
separately. The fixed-size array will be contained in the returned
class, so it will still be stack-allocated like before. The copies to
iteratively build up this array should be completely eliminated by the
compiler, so the binary code should look exactly the same.

R=ahaas@chromium.org

Bug: v8:11384
Change-Id: I167830d6c3429f535b7d1241920730498a9bb4c1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2747505
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73341}
parent f7bb9267
......@@ -124,6 +124,44 @@ size_t hash_value(const Signature<T>& sig) {
return hash;
}
template <typename T, size_t num_returns = 0, size_t num_params = 0>
class FixedSizeSignature : public Signature<T> {
public:
explicit FixedSizeSignature(std::array<T, num_returns + num_params> reps)
: Signature<T>(num_returns, num_params, InitReps(reps)) {}
// Add return types to this signature (only allowed if there are none yet).
template <typename... ReturnTypes>
auto Returns(ReturnTypes... return_types) const {
static_assert(num_returns == 0, "Please specify all return types at once");
return FixedSizeSignature<T, sizeof...(ReturnTypes), num_params>{Concat(
std::array<T, sizeof...(ReturnTypes)>{{return_types...}}, reps_)};
}
// Add parameters to this signature (only allowed if there are none yet).
template <typename... ParamTypes>
auto Params(ParamTypes... param_types) const {
static_assert(num_params == 0, "Please specify all parameters at once");
return FixedSizeSignature<T, num_returns, sizeof...(ParamTypes)>{
Concat(reps_, std::array<T, sizeof...(ParamTypes)>{{param_types...}})};
}
private:
T* InitReps(const std::array<T, num_returns + num_params>& reps) {
reps_ = reps;
return reps_.data();
}
template <size_t sizeA, size_t sizeB>
static std::array<T, sizeA + sizeB> Concat(const std::array<T, sizeA>& a,
const std::array<T, sizeB>& b) {
return base::make_array<sizeA + sizeB>(
[&a, &b](std::size_t i) { return i < sizeA ? a[i] : b[i - sizeA]; });
}
std::array<T, num_returns + num_params> reps_;
};
} // namespace internal
} // namespace v8
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment