V8 Project
v8::internal::compiler::BasicBlockInstrumentor Class Reference

#include <basic-block-instrumentor.h>

+ Inheritance diagram for v8::internal::compiler::BasicBlockInstrumentor:
+ Collaboration diagram for v8::internal::compiler::BasicBlockInstrumentor:

Static Public Member Functions

static BasicBlockProfiler::DataInstrument (CompilationInfo *info, Graph *graph, Schedule *schedule)
 

Detailed Description

Definition at line 22 of file basic-block-instrumentor.h.

Member Function Documentation

◆ Instrument()

BasicBlockProfiler::Data * v8::internal::compiler::BasicBlockInstrumentor::Instrument ( CompilationInfo info,
Graph graph,
Schedule schedule 
)
static

Definition at line 45 of file basic-block-instrumentor.cc.

46  {
47  // Skip the exit block in profiles, since the register allocator can't handle
48  // it and entry into it means falling off the end of the function anyway.
49  size_t n_blocks = static_cast<size_t>(schedule->RpoBlockCount()) - 1;
50  BasicBlockProfiler::Data* data =
51  info->isolate()->GetOrCreateBasicBlockProfiler()->NewData(n_blocks);
52  // Set the function name.
53  if (!info->shared_info().is_null() &&
54  info->shared_info()->name()->IsString()) {
55  OStringStream os;
56  String::cast(info->shared_info()->name())->PrintUC16(os);
57  data->SetFunctionName(&os);
58  }
59  // Capture the schedule string before instrumentation.
60  {
61  OStringStream os;
62  os << *schedule;
63  data->SetSchedule(&os);
64  }
65  // Add the increment instructions to the start of every block.
66  CommonOperatorBuilder common(graph->zone());
67  Node* zero = graph->NewNode(common.Int32Constant(0));
68  Node* one = graph->NewNode(common.Int32Constant(1));
69  MachineOperatorBuilder machine;
70  BasicBlockVector* blocks = schedule->rpo_order();
71  size_t block_number = 0;
72  for (BasicBlockVector::iterator it = blocks->begin(); block_number < n_blocks;
73  ++it, ++block_number) {
74  BasicBlock* block = (*it);
75  data->SetBlockId(block_number, block->id());
76  // TODO(dcarney): wire effect and control deps for load and store.
77  // Construct increment operation.
78  Node* base = graph->NewNode(
79  PointerConstant(&common, data->GetCounterAddress(block_number)));
80  Node* load = graph->NewNode(machine.Load(kMachUint32), base, zero);
81  Node* inc = graph->NewNode(machine.Int32Add(), load, one);
82  Node* store = graph->NewNode(
83  machine.Store(StoreRepresentation(kMachUint32, kNoWriteBarrier)), base,
84  zero, inc);
85  // Insert the new nodes.
86  static const int kArraySize = 6;
87  Node* to_insert[kArraySize] = {zero, one, base, load, inc, store};
88  int insertion_start = block_number == 0 ? 0 : 2;
89  NodeVector* nodes = &block->nodes_;
90  NodeVector::iterator insertion_point = FindInsertionPoint(nodes);
91  nodes->insert(insertion_point, &to_insert[insertion_start],
92  &to_insert[kArraySize]);
93  // Tell the scheduler about the new nodes.
94  for (int i = insertion_start; i < kArraySize; ++i) {
95  schedule->SetBlockForNode(block, to_insert[i]);
96  }
97  }
98  return data;
99 }
ZoneVector< Node * > NodeVector
Definition: node.h:72
ZoneVector< BasicBlock * > BasicBlockVector
Definition: schedule.h:149
static const Operator * PointerConstant(CommonOperatorBuilder *common, void *ptr)
static NodeVector::iterator FindInsertionPoint(NodeVector *nodes)

References v8::internal::compiler::FindInsertionPoint(), v8::internal::BasicBlockProfiler::Data::GetCounterAddress(), v8::internal::Isolate::GetOrCreateBasicBlockProfiler(), v8::internal::CompilationInfo::isolate(), v8::internal::compiler::kMachUint32, v8::internal::compiler::kNoWriteBarrier, v8::internal::BasicBlockProfiler::NewData(), v8::internal::compiler::Graph::NewNode(), v8::internal::compiler::PointerConstant(), v8::internal::compiler::Schedule::rpo_order(), v8::internal::compiler::Schedule::RpoBlockCount(), v8::internal::compiler::Schedule::SetBlockForNode(), v8::internal::BasicBlockProfiler::Data::SetBlockId(), v8::internal::BasicBlockProfiler::Data::SetFunctionName(), v8::internal::BasicBlockProfiler::Data::SetSchedule(), v8::internal::CompilationInfo::shared_info(), v8::internal::zero, and v8::internal::compiler::GenericGraphBase::zone().

Referenced by v8::internal::compiler::Pipeline::GenerateCode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: