Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/compiler/basic-block-instrumentor.h" | |
| 6 #include "src/compiler/common-operator.h" | |
| 7 #include "src/compiler/graph.h" | |
| 8 #include "src/compiler/machine-operator.h" | |
| 9 #include "src/compiler/operator-properties-inl.h" | |
| 10 #include "src/compiler/schedule.h" | |
| 11 | |
| 12 namespace v8 { | |
| 13 namespace internal { | |
| 14 namespace compiler { | |
| 15 | |
| 16 static NodeVector::iterator FindInsertionPoint(NodeVector* nodes) { | |
|
titzer
2014/09/24 14:59:31
Comment me.
dcarney
2014/09/25 08:15:15
Done.
| |
| 17 NodeVector::iterator i = nodes->begin(); | |
| 18 for (; i != nodes->end(); ++i) { | |
| 19 const Operator* op = (*i)->op(); | |
| 20 if (OperatorProperties::IsBasicBlockBegin(op)) continue; | |
| 21 switch (op->opcode()) { | |
| 22 case IrOpcode::kParameter: | |
| 23 case IrOpcode::kPhi: | |
| 24 case IrOpcode::kEffectPhi: | |
| 25 continue; | |
| 26 } | |
| 27 break; | |
| 28 } | |
| 29 return i; | |
| 30 } | |
| 31 | |
| 32 | |
| 33 BasicBlockProfiler::Data* BasicBlockInstrumentor::Instrument( | |
| 34 CompilationInfo* info, Graph* graph, Schedule* schedule) { | |
| 35 // Apply filter. | |
| 36 if (!info->closure().is_null() && | |
| 37 !info->closure()->PassesFilter(FLAG_turbo_profiling_filter)) { | |
| 38 return NULL; | |
| 39 } | |
| 40 size_t n_blocks = static_cast<size_t>(schedule->RpoBlockCount()); | |
| 41 BasicBlockProfiler::Data* data = | |
| 42 info->isolate()->GetOrCreateBasicBlockProfiler()->NewData(n_blocks); | |
| 43 // Set the function name. | |
| 44 if (!info->shared_info().is_null() && | |
| 45 info->shared_info()->name()->IsString()) { | |
| 46 OStringStream os; | |
| 47 String::cast(info->shared_info()->name())->PrintUC16(os); | |
| 48 data->SetFunctionName(&os); | |
| 49 } | |
| 50 // Capture the schedule string before instrumentation. | |
| 51 { | |
| 52 OStringStream os; | |
| 53 os << *schedule; | |
| 54 data->SetSchedule(&os); | |
| 55 } | |
| 56 // Add the increment instructions to the start of every block. | |
| 57 CommonOperatorBuilder common(graph->zone()); | |
| 58 uint32_t* counts = data->counts(); | |
| 59 intptr_t base_address = reinterpret_cast<intptr_t>(counts); | |
| 60 // TODO(dcarney): need to mark code as non-serializable. | |
| 61 const Operator* base_op = | |
| 62 kPointerSize == 8 ? common.Int64Constant(base_address) | |
| 63 : common.Int32Constant(static_cast<int>(base_address)); | |
| 64 Node* base = graph->NewNode(base_op); | |
| 65 Node* one = graph->NewNode(common.Int32Constant(1)); | |
| 66 MachineOperatorBuilder machine; | |
| 67 BasicBlockVector* blocks = schedule->rpo_order(); | |
| 68 int block_number = 0; | |
| 69 int* block_ids = data->block_ids(); | |
| 70 for (BasicBlockVector::iterator it = blocks->begin(); it != blocks->end(); | |
| 71 ++it, ++block_number) { | |
| 72 BasicBlock* block = (*it); | |
|
titzer
2014/09/24 14:59:31
Pull me out into a separate function
dcarney
2014/09/25 08:15:14
that would be ugly
| |
| 73 block_ids[block_number] = block->id(); | |
| 74 // Don't instrument exit block. Register allocator doesn't like this. | |
| 75 if (static_cast<size_t>(block_number) == n_blocks - 1) { | |
| 76 continue; | |
| 77 } | |
| 78 // Construct increment operation. | |
| 79 int index_value = sizeof(counts[0]) * block_number; | |
| 80 Node* index = graph->NewNode(common.Int32Constant(index_value)); | |
| 81 // TODO(dcarney): wire effect and control deps for load and store. | |
| 82 Node* load = graph->NewNode(machine.Load(kMachUint32), base, index); | |
|
titzer
2014/09/24 14:59:31
I'd just smash in the direct pointer into the midd
dcarney
2014/09/25 08:15:14
Done.
| |
| 83 Node* inc = graph->NewNode(machine.Int32Add(), load, one); | |
| 84 Node* store = graph->NewNode( | |
| 85 machine.Store(StoreRepresentation(kMachUint32, kNoWriteBarrier)), base, | |
| 86 index, inc); | |
| 87 // skip parameters and phis when inserting. | |
| 88 static const int kArraySize = 6; | |
| 89 Node* to_insert[kArraySize] = {base, one, index, load, inc, store}; | |
| 90 int insertion_start = block_number == 0 ? 0 : 2; | |
| 91 NodeVector* nodes = &block->nodes_; | |
| 92 NodeVector::iterator insertion_point = FindInsertionPoint(nodes); | |
| 93 nodes->insert(insertion_point, &to_insert[insertion_start], | |
| 94 &to_insert[kArraySize]); | |
| 95 for (int i = insertion_start; i < kArraySize; ++i) { | |
| 96 schedule->SetBlockForNode(block, to_insert[i]); | |
| 97 } | |
| 98 } | |
| 99 return data; | |
| 100 } | |
| 101 | |
| 102 } // namespace compiler | |
| 103 } // namespace internal | |
| 104 } // namespace v8 | |
| OLD | NEW |