Commit 40b5c1d4 authored by danno's avatar danno Committed by Commit bot

[turbofan] Add comments to CodeAssembler

Review-Url: https://codereview.chromium.org/2056503003
Cr-Commit-Position: refs/heads/master@{#36842}
parent fe561a7a
...@@ -790,6 +790,8 @@ Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map, ...@@ -790,6 +790,8 @@ Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map,
int base_size = JSArray::kSize + FixedArray::kHeaderSize; int base_size = JSArray::kSize + FixedArray::kHeaderSize;
int elements_offset = JSArray::kSize; int elements_offset = JSArray::kSize;
Comment("begin allocation of JSArray");
if (allocation_site != nullptr) { if (allocation_site != nullptr) {
base_size += AllocationMemento::kSize; base_size += AllocationMemento::kSize;
elements_offset += AllocationMemento::kSize; elements_offset += AllocationMemento::kSize;
......
...@@ -590,6 +590,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -590,6 +590,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kArchDebugBreak: case kArchDebugBreak:
__ stop("kArchDebugBreak"); __ stop("kArchDebugBreak");
break; break;
case kArchComment: {
Address comment_string = i.InputExternalReference(0).address();
__ RecordComment(reinterpret_cast<const char*>(comment_string));
break;
}
case kArchNop: case kArchNop:
case kArchThrowTerminator: case kArchThrowTerminator:
// don't emit code for nops. // don't emit code for nops.
......
...@@ -717,6 +717,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -717,6 +717,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kArchDebugBreak: case kArchDebugBreak:
__ Debug("kArchDebugBreak", 0, BREAK); __ Debug("kArchDebugBreak", 0, BREAK);
break; break;
case kArchComment: {
Address comment_string = i.InputExternalReference(0).address();
__ RecordComment(reinterpret_cast<const char*>(comment_string));
break;
}
case kArchNop: case kArchNop:
case kArchThrowTerminator: case kArchThrowTerminator:
// don't emit code for nops. // don't emit code for nops.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "src/interpreter/bytecodes.h" #include "src/interpreter/bytecodes.h"
#include "src/machine-type.h" #include "src/machine-type.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
#include "src/utils.h"
#include "src/zone.h" #include "src/zone.h"
namespace v8 { namespace v8 {
...@@ -162,6 +163,25 @@ void CodeAssembler::Return(Node* value) { ...@@ -162,6 +163,25 @@ void CodeAssembler::Return(Node* value) {
void CodeAssembler::DebugBreak() { raw_assembler_->DebugBreak(); } void CodeAssembler::DebugBreak() { raw_assembler_->DebugBreak(); }
void CodeAssembler::Comment(const char* format, ...) {
if (!FLAG_code_comments) return;
char buffer[4 * KB];
StringBuilder builder(buffer, arraysize(buffer));
va_list arguments;
va_start(arguments, format);
builder.AddFormattedList(format, arguments);
va_end(arguments);
// Copy the string before recording it in the assembler to avoid
// issues when the stack allocated buffer goes out of scope.
size_t length = builder.position() + 3;
char* copy = reinterpret_cast<char*>(malloc(static_cast<int>(length)));
MemCopy(copy + 2, builder.Finalize(), length);
copy[0] = ';';
copy[1] = ' ';
raw_assembler_->Comment(copy);
}
void CodeAssembler::Bind(CodeAssembler::Label* label) { return label->Bind(); } void CodeAssembler::Bind(CodeAssembler::Label* label) { return label->Bind(); }
Node* CodeAssembler::LoadFramePointer() { Node* CodeAssembler::LoadFramePointer() {
......
...@@ -212,6 +212,7 @@ class CodeAssembler { ...@@ -212,6 +212,7 @@ class CodeAssembler {
void Return(Node* value); void Return(Node* value);
void DebugBreak(); void DebugBreak();
void Comment(const char* format, ...);
void Bind(Label* label); void Bind(Label* label);
void Goto(Label* label); void Goto(Label* label);
......
...@@ -539,6 +539,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -539,6 +539,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kArchTableSwitch: case kArchTableSwitch:
AssembleArchTableSwitch(instr); AssembleArchTableSwitch(instr);
break; break;
case kArchComment: {
Address comment_string = i.InputExternalReference(0).address();
__ RecordComment(reinterpret_cast<const char*>(comment_string));
break;
}
case kArchDebugBreak: case kArchDebugBreak:
__ int3(); __ int3();
break; break;
......
...@@ -57,6 +57,7 @@ enum class RecordWriteMode { kValueIsMap, kValueIsPointer, kValueIsAny }; ...@@ -57,6 +57,7 @@ enum class RecordWriteMode { kValueIsMap, kValueIsPointer, kValueIsAny };
V(ArchTableSwitch) \ V(ArchTableSwitch) \
V(ArchNop) \ V(ArchNop) \
V(ArchDebugBreak) \ V(ArchDebugBreak) \
V(ArchComment) \
V(ArchThrowTerminator) \ V(ArchThrowTerminator) \
V(ArchDeoptimize) \ V(ArchDeoptimize) \
V(ArchRet) \ V(ArchRet) \
......
...@@ -223,6 +223,7 @@ int InstructionScheduler::GetInstructionFlags(const Instruction* instr) const { ...@@ -223,6 +223,7 @@ int InstructionScheduler::GetInstructionFlags(const Instruction* instr) const {
case kArchTruncateDoubleToI: case kArchTruncateDoubleToI:
case kArchStackSlot: case kArchStackSlot:
case kArchDebugBreak: case kArchDebugBreak:
case kArchComment:
return kNoOpcodeFlags; return kNoOpcodeFlags;
case kArchStackPointer: case kArchStackPointer:
......
...@@ -219,6 +219,7 @@ class OperandGenerator { ...@@ -219,6 +219,7 @@ class OperandGenerator {
case IrOpcode::kNumberConstant: case IrOpcode::kNumberConstant:
return Constant(OpParameter<double>(node)); return Constant(OpParameter<double>(node));
case IrOpcode::kExternalConstant: case IrOpcode::kExternalConstant:
case IrOpcode::kComment:
return Constant(OpParameter<ExternalReference>(node)); return Constant(OpParameter<ExternalReference>(node));
case IrOpcode::kHeapConstant: case IrOpcode::kHeapConstant:
return Constant(OpParameter<Handle<HeapObject>>(node)); return Constant(OpParameter<Handle<HeapObject>>(node));
......
...@@ -907,7 +907,10 @@ void InstructionSelector::VisitNode(Node* node) { ...@@ -907,7 +907,10 @@ void InstructionSelector::VisitNode(Node* node) {
case IrOpcode::kObjectState: case IrOpcode::kObjectState:
return; return;
case IrOpcode::kDebugBreak: case IrOpcode::kDebugBreak:
VisitDebugBreak(); VisitDebugBreak(node);
return;
case IrOpcode::kComment:
VisitComment(node);
return; return;
case IrOpcode::kLoad: { case IrOpcode::kLoad: {
LoadRepresentation type = LoadRepresentationOf(node->op()); LoadRepresentation type = LoadRepresentationOf(node->op());
...@@ -1800,11 +1803,17 @@ void InstructionSelector::VisitThrow(Node* value) { ...@@ -1800,11 +1803,17 @@ void InstructionSelector::VisitThrow(Node* value) {
Emit(kArchThrowTerminator, g.NoOutput()); Emit(kArchThrowTerminator, g.NoOutput());
} }
void InstructionSelector::VisitDebugBreak() { void InstructionSelector::VisitDebugBreak(Node* node) {
OperandGenerator g(this); OperandGenerator g(this);
Emit(kArchDebugBreak, g.NoOutput()); Emit(kArchDebugBreak, g.NoOutput());
} }
void InstructionSelector::VisitComment(Node* node) {
OperandGenerator g(this);
InstructionOperand operand(g.UseImmediate(node));
Emit(kArchComment, 0, nullptr, 1, &operand);
}
FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor( FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor(
Node* state) { Node* state) {
DCHECK(state->opcode() == IrOpcode::kFrameState); DCHECK(state->opcode() == IrOpcode::kFrameState);
......
...@@ -265,7 +265,6 @@ class InstructionSelector final { ...@@ -265,7 +265,6 @@ class InstructionSelector final {
void VisitDeoptimize(DeoptimizeKind kind, Node* value); void VisitDeoptimize(DeoptimizeKind kind, Node* value);
void VisitReturn(Node* ret); void VisitReturn(Node* ret);
void VisitThrow(Node* value); void VisitThrow(Node* value);
void VisitDebugBreak();
void EmitPrepareArguments(ZoneVector<compiler::PushParameter>* arguments, void EmitPrepareArguments(ZoneVector<compiler::PushParameter>* arguments,
const CallDescriptor* descriptor, Node* node); const CallDescriptor* descriptor, Node* node);
......
...@@ -538,6 +538,11 @@ struct MachineOperatorGlobalCache { ...@@ -538,6 +538,11 @@ struct MachineOperatorGlobalCache {
DebugBreakOperator kDebugBreak; DebugBreakOperator kDebugBreak;
}; };
struct CommentOperator : public Operator1<const char*> {
explicit CommentOperator(const char* msg)
: Operator1<const char*>(IrOpcode::kComment, Operator::kNoThrow,
"Comment", 0, 0, 0, 0, 0, 0, msg) {}
};
static base::LazyInstance<MachineOperatorGlobalCache>::type kCache = static base::LazyInstance<MachineOperatorGlobalCache>::type kCache =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
...@@ -545,7 +550,8 @@ static base::LazyInstance<MachineOperatorGlobalCache>::type kCache = ...@@ -545,7 +550,8 @@ static base::LazyInstance<MachineOperatorGlobalCache>::type kCache =
MachineOperatorBuilder::MachineOperatorBuilder( MachineOperatorBuilder::MachineOperatorBuilder(
Zone* zone, MachineRepresentation word, Flags flags, Zone* zone, MachineRepresentation word, Flags flags,
AlignmentRequirements alignmentRequirements) AlignmentRequirements alignmentRequirements)
: cache_(kCache.Get()), : zone_(zone),
cache_(kCache.Get()),
word_(word), word_(word),
flags_(flags), flags_(flags),
alignment_requirements_(alignmentRequirements) { alignment_requirements_(alignmentRequirements) {
...@@ -620,6 +626,10 @@ const Operator* MachineOperatorBuilder::DebugBreak() { ...@@ -620,6 +626,10 @@ const Operator* MachineOperatorBuilder::DebugBreak() {
return &cache_.kDebugBreak; return &cache_.kDebugBreak;
} }
const Operator* MachineOperatorBuilder::Comment(const char* msg) {
return new (zone_) CommentOperator(msg);
}
const Operator* MachineOperatorBuilder::CheckedLoad( const Operator* MachineOperatorBuilder::CheckedLoad(
CheckedLoadRepresentation rep) { CheckedLoadRepresentation rep) {
#define LOAD(Type) \ #define LOAD(Type) \
......
...@@ -194,6 +194,7 @@ class MachineOperatorBuilder final : public ZoneObject { ...@@ -194,6 +194,7 @@ class MachineOperatorBuilder final : public ZoneObject {
AlignmentRequirements alignmentRequirements = AlignmentRequirements alignmentRequirements =
AlignmentRequirements::NoUnalignedAccessSupport()); AlignmentRequirements::NoUnalignedAccessSupport());
const Operator* Comment(const char* msg);
const Operator* DebugBreak(); const Operator* DebugBreak();
const Operator* Word32And(); const Operator* Word32And();
...@@ -631,6 +632,7 @@ class MachineOperatorBuilder final : public ZoneObject { ...@@ -631,6 +632,7 @@ class MachineOperatorBuilder final : public ZoneObject {
#undef PSEUDO_OP_LIST #undef PSEUDO_OP_LIST
private: private:
Zone* zone_;
MachineOperatorGlobalCache const& cache_; MachineOperatorGlobalCache const& cache_;
MachineRepresentation const word_; MachineRepresentation const word_;
Flags const flags_; Flags const flags_;
......
...@@ -655,6 +655,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -655,6 +655,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kArchDebugBreak: case kArchDebugBreak:
__ stop("kArchDebugBreak"); __ stop("kArchDebugBreak");
break; break;
case kArchComment: {
Address comment_string = i.InputExternalReference(0).address();
__ RecordComment(reinterpret_cast<const char*>(comment_string));
break;
}
case kArchNop: case kArchNop:
case kArchThrowTerminator: case kArchThrowTerminator:
// don't emit code for nops. // don't emit code for nops.
......
...@@ -664,6 +664,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -664,6 +664,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kArchDebugBreak: case kArchDebugBreak:
__ stop("kArchDebugBreak"); __ stop("kArchDebugBreak");
break; break;
case kArchComment: {
Address comment_string = i.InputExternalReference(0).address();
__ RecordComment(reinterpret_cast<const char*>(comment_string));
break;
}
case kArchNop: case kArchNop:
case kArchThrowTerminator: case kArchThrowTerminator:
// don't emit code for nops. // don't emit code for nops.
......
...@@ -256,6 +256,7 @@ ...@@ -256,6 +256,7 @@
#define MACHINE_OP_LIST(V) \ #define MACHINE_OP_LIST(V) \
MACHINE_COMPARE_BINOP_LIST(V) \ MACHINE_COMPARE_BINOP_LIST(V) \
V(DebugBreak) \ V(DebugBreak) \
V(Comment) \
V(Load) \ V(Load) \
V(Store) \ V(Store) \
V(StackSlot) \ V(StackSlot) \
......
...@@ -137,6 +137,10 @@ void RawMachineAssembler::Return(Node* v1, Node* v2, Node* v3) { ...@@ -137,6 +137,10 @@ void RawMachineAssembler::Return(Node* v1, Node* v2, Node* v3) {
void RawMachineAssembler::DebugBreak() { AddNode(machine()->DebugBreak()); } void RawMachineAssembler::DebugBreak() { AddNode(machine()->DebugBreak()); }
void RawMachineAssembler::Comment(const char* msg) {
AddNode(machine()->Comment(msg));
}
Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function, Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
Node** args) { Node** args) {
int param_count = int param_count =
......
...@@ -699,6 +699,7 @@ class RawMachineAssembler { ...@@ -699,6 +699,7 @@ class RawMachineAssembler {
void Bind(RawMachineLabel* label); void Bind(RawMachineLabel* label);
void Deoptimize(Node* state); void Deoptimize(Node* state);
void DebugBreak(); void DebugBreak();
void Comment(const char* msg);
// Variables. // Variables.
Node* Phi(MachineRepresentation rep, Node* n1, Node* n2) { Node* Phi(MachineRepresentation rep, Node* n1, Node* n2) {
......
...@@ -2080,6 +2080,8 @@ Type* Typer::Visitor::TypeObjectIsUndetectable(Node* node) { ...@@ -2080,6 +2080,8 @@ Type* Typer::Visitor::TypeObjectIsUndetectable(Node* node) {
Type* Typer::Visitor::TypeDebugBreak(Node* node) { return Type::None(); } Type* Typer::Visitor::TypeDebugBreak(Node* node) { return Type::None(); }
Type* Typer::Visitor::TypeComment(Node* node) { return Type::None(); }
Type* Typer::Visitor::TypeLoad(Node* node) { return Type::Any(); } Type* Typer::Visitor::TypeLoad(Node* node) { return Type::Any(); }
Type* Typer::Visitor::TypeStackSlot(Node* node) { return Type::Any(); } Type* Typer::Visitor::TypeStackSlot(Node* node) { return Type::Any(); }
......
...@@ -658,6 +658,10 @@ void Verifier::Visitor::Check(Node* node) { ...@@ -658,6 +658,10 @@ void Verifier::Visitor::Check(Node* node) {
CheckNotTyped(node); CheckNotTyped(node);
break; break;
case IrOpcode::kComment:
CheckNotTyped(node);
break;
// Simplified operators // Simplified operators
// ------------------------------- // -------------------------------
case IrOpcode::kBooleanNot: case IrOpcode::kBooleanNot:
......
...@@ -759,6 +759,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -759,6 +759,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kArchTableSwitch: case kArchTableSwitch:
AssembleArchTableSwitch(instr); AssembleArchTableSwitch(instr);
break; break;
case kArchComment: {
Address comment_string = i.InputExternalReference(0).address();
__ RecordComment(reinterpret_cast<const char*>(comment_string));
break;
}
case kArchDebugBreak: case kArchDebugBreak:
__ int3(); __ int3();
break; break;
......
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