builder.h revision e53798a7e3267305f696bf658e418c92e63e0834
1818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray/* 2818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 3818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * 4818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * you may not use this file except in compliance with the License. 6818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * You may obtain a copy of the License at 7818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * 8818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * 10818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * See the License for the specific language governing permissions and 14818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray * limitations under the License. 15818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray */ 16818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 17818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray#ifndef ART_COMPILER_OPTIMIZING_BUILDER_H_ 18818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray#define ART_COMPILER_OPTIMIZING_BUILDER_H_ 19818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 203ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray#include "dex_file.h" 217fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray#include "dex_file-inl.h" 22e50383288a75244255d3ecedcc79ffe9caf774cbNicolas Geoffray#include "driver/compiler_driver.h" 238ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray#include "driver/dex_compilation_unit.h" 2448c2b03965830c73cdddeae8aea8030f08430137Calin Juravle#include "optimizing_compiler_stats.h" 2501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray#include "primitive.h" 260279ebb3efd653e6bb255470c99d26949c7bcd95Ian Rogers#include "utils/arena_object.h" 27be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray#include "utils/growable_array.h" 2820dfc797dc631bf8d655dcf123f46f13332d3074Dave Allison#include "nodes.h" 29818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 30818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffraynamespace art { 31818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 32818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffrayclass Instruction; 33e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampeclass SwitchTable; 34818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 35818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffrayclass HGraphBuilder : public ValueObject { 36818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray public: 378ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray HGraphBuilder(ArenaAllocator* arena, 387fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray DexCompilationUnit* dex_compilation_unit, 39e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray const DexCompilationUnit* const outer_compilation_unit, 407fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray const DexFile* dex_file, 4148c2b03965830c73cdddeae8aea8030f08430137Calin Juravle CompilerDriver* driver, 4248c2b03965830c73cdddeae8aea8030f08430137Calin Juravle OptimizingCompilerStats* compiler_stats) 43818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray : arena_(arena), 44be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray branch_targets_(arena, 0), 453ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray locals_(arena, 0), 46818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray entry_block_(nullptr), 47818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray exit_block_(nullptr), 48818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray current_block_(nullptr), 493ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray graph_(nullptr), 50bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray constant0_(nullptr), 518ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray constant1_(nullptr), 528ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray dex_file_(dex_file), 53e50383288a75244255d3ecedcc79ffe9caf774cbNicolas Geoffray dex_compilation_unit_(dex_compilation_unit), 547fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray compiler_driver_(driver), 55e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray outer_compilation_unit_(outer_compilation_unit), 56a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray return_type_(Primitive::GetType(dex_compilation_unit_->GetShorty()[0])), 57a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray code_start_(nullptr), 5848c2b03965830c73cdddeae8aea8030f08430137Calin Juravle latest_result_(nullptr), 5948c2b03965830c73cdddeae8aea8030f08430137Calin Juravle compilation_stats_(compiler_stats) {} 607fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray 617fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray // Only for unit testing. 627fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray HGraphBuilder(ArenaAllocator* arena, Primitive::Type return_type = Primitive::kPrimInt) 637fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray : arena_(arena), 647fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray branch_targets_(arena, 0), 657fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray locals_(arena, 0), 667fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray entry_block_(nullptr), 677fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray exit_block_(nullptr), 687fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray current_block_(nullptr), 697fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray graph_(nullptr), 707fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray constant0_(nullptr), 717fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray constant1_(nullptr), 727fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray dex_file_(nullptr), 737fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray dex_compilation_unit_(nullptr), 747fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray compiler_driver_(nullptr), 75e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray outer_compilation_unit_(nullptr), 76a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray return_type_(return_type), 77a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray code_start_(nullptr), 7848c2b03965830c73cdddeae8aea8030f08430137Calin Juravle latest_result_(nullptr), 7948c2b03965830c73cdddeae8aea8030f08430137Calin Juravle compilation_stats_(nullptr) {} 80818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 81e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray HGraph* BuildGraph(const DexFile::CodeItem& code, int start_instruction_id = 0); 82818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 83818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray private: 84818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray // Analyzes the dex instruction and adds HInstruction to the graph 85818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray // to execute that instruction. Returns whether the instruction can 86818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray // be handled. 87225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle bool AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc); 88be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray 89be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray // Finds all instructions that start a new block, and populates branch_targets_ with 90be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray // the newly created blocks. 9143a539f780af20a1854bca81c3d4835a585f0620Nicolas Geoffray // As a side effect, also compute the number of dex instructions, blocks, and 9243a539f780af20a1854bca81c3d4835a585f0620Nicolas Geoffray // branches. 9343a539f780af20a1854bca81c3d4835a585f0620Nicolas Geoffray void ComputeBranchTargets(const uint16_t* start, 9443a539f780af20a1854bca81c3d4835a585f0620Nicolas Geoffray const uint16_t* end, 9543a539f780af20a1854bca81c3d4835a585f0620Nicolas Geoffray size_t* number_of_dex_instructions, 9643a539f780af20a1854bca81c3d4835a585f0620Nicolas Geoffray size_t* number_of_block, 9743a539f780af20a1854bca81c3d4835a585f0620Nicolas Geoffray size_t* number_of_branches); 98be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray void MaybeUpdateCurrentBlock(size_t index); 99be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray HBasicBlock* FindBlockStartingAt(int32_t index) const; 100818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 10101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray HIntConstant* GetIntConstant0(); 10201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray HIntConstant* GetIntConstant1(); 10301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray HIntConstant* GetIntConstant(int32_t constant); 10401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray HLongConstant* GetLongConstant(int64_t constant); 105f583e5976e1de9aa206fb8de4f91000180685066Nicolas Geoffray void InitializeLocals(uint16_t count); 1063ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray HLocal* GetLocalAt(int register_index) const; 1073ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray void UpdateLocal(int register_index, HInstruction* instruction) const; 10801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray HInstruction* LoadLocal(int register_index, Primitive::Type type) const; 109225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle void PotentiallyAddSuspendCheck(int32_t target_offset, uint32_t dex_pc); 11052e832b1278449e62d9eb502d54d5ff18f8606edNicolas Geoffray void InitializeParameters(uint16_t number_of_parameters); 111f583e5976e1de9aa206fb8de4f91000180685066Nicolas Geoffray 11201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray template<typename T> 11388cb1755e1d6acaed0f66ce65d7a2a4465053342Roland Levillain void Unop_12x(const Instruction& instruction, Primitive::Type type); 11488cb1755e1d6acaed0f66ce65d7a2a4465053342Roland Levillain 11588cb1755e1d6acaed0f66ce65d7a2a4465053342Roland Levillain template<typename T> 116412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Binop_23x(const Instruction& instruction, Primitive::Type type); 11701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 11801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray template<typename T> 119d6fb6cfb6f2d0d9595f55e8cc18d2753be5d9a13Calin Juravle void Binop_23x(const Instruction& instruction, Primitive::Type type, uint32_t dex_pc); 120d6fb6cfb6f2d0d9595f55e8cc18d2753be5d9a13Calin Juravle 121d6fb6cfb6f2d0d9595f55e8cc18d2753be5d9a13Calin Juravle template<typename T> 1229aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void Binop_23x_shift(const Instruction& instruction, Primitive::Type type); 1239aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle 124ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle void Binop_23x_cmp(const Instruction& instruction, Primitive::Type type, HCompare::Bias bias); 125ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle 1269aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle template<typename T> 12701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray void Binop_12x(const Instruction& instruction, Primitive::Type type); 12801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 12901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray template<typename T> 130d6fb6cfb6f2d0d9595f55e8cc18d2753be5d9a13Calin Juravle void Binop_12x(const Instruction& instruction, Primitive::Type type, uint32_t dex_pc); 131d6fb6cfb6f2d0d9595f55e8cc18d2753be5d9a13Calin Juravle 132d6fb6cfb6f2d0d9595f55e8cc18d2753be5d9a13Calin Juravle template<typename T> 1339aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void Binop_12x_shift(const Instruction& instruction, Primitive::Type type); 1349aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle 1359aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle template<typename T> 13601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray void Binop_22b(const Instruction& instruction, bool reverse); 13701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 13801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray template<typename T> 13901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray void Binop_22s(const Instruction& instruction, bool reverse); 14001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 141225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle template<typename T> void If_21t(const Instruction& instruction, uint32_t dex_pc); 142225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle template<typename T> void If_22t(const Instruction& instruction, uint32_t dex_pc); 143f583e5976e1de9aa206fb8de4f91000180685066Nicolas Geoffray 144dff1f2812ecdaea89978c5351f0c70cdabbc0821Roland Levillain void Conversion_12x(const Instruction& instruction, 145dff1f2812ecdaea89978c5351f0c70cdabbc0821Roland Levillain Primitive::Type input_type, 146624279f3c70f9904cbaf428078981b05d3b324c0Roland Levillain Primitive::Type result_type, 147624279f3c70f9904cbaf428078981b05d3b324c0Roland Levillain uint32_t dex_pc); 148dff1f2812ecdaea89978c5351f0c70cdabbc0821Roland Levillain 149bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle void BuildCheckedDivRem(uint16_t out_reg, 150bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle uint16_t first_reg, 151bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle int64_t second_reg_or_constant, 152bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle uint32_t dex_pc, 153bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle Primitive::Type type, 154bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle bool second_is_lit, 155bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle bool is_div); 156d0d4852847432368b090c184d6639e573538dccfCalin Juravle 15701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray void BuildReturn(const Instruction& instruction, Primitive::Type type); 15801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 15919a19cffd197a28ae4c9c3e59eff6352fd392241Nicolas Geoffray // Builds an instance field access node and returns whether the instruction is supported. 160225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle bool BuildInstanceFieldAccess(const Instruction& instruction, uint32_t dex_pc, bool is_put); 16119a19cffd197a28ae4c9c3e59eff6352fd392241Nicolas Geoffray 16219a19cffd197a28ae4c9c3e59eff6352fd392241Nicolas Geoffray // Builds a static field access node and returns whether the instruction is supported. 163225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle bool BuildStaticFieldAccess(const Instruction& instruction, uint32_t dex_pc, bool is_put); 16419a19cffd197a28ae4c9c3e59eff6352fd392241Nicolas Geoffray 1653c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray void BuildArrayAccess(const Instruction& instruction, 166225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle uint32_t dex_pc, 1673c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray bool is_get, 1683c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray Primitive::Type anticipated_type); 169e50383288a75244255d3ecedcc79ffe9caf774cbNicolas Geoffray 17001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray // Builds an invocation node and returns whether the instruction is supported. 17101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray bool BuildInvoke(const Instruction& instruction, 172225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle uint32_t dex_pc, 17301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray uint32_t method_idx, 17401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray uint32_t number_of_vreg_arguments, 17501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray bool is_range, 17601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray uint32_t* args, 17701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray uint32_t register_index); 17801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 179a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // Builds a new array node and the instructions that fill it. 180225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle void BuildFilledNewArray(uint32_t dex_pc, 181a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray uint32_t type_index, 182a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray uint32_t number_of_vreg_arguments, 183a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray bool is_range, 184a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray uint32_t* args, 185a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray uint32_t register_index); 186a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray 187225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle void BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc); 188d0d4852847432368b090c184d6639e573538dccfCalin Juravle 189a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // Fills the given object with data as specified in the fill-array-data 190a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // instruction. Currently only used for non-reference and non-floating point 191a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // arrays. 192a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray template <typename T> 193a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray void BuildFillArrayData(HInstruction* object, 194a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray const T* data, 195a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray uint32_t element_count, 196a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray Primitive::Type anticipated_type, 197225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle uint32_t dex_pc); 198a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray 199a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // Fills the given object with data as specified in the fill-array-data 200a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // instruction. The data must be for long and double arrays. 201a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray void BuildFillWideArrayData(HInstruction* object, 2028d6ae524ed5d2fed1f9e789d6de9764d374afa43Nicolas Geoffray const int64_t* data, 203a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray uint32_t element_count, 204225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle uint32_t dex_pc); 205a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray 20657a88d4ac205874dc85d22f9f6a9ca3c4c373eebNicolas Geoffray // Builds a `HInstanceOf`, or a `HCheckCast` instruction. 20757a88d4ac205874dc85d22f9f6a9ca3c4c373eebNicolas Geoffray // Returns whether we succeeded in building the instruction. 20857a88d4ac205874dc85d22f9f6a9ca3c4c373eebNicolas Geoffray bool BuildTypeCheck(const Instruction& instruction, 20957a88d4ac205874dc85d22f9f6a9ca3c4c373eebNicolas Geoffray uint8_t destination, 21057a88d4ac205874dc85d22f9f6a9ca3c4c373eebNicolas Geoffray uint8_t reference, 21157a88d4ac205874dc85d22f9f6a9ca3c4c373eebNicolas Geoffray uint16_t type_index, 212225ff81cd34e20c97897a6b3f755a0a284b08f46Calin Juravle uint32_t dex_pc); 21357a88d4ac205874dc85d22f9f6a9ca3c4c373eebNicolas Geoffray 214e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampe // Builds an instruction sequence for a packed switch statement. 21548c2b03965830c73cdddeae8aea8030f08430137Calin Juravle void BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc); 216d881df5aad7950a185480876951762c1f60ea708Andreas Gampe 217e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampe // Builds an instruction sequence for a sparse switch statement. 21848c2b03965830c73cdddeae8aea8030f08430137Calin Juravle void BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc); 219e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampe 220e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampe void BuildSwitchCaseHelper(const Instruction& instruction, size_t index, 221e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampe bool is_last_case, const SwitchTable& table, 222e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampe HInstruction* value, int32_t case_value_int, 223e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampe int32_t target_offset, uint32_t dex_pc); 224e4d4d323aa42506351b03e842818e9ec09ea6c37Andreas Gampe 22548c2b03965830c73cdddeae8aea8030f08430137Calin Juravle bool SkipCompilation(size_t number_of_dex_instructions, 22648c2b03965830c73cdddeae8aea8030f08430137Calin Juravle size_t number_of_blocks, 22748c2b03965830c73cdddeae8aea8030f08430137Calin Juravle size_t number_of_branches); 22848c2b03965830c73cdddeae8aea8030f08430137Calin Juravle 22948c2b03965830c73cdddeae8aea8030f08430137Calin Juravle void MaybeRecordStat(MethodCompilationStat compilation_stat); 23048c2b03965830c73cdddeae8aea8030f08430137Calin Juravle 231e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray // Returns whether `type_index` points to the outer-most compiling method's class. 232e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray bool IsCompilingClass(uint16_t type_index) const { 233e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray uint32_t referrer_index = outer_compilation_unit_->GetDexMethodIndex(); 234e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray const DexFile::MethodId& method_id = 235e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray outer_compilation_unit_->GetDexFile()->GetMethodId(referrer_index); 236e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray return method_id.class_idx_ == type_index; 237e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray } 238e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray 239818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray ArenaAllocator* const arena_; 240be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray 241be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray // A list of the size of the dex code holding block information for 242be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray // the method. If an entry contains a block, then the dex instruction 243be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray // starting at that entry is the first instruction of a new block. 244be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray GrowableArray<HBasicBlock*> branch_targets_; 245be9a92aa804c0d210f80966b74ef8ed3987f335aNicolas Geoffray 2463ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray GrowableArray<HLocal*> locals_; 2473ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray 248818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray HBasicBlock* entry_block_; 249818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray HBasicBlock* exit_block_; 250818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray HBasicBlock* current_block_; 251818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray HGraph* graph_; 252818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 2533ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray HIntConstant* constant0_; 254bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray HIntConstant* constant1_; 2553ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray 256e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray // The dex file where the method being compiled is. 2578ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray const DexFile* const dex_file_; 258e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray 259e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray // The compilation unit of the current method being compiled. Note that 260e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray // it can be an inlined method. 26101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray DexCompilationUnit* const dex_compilation_unit_; 262e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray 263e50383288a75244255d3ecedcc79ffe9caf774cbNicolas Geoffray CompilerDriver* const compiler_driver_; 264e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray 265e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray // The compilation unit of the outermost method being compiled. That is the 266e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray // method being compiled (and not inlined), and potentially inlining other 267e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray // methods. 268e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray const DexCompilationUnit* const outer_compilation_unit_; 269e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray 270e53798a7e3267305f696bf658e418c92e63e0834Nicolas Geoffray // The return type of the method being compiled. 2717fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray const Primitive::Type return_type_; 2728ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray 273a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // The pointer in the dex file where the instructions of the code item 274a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // being currently compiled start. 275a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray const uint16_t* code_start_; 276a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray 277a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // The last invoke or fill-new-array being built. Only to be 278a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray // used by move-result instructions. 279a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray HInstruction* latest_result_; 280a3d05a40de076aabf12ea284c67c99ff28b43dbfNicolas Geoffray 28148c2b03965830c73cdddeae8aea8030f08430137Calin Juravle OptimizingCompilerStats* compilation_stats_; 28248c2b03965830c73cdddeae8aea8030f08430137Calin Juravle 283818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(HGraphBuilder); 284818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray}; 285818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 286818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray} // namespace art 287818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray 288818f2107e6d2d9e80faac8ae8c92faffa83cbd11Nicolas Geoffray#endif // ART_COMPILER_OPTIMIZING_BUILDER_H_ 289