Skip to content

Commit

Permalink
Added interference info in BHiveImporter
Browse files Browse the repository at this point in the history
  • Loading branch information
9Tempest committed Dec 5, 2023
1 parent 9867517 commit a91c428
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
85 changes: 81 additions & 4 deletions gematria/datasets/bhive_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,42 @@ absl::StatusOr<bool> BHiveImporter::InteferenceGraphParser(
return true;
}

absl::StatusOr<bool> BHiveImporter::addInterferenceGraph(
BasicBlockProto& bb_proto,
const BHiveImporter::FunctionLiveIntervalInfo& func_live_infos,
static bool checkRegIntersectionsWithBBRange(
const BHiveImporter::RegLiveIntervals& reg_live_interval1,
const BHiveImporter::RegLiveIntervals& reg_live_interval2,
const BHiveImporter::BhiveLiveRange& bb_range) {
const BHiveImporter::BhiveLiveRange* range1HitsBB = nullptr;
for (auto& interval : reg_live_interval1.rangeList) {
if (areIntersected(interval, bb_range)) {
range1HitsBB = &interval;
}
}
if (!range1HitsBB) {
return false;
}
for (auto& interval : reg_live_interval2.rangeList) {
if (areIntersected(interval, bb_range)) {
if (areIntersected(*range1HitsBB, interval)) {
return true;
}
}
}
return false;
}

// void ToRepeatedPtrField(
// const std::vector<InstructionOperand>& operands,
// google::protobuf::RepeatedPtrField<CanonicalizedOperandProto>*
// repeated_field) {
// repeated_field->Reserve(operands.size());
// std::transform(operands.begin(), operands.end(),
// google::protobuf::RepeatedFieldBackInserter(repeated_field));
// }

void BHiveImporter::addInterferenceGraph(
BasicBlockProto& bb_proto,
BHiveImporter::FunctionLiveIntervalInfo& func_live_infos,
BHiveImporter::BhiveLiveRange& bb_range) {
std::set<std::string> live_virtual_registers;
// iterate over all operands in bb_proto, add virtual registers to
// live_virtual_registers
Expand All @@ -536,7 +568,52 @@ absl::StatusOr<bool> BHiveImporter::addInterferenceGraph(
}
}
}
return true;

// Iterate over all operands in bb_proto, add interference registers to each operand
for (auto& instruction : *bb_proto.mutable_canonicalized_instructions()) {
LOG("before: " << instruction.DebugString());
for (auto& operand : *instruction.mutable_input_operands()) {
if (operand.operand_case() ==
CanonicalizedOperandProto::kVirtualRegister) {
for (auto vRegs : live_virtual_registers){
if (vRegs == operand.virtual_register().name()) continue;
assert(func_live_infos.virtual_register_live_range_func.find(vRegs) !=
func_live_infos.virtual_register_live_range_func.end() &&
"Virtual register not found in map");
// If the live range of the two registers intersect, then add
// interference to proto
if (checkRegIntersectionsWithBBRange(
func_live_infos.virtual_register_live_range_func[
operand.virtual_register().name()],
func_live_infos.virtual_register_live_range_func[vRegs],
bb_range)) {
operand.mutable_intefered_register()->Add(std::move(vRegs));
}
}
}
}
for (auto& operand : *instruction.mutable_output_operands()) {
if (operand.operand_case() ==
CanonicalizedOperandProto::kVirtualRegister) {
for (auto vRegs : live_virtual_registers){
if (vRegs == operand.virtual_register().name()) continue;
assert(func_live_infos.virtual_register_live_range_func.find(vRegs) !=
func_live_infos.virtual_register_live_range_func.end() &&
"Virtual register not found in map");
// If the live range of the two registers intersect, then add
// interference to proto
if (checkRegIntersectionsWithBBRange(
func_live_infos.virtual_register_live_range_func[
operand.virtual_register().name()],
func_live_infos.virtual_register_live_range_func[vRegs],
bb_range)) {
operand.mutable_intefered_register()->Add(std::move(vRegs));
}
}
}
}
LOG("after: " << instruction.DebugString());
}
}

} // namespace gematria
2 changes: 1 addition & 1 deletion gematria/datasets/bhive_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class BHiveImporter {
// to take in machine instruction/ fucntion
absl::StatusOr<bool> InteferenceGraphParser(std::string_view file_name);

absl::StatusOr<bool> addInterferenceGraph(BasicBlockProto& bb_proto, const FunctionLiveIntervalInfo& func_live_infos, const BhiveLiveRange& bb_range);
void addInterferenceGraph(BasicBlockProto& bb_proto, FunctionLiveIntervalInfo& func_live_infos, BhiveLiveRange& bb_range);

private:
const Canonicalizer& canonicalizer_;
Expand Down
2 changes: 1 addition & 1 deletion gematria/datasets/bhive_importer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ TEST_F(BHiveImporterTest, MIRDatasetTest2) {
x86_bhive_importer_->InteferenceGraphParser("sample_dataset/liveinfo"),
IsOk());
EXPECT_THAT(x86_bhive_importer_->ParseMIRCsvLine(
kSourceName, "a,b,BB_13,2.37", 2, 3, kScaling),
kSourceName, "a,b,BB_21,2.37", 2, 3, kScaling),
IsOk());
}

Expand Down
2 changes: 1 addition & 1 deletion gematria/proto/canonicalized_instruction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ message CanonicalizedOperandProto {
}

// Optional. The name of the registers where the current register interfered with
repeated string intefered_registers = 7;
repeated string intefered_register = 7;
}

0 comments on commit a91c428

Please sign in to comment.