Commit c6004a32 authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Clean up TRACE macros and use variadic macros.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1014853002

Cr-Commit-Position: refs/heads/master@{#27248}
parent 33514ec2
......@@ -14,6 +14,11 @@ namespace v8 {
namespace internal {
namespace compiler {
#define TRACE(...) \
do { \
if (FLAG_trace_turbo_scheduler) PrintF(__VA_ARGS__); \
} while (false)
// Determines control dependence equivalence classes for control nodes. Any two
// nodes having the same set of control dependences land in one class. These
// classes can in turn be used to:
......@@ -96,16 +101,16 @@ class ControlEquivalence : public ZoneObject {
// Called at pre-visit during DFS walk.
void VisitPre(Node* node) {
Trace("CEQ: Pre-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
TRACE("CEQ: Pre-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
// Dispense a new pre-order number.
SetNumber(node, NewDFSNumber());
Trace(" Assigned DFS number is %d\n", GetNumber(node));
TRACE(" Assigned DFS number is %zu\n", GetNumber(node));
}
// Called at mid-visit during DFS walk.
void VisitMid(Node* node, DFSDirection direction) {
Trace("CEQ: Mid-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
TRACE("CEQ: Mid-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
BracketList& blist = GetBracketList(node);
// Remove brackets pointing to this node [line:19].
......@@ -118,7 +123,7 @@ class ControlEquivalence : public ZoneObject {
}
// Potentially start a new equivalence class [line:37].
BracketListTrace(blist);
BracketListTRACE(blist);
Bracket* recent = &blist.back();
if (recent->recent_size != blist.size()) {
recent->recent_size = blist.size();
......@@ -127,12 +132,12 @@ class ControlEquivalence : public ZoneObject {
// Assign equivalence class to node.
SetClass(node, recent->recent_class);
Trace(" Assigned class number is %d\n", GetClass(node));
TRACE(" Assigned class number is %zu\n", GetClass(node));
}
// Called at post-visit during DFS walk.
void VisitPost(Node* node, Node* parent_node, DFSDirection direction) {
Trace("CEQ: Post-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
TRACE("CEQ: Post-visit of #%d:%s\n", node->id(), node->op()->mnemonic());
BracketList& blist = GetBracketList(node);
// Remove brackets pointing to this node [line:19].
......@@ -147,7 +152,7 @@ class ControlEquivalence : public ZoneObject {
// Called when hitting a back edge in the DFS walk.
void VisitBackedge(Node* from, Node* to, DFSDirection direction) {
Trace("CEQ: Backedge from #%d:%s to #%d:%s\n", from->id(),
TRACE("CEQ: Backedge from #%d:%s to #%d:%s\n", from->id(),
from->op()->mnemonic(), to->id(), to->op()->mnemonic());
// Push backedge onto the bracket list [line:25].
......@@ -316,7 +321,7 @@ class ControlEquivalence : public ZoneObject {
void BracketListDelete(BracketList& blist, Node* to, DFSDirection direction) {
for (BracketList::iterator i = blist.begin(); i != blist.end(); /*nop*/) {
if (i->to == to && i->direction != direction) {
Trace(" BList erased: {%d->%d}\n", i->from->id(), i->to->id());
TRACE(" BList erased: {%d->%d}\n", i->from->id(), i->to->id());
i = blist.erase(i);
} else {
++i;
......@@ -324,22 +329,13 @@ class ControlEquivalence : public ZoneObject {
}
}
void BracketListTrace(BracketList& blist) {
void BracketListTRACE(BracketList& blist) {
if (FLAG_trace_turbo_scheduler) {
Trace(" BList: ");
TRACE(" BList: ");
for (Bracket bracket : blist) {
Trace("{%d->%d} ", bracket.from->id(), bracket.to->id());
TRACE("{%d->%d} ", bracket.from->id(), bracket.to->id());
}
Trace("\n");
}
}
void Trace(const char* msg, ...) {
if (FLAG_trace_turbo_scheduler) {
va_list arguments;
va_start(arguments, msg);
base::OS::VPrint(msg, arguments);
va_end(arguments);
TRACE("\n");
}
}
......@@ -350,6 +346,8 @@ class ControlEquivalence : public ZoneObject {
Data node_data_; // Per-node data stored as a side-table.
};
#undef TRACE
} // namespace compiler
} // namespace internal
} // namespace v8
......
......@@ -15,6 +15,11 @@ namespace v8 {
namespace internal {
namespace compiler {
#define TRACE(...) \
do { \
if (FLAG_trace_turbo_reduction) PrintF(__VA_ARGS__); \
} while (false)
enum VisitState { kUnvisited = 0, kOnStack = 1, kRevisit = 2, kVisited = 3 };
enum Decision { kFalse, kUnknown, kTrue };
......@@ -42,9 +47,6 @@ class ReachabilityMarker : public NodeMarker<uint8_t> {
};
#define TRACE(x) \
if (FLAG_trace_turbo_reduction) PrintF x
class ControlReducerImpl {
public:
ControlReducerImpl(Zone* zone, JSGraph* jsgraph,
......@@ -112,7 +114,7 @@ class ControlReducerImpl {
while (!fw_stack.empty()) {
Node* node = fw_stack.back().first;
TRACE(("ControlFw: #%d:%s\n", node->id(), node->op()->mnemonic()));
TRACE("ControlFw: #%d:%s\n", node->id(), node->op()->mnemonic());
bool pop = true;
while (fw_stack.back().second != node->uses().end()) {
Node* succ = *(fw_stack.back().second);
......@@ -165,7 +167,7 @@ class ControlReducerImpl {
// Connect {loop}, the header of a non-terminating loop, to the end node.
Node* ConnectNTL(Node* loop) {
TRACE(("ConnectNTL: #%d:%s\n", loop->id(), loop->op()->mnemonic()));
TRACE("ConnectNTL: #%d:%s\n", loop->id(), loop->op()->mnemonic());
Node* always = graph()->NewNode(common_->Always());
// Mark the node as visited so that we can revisit later.
......@@ -280,9 +282,9 @@ class ControlReducerImpl {
for (Edge edge : node->use_edges()) {
Node* use = edge.from();
if (!marked.IsReachableFromEnd(use)) {
TRACE(("DeadLink: #%d:%s(%d) -> #%d:%s\n", use->id(),
use->op()->mnemonic(), edge.index(), node->id(),
node->op()->mnemonic()));
TRACE("DeadLink: #%d:%s(%d) -> #%d:%s\n", use->id(),
use->op()->mnemonic(), edge.index(), node->id(),
node->op()->mnemonic());
edge.UpdateTo(NULL);
}
}
......@@ -322,7 +324,7 @@ class ControlReducerImpl {
if (node->IsDead()) return Pop(); // Node was killed while on stack.
TRACE(("ControlReduce: #%d:%s\n", node->id(), node->op()->mnemonic()));
TRACE("ControlReduce: #%d:%s\n", node->id(), node->op()->mnemonic());
// Recurse on an input if necessary.
for (Node* const input : node->inputs()) {
......@@ -374,7 +376,7 @@ class ControlReducerImpl {
void Revisit(Node* node) {
size_t id = static_cast<size_t>(node->id());
if (id < state_.size() && state_[id] == kVisited) {
TRACE((" Revisit #%d:%s\n", node->id(), node->op()->mnemonic()));
TRACE(" Revisit #%d:%s\n", node->id(), node->op()->mnemonic());
state_[id] = kRevisit;
revisit_.push_back(node);
}
......@@ -398,7 +400,7 @@ class ControlReducerImpl {
// If a node has only one control input and it is dead, replace with dead.
Node* control = NodeProperties::GetControlInput(node);
if (control->opcode() == IrOpcode::kDead) {
TRACE(("ControlDead: #%d:%s\n", node->id(), node->op()->mnemonic()));
TRACE("ControlDead: #%d:%s\n", node->id(), node->op()->mnemonic());
return control;
}
}
......@@ -507,8 +509,8 @@ class ControlReducerImpl {
index++;
}
TRACE(("ReduceMerge: #%d:%s (%d live)\n", node->id(),
node->op()->mnemonic(), live));
TRACE("ReduceMerge: #%d:%s (%d live)\n", node->id(), node->op()->mnemonic(),
live);
if (live == 0) return dead(); // no remaining inputs.
......@@ -530,8 +532,8 @@ class ControlReducerImpl {
if (live < node->InputCount()) {
// Edit phis in place, removing dead inputs and revisiting them.
for (Node* const phi : phis) {
TRACE((" PhiInMerge: #%d:%s (%d live)\n", phi->id(),
phi->op()->mnemonic(), live));
TRACE(" PhiInMerge: #%d:%s (%d live)\n", phi->id(),
phi->op()->mnemonic(), live);
RemoveDeadInputs(node, phi);
Revisit(phi);
}
......@@ -557,9 +559,9 @@ class ControlReducerImpl {
// have users except for the Merge and the Merge has no Phi or
// EffectPhi uses, so replace the Merge with the control input of the
// diamond.
TRACE((" DeadDiamond: #%d:%s #%d:%s #%d:%s\n", node0->id(),
node0->op()->mnemonic(), node1->id(), node1->op()->mnemonic(),
branch0->id(), branch0->op()->mnemonic()));
TRACE(" DeadDiamond: #%d:%s #%d:%s #%d:%s\n", node0->id(),
node0->op()->mnemonic(), node1->id(), node1->op()->mnemonic(),
branch0->id(), branch0->op()->mnemonic());
return NodeProperties::GetControlInput(branch0);
}
}
......@@ -575,8 +577,8 @@ class ControlReducerImpl {
Decision result = DecideCondition(branch->InputAt(0));
if (result == kTrue) {
// fold a true branch by replacing IfTrue with the branch control.
TRACE(("BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
branch->op()->mnemonic(), node->id(), node->op()->mnemonic()));
TRACE("BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
branch->op()->mnemonic(), node->id(), node->op()->mnemonic());
return branch->InputAt(1);
}
return result == kUnknown ? node : dead();
......@@ -589,8 +591,8 @@ class ControlReducerImpl {
Decision result = DecideCondition(branch->InputAt(0));
if (result == kFalse) {
// fold a false branch by replacing IfFalse with the branch control.
TRACE(("BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
branch->op()->mnemonic(), node->id(), node->op()->mnemonic()));
TRACE("BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
branch->op()->mnemonic(), node->id(), node->op()->mnemonic());
return branch->InputAt(1);
}
return result == kUnknown ? node : dead();
......@@ -622,9 +624,8 @@ class ControlReducerImpl {
// Replace uses of {node} with {replacement} and revisit the uses.
void ReplaceNode(Node* node, Node* replacement) {
if (node == replacement) return;
TRACE((" Replace: #%d:%s with #%d:%s\n", node->id(),
node->op()->mnemonic(), replacement->id(),
replacement->op()->mnemonic()));
TRACE(" Replace: #%d:%s with #%d:%s\n", node->id(), node->op()->mnemonic(),
replacement->id(), replacement->op()->mnemonic());
for (Node* const use : node->uses()) {
// Don't revisit this node if it refers to itself.
if (use != node) Revisit(use);
......
......@@ -23,6 +23,11 @@ namespace v8 {
namespace internal {
namespace compiler {
#define TRACE(...) \
do { \
if (FLAG_trace_turbo_inlining) PrintF(__VA_ARGS__); \
} while (false)
// Provides convenience accessors for calls to JS functions.
class JSCallFunctionAccessor {
......@@ -322,21 +327,15 @@ Reduction JSInliner::Reduce(Node* node) {
if (info.scope()->arguments() != NULL && is_sloppy(info.language_mode())) {
// For now do not inline functions that use their arguments array.
SmartArrayPointer<char> name = function->shared()->DebugName()->ToCString();
if (FLAG_trace_turbo_inlining) {
PrintF(
"Not Inlining %s into %s because inlinee uses arguments "
"array\n",
name.get(), info_->shared_info()->DebugName()->ToCString().get());
}
TRACE("Not Inlining %s into %s because inlinee uses arguments array\n",
function->shared()->DebugName()->ToCString().get(),
info_->shared_info()->DebugName()->ToCString().get());
return NoChange();
}
if (FLAG_trace_turbo_inlining) {
SmartArrayPointer<char> name = function->shared()->DebugName()->ToCString();
PrintF("Inlining %s into %s\n", name.get(),
info_->shared_info()->DebugName()->ToCString().get());
}
TRACE("Inlining %s into %s\n",
function->shared()->DebugName()->ToCString().get(),
info_->shared_info()->DebugName()->ToCString().get());
Graph graph(info.zone());
JSGraph jsgraph(info.isolate(), &graph, jsgraph_->common(),
......
......@@ -9,8 +9,10 @@ namespace v8 {
namespace internal {
namespace compiler {
#define TRACE(x) \
if (FLAG_trace_turbo_jt) PrintF x
#define TRACE(...) \
do { \
if (FLAG_trace_turbo_jt) PrintF(__VA_ARGS__); \
} while (false)
struct JumpThreadingState {
bool forwarded;
......@@ -29,19 +31,19 @@ struct JumpThreadingState {
RpoNumber to_to = result[to.ToInt()];
bool pop = true;
if (to == from) {
TRACE((" xx %d\n", from.ToInt()));
TRACE(" xx %d\n", from.ToInt());
result[from.ToInt()] = from;
} else if (to_to == unvisited()) {
TRACE((" fw %d -> %d (recurse)\n", from.ToInt(), to.ToInt()));
TRACE(" fw %d -> %d (recurse)\n", from.ToInt(), to.ToInt());
stack.push(to);
result[to.ToInt()] = onstack();
pop = false; // recurse.
} else if (to_to == onstack()) {
TRACE((" fw %d -> %d (cycle)\n", from.ToInt(), to.ToInt()));
TRACE(" fw %d -> %d (cycle)\n", from.ToInt(), to.ToInt());
result[from.ToInt()] = to; // break the cycle.
forwarded = true;
} else {
TRACE((" fw %d -> %d (forward)\n", from.ToInt(), to.ToInt()));
TRACE(" fw %d -> %d (forward)\n", from.ToInt(), to.ToInt());
result[from.ToInt()] = to_to; // forward the block.
forwarded = true;
}
......@@ -68,36 +70,36 @@ bool JumpThreading::ComputeForwarding(Zone* local_zone,
while (!state.stack.empty()) {
InstructionBlock* block = code->InstructionBlockAt(state.stack.top());
// Process the instructions in a block up to a non-empty instruction.
TRACE(("jt [%d] B%d\n", static_cast<int>(stack.size()),
block->rpo_number().ToInt()));
TRACE("jt [%d] B%d\n", static_cast<int>(stack.size()),
block->rpo_number().ToInt());
bool fallthru = true;
RpoNumber fw = block->rpo_number();
for (int i = block->code_start(); i < block->code_end(); ++i) {
Instruction* instr = code->InstructionAt(i);
if (instr->IsGapMoves() && GapInstruction::cast(instr)->IsRedundant()) {
// skip redundant gap moves.
TRACE((" nop gap\n"));
TRACE(" nop gap\n");
continue;
} else if (instr->IsSourcePosition()) {
// skip source positions.
TRACE((" src pos\n"));
TRACE(" src pos\n");
continue;
} else if (FlagsModeField::decode(instr->opcode()) != kFlags_none) {
// can't skip instructions with flags continuations.
TRACE((" flags\n"));
TRACE(" flags\n");
fallthru = false;
} else if (instr->IsNop()) {
// skip nops.
TRACE((" nop\n"));
TRACE(" nop\n");
continue;
} else if (instr->arch_opcode() == kArchJmp) {
// try to forward the jump instruction.
TRACE((" jmp\n"));
TRACE(" jmp\n");
fw = code->InputRpo(instr, 0);
fallthru = false;
} else {
// can't skip other instructions.
TRACE((" other\n"));
TRACE(" other\n");
fallthru = false;
}
break;
......@@ -118,12 +120,12 @@ bool JumpThreading::ComputeForwarding(Zone* local_zone,
if (FLAG_trace_turbo_jt) {
for (int i = 0; i < static_cast<int>(result.size()); i++) {
TRACE(("B%d ", i));
TRACE("B%d ", i);
int to = result[i].ToInt();
if (i != to) {
TRACE(("-> B%d\n", to));
TRACE("-> B%d\n", to);
} else {
TRACE(("\n"));
TRACE("\n");
}
}
}
......@@ -153,7 +155,7 @@ void JumpThreading::ApplyForwarding(ZoneVector<RpoNumber>& result,
} else if (instr->arch_opcode() == kArchJmp) {
if (skip[block_num]) {
// Overwrite a redundant jump with a nop.
TRACE(("jt-fw nop @%d\n", i));
TRACE("jt-fw nop @%d\n", i);
instr->OverwriteWithNop();
}
fallthru = false; // jumps don't fall through to the next block.
......
This diff is collapsed.
......@@ -25,8 +25,10 @@ namespace internal {
namespace compiler {
// Macro for outputting trace information from representation inference.
#define TRACE(x) \
if (FLAG_trace_representation) PrintF x
#define TRACE(...) \
do { \
if (FLAG_trace_representation) PrintF(__VA_ARGS__); \
} while (false)
// Representation selection and lowering of {Simplified} operators to machine
// operators are interwined. We use a fixpoint calculation to compute both the
......@@ -85,7 +87,7 @@ class RepresentationSelector {
void Run(SimplifiedLowering* lowering) {
// Run propagation phase to a fixpoint.
TRACE(("--{Propagation phase}--\n"));
TRACE("--{Propagation phase}--\n");
phase_ = PROPAGATE;
Enqueue(jsgraph_->graph()->end());
// Process nodes from the queue until it is empty.
......@@ -94,20 +96,20 @@ class RepresentationSelector {
NodeInfo* info = GetInfo(node);
queue_.pop();
info->queued = false;
TRACE((" visit #%d: %s\n", node->id(), node->op()->mnemonic()));
TRACE(" visit #%d: %s\n", node->id(), node->op()->mnemonic());
VisitNode(node, info->use, NULL);
TRACE((" ==> output "));
TRACE(" ==> output ");
PrintInfo(info->output);
TRACE(("\n"));
TRACE("\n");
}
// Run lowering and change insertion phase.
TRACE(("--{Simplified lowering phase}--\n"));
TRACE("--{Simplified lowering phase}--\n");
phase_ = LOWER;
// Process nodes from the collected {nodes_} vector.
for (NodeVector::iterator i = nodes_.begin(); i != nodes_.end(); ++i) {
Node* node = *i;
TRACE((" visit #%d: %s\n", node->id(), node->op()->mnemonic()));
TRACE(" visit #%d: %s\n", node->id(), node->op()->mnemonic());
// Reuse {VisitNode()} so the representation rules are in one place.
if (FLAG_turbo_source_positions) {
SourcePositionTable::Scope scope(
......@@ -143,21 +145,21 @@ class RepresentationSelector {
info->queued = true;
nodes_.push_back(node);
queue_.push(node);
TRACE((" initial: "));
TRACE(" initial: ");
info->use |= use;
PrintUseInfo(node);
return;
}
TRACE((" queue?: "));
TRACE(" queue?: ");
PrintUseInfo(node);
if ((info->use & use) != use) {
// New usage information for the node is available.
if (!info->queued) {
queue_.push(node);
info->queued = true;
TRACE((" added: "));
TRACE(" added: ");
} else {
TRACE((" inqueue: "));
TRACE(" inqueue: ");
}
info->use |= use;
PrintUseInfo(node);
......@@ -195,14 +197,14 @@ class RepresentationSelector {
MachineTypeUnion output = GetInfo(input)->output;
if ((output & (kRepBit | kRepWord8 | kRepWord16 | kRepWord32)) == 0) {
// Output representation doesn't match usage.
TRACE((" truncate-to-int32: #%d:%s(@%d #%d:%s) ", node->id(),
node->op()->mnemonic(), index, input->id(),
input->op()->mnemonic()));
TRACE((" from "));
TRACE(" truncate-to-int32: #%d:%s(@%d #%d:%s) ", node->id(),
node->op()->mnemonic(), index, input->id(),
input->op()->mnemonic());
TRACE(" from ");
PrintInfo(output);
TRACE((" to "));
TRACE(" to ");
PrintInfo(use);
TRACE(("\n"));
TRACE("\n");
Node* n = changer_->GetTruncatedWord32For(input, output);
node->ReplaceInput(index, n);
}
......@@ -220,14 +222,14 @@ class RepresentationSelector {
MachineTypeUnion output = GetInfo(input)->output;
if ((output & kRepMask & use) == 0) {
// Output representation doesn't match usage.
TRACE((" change: #%d:%s(@%d #%d:%s) ", node->id(),
node->op()->mnemonic(), index, input->id(),
input->op()->mnemonic()));
TRACE((" from "));
TRACE(" change: #%d:%s(@%d #%d:%s) ", node->id(),
node->op()->mnemonic(), index, input->id(),
input->op()->mnemonic());
TRACE(" from ");
PrintInfo(output);
TRACE((" to "));
TRACE(" to ");
PrintInfo(use);
TRACE(("\n"));
TRACE("\n");
Node* n = changer_->GetRepresentationFor(input, output, use);
node->ReplaceInput(index, n);
}
......@@ -1049,11 +1051,10 @@ class RepresentationSelector {
}
void DeferReplacement(Node* node, Node* replacement) {
if (FLAG_trace_representation) {
TRACE(("defer replacement #%d:%s with #%d:%s\n", node->id(),
node->op()->mnemonic(), replacement->id(),
replacement->op()->mnemonic()));
}
TRACE("defer replacement #%d:%s with #%d:%s\n", node->id(),
node->op()->mnemonic(), replacement->id(),
replacement->op()->mnemonic());
if (replacement->id() < count_ &&
GetInfo(replacement)->output == GetInfo(node)->output) {
// Replace with a previously existing node eagerly only if the type is the
......@@ -1071,9 +1072,9 @@ class RepresentationSelector {
}
void PrintUseInfo(Node* node) {
TRACE(("#%d:%-20s ", node->id(), node->op()->mnemonic()));
TRACE("#%d:%-20s ", node->id(), node->op()->mnemonic());
PrintInfo(GetUseInfo(node));
TRACE(("\n"));
TRACE("\n");
}
void PrintInfo(MachineTypeUnion info) {
......
......@@ -17,7 +17,7 @@ namespace compiler {
do { \
Node* __n[] = {__VA_ARGS__}; \
ASSERT_TRUE(IsEquivalenceClass(arraysize(__n), __n)); \
} while (false);
} while (false)
class ControlEquivalenceTest : public GraphTest {
public:
......
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