[wasm][i64-lowering] Refactor special CallDescriptor lowering

This CL generalizes the lowering of special CallDescriptors in the
int64-lowering. The reason is a planned extension of the special
handling due to a refactoring of the AtomicWait implementation.

R=jkummerow@chromium.org

Bug: v8:10108
Change-Id: I48d0087e2ad00ba9b44c5198ffdbbae8eb575a85
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2069333
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66420}
This commit is contained in:
Andreas Haas 2020-02-24 17:56:24 +01:00 committed by Commit Bot
parent 8af03419a6
commit 300c139b86
4 changed files with 44 additions and 86 deletions

View File

@ -1023,14 +1023,12 @@ bool Int64Lowering::DefaultLowering(Node* node, bool low_word_only) {
return something_changed;
}
CallDescriptor* Int64Lowering::LowerCallDescriptor(
const CallDescriptor* Int64Lowering::LowerCallDescriptor(
const CallDescriptor* call_descriptor) {
if (special_case_) {
if (call_descriptor == special_case_->bigint_to_i64_call_descriptor) {
return special_case_->bigint_to_i32_pair_call_descriptor;
}
if (call_descriptor == special_case_->i64_to_bigint_call_descriptor) {
return special_case_->i32_pair_to_bigint_call_descriptor;
auto replacement = special_case_->replacements.find(call_descriptor);
if (replacement != special_case_->replacements.end()) {
return replacement->second;
}
}
return GetI32WasmCallDescriptor(zone(), call_descriptor);

View File

@ -24,19 +24,9 @@ namespace compiler {
// Struct for CallDescriptors that need special lowering.
struct V8_EXPORT_PRIVATE Int64LoweringSpecialCase {
Int64LoweringSpecialCase()
: bigint_to_i64_call_descriptor(nullptr),
i64_to_bigint_call_descriptor(nullptr),
bigint_to_i32_pair_call_descriptor(nullptr),
i32_pair_to_bigint_call_descriptor(nullptr) {}
// CallDescriptors that need special lowering.
CallDescriptor* bigint_to_i64_call_descriptor;
CallDescriptor* i64_to_bigint_call_descriptor;
// The replacement CallDescriptors.
CallDescriptor* bigint_to_i32_pair_call_descriptor;
CallDescriptor* i32_pair_to_bigint_call_descriptor;
// Map from CallDescriptors that should be replaced, to the replacement
// CallDescriptors.
std::unordered_map<const CallDescriptor*, const CallDescriptor*> replacements;
};
class V8_EXPORT_PRIVATE Int64Lowering {
@ -74,7 +64,8 @@ class V8_EXPORT_PRIVATE Int64Lowering {
void LowerWord64AtomicBinop(Node* node, const Operator* op);
void LowerWord64AtomicNarrowOp(Node* node, const Operator* op);
CallDescriptor* LowerCallDescriptor(const CallDescriptor* call_descriptor);
const CallDescriptor* LowerCallDescriptor(
const CallDescriptor* call_descriptor);
void ReplaceNode(Node* old, Node* new_low, Node* new_high);
bool HasReplacementLow(Node* node);

View File

@ -5073,6 +5073,19 @@ void WasmGraphBuilder::RemoveBytecodePositionDecorator() {
}
namespace {
template <typename BuiltinDescriptor>
CallDescriptor* GetBuiltinCallDescriptor(WasmGraphBuilder* builder,
StubCallMode stub_mode) {
BuiltinDescriptor interface_descriptor;
return Linkage::GetStubCallDescriptor(
builder->mcgraph()->zone(), // zone
interface_descriptor, // descriptor
interface_descriptor.GetStackParameterCount(), // stack parameter count
CallDescriptor::kNoFlags, // flags
Operator::kNoProperties, // properties
stub_mode); // stub call mode
}
class WasmWrapperGraphBuilder : public WasmGraphBuilder {
public:
WasmWrapperGraphBuilder(Zone* zone, MachineGraph* mcgraph,
@ -5083,76 +5096,34 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
stub_mode_(stub_mode),
enabled_features_(features) {}
CallDescriptor* GetI32PairToBigIntCallDescriptor() {
I32PairToBigIntDescriptor interface_descriptor;
return Linkage::GetStubCallDescriptor(
mcgraph()->zone(), // zone
interface_descriptor, // descriptor
interface_descriptor.GetStackParameterCount(), // stack parameter count
CallDescriptor::kNoFlags, // flags
Operator::kNoProperties, // properties
stub_mode_); // stub call mode
}
CallDescriptor* GetI64ToBigIntCallDescriptor() {
if (i64_to_bigint_descriptor_) return i64_to_bigint_descriptor_;
i64_to_bigint_descriptor_ =
GetBuiltinCallDescriptor<I64ToBigIntDescriptor>(this, stub_mode_);
if (!lowering_special_case_) {
lowering_special_case_ = std::make_unique<Int64LoweringSpecialCase>();
}
if (lowering_special_case_->i64_to_bigint_call_descriptor) {
return lowering_special_case_->i64_to_bigint_call_descriptor;
}
I64ToBigIntDescriptor interface_descriptor;
auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), // zone
interface_descriptor, // descriptor
interface_descriptor.GetStackParameterCount(), // stack parameter count
CallDescriptor::kNoFlags, // flags
Operator::kNoProperties, // properties
stub_mode_); // stub call mode
lowering_special_case_->i64_to_bigint_call_descriptor = call_descriptor;
lowering_special_case_->i32_pair_to_bigint_call_descriptor =
GetI32PairToBigIntCallDescriptor();
return call_descriptor;
}
CallDescriptor* GetBigIntToI32PairCallDescriptor() {
BigIntToI32PairDescriptor interface_descriptor;
return Linkage::GetStubCallDescriptor(
mcgraph()->zone(), // zone
interface_descriptor, // descriptor
interface_descriptor.GetStackParameterCount(), // stack parameter count
CallDescriptor::kNoFlags, // flags
Operator::kNoProperties, // properties
stub_mode_); // stub call mode
lowering_special_case_->replacements.insert(
{i64_to_bigint_descriptor_,
GetBuiltinCallDescriptor<I32PairToBigIntDescriptor>(this,
stub_mode_)});
return i64_to_bigint_descriptor_;
}
CallDescriptor* GetBigIntToI64CallDescriptor() {
if (bigint_to_i64_descriptor_) return bigint_to_i64_descriptor_;
if (!lowering_special_case_) {
lowering_special_case_ = std::make_unique<Int64LoweringSpecialCase>();
}
if (lowering_special_case_->bigint_to_i64_call_descriptor) {
return lowering_special_case_->bigint_to_i64_call_descriptor;
}
bigint_to_i64_descriptor_ =
GetBuiltinCallDescriptor<BigIntToI64Descriptor>(this, stub_mode_);
BigIntToI64Descriptor interface_descriptor;
auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), // zone
interface_descriptor, // descriptor
interface_descriptor.GetStackParameterCount(), // stack parameter count
CallDescriptor::kNoFlags, // flags
Operator::kNoProperties, // properties
stub_mode_); // stub call mode
lowering_special_case_->bigint_to_i64_call_descriptor = call_descriptor;
lowering_special_case_->bigint_to_i32_pair_call_descriptor =
GetBigIntToI32PairCallDescriptor();
return call_descriptor;
lowering_special_case_->replacements.insert(
{bigint_to_i64_descriptor_,
GetBuiltinCallDescriptor<BigIntToI32PairDescriptor>(this,
stub_mode_)});
return bigint_to_i64_descriptor_;
}
Node* GetBuiltinPointerTarget(Builtins::Name builtin_id) {
@ -6307,6 +6278,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
SetOncePointer<Node> undefined_value_node_;
SetOncePointer<const Operator> allocate_heap_number_operator_;
wasm::WasmFeatures enabled_features_;
CallDescriptor* bigint_to_i64_descriptor_ = nullptr;
CallDescriptor* i64_to_bigint_descriptor_ = nullptr;
};
} // namespace

View File

@ -1016,10 +1016,8 @@ TEST_F(Int64LoweringTest, WasmBigIntSpecialCaseBigIntToI64) {
StubCallMode::kCallCodeObject); // stub call mode
auto lowering_special_case = std::make_unique<Int64LoweringSpecialCase>();
lowering_special_case->bigint_to_i64_call_descriptor =
bigint_to_i64_call_descriptor;
lowering_special_case->bigint_to_i32_pair_call_descriptor =
bigint_to_i32_pair_call_descriptor;
lowering_special_case->replacements.insert(
{bigint_to_i64_call_descriptor, bigint_to_i32_pair_call_descriptor});
Node* call_node =
graph()->NewNode(common()->Call(bigint_to_i64_call_descriptor), target,
@ -1064,10 +1062,8 @@ TEST_F(Int64LoweringTest, WasmBigIntSpecialCaseI64ToBigInt) {
StubCallMode::kCallCodeObject); // stub call mode
auto lowering_special_case = std::make_unique<Int64LoweringSpecialCase>();
lowering_special_case->i64_to_bigint_call_descriptor =
i64_to_bigint_call_descriptor;
lowering_special_case->i32_pair_to_bigint_call_descriptor =
i32_pair_to_bigint_call_descriptor;
lowering_special_case->replacements.insert(
{i64_to_bigint_call_descriptor, i32_pair_to_bigint_call_descriptor});
Node* call = graph()->NewNode(common()->Call(i64_to_bigint_call_descriptor),
target, i64, start(), start());