Skip to content

Commit

Permalink
Fix to accommodate annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
virajbshah committed Nov 27, 2023
1 parent 555ef25 commit 8cb7bb1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion gematria/basic_block/basic_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,16 @@ std::string Instruction::ToString() const {
add_operand_list("output_operands", output_operands);
add_operand_list("implicit_output_operands", implicit_output_operands);

// TODO(virajbshah): Include instruction annotations at the end of the string.
if (!instruction_annotations.empty()) {
buffer << "instruction_annotations=(";
for (const Annotation& annotation : instruction_annotations) {
buffer << annotation.ToString() << ", ";
}
// Pop only the trailing space. For simplicity, we leave the trailing comma
// which is required in case there is only one element.
buffer.seekp(-1, std::ios_base::end);
buffer << "), ";
}

auto msg = buffer.str();
assert(msg.size() >= 2);
Expand Down
6 changes: 4 additions & 2 deletions gematria/basic_block/basic_block_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ TEST(InstructionTest, ToString) {
"InstructionOperand.from_register('RBX'),), "
"implicit_input_operands=(InstructionOperand.from_register('EFLAGS'),), "
"output_operands=(InstructionOperand.from_register('RAX'),), "
"implicit_output_operands=(InstructionOperand.from_register('EFLAGS'),))";
"implicit_output_operands=(InstructionOperand.from_register('EFLAGS'),), "
"instruction_annotations=(Annotation(name='MEM_LOAD_RETIRED:L3_MISS', value=0.875),))";
EXPECT_EQ(instruction.ToString(), kExpectedString);
}

Expand Down Expand Up @@ -583,7 +584,8 @@ TEST(BasicBlockTest, ToString) {
"InstructionOperand.from_register('RBX'),), "
"implicit_input_operands=(InstructionOperand.from_register('EFLAGS'),), "
"output_operands=(InstructionOperand.from_register('RAX'),), "
"implicit_output_operands=(InstructionOperand.from_register('EFLAGS'),)),"
"implicit_output_operands=(InstructionOperand.from_register('EFLAGS'),), "
"instruction_annotations=(Annotation(name='MEM_LOAD_RETIRED:L3_MISS', value=0.875),)),"
")))";
EXPECT_EQ(block.ToString(), kExpectedString);
}
Expand Down

0 comments on commit 8cb7bb1

Please sign in to comment.