From 8cb7bb1580f0b6bea9d0e186efeb2ed9c780d66c Mon Sep 17 00:00:00 2001 From: "Viraj B. Shah" Date: Mon, 27 Nov 2023 21:26:44 +0530 Subject: [PATCH] Fix to accommodate annotations. --- gematria/basic_block/basic_block.cc | 11 ++++++++++- gematria/basic_block/basic_block_test.cc | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gematria/basic_block/basic_block.cc b/gematria/basic_block/basic_block.cc index 2f818d3c..0d638799 100644 --- a/gematria/basic_block/basic_block.cc +++ b/gematria/basic_block/basic_block.cc @@ -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); diff --git a/gematria/basic_block/basic_block_test.cc b/gematria/basic_block/basic_block_test.cc index 49121965..b40c856e 100644 --- a/gematria/basic_block/basic_block_test.cc +++ b/gematria/basic_block/basic_block_test.cc @@ -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); } @@ -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); }