From 865de1601ed4e3f864c6f6d06d91d9666c4774a3 Mon Sep 17 00:00:00 2001 From: z277zhu Date: Mon, 13 Nov 2023 21:31:54 -0500 Subject: [PATCH] Added RSP in generated code snippets & Fixed memory mapping annotation --- .../convert_bhive_to_llvm_exegesis_input.cc | 18 ++++++++++-------- gematria/datasets/llvm-exegesis_warpper.S | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/gematria/datasets/convert_bhive_to_llvm_exegesis_input.cc b/gematria/datasets/convert_bhive_to_llvm_exegesis_input.cc index 050737f8..bf0539e2 100644 --- a/gematria/datasets/convert_bhive_to_llvm_exegesis_input.cc +++ b/gematria/datasets/convert_bhive_to_llvm_exegesis_input.cc @@ -33,7 +33,6 @@ #define LLVM_EXEGESIS_MEM_MAP_PREFIX "# LLVM-EXEGESIS-MEM-MAP " #define LLVM_EXEGESIS_MEM_NAME_PREFIX "MEM" -static unsigned int mem_counter = 0; static unsigned int file_counter = 0; ABSL_FLAG(std::string, bhive_csv, "", @@ -94,11 +93,12 @@ int main(int argc, char* argv[]) { // for each line, find the accessed addresses & disassemble instructions const auto& bytes = bytes_or.value(); + + // this will only get the first segfault address auto addrs_or = gematria::FindAccessedAddrs(bytes); auto proto = bhive_importer.BasicBlockProtoFromMachineCode(bytes); if (addrs_or.ok() && proto.ok()) { - // TODO: attach those addresses to input that can be executed by - // llvm-exegesis Create output file path + // Create output file path std::string output_file_path = output_dir + "/" + std::to_string(file_counter) + ".test"; @@ -114,12 +114,14 @@ int main(int argc, char* argv[]) { // Append memory annotations auto addrs = addrs_or.value(); - for (const auto& addr : addrs.accessed_blocks) { - std::string mem_name = - LLVM_EXEGESIS_MEM_NAME_PREFIX + std::to_string(mem_counter++); - output_file << LLVM_EXEGESIS_MEM_DEF_PREFIX << mem_name << " " + + // Multiple mappings can point to the same definition + if (addrs.accessed_blocks.size() > 0) { + output_file << LLVM_EXEGESIS_MEM_DEF_PREFIX << LLVM_EXEGESIS_MEM_NAME_PREFIX << " " << addrs.block_size << " " << INITIAL_MEM_VALUE << "\n"; - output_file << LLVM_EXEGESIS_MEM_MAP_PREFIX << mem_name << " " + } + for (const auto& addr : addrs.accessed_blocks) { + output_file << LLVM_EXEGESIS_MEM_MAP_PREFIX << LLVM_EXEGESIS_MEM_NAME_PREFIX << " " << std::dec << addr << "\n"; } diff --git a/gematria/datasets/llvm-exegesis_warpper.S b/gematria/datasets/llvm-exegesis_warpper.S index 3bf5d7df..91361b68 100644 --- a/gematria/datasets/llvm-exegesis_warpper.S +++ b/gematria/datasets/llvm-exegesis_warpper.S @@ -5,6 +5,7 @@ # LLVM-EXEGESIS-DEFREG RSI 10000 # LLVM-EXEGESIS-DEFREG RDI 10000 # LLVM-EXEGESIS-DEFREG RBP 10000 +# LLVM-EXEGESIS-DEFREG RSP 10000 # LLVM-EXEGESIS-DEFREG R8 10000 # LLVM-EXEGESIS-DEFREG R9 10000 # LLVM-EXEGESIS-DEFREG R10 10000