blob: 2ae5c0bae838fe3aa5cefe69b415e631829571c8 [file] [log] [blame]
Logan Chien8b977d32012-02-21 19:14:55 +08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_SRC_COMPILER_LLVM_COMPILATION_UNIT_H_
18#define ART_SRC_COMPILER_LLVM_COMPILATION_UNIT_H_
19
20#include "constants.h"
21#include "logging.h"
22
23#include <UniquePtr.h>
24#include <string>
25
26namespace llvm {
27 class LLVMContext;
28 class Module;
29}
30
31namespace art {
32namespace compiler_llvm {
33
34class IRBuilder;
35
36class CompilationUnit {
37 public:
38 CompilationUnit(InstructionSet insn_set);
39
40 ~CompilationUnit();
41
42 InstructionSet GetInstructionSet() const {
43 return insn_set_;
44 }
45
46 llvm::LLVMContext* GetLLVMContext() const {
47 return context_.get();
48 }
49
50 llvm::Module* GetModule() const {
51 return module_;
52 }
53
54 IRBuilder* GetIRBuilder() const {
55 return irb_.get();
56 }
57
58 std::string const& GetElfFileName() const {
Logan Chien8b977d32012-02-21 19:14:55 +080059 return elf_filename_;
60 }
61
62 std::string const& GetBitcodeFileName() const {
Logan Chien8b977d32012-02-21 19:14:55 +080063 return bitcode_filename_;
64 }
65
66 void SetElfFileName(std::string const& filename) {
67 elf_filename_ = filename;
68 }
69
70 void SetBitcodeFileName(std::string const& filename) {
71 bitcode_filename_ = filename;
72 }
73
74 bool WriteBitcodeToFile();
75
76 bool Materialize();
77
Logan Chien7f767612012-03-01 18:54:49 +080078 bool IsMaterialized() const {
Logan Chien8b977d32012-02-21 19:14:55 +080079 return (context_.get() == NULL);
80 }
81
Logan Chien8b977d32012-02-21 19:14:55 +080082 bool IsMaterializeThresholdReached() const {
83 return (mem_usage_ > 300000000u); // (threshold: 300 MB)
84 }
85
86 void AddMemUsageApproximation(size_t usage) {
87 mem_usage_ += usage;
88 }
89
90 private:
91 InstructionSet insn_set_;
92
93 UniquePtr<llvm::LLVMContext> context_;
94 UniquePtr<IRBuilder> irb_;
95 llvm::Module* module_;
96
97 std::string elf_filename_;
98 std::string bitcode_filename_;
99
100 size_t mem_usage_;
101};
102
103} // namespace compiler_llvm
104} // namespace art
105
106#endif // ART_SRC_COMPILER_LLVM_COMPILATION_UNIT_H_