diff options
| author | 2012-05-08 15:08:51 +0800 | |
|---|---|---|
| committer | 2012-05-08 11:53:40 -0700 | |
| commit | 08e1ba3c5899213e63007b0158e0a491f2449ea4 (patch) | |
| tree | f53f9352a3c9e6fe6e6e9a3f0a90f58bae69ac8a /src/compiler_llvm/compilation_unit.cc | |
| parent | e0e4024b2e3f6fa6feb3ef42f0f072ffb004f8f7 (diff) | |
Don't fork dex2oat process on target device.
Change-Id: I35370d328aaa1aaaed5b56e62e51c4c74afa9cba
Diffstat (limited to 'src/compiler_llvm/compilation_unit.cc')
| -rw-r--r-- | src/compiler_llvm/compilation_unit.cc | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/compiler_llvm/compilation_unit.cc b/src/compiler_llvm/compilation_unit.cc index 1c473921cf..10844b88a1 100644 --- a/src/compiler_llvm/compilation_unit.cc +++ b/src/compiler_llvm/compilation_unit.cc @@ -166,9 +166,14 @@ bool CompilationUnit::WriteBitcodeToFile(const std::string& bitcode_filename) { } -bool CompilationUnit::Materialize() { +bool CompilationUnit::Materialize(size_t thread_count) { MutexLock GUARD(cunit_lock_); + if (thread_count == 1) { + llvm::raw_string_ostream str_os(elf_image_); + return MaterializeToFile(str_os, insn_set_); + } + // Prepare the pipe between parent process and child process int pipe_fd[2]; if (pipe(pipe_fd) == -1) { @@ -191,9 +196,11 @@ bool CompilationUnit::Materialize() { // Change process groups, so we don't get ripped by ProcessManager setpgid(0, 0); + llvm::raw_fd_ostream fd_os(pipe_fd[1], /* shouldClose */true); + // TODO: Should use exec* family instead of invoking a function. // Forward our compilation request to bcc. - exit(static_cast<int>(!MaterializeToFile(pipe_fd[1], insn_set_))); + exit(static_cast<int>(!MaterializeToFile(fd_os, insn_set_))); } else { // Parent process // Close the unused pipe write end @@ -219,7 +226,7 @@ bool CompilationUnit::Materialize() { } // Append to the end of the elf_image_ - elf_image_.insert(elf_image_.end(), buf.begin(), buf.begin() + nread); + elf_image_.append(buf.begin(), buf.begin() + nread); if (nread < static_cast<ssize_t>(buf_size)) { // EOF reached! break; @@ -274,7 +281,7 @@ void CompilationUnit::UpdateFrameSizeInBytes(const llvm::Function* func, } } -bool CompilationUnit::MaterializeToFile(int output_fd, +bool CompilationUnit::MaterializeToFile(llvm::raw_ostream& out_stream, InstructionSet insn_set) { // Initialize the LLVM first llvm::InitializeAllTargets(); @@ -357,8 +364,7 @@ bool CompilationUnit::MaterializeToFile(int output_fd, // Add passes to emit ELF image { - llvm::formatted_raw_ostream formatted_os( - *(new llvm::raw_fd_ostream(output_fd, /* shouldClose */false)), true); + llvm::formatted_raw_ostream formatted_os(out_stream, false); // Ask the target to add backend passes as necessary. if (target_machine->addPassesToEmitFile(pm, |