Skip to content

Commit 5bfb36d

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[vm, compiler] Use leaf calls for exp and log.
We already do this for the other functions in dart:math. TEST=ci Bug: #45414 Change-Id: Ic1fb1c7cdbbf39eaa4af645219874408988b740b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192522 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
1 parent 77fbd1d commit 5bfb36d

File tree

8 files changed

+392
-432
lines changed

8 files changed

+392
-432
lines changed

runtime/vm/compiler/backend/il.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6202,6 +6202,8 @@ intptr_t InvokeMathCFunctionInstr::ArgumentCountFor(
62026202
case MethodRecognizer::kMathAsin:
62036203
case MethodRecognizer::kMathSin:
62046204
case MethodRecognizer::kMathCos:
6205+
case MethodRecognizer::kMathExp:
6206+
case MethodRecognizer::kMathLog:
62056207
return 1;
62066208
case MethodRecognizer::kDoubleMod:
62076209
case MethodRecognizer::kMathDoublePow:
@@ -6241,6 +6243,10 @@ const RuntimeEntry& InvokeMathCFunctionInstr::TargetFunction() const {
62416243
return kLibcAtanRuntimeEntry;
62426244
case MethodRecognizer::kMathAtan2:
62436245
return kLibcAtan2RuntimeEntry;
6246+
case MethodRecognizer::kMathExp:
6247+
return kLibcExpRuntimeEntry;
6248+
case MethodRecognizer::kMathLog:
6249+
return kLibcLogRuntimeEntry;
62446250
default:
62456251
UNREACHABLE();
62466252
}

runtime/vm/compiler/backend/inliner.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,6 +3985,8 @@ bool FlowGraphInliner::TryInlineRecognizedMethod(
39853985
case MethodRecognizer::kMathAcos:
39863986
case MethodRecognizer::kMathAtan:
39873987
case MethodRecognizer::kMathAtan2:
3988+
case MethodRecognizer::kMathExp:
3989+
case MethodRecognizer::kMathLog:
39883990
return InlineMathCFunction(flow_graph, call, kind, graph_entry, entry,
39893991
last, result);
39903992

runtime/vm/compiler/graph_intrinsifier.cc

Lines changed: 32 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -962,177 +962,109 @@ bool GraphIntrinsifier::Build_DoubleFlipSignBit(FlowGraph* flow_graph) {
962962
return true;
963963
}
964964

965-
static bool BuildInvokeMathCFunction(BlockBuilder* builder,
965+
static bool BuildInvokeMathCFunction(FlowGraph* flow_graph,
966966
MethodRecognizer::Kind kind,
967-
FlowGraph* flow_graph,
968967
intptr_t num_parameters = 1) {
969968
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) {
970969
return false;
971970
}
971+
972+
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
973+
auto normal_entry = graph_entry->normal_entry();
974+
BlockBuilder builder(flow_graph, normal_entry);
975+
972976
ZoneGrowableArray<Value*>* args =
973977
new ZoneGrowableArray<Value*>(num_parameters);
974978

975979
for (intptr_t i = 0; i < num_parameters; i++) {
976-
Definition* value = builder->AddParameter(i, /*with_frame=*/false);
980+
Definition* value = builder.AddParameter(i, /*with_frame=*/false);
977981
Definition* unboxed_value = ConvertOrUnboxDoubleParameter(
978-
builder, value, i, /* is_checked = */ false);
982+
&builder, value, i, /* is_checked = */ false);
979983
if (unboxed_value == nullptr) {
980984
return false;
981985
}
982986
args->Add(new Value(unboxed_value));
983987
}
984988

985989
Definition* unboxed_result =
986-
builder->AddDefinition(new InvokeMathCFunctionInstr(
987-
args, DeoptId::kNone, kind, builder->Source()));
990+
builder.AddDefinition(new InvokeMathCFunctionInstr(
991+
args, DeoptId::kNone, kind, builder.Source()));
988992
Definition* result =
989-
CreateBoxedResultIfNeeded(builder, unboxed_result, kUnboxedDouble);
990-
builder->AddReturn(new Value(result));
993+
CreateBoxedResultIfNeeded(&builder, unboxed_result, kUnboxedDouble);
994+
builder.AddReturn(new Value(result));
991995

992996
return true;
993997
}
994998

995999
bool GraphIntrinsifier::Build_MathSin(FlowGraph* flow_graph) {
996-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
997-
998-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
999-
auto normal_entry = graph_entry->normal_entry();
1000-
BlockBuilder builder(flow_graph, normal_entry);
1001-
1002-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kMathSin,
1003-
flow_graph);
1000+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathSin);
10041001
}
10051002

10061003
bool GraphIntrinsifier::Build_MathCos(FlowGraph* flow_graph) {
1007-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1008-
1009-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1010-
auto normal_entry = graph_entry->normal_entry();
1011-
BlockBuilder builder(flow_graph, normal_entry);
1012-
1013-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kMathCos,
1014-
flow_graph);
1004+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathCos);
10151005
}
10161006

10171007
bool GraphIntrinsifier::Build_MathTan(FlowGraph* flow_graph) {
1018-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1019-
1020-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1021-
auto normal_entry = graph_entry->normal_entry();
1022-
BlockBuilder builder(flow_graph, normal_entry);
1023-
1024-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kMathTan,
1025-
flow_graph);
1008+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathTan);
10261009
}
10271010

10281011
bool GraphIntrinsifier::Build_MathAsin(FlowGraph* flow_graph) {
1029-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1030-
1031-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1032-
auto normal_entry = graph_entry->normal_entry();
1033-
BlockBuilder builder(flow_graph, normal_entry);
1034-
1035-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kMathAsin,
1036-
flow_graph);
1012+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathAsin);
10371013
}
10381014

10391015
bool GraphIntrinsifier::Build_MathAcos(FlowGraph* flow_graph) {
1040-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1041-
1042-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1043-
auto normal_entry = graph_entry->normal_entry();
1044-
BlockBuilder builder(flow_graph, normal_entry);
1045-
1046-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kMathAcos,
1047-
flow_graph);
1016+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathAcos);
10481017
}
10491018

10501019
bool GraphIntrinsifier::Build_MathAtan(FlowGraph* flow_graph) {
1051-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1052-
1053-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1054-
auto normal_entry = graph_entry->normal_entry();
1055-
BlockBuilder builder(flow_graph, normal_entry);
1056-
1057-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kMathAtan,
1058-
flow_graph);
1020+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathAtan);
10591021
}
10601022

10611023
bool GraphIntrinsifier::Build_MathAtan2(FlowGraph* flow_graph) {
1062-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1063-
1064-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1065-
auto normal_entry = graph_entry->normal_entry();
1066-
BlockBuilder builder(flow_graph, normal_entry);
1067-
1068-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kMathAtan2,
1069-
flow_graph,
1024+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathAtan2,
10701025
/* num_parameters = */ 2);
10711026
}
10721027

1073-
bool GraphIntrinsifier::Build_DoubleMod(FlowGraph* flow_graph) {
1074-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1028+
bool GraphIntrinsifier::Build_MathExp(FlowGraph* flow_graph) {
1029+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathExp);
1030+
}
10751031

1076-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1077-
auto normal_entry = graph_entry->normal_entry();
1078-
BlockBuilder builder(flow_graph, normal_entry);
1032+
bool GraphIntrinsifier::Build_MathLog(FlowGraph* flow_graph) {
1033+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kMathLog);
1034+
}
10791035

1080-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kDoubleMod,
1081-
flow_graph,
1036+
bool GraphIntrinsifier::Build_DoubleMod(FlowGraph* flow_graph) {
1037+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kDoubleMod,
10821038
/* num_parameters = */ 2);
10831039
}
10841040

10851041
bool GraphIntrinsifier::Build_DoubleCeil(FlowGraph* flow_graph) {
1086-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
10871042
// TODO(johnmccutchan): On X86 this intrinsic can be written in a different
10881043
// way.
10891044
if (TargetCPUFeatures::double_truncate_round_supported()) return false;
10901045

1091-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1092-
auto normal_entry = graph_entry->normal_entry();
1093-
BlockBuilder builder(flow_graph, normal_entry);
1094-
1095-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kDoubleCeil,
1096-
flow_graph);
1046+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kDoubleCeil);
10971047
}
10981048

10991049
bool GraphIntrinsifier::Build_DoubleFloor(FlowGraph* flow_graph) {
1100-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
11011050
// TODO(johnmccutchan): On X86 this intrinsic can be written in a different
11021051
// way.
11031052
if (TargetCPUFeatures::double_truncate_round_supported()) return false;
11041053

1105-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1106-
auto normal_entry = graph_entry->normal_entry();
1107-
BlockBuilder builder(flow_graph, normal_entry);
1108-
1109-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kDoubleFloor,
1110-
flow_graph);
1054+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kDoubleFloor);
11111055
}
11121056

11131057
bool GraphIntrinsifier::Build_DoubleTruncate(FlowGraph* flow_graph) {
1114-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
11151058
// TODO(johnmccutchan): On X86 this intrinsic can be written in a different
11161059
// way.
11171060
if (TargetCPUFeatures::double_truncate_round_supported()) return false;
11181061

1119-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1120-
auto normal_entry = graph_entry->normal_entry();
1121-
BlockBuilder builder(flow_graph, normal_entry);
1122-
1123-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kDoubleTruncate,
1124-
flow_graph);
1062+
return BuildInvokeMathCFunction(flow_graph,
1063+
MethodRecognizer::kDoubleTruncate);
11251064
}
11261065

11271066
bool GraphIntrinsifier::Build_DoubleRound(FlowGraph* flow_graph) {
1128-
if (!FlowGraphCompiler::SupportsUnboxedDoubles()) return false;
1129-
1130-
GraphEntryInstr* graph_entry = flow_graph->graph_entry();
1131-
auto normal_entry = graph_entry->normal_entry();
1132-
BlockBuilder builder(flow_graph, normal_entry);
1133-
1134-
return BuildInvokeMathCFunction(&builder, MethodRecognizer::kDoubleRound,
1135-
flow_graph);
1067+
return BuildInvokeMathCFunction(flow_graph, MethodRecognizer::kDoubleRound);
11361068
}
11371069

11381070
bool GraphIntrinsifier::Build_ImplicitGetter(FlowGraph* flow_graph) {

runtime/vm/compiler/recognized_methods_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ namespace dart {
289289
V(::, acos, MathAcos, 0xffb03167) \
290290
V(::, atan, MathAtan, 0xf1ecb41a) \
291291
V(::, atan2, MathAtan2, 0xff585505) \
292+
V(::, exp, MathExp, 0xbb87ac43) \
293+
V(::, log, MathLog, 0x27ec861f) \
292294

293295
#define GRAPH_TYPED_DATA_INTRINSICS_LIST(V) \
294296
V(_Int8List, [], Int8ArrayGetIndexed, 0x281e2e42) \

0 commit comments

Comments
 (0)