Skip to content

Commit

Permalink
Fixed graph builder & import from mir
Browse files Browse the repository at this point in the history
  • Loading branch information
9Tempest committed Dec 7, 2023
1 parent eff6be5 commit d76ec12
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
28 changes: 14 additions & 14 deletions gematria/datasets/bhive_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ absl::StatusOr<BasicBlockProto> BHiveImporter::BasicBlockProtoFromMBBName(

// Assert MI cannot be a CALL instruction
if (MI.isCall()) {
LOG("MI is a CALL instruction, abort this BB " << MI);
// LOG("MI is a CALL instruction, abort this BB " << MI);
return absl::InvalidArgumentError(
absl::StrCat("Cannot handle CALL instruction "));
}
Expand Down Expand Up @@ -253,15 +253,15 @@ absl::StatusOr<BasicBlockWithThroughputProto> BHiveImporter::ParseMIRCsvLine(
absl::StrCat("Could not find MBB with name ", BB_unique_name));
}

llvm::MachineBasicBlock* MBB = name_to_mbb_[MBB_name_ref];
std::string func_name = MBB->getParent()->getName().str();
assert(func_to_live_intervals_.find(func_name) !=
func_to_live_intervals_.end() &&
"Function not found in map");
addInterferenceGraph(*block_proto_or_status,
func_to_live_intervals_[func_name],
func_to_live_intervals_[func_name]
.BBRangeList[std::string(BB_unique_name)]);
// llvm::MachineBasicBlock* MBB = name_to_mbb_[MBB_name_ref];
// std::string func_name = MBB->getParent()->getName().str();
// assert(func_to_live_intervals_.find(func_name) !=
// func_to_live_intervals_.end() &&
// "Function not found in map");
// addInterferenceGraph(*block_proto_or_status,
// func_to_live_intervals_[func_name],
// func_to_live_intervals_[func_name]
// .BBRangeList[std::string(BB_unique_name)]);
*proto.mutable_basic_block() = std::move(block_proto_or_status).value();

double throughput_cycles = 0.0;
Expand Down Expand Up @@ -680,10 +680,10 @@ void BHiveImporter::addInterferenceGraph(
}

// pretty print physical registers
LOG("Physical Registers: ");
for (auto& reg : live_physical_registers) {
LOG("Physical Register: " << reg);
}
// LOG("Physical Registers: ");
// for (auto& reg : live_physical_registers) {
// LOG("Physical Register: " << reg);
// }

// Iterate over all operands in bb_proto, add interference registers to each
// operand
Expand Down
4 changes: 2 additions & 2 deletions gematria/datasets/python/import_from_mir.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ def main(argv: Sequence[str]) -> None:
num_input_files,
num_skipped_files,
)
mir_file = os.path.join(_INPUT_DIR.value, filename)
mir_file = os.path.join(input_dir, filename)
print("mir file is " + mir_file)
perf_file = os.path.join(_INPUT_DIR.value, filename.replace(".mir", ".perf"))
perf_file = os.path.join(input_dir, filename.replace(".mir", ".perf"))
try:
# load the MIR file
module = importer.LoadMIRModule(mir_file)
Expand Down
4 changes: 2 additions & 2 deletions gematria/granite/graph_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ bool BasicBlockGraphBuilder::AddInputOperand(
}
}
if (!address_tuple.index_register.empty()) {
bool is_virtual_reg = address_tuple.base_register[0] == '%';
bool is_virtual_reg = address_tuple.index_register[0] == '%';
std::string vreg_token = getVREG_TOKEN(64);
bool result = AddDependencyOnRegister(address_node,
address_tuple.index_register,
Expand All @@ -317,7 +317,7 @@ bool BasicBlockGraphBuilder::AddInputOperand(
}
}
if (!address_tuple.segment_register.empty()) {
bool is_virtual_reg = address_tuple.base_register[0] == '%';
bool is_virtual_reg = address_tuple.segment_register[0] == '%';
std::string vreg_token = getVREG_TOKEN(64);
bool result = AddDependencyOnRegister(address_node,
address_tuple.segment_register,
Expand Down
6 changes: 3 additions & 3 deletions gematria/llvm/canonicalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ llvm::SmallVector<std::string_view, 2> SplitByAny(std::string_view str,
void AddX86VendorMnemonicAndPrefixes(
llvm::MCInstPrinter& printer, const llvm::MCSubtargetInfo& subtarget_info,
const llvm::MCInst& mcinst, Instruction& instruction) {
constexpr const char* kKnownPrefixes[] = {"REP", "LOCK", "REPNE", "REPE"};
constexpr const char* kKnownPrefixes[] = {"nofpexcept"};

std::string assembly_code;
llvm::raw_string_ostream stream(assembly_code);
Expand Down Expand Up @@ -291,8 +291,8 @@ Instruction X86Canonicalizer::PlatformSpecificInstructionFromMachineInstr(const
Instruction instruction;
instruction.llvm_mnemonic =
target_machine_.getMCInstrInfo()->getName(MI.getOpcode());
AddMIRVendorMnemonicAndPrefixes(*target_machine_.getMCSubtargetInfo(), MI,
instruction);
instruction.mnemonic =
target_machine_.getMCInstrInfo()->getName(MI.getOpcode());

const llvm::MCInstrDesc& descriptor = instr_info.get(MI.getOpcode());
if (descriptor.mayLoad()) {
Expand Down

0 comments on commit d76ec12

Please sign in to comment.