-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into users/boomanaiden154/bhive-comparison-script
- Loading branch information
Showing
35 changed files
with
1,381 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
USE_BAZEL_VERSION=6.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 19 additions & 3 deletions
22
gematria/datasets/convert_bhive_to_llvm_exegesis_input_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
from lit.main import main | ||
# Copyright 2024 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import lit.main | ||
import sys | ||
|
||
# Lit expects the test folder path to be specifided on the command-line, which | ||
# is usually passed in through CMake. Bazel doesn't support this configuration, | ||
# so we manually add the path here. | ||
sys.argv.append("./gematria/datasets/tests") | ||
sys.argv.append( | ||
"./gematria/datasets/convert_bhive_to_llvm_exegesis_input_tests" | ||
) | ||
sys.argv.append("-vv") | ||
|
||
if __name__ == "__main__": | ||
main() | ||
lit.main.main() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 15 additions & 1 deletion
16
gematria/datasets/tests/lit.cfg.py → ...e_to_llvm_exegesis_input_tests/lit.cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
gematria/datasets/convert_bhive_to_llvm_exegesis_input_tests/lit.site.cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2024 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
|
||
config.obj_root = os.path.join( | ||
os.getcwd(), 'gematria/datasets/convert_bhive_to_llvm_exegesis_input_tests' | ||
) | ||
config.tools_root = os.path.join(os.getcwd(), 'gematria/datasets') | ||
config.llvm_tools_root = os.path.join(os.getcwd(), 'external/llvm-project/llvm') | ||
|
||
lit_config.load_config(config, os.path.join(config.obj_root, 'lit.cfg.py')) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2024 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/Object/ELFObjectFile.h" | ||
#include "llvm/Object/ELFTypes.h" | ||
#include "llvm/Object/ObjectFile.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include "llvm/Support/Errc.h" | ||
#include "llvm/Support/WithColor.h" | ||
|
||
using namespace llvm; | ||
|
||
static cl::opt<std::string> InputFilename(cl::Positional, | ||
cl::desc("Input object file"), | ||
cl::init("-")); | ||
|
||
int main(int argc, char **argv) { | ||
cl::ParseCommandLineOptions(argc, argv, "extract_bbs_from_obj\n"); | ||
|
||
ExitOnError ExitOnErr("extract_bbs_from_obj error: "); | ||
|
||
object::OwningBinary<object::Binary> ObjBinary = | ||
ExitOnErr(object::createBinary(InputFilename)); | ||
object::Binary &Binary = *ObjBinary.getBinary(); | ||
object::ObjectFile *Obj = cast<object::ObjectFile>(&Binary); | ||
|
||
for (const auto &Section : Obj->sections()) { | ||
if (!Section.isText()) continue; | ||
|
||
DenseMap<uint64_t, object::BBAddrMap> BBAddrMap; | ||
if (const auto *Elf = dyn_cast<object::ELFObjectFileBase>(Obj)) { | ||
auto BBAddrMapping = ExitOnErr(Elf->readBBAddrMap(Section.getIndex())); | ||
for (auto &BBAddr : BBAddrMapping) { | ||
BBAddrMap.try_emplace(BBAddr.getFunctionAddress(), std::move(BBAddr)); | ||
} | ||
} else { | ||
ExitOnErr(make_error<StringError>(errc::invalid_argument, | ||
"Specified object file is not ELF.")); | ||
} | ||
|
||
std::vector<std::pair<uint64_t, uint64_t>> BasicBlocks; | ||
|
||
for (const auto &[FunctionAddress, BasicBlockAddressMap] : BBAddrMap) { | ||
for (const auto &BasicBlockEntry : BasicBlockAddressMap.getBBEntries()) { | ||
uint64_t StartAddress = FunctionAddress + BasicBlockEntry.Offset; | ||
BasicBlocks.push_back( | ||
std::make_pair(StartAddress, BasicBlockEntry.Size)); | ||
} | ||
} | ||
|
||
std::sort(BasicBlocks.begin(), BasicBlocks.end(), [](auto &LHS, auto &RHS) { | ||
return std::get<0>(LHS) < std::get<1>(RHS); | ||
}); | ||
|
||
if (BasicBlocks.size() == 0) { | ||
dbgs() << "No basic blocks present in section.\n"; | ||
continue; | ||
} | ||
|
||
size_t BasicBlockIndex = 0; | ||
|
||
uint64_t SectionEndAddress = Section.getAddress() + Section.getSize(); | ||
|
||
uint64_t CurrentAddress = std::get<0>(BasicBlocks[BasicBlockIndex]); | ||
|
||
if (SectionEndAddress < CurrentAddress) continue; | ||
|
||
StringRef SectionContents = ExitOnErr(Section.getContents()); | ||
|
||
while (CurrentAddress < SectionEndAddress && | ||
BasicBlockIndex < BasicBlocks.size()) { | ||
uint64_t OffsetInSection = CurrentAddress - Section.getAddress(); | ||
StringRef BasicBlock(SectionContents.data() + OffsetInSection, | ||
std::get<1>(BasicBlocks[BasicBlockIndex])); | ||
std::string BBHex = toHex(BasicBlock); | ||
outs() << BBHex << "\n"; | ||
BasicBlockIndex++; | ||
if (BasicBlockIndex >= BasicBlocks.size()) { | ||
break; | ||
} | ||
CurrentAddress = std::get<0>(BasicBlocks[BasicBlockIndex]); | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2024 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import lit.main | ||
import sys | ||
|
||
# Lit expects the test folder path to be specifided on the command-line, which | ||
# is usually passed in through CMake. Bazel doesn't support this configuration, | ||
# so we manually add the path here. | ||
sys.argv.append("./gematria/datasets/extract_bbs_from_obj_tests") | ||
sys.argv.append("-vv") | ||
|
||
if __name__ == "__main__": | ||
lit.main.main() |
Oops, something went wrong.