Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 16 | |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_COMPILED_METHOD_H_ |
| 18 | #define ART_COMPILER_COMPILED_METHOD_H_ |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 19 | |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 20 | #include <string> |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 23 | #include "instruction_set.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 24 | #include "utils.h" |
TDYa127 | eead4ac | 2012-06-03 07:15:25 -0700 | [diff] [blame] | 25 | #include "UniquePtr.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 26 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 27 | namespace llvm { |
| 28 | class Function; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 29 | } // namespace llvm |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 30 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 31 | namespace art { |
| 32 | |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 33 | class CompilerDriver; |
| 34 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 35 | class CompiledCode { |
| 36 | public: |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 37 | // For Quick to supply an code blob |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 38 | CompiledCode(CompilerDriver* compiler_driver, InstructionSet instruction_set, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 39 | const std::vector<uint8_t>& quick_code); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 40 | |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 41 | // For Portable to supply an ELF object |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 42 | CompiledCode(CompilerDriver* compiler_driver, InstructionSet instruction_set, |
| 43 | const std::string& elf_object, const std::string &symbol); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 44 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 45 | InstructionSet GetInstructionSet() const { |
| 46 | return instruction_set_; |
| 47 | } |
| 48 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 49 | const std::vector<uint8_t>* GetPortableCode() const { |
| 50 | return portable_code_; |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 51 | } |
| 52 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 53 | const std::vector<uint8_t>* GetQuickCode() const { |
| 54 | return quick_code_; |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 55 | } |
| 56 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 57 | void SetCode(const std::vector<uint8_t>* quick_code, const std::vector<uint8_t>* portable_code); |
| 58 | |
| 59 | bool operator==(const CompiledCode& rhs) const; |
| 60 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 61 | // To align an offset from a page-aligned value to make it suitable |
| 62 | // for code storage. For example on ARM, to ensure that PC relative |
| 63 | // valu computations work out as expected. |
| 64 | uint32_t AlignCode(uint32_t offset) const; |
| 65 | static uint32_t AlignCode(uint32_t offset, InstructionSet instruction_set); |
| 66 | |
| 67 | // returns the difference between the code address and a usable PC. |
| 68 | // mainly to cope with kThumb2 where the lower bit must be set. |
| 69 | size_t CodeDelta() const; |
| 70 | |
| 71 | // Returns a pointer suitable for invoking the code at the argument |
| 72 | // code_pointer address. Mainly to cope with kThumb2 where the |
| 73 | // lower bit must be set to indicate Thumb mode. |
| 74 | static const void* CodePointer(const void* code_pointer, |
| 75 | InstructionSet instruction_set); |
| 76 | |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 77 | const std::string& GetSymbol() const; |
| 78 | const std::vector<uint32_t>& GetOatdataOffsetsToCompliledCodeOffset() const; |
| 79 | void AddOatdataOffsetToCompliledCodeOffset(uint32_t offset); |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 80 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 81 | private: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 82 | CompilerDriver* const compiler_driver_; |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 83 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 84 | const InstructionSet instruction_set_; |
Brian Carlstrom | 8227cc1 | 2013-03-06 14:26:48 -0800 | [diff] [blame] | 85 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 86 | // The ELF image for portable. |
| 87 | std::vector<uint8_t>* portable_code_; |
| 88 | |
| 89 | // Used to store the PIC code for Quick. |
| 90 | std::vector<uint8_t>* quick_code_; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 91 | |
| 92 | // Used for the Portable ELF symbol name. |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 93 | const std::string symbol_; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 94 | |
| 95 | // There are offsets from the oatdata symbol to where the offset to |
| 96 | // the compiled method will be found. These are computed by the |
| 97 | // OatWriter and then used by the ElfWriter to add relocations so |
| 98 | // that MCLinker can update the values to the location in the linked .so. |
| 99 | std::vector<uint32_t> oatdata_offsets_to_compiled_code_offset_; |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | class CompiledMethod : public CompiledCode { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 103 | public: |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame] | 104 | // Constructs a CompiledMethod for the non-LLVM compilers. |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 105 | CompiledMethod(CompilerDriver& driver, |
| 106 | InstructionSet instruction_set, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 107 | const std::vector<uint8_t>& quick_code, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 108 | const size_t frame_size_in_bytes, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 109 | const uint32_t core_spill_mask, |
| 110 | const uint32_t fp_spill_mask, |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 111 | const std::vector<uint8_t>& mapping_table, |
| 112 | const std::vector<uint8_t>& vmap_table, |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame^] | 113 | const std::vector<uint8_t>& native_gc_map, |
| 114 | const std::vector<uint8_t>* cfi_info); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 115 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 116 | // Constructs a CompiledMethod for the QuickJniCompiler. |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 117 | CompiledMethod(CompilerDriver& driver, |
| 118 | InstructionSet instruction_set, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 119 | const std::vector<uint8_t>& quick_code, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 120 | const size_t frame_size_in_bytes, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 121 | const uint32_t core_spill_mask, |
| 122 | const uint32_t fp_spill_mask); |
| 123 | |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 124 | // Constructs a CompiledMethod for the Portable compiler. |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 125 | CompiledMethod(CompilerDriver& driver, InstructionSet instruction_set, const std::string& code, |
| 126 | const std::vector<uint8_t>& gc_map, const std::string& symbol); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 127 | |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 128 | // Constructs a CompiledMethod for the Portable JniCompiler. |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 129 | CompiledMethod(CompilerDriver& driver, InstructionSet instruction_set, const std::string& code, |
| 130 | const std::string& symbol); |
Logan Chien | 6920bce | 2012-03-17 21:44:01 +0800 | [diff] [blame] | 131 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 132 | ~CompiledMethod() {} |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 133 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 134 | size_t GetFrameSizeInBytes() const { |
| 135 | return frame_size_in_bytes_; |
Logan Chien | 110bcba | 2012-04-16 19:11:28 +0800 | [diff] [blame] | 136 | } |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 137 | |
| 138 | uint32_t GetCoreSpillMask() const { |
| 139 | return core_spill_mask_; |
| 140 | } |
| 141 | |
| 142 | uint32_t GetFpSpillMask() const { |
| 143 | return fp_spill_mask_; |
| 144 | } |
| 145 | |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 146 | const std::vector<uint8_t>& GetMappingTable() const { |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 147 | DCHECK(mapping_table_ != nullptr); |
| 148 | return *mapping_table_; |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 151 | const std::vector<uint8_t>& GetVmapTable() const { |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 152 | DCHECK(vmap_table_ != nullptr); |
| 153 | return *vmap_table_; |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 156 | const std::vector<uint8_t>& GetGcMap() const { |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 157 | DCHECK(gc_map_ != nullptr); |
| 158 | return *gc_map_; |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 159 | } |
Logan Chien | 110bcba | 2012-04-16 19:11:28 +0800 | [diff] [blame] | 160 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame^] | 161 | const std::vector<uint8_t>* GetCFIInfo() const { |
| 162 | return cfi_info_; |
| 163 | } |
| 164 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 165 | private: |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 166 | // For quick code, the size of the activation used by the code. |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 167 | const size_t frame_size_in_bytes_; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 168 | // For quick code, a bit mask describing spilled GPR callee-save registers. |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 169 | const uint32_t core_spill_mask_; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 170 | // For quick code, a bit mask describing spilled FPR callee-save registers. |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 171 | const uint32_t fp_spill_mask_; |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 172 | // For quick code, a uleb128 encoded map from native PC offset to dex PC aswell as dex PC to |
| 173 | // native PC offset. Size prefixed. |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 174 | std::vector<uint8_t>* mapping_table_; |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 175 | // For quick code, a uleb128 encoded map from GPR/FPR register to dex register. Size prefixed. |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 176 | std::vector<uint8_t>* vmap_table_; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 177 | // For quick code, a map keyed by native PC indices to bitmaps describing what dalvik registers |
| 178 | // are live. For portable code, the key is a dalvik PC. |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 179 | std::vector<uint8_t>* gc_map_; |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame^] | 180 | // For quick code, a FDE entry for the debug_frame section. |
| 181 | std::vector<uint8_t>* cfi_info_; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 184 | } // namespace art |
| 185 | |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 186 | #endif // ART_COMPILER_COMPILED_METHOD_H_ |