Skip to content

Commit

Permalink
Fixed syntax issues && handled EH label &&TODO: fix computation tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
9Tempest committed Nov 20, 2023
1 parent 1e874a4 commit cc2fad5
Show file tree
Hide file tree
Showing 7 changed files with 138,471 additions and 25 deletions.
3 changes: 3 additions & 0 deletions gematria/basic_block/basic_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ struct Instruction {
uint64_t address = 0;
// The size of the instruction.
size_t size = 0;

// The instruction is valid or not
bool is_valid = true;
};

std::ostream& operator<<(std::ostream& os, const Instruction& instruction);
Expand Down
36 changes: 14 additions & 22 deletions gematria/datasets/bhive_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,29 +174,21 @@ absl::StatusOr<BasicBlockProto> BHiveImporter::BasicBlockProtoFromMBBName(
LOG("MBB is " << *MBB);
for (llvm::MachineInstr& MI : *MBB){
// if MI is a control instruction(ret,branch,jmp), skip it
if (MI.isInlineAsm() || MI.isTerminator()) {
if (MI.isInlineAsm() || MI.isTerminator() || MI.isEHLabel()) {
LOG("MI is a control instruction, skipping it " << MI);
continue;
}

// Assert MI cannot be a CALL instruction
assert(!MI.isCall() && "MI is a CALL instruction, bad dataset");
*basic_block_proto.add_canonicalized_instructions() = ProtoFromInstruction(
canonicalizer_.InstructionFromMachineInstr(MI));
auto I = canonicalizer_.InstructionFromMachineInstr(MI);
if (!I.is_valid) {
LOG("MI is not valid, skipping it " << MI);
return absl::InvalidArgumentError(
absl::StrCat("Could not parse MachineInstr "));
}
*basic_block_proto.add_canonicalized_instructions() = ProtoFromInstruction(I);
}

// for (DisassembledInstruction& instruction : *instructions) {
// NOT VERY IMPORTANT THESE 3 LINES
// MachineInstructionProto& machine_instruction =
// *basic_block_proto.add_machine_instructions();
// machine_instruction.set_address(instruction.address);
// machine_instruction.set_assembly(instruction.assembly);
// machine_instruction.set_machine_code(instruction.machine_code);
// VERY IMPORTANT!!! Do this first TODO: change this to use the unique name to get the MBB
// *basic_block_proto.add_canonicalized_instructions() = ProtoFromInstruction(
// canonicalizer_.InstructionFromMCInst(instruction.mc_inst));
// }

return basic_block_proto;
}

Expand All @@ -219,16 +211,16 @@ absl::StatusOr<BasicBlockWithThroughputProto> BHiveImporter::ParseMIRCsvLine(
"different, but were both %d: %s",
BB_name_index, line));
}
// const std::string_view BB_unique_name =
// columns[BB_name_index];
const std::string_view BB_unique_name =
columns[BB_name_index];
const std::string_view throughput_str = columns[throughput_column_index];

BasicBlockWithThroughputProto proto;

// absl::StatusOr<BasicBlockProto> block_proto_or_status =
// BasicBlockProtoFromMBBName(BB_unique_name, base_address);
// if (!block_proto_or_status.ok()) return block_proto_or_status.status();
// *proto.mutable_basic_block() = std::move(block_proto_or_status).value();
absl::StatusOr<BasicBlockProto> block_proto_or_status =
BasicBlockProtoFromMBBName(BB_unique_name, base_address);
if (!block_proto_or_status.ok()) return block_proto_or_status.status();
*proto.mutable_basic_block() = std::move(block_proto_or_status).value();

double throughput_cycles = 0.0;
if (!absl::SimpleAtod(throughput_str, &throughput_cycles)) {
Expand Down
5 changes: 4 additions & 1 deletion gematria/datasets/bhive_importer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ TEST_F(BHiveImporterTest, MIRDatasetBasicTest) {
}

TEST_F(BHiveImporterTest, MIRDatasetTest2) {
EXPECT_THAT(x86_bhive_importer_->LoadMIRModule("mir_input/output/BatchRulesReduceOps.mir"),
EXPECT_THAT(x86_bhive_importer_->LoadMIRModule("sample_dataset/native_test.mir"),
IsOk());
EXPECT_THAT(x86_bhive_importer_->ParseMIRCsvLine(kSourceName, "a,b,BB_13,2.37", 2,
3, kScaling),
IsOk());
}

Expand Down
2 changes: 1 addition & 1 deletion gematria/datasets/python/import_from_mir.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def main(argv: Sequence[str]) -> None:
throughput_scaling=_THROUGHPUT_SCALING.value,
)
writer.write(block_proto.SerializeToString())
except bhive_importer.BasicBlockNotFoundError:
except:
num_skipped_blocks += 1
except:
logging.exception('Could not load file "%s"', mir_file)
Expand Down
2 changes: 1 addition & 1 deletion gematria/llvm/canonicalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void X86Canonicalizer::AddOperand(const llvm::MachineInstr& mi, int operand_inde
llvm::errs() << "Unsupported operand type: ";
operand.print(llvm::errs());
llvm::errs() << "\n";
assert(false);
instruction.is_valid = false;
}
}

Expand Down
Loading

0 comments on commit cc2fad5

Please sign in to comment.