diff --git a/examples/example_unrolling_service/loop_unroller/BUILD b/examples/example_unrolling_service/loop_unroller/BUILD index 3bec18c35..c70be0a16 100644 --- a/examples/example_unrolling_service/loop_unroller/BUILD +++ b/examples/example_unrolling_service/loop_unroller/BUILD @@ -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", ], ) diff --git a/examples/example_unrolling_service/loop_unroller/loop_unroller.cc b/examples/example_unrolling_service/loop_unroller/loop_unroller.cc index 29c87559a..cb8d8c1e4 100644 --- a/examples/example_unrolling_service/loop_unroller/loop_unroller.cc +++ b/examples/example_unrolling_service/loop_unroller/loop_unroller.cc @@ -72,6 +72,7 @@ class LoopCounter : public llvm::FunctionPass { public: static char ID; std::unordered_map counts; + std::vector line_numbers; LoopCounter() : FunctionPass(ID) {} @@ -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; } }; @@ -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; @@ -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();