Skip to content

Commit

Permalink
Added patch to llvm & works on loading mir files
Browse files Browse the repository at this point in the history
  • Loading branch information
9Tempest committed Nov 15, 2023
1 parent 37f17f5 commit d7fb212
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ http_archive(
sha256 = LLVM_SHA256,
strip_prefix = "llvm-project-" + LLVM_COMMIT,
urls = ["https://github.com/llvm/llvm-project/archive/{commit}.zip".format(commit = LLVM_COMMIT)],
patches = ["//:mir_parser.patch"], # Hack to make the MIR parser work
patch_args = ["-p1"],
)

load(
Expand Down
5 changes: 5 additions & 0 deletions gematria/datasets/bhive_importer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,10 @@ TEST_F(BHiveImporterTest, MIRDatasetBasicTest) {
IsOk());
}

TEST_F(BHiveImporterTest, MIRDatasetTest2) {
EXPECT_THAT(x86_bhive_importer_->LoadMIRModule("/u9/z277zhu/research/gematria/mir_input/output/native_test.mir"),
IsOk());
}

} // namespace
} // namespace gematria
11 changes: 11 additions & 0 deletions gematria/datasets/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ gematria_py_binary(
"//gematria/utils/python:pybind11_abseil_status",
],
)

gematria_py_binary(
name = "import_from_mir",
srcs = ["import_from_mir.py"],
deps = [
":bhive_importer",
"//gematria/llvm/python:canonicalizer",
"//gematria/llvm/python:llvm_architecture_support",
"//gematria/utils/python:pybind11_abseil_status",
],
)
6 changes: 4 additions & 2 deletions gematria/datasets/python/import_from_mir.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ def main(argv: Sequence[str]) -> None:
for filename in os.listdir(_INPUT_DIR.value):
if filename.endswith(".mir"):
mir_file = os.path.join(_INPUT_DIR.value, filename)
perf_file = os.path.join(_INPUT_DIR.value, filename.replace(".mir", ".perf"))
print("mir file is " + mir_file)
perf_file = os.path.join(_INPUT_DIR.value, filename.replace(".mir", ".ll.perf"))
# load the MIR file
module = importer.loadMIRModule(mir_file)
module = importer.LoadMIRModule(mir_file)
logging.info('Procssing %s file', mir_file)
# iterate over each line in the corresponding .perf file
with tf.io.gfile.GFile(perf_file, 'r') as bhive_csv_file:
for line in bhive_csv_file:
Expand Down
22 changes: 22 additions & 0 deletions mir_parser.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index a1dde3e1fecb..88d8b11180e1 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -201,8 +201,15 @@ MCInst *MCContext::createMCInst() {
MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
SmallString<128> NameSV;
StringRef NameRef = Name.toStringRef(NameSV);
-
- assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
+ static int cnt = 0;
+ if (NameRef.empty()){
+ // Append cnt to the end of NameRef
+ std::string ModifiedName = ("INVALID" + std::to_string(cnt));
+ cnt++; // Increment cnt
+
+ // Convert ModifiedName back to StringRef
+ NameRef = StringRef(ModifiedName);
+ }

MCSymbol *&Sym = Symbols[NameRef];
if (!Sym)

0 comments on commit d7fb212

Please sign in to comment.