Skip to content

Commit

Permalink
Merge pull request #515 from ChrisCummins/bitcode-writer
Browse files Browse the repository at this point in the history
[llvm] Fix invalid use of BitcodeWriter API.
  • Loading branch information
ChrisCummins authored Dec 14, 2021
2 parents a056c6c + 085e79c commit 283941e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compiler_gym/envs/llvm/service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ cc_binary(
genrule(
name = "strip-optnone-bin",
srcs = [":strip-optnone-attribute-prelinked"],
outs = ["strip-optnone"],
outs = ["strip-optnone-attribute"],
cmd = select({
"@llvm//:darwin": (
"cp $(location :strip-optnone-attribute-prelinked) $@"
Expand Down
11 changes: 7 additions & 4 deletions compiler_gym/envs/llvm/service/Benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ namespace {

BenchmarkHash getModuleHash(const llvm::Module& module) {
BenchmarkHash hash;
llvm::SmallVector<char, 256> buffer;
Bitcode bitcode;

// Writing the entire bitcode to a buffer that is then discarded is
// inefficient.
llvm::BitcodeWriter writer(buffer);
writer.writeModule(module, /*ShouldPreserveUseListOrder=*/false,
/*Index=*/nullptr, /*GenerateHash=*/true, &hash);
llvm::raw_svector_ostream ostream(bitcode);
llvm::WriteBitcodeToFile(module, ostream,
/*ShouldPreserveUseListOrder=*/false,
/*Index=*/nullptr, /*GenerateHash=*/true, &hash);

return hash;
}

Expand Down
2 changes: 0 additions & 2 deletions compiler_gym/envs/llvm/service/StripOptNoneAttribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <iostream>

#include "compiler_gym/envs/llvm/service/BenchmarkFactory.h"
#include "compiler_gym/envs/llvm/service/Observation.h"
#include "compiler_gym/envs/llvm/service/ObservationSpaces.h"
#include "compiler_gym/service/proto/compiler_gym_service.pb.h"
#include "compiler_gym/util/GrpcStatusMacros.h"
#include "llvm/IR/Module.h"
Expand Down

0 comments on commit 283941e

Please sign in to comment.