Commit ecfbc749 authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

Add stack load/store counters for x64

The change instruments code generation for Gap Solver so that these
counters are run-time and didn't impact register allocation.

The implementation is put behind a flag to help better register
allocation analysis.

Bug: v8:10663
Change-Id: Ia342d990e2b2bfc6a7653a770f670e51eef71312
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2269362
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarSeth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#68664}
parent b804266f
......@@ -424,6 +424,14 @@ ExternalReference ExternalReference::address_of_runtime_stats_flag() {
return ExternalReference(&TracingFlags::runtime_stats);
}
ExternalReference ExternalReference::address_of_load_from_stack_count() {
return ExternalReference(Isolate::load_from_stack_count_address());
}
ExternalReference ExternalReference::address_of_store_to_stack_count() {
return ExternalReference(Isolate::store_to_stack_count_address());
}
ExternalReference ExternalReference::address_of_one_half() {
return ExternalReference(
reinterpret_cast<Address>(&double_one_half_constant));
......
......@@ -98,6 +98,8 @@ class StatsCounter;
"FLAG_mock_arraybuffer_allocator") \
V(address_of_one_half, "LDoubleConstant::one_half") \
V(address_of_runtime_stats_flag, "TracingFlags::runtime_stats") \
V(address_of_load_from_stack_count, "load_from_stack_count") \
V(address_of_store_to_stack_count, "store_to_stack_count") \
V(address_of_the_hole_nan, "the_hole_nan") \
V(address_of_uint32_bias, "uint32_bias") \
V(bytecode_size_table_address, "Bytecodes::bytecode_size_table_address") \
......
......@@ -354,6 +354,9 @@ class V8_EXPORT_PRIVATE CodeGenerator final : public GapResolver::Assembler {
void FinishCode();
void MaybeEmitOutOfLineConstantPool();
void IncrementStackAccessCounter(InstructionOperand* source,
InstructionOperand* destination);
// ===========================================================================
// ============== Architecture-specific gap resolver methods. ================
// ===========================================================================
......
......@@ -4670,6 +4670,20 @@ void CodeGenerator::FinishCode() { tasm()->PatchConstPool(); }
void CodeGenerator::PrepareForDeoptimizationExits(int deopt_count) {}
void CodeGenerator::IncrementStackAccessCounter(
InstructionOperand* source, InstructionOperand* destination) {
DCHECK(FLAG_trace_turbo_stack_accesses);
auto IncrementCounter = [&](ExternalReference counter) {
__ incl(__ ExternalReferenceAsOperand(counter));
};
if (source->IsAnyStackSlot()) {
IncrementCounter(ExternalReference::address_of_load_from_stack_count());
}
if (destination->IsAnyStackSlot()) {
IncrementCounter(ExternalReference::address_of_store_to_stack_count());
}
}
void CodeGenerator::AssembleMove(InstructionOperand* source,
InstructionOperand* destination) {
X64OperandConverter g(this, nullptr);
......@@ -4752,6 +4766,11 @@ void CodeGenerator::AssembleMove(InstructionOperand* source,
MoveConstantToRegister(kScratchRegister, src);
__ movq(dst, kScratchRegister);
};
if (FLAG_trace_turbo_stack_accesses) {
IncrementStackAccessCounter(source, destination);
}
// Dispatch on the source and destination operand kinds.
switch (MoveType::InferMove(source, destination)) {
case MoveType::kRegisterToRegister:
......@@ -4858,6 +4877,11 @@ void CodeGenerator::AssembleMove(InstructionOperand* source,
void CodeGenerator::AssembleSwap(InstructionOperand* source,
InstructionOperand* destination) {
if (FLAG_trace_turbo_stack_accesses) {
IncrementStackAccessCounter(source, destination);
IncrementStackAccessCounter(destination, source);
}
X64OperandConverter g(this, nullptr);
// Dispatch on the source and destination operand kinds. Not all
// combinations are possible.
......
......@@ -3321,6 +3321,14 @@ void Isolate::InitializeCodeRanges() {
SetCodePages(&code_pages_buffer1_);
}
namespace {
// Some global counters.
uint64_t load_from_stack_count = 0;
uint64_t store_to_stack_count = 0;
} // namespace
bool Isolate::Init(ReadOnlyDeserializer* read_only_deserializer,
StartupDeserializer* startup_deserializer) {
TRACE_ISOLATE(init);
......@@ -3655,6 +3663,13 @@ std::unique_ptr<PersistentHandles> Isolate::NewPersistentHandles() {
}
void Isolate::DumpAndResetStats() {
if (FLAG_trace_turbo_stack_accesses) {
StdoutStream os;
os << "=== Load from stack counter: " << load_from_stack_count << std::endl;
os << "=== Store to stack counter: " << store_to_stack_count << std::endl;
load_from_stack_count = 0;
store_to_stack_count = 0;
}
if (turbo_statistics() != nullptr) {
DCHECK(FLAG_turbo_stats || FLAG_turbo_stats_nvp);
StdoutStream os;
......@@ -4547,5 +4562,15 @@ void Isolate::RemoveCodeMemoryChunk(MemoryChunk* chunk) {
#undef TRACE_ISOLATE
// static
Address Isolate::load_from_stack_count_address() {
return reinterpret_cast<Address>(&load_from_stack_count);
}
// static
Address Isolate::store_to_stack_count_address() {
return reinterpret_cast<Address>(&store_to_stack_count);
}
} // namespace internal
} // namespace v8
......@@ -1527,6 +1527,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
bool RequiresCodeRange() const;
static Address load_from_stack_count_address();
static Address store_to_stack_count_address();
private:
explicit Isolate(std::unique_ptr<IsolateAllocator> isolate_allocator);
~Isolate();
......
......@@ -573,6 +573,9 @@ DEFINE_BOOL(trace_turbo_loop, false, "trace TurboFan's loop optimizations")
DEFINE_BOOL(trace_turbo_alloc, false, "trace TurboFan's register allocator")
DEFINE_BOOL(trace_all_uses, false, "trace all use positions")
DEFINE_BOOL(trace_representation, false, "trace representation types")
DEFINE_BOOL(
trace_turbo_stack_accesses, false,
"trace stack load/store counters for optimized code in run-time (x64 only)")
DEFINE_BOOL(turbo_verify, DEBUG_BOOL, "verify TurboFan graphs at each phase")
DEFINE_STRING(turbo_verify_machine_graph, nullptr,
"verify TurboFan machine graph before instruction selection")
......
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