Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Trying to Dump IR or Line Numbers of Loops #493

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/example_unrolling_service/loop_unroller/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,33 @@
# This package exposes the LLVM optimization pipeline as a CompilerGym service.
load("@rules_cc//cc:defs.bzl", "cc_binary")

genrule(
name = "libLLVMRuntimeDyld",
srcs = [
"@clang-llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04//:all_files",
"@clang-llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04//:clang",
],
outs = ["libLLVMRuntimeDyld.a"],
cmd = "cp $$(dirname $(location @clang-llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04//:clang))/../lib/libLLVMRuntimeDyld.a $@",
visibility = ["//visibility:public"],
)

cc_binary(
name = "loop_unroller",
srcs = [
"loop_unroller.cc",
#"@clang-llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04//:lib/libLLVMRuntimeDyld.a",
":libLLVMRuntimeDyld",
],
copts = [
"-Wall",
"-fdiagnostics-color=always",
"-fno-rtti",
"-force_load",
],
visibility = ["//visibility:public"],
deps = [
"@llvm//10.0.0",
#":libLLVMRuntimeDyld",
],
)
19 changes: 16 additions & 3 deletions examples/example_unrolling_service/loop_unroller/loop_unroller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class LoopCounter : public llvm::FunctionPass {
public:
static char ID;
std::unordered_map<std::string, int> counts;
std::vector<int> line_numbers;

LoopCounter() : FunctionPass(ID) {}

Expand All @@ -86,6 +87,15 @@ class LoopCounter : public llvm::FunctionPass {
// Should really account for module, too.
counts[F.getName().str()] = Loops.size();

for (auto L : Loops) {
// any of these lines throws "dyld: lazy symbol binding failed: Symbol not found" error
L->getLoopID()->dump();
// L->dump();
// L->getLocRange().getStart().dump();
// L->getLocRange().getEnd().dump();
// line_numbers.push_back( L->getStartLoc().getLine());
}

return false;
}
};
Expand Down Expand Up @@ -114,11 +124,11 @@ class LoopUnrollConfigurator : public llvm::FunctionPass {
auto Loops = LI.getLoopsInPreorder();

// Should really account for module, too.
for (auto ALoop : Loops) {
for (auto L : Loops) {
if (UnrollEnable)
addStringMetadataToLoop(ALoop, "llvm.loop.unroll.enable", UnrollEnable);
addStringMetadataToLoop(L, "llvm.loop.unroll.enable", UnrollEnable);
if (UnrollCount)
addStringMetadataToLoop(ALoop, "llvm.loop.unroll.count", UnrollCount);
addStringMetadataToLoop(L, "llvm.loop.unroll.count", UnrollCount);
}

return false;
Expand Down Expand Up @@ -194,6 +204,9 @@ int main(int argc, char** argv) {
for (auto& x : Counter->counts) {
llvm::dbgs() << x.first << ": " << x.second << " loops" << '\n';
}
for (auto& x : Counter->line_numbers) {
llvm::dbgs() << x << '\n';
}

Out.keep();

Expand Down