Some common frontend tidying.
Change-Id: I1fa955cf8c4be45887e63085cbc2637569b7e545
diff --git a/src/compiler/dex/mir_graph.h b/src/compiler/dex/mir_graph.h
index 2f91787..8329010 100644
--- a/src/compiler/dex/mir_graph.h
+++ b/src/compiler/dex/mir_graph.h
@@ -117,313 +117,282 @@
extern const int oat_data_flow_attributes[kMirOpLast];
class MIRGraph {
- public:
- MIRGraph(CompilationUnit* cu);
- ~MIRGraph() {}
+ public:
+ MIRGraph(CompilationUnit* cu);
+ ~MIRGraph() {}
- /*
- * Parse dex method and add MIR at current insert point. Returns id (which is
- * actually the index of the method in the m_units_ array).
- */
- void InlineMethod(const DexFile::CodeItem* code_item, uint32_t access_flags,
- InvokeType invoke_type, uint32_t class_def_idx,
- uint32_t method_idx, jobject class_loader, const DexFile& dex_file);
+ /*
+ * Parse dex method and add MIR at current insert point. Returns id (which is
+ * actually the index of the method in the m_units_ array).
+ */
+ void InlineMethod(const DexFile::CodeItem* code_item, uint32_t access_flags,
+ InvokeType invoke_type, uint32_t class_def_idx,
+ uint32_t method_idx, jobject class_loader, const DexFile& dex_file);
- /* Find existing block */
- BasicBlock* FindBlock(unsigned int code_offset)
- {
- return FindBlock(code_offset, false, false, NULL);
- }
+ /* Find existing block */
+ BasicBlock* FindBlock(unsigned int code_offset) {
+ return FindBlock(code_offset, false, false, NULL);
+ }
- const uint16_t* GetCurrentInsns()
- {
- return current_code_item_->insns_;
- }
+ const uint16_t* GetCurrentInsns() const {
+ return current_code_item_->insns_;
+ }
- const uint16_t* GetInsns(int m_unit_index)
- {
- return m_units_[m_unit_index]->GetCodeItem()->insns_;
- }
+ const uint16_t* GetInsns(int m_unit_index) const {
+ return m_units_[m_unit_index]->GetCodeItem()->insns_;
+ }
- int GetNumBlocks()
- {
- return num_blocks_;
- }
+ int GetNumBlocks() const {
+ return num_blocks_;
+ }
- ArenaBitVector* GetTryBlockAddr()
- {
- return try_block_addr_;
- }
+ ArenaBitVector* GetTryBlockAddr() const {
+ return try_block_addr_;
+ }
- BasicBlock* GetEntryBlock()
- {
- return entry_block_;
- }
+ BasicBlock* GetEntryBlock() const {
+ return entry_block_;
+ }
- BasicBlock* GetExitBlock()
- {
- return exit_block_;
- }
+ BasicBlock* GetExitBlock() const {
+ return exit_block_;
+ }
- GrowableListIterator GetBasicBlockIterator()
- {
- GrowableListIterator iterator;
- GrowableListIteratorInit(&block_list_, &iterator);
- return iterator;
- }
+ GrowableListIterator GetBasicBlockIterator() {
+ GrowableListIterator iterator;
+ GrowableListIteratorInit(&block_list_, &iterator);
+ return iterator;
+ }
- BasicBlock* GetBasicBlock(int block_id)
- {
- return reinterpret_cast<BasicBlock*>(GrowableListGetElement(&block_list_, block_id));
- }
+ BasicBlock* GetBasicBlock(int block_id) const {
+ return reinterpret_cast<BasicBlock*>(GrowableListGetElement(&block_list_, block_id));
+ }
- size_t GetBasicBlockListCount()
- {
- return block_list_.num_used;
- }
+ size_t GetBasicBlockListCount() const {
+ return block_list_.num_used;
+ }
- GrowableList* GetBlockList()
- {
- return &block_list_;
- }
+ GrowableList* GetBlockList() {
+ return &block_list_;
+ }
- GrowableList* GetDfsOrder()
- {
- return &dfs_order_;
- }
+ GrowableList* GetDfsOrder() {
+ return &dfs_order_;
+ }
- GrowableList* GetDfsPostOrder()
- {
- return &dfs_post_order_;
- }
+ GrowableList* GetDfsPostOrder() {
+ return &dfs_post_order_;
+ }
- GrowableList* GetDomPostOrder()
- {
- return &dom_post_order_traversal_;
- }
+ GrowableList* GetDomPostOrder() {
+ return &dom_post_order_traversal_;
+ }
- GrowableList* GetSSASubscripts()
- {
- return ssa_subscripts_;
- }
+ GrowableList* GetSSASubscripts() {
+ return ssa_subscripts_;
+ }
- int GetDefCount()
- {
- return def_count_;
- }
+ int GetDefCount() const {
+ return def_count_;
+ }
- void EnableOpcodeCounting()
- {
- opcode_count_ = static_cast<int*>(NewMem(cu_, kNumPackedOpcodes * sizeof(int), true,
- kAllocMisc));
- }
+ void EnableOpcodeCounting() {
+ opcode_count_ = static_cast<int*>(NewMem(cu_, kNumPackedOpcodes * sizeof(int), true,
+ kAllocMisc));
+ }
- void ShowOpcodeStats();
+ void ShowOpcodeStats();
- DexCompilationUnit* GetCurrentDexCompilationUnit()
- {
- return m_units_[current_method_];
- }
+ DexCompilationUnit* GetCurrentDexCompilationUnit() const {
+ return m_units_[current_method_];
+ }
- void DumpCFG(const char* dir_prefix, bool all_blocks);
+ void DumpCFG(const char* dir_prefix, bool all_blocks);
- void BuildRegLocations();
+ void BuildRegLocations();
- void DumpRegLocTable(RegLocation* table, int count);
+ void DumpRegLocTable(RegLocation* table, int count);
- int ComputeFrameSize();
+ int ComputeFrameSize();
- void BasicBlockOptimization();
+ void BasicBlockOptimization();
- bool IsConst(int32_t s_reg)
- {
- return (IsBitSet(is_constant_v_, s_reg));
- }
+ bool IsConst(int32_t s_reg) const {
+ return (IsBitSet(is_constant_v_, s_reg));
+ }
- bool IsConst(RegLocation loc)
- {
- return (IsConst(loc.orig_sreg));
- }
+ bool IsConst(RegLocation loc) const {
+ return (IsConst(loc.orig_sreg));
+ }
- int32_t ConstantValue(RegLocation loc)
- {
- DCHECK(IsConst(loc));
- return constant_values_[loc.orig_sreg];
- }
+ int32_t ConstantValue(RegLocation loc) const {
+ DCHECK(IsConst(loc));
+ return constant_values_[loc.orig_sreg];
+ }
- int32_t ConstantValue(int32_t s_reg)
- {
- DCHECK(IsConst(s_reg));
- return constant_values_[s_reg];
- }
+ int32_t ConstantValue(int32_t s_reg) const {
+ DCHECK(IsConst(s_reg));
+ return constant_values_[s_reg];
+ }
- int64_t ConstantValueWide(RegLocation loc)
- {
- DCHECK(IsConst(loc));
- return (static_cast<int64_t>(constant_values_[loc.orig_sreg + 1]) << 32) |
- Low32Bits(static_cast<int64_t>(constant_values_[loc.orig_sreg]));
- }
+ int64_t ConstantValueWide(RegLocation loc) const {
+ DCHECK(IsConst(loc));
+ return (static_cast<int64_t>(constant_values_[loc.orig_sreg + 1]) << 32) |
+ Low32Bits(static_cast<int64_t>(constant_values_[loc.orig_sreg]));
+ }
- bool IsConstantNullRef(RegLocation loc)
- {
- return loc.ref && loc.is_const && (ConstantValue(loc) == 0);
- }
+ bool IsConstantNullRef(RegLocation loc) const {
+ return loc.ref && loc.is_const && (ConstantValue(loc) == 0);
+ }
- int GetNumSSARegs()
- {
- return num_ssa_regs_;
- }
+ int GetNumSSARegs() const {
+ return num_ssa_regs_;
+ }
- void SetNumSSARegs(int new_num)
- {
- num_ssa_regs_ = new_num;
- }
+ void SetNumSSARegs(int new_num) {
+ num_ssa_regs_ = new_num;
+ }
- int GetNumReachableBlocks()
- {
- return num_reachable_blocks_;
- }
+ int GetNumReachableBlocks() const {
+ return num_reachable_blocks_;
+ }
- int GetUseCount(int vreg)
- {
- return GrowableListGetElement(&use_counts_, vreg);
- }
+ int GetUseCount(int vreg) const {
+ return GrowableListGetElement(&use_counts_, vreg);
+ }
- int GetRawUseCount(int vreg)
- {
- return GrowableListGetElement(&raw_use_counts_, vreg);
- }
+ int GetRawUseCount(int vreg) const {
+ return GrowableListGetElement(&raw_use_counts_, vreg);
+ }
- int GetSSASubscript(int ssa_reg)
- {
- return GrowableListGetElement(ssa_subscripts_, ssa_reg);
- }
+ int GetSSASubscript(int ssa_reg) const {
+ return GrowableListGetElement(ssa_subscripts_, ssa_reg);
+ }
- const char* GetSSAString(int ssa_reg)
- {
- return GET_ELEM_N(ssa_strings_, char*, ssa_reg);
- }
+ const char* GetSSAString(int ssa_reg) const {
+ return GET_ELEM_N(ssa_strings_, char*, ssa_reg);
+ }
- void BasicBlockCombine();
- void CodeLayout();
- void DumpCheckStats();
- void PropagateConstants();
- MIR* FindMoveResult(BasicBlock* bb, MIR* mir);
- int SRegToVReg(int ssa_reg);
- void VerifyDataflow();
- void MethodUseCount();
- void SSATransformation();
- void CheckForDominanceFrontier(BasicBlock* dom_bb, const BasicBlock* succ_bb);
- void NullCheckElimination();
+ void BasicBlockCombine();
+ void CodeLayout();
+ void DumpCheckStats();
+ void PropagateConstants();
+ MIR* FindMoveResult(BasicBlock* bb, MIR* mir);
+ int SRegToVReg(int ssa_reg) const;
+ void VerifyDataflow();
+ void MethodUseCount();
+ void SSATransformation();
+ void CheckForDominanceFrontier(BasicBlock* dom_bb, const BasicBlock* succ_bb);
+ void NullCheckElimination();
- /*
- * IsDebugBuild sanity check: keep track of the Dex PCs for catch entries so that later on
- * we can verify that all catch entries have native PC entries.
- */
- std::set<uint32_t> catches_;
+ /*
+ * IsDebugBuild sanity check: keep track of the Dex PCs for catch entries so that later on
+ * we can verify that all catch entries have native PC entries.
+ */
+ std::set<uint32_t> catches_;
- private:
+ private:
- int FindCommonParent(int block1, int block2);
- void ComputeSuccLineIn(ArenaBitVector* dest, const ArenaBitVector* src1,
- const ArenaBitVector* src2);
- void HandleLiveInUse(ArenaBitVector* use_v, ArenaBitVector* def_v,
- ArenaBitVector* live_in_v, int dalvik_reg_id);
- void HandleDef(ArenaBitVector* def_v, int dalvik_reg_id);
- void CompilerInitializeSSAConversion();
- bool DoSSAConversion(BasicBlock* bb);
- bool InvokeUsesMethodStar(MIR* mir);
- int ParseInsn(const uint16_t* code_ptr, DecodedInstruction* decoded_instruction);
- bool ContentIsInsn(const uint16_t* code_ptr);
- BasicBlock* SplitBlock(unsigned int code_offset, BasicBlock* orig_block,
- BasicBlock** immed_pred_block_p);
- BasicBlock* FindBlock(unsigned int code_offset, bool split, bool create,
+ int FindCommonParent(int block1, int block2);
+ void ComputeSuccLineIn(ArenaBitVector* dest, const ArenaBitVector* src1,
+ const ArenaBitVector* src2);
+ void HandleLiveInUse(ArenaBitVector* use_v, ArenaBitVector* def_v,
+ ArenaBitVector* live_in_v, int dalvik_reg_id);
+ void HandleDef(ArenaBitVector* def_v, int dalvik_reg_id);
+ void CompilerInitializeSSAConversion();
+ bool DoSSAConversion(BasicBlock* bb);
+ bool InvokeUsesMethodStar(MIR* mir);
+ int ParseInsn(const uint16_t* code_ptr, DecodedInstruction* decoded_instruction);
+ bool ContentIsInsn(const uint16_t* code_ptr);
+ BasicBlock* SplitBlock(unsigned int code_offset, BasicBlock* orig_block,
BasicBlock** immed_pred_block_p);
- void ProcessTryCatchBlocks();
- BasicBlock* ProcessCanBranch(BasicBlock* cur_block, MIR* insn, int cur_offset, int width,
- int flags, const uint16_t* code_ptr, const uint16_t* code_end);
- void ProcessCanSwitch(BasicBlock* cur_block, MIR* insn, int cur_offset, int width, int flags);
- BasicBlock* ProcessCanThrow(BasicBlock* cur_block, MIR* insn, int cur_offset, int width,
- int flags, ArenaBitVector* try_block_addr, const uint16_t* code_ptr,
- const uint16_t* code_end);
- int AddNewSReg(int v_reg);
- void HandleSSAUse(int* uses, int dalvik_reg, int reg_index);
- void HandleSSADef(int* defs, int dalvik_reg, int reg_index);
- void DataFlowSSAFormat35C(MIR* mir);
- void DataFlowSSAFormat3RC(MIR* mir);
- bool FindLocalLiveIn(BasicBlock* bb);
- bool ClearVisitedFlag(struct BasicBlock* bb);
- bool CountUses(struct BasicBlock* bb);
- bool InferTypeAndSize(BasicBlock* bb);
- bool VerifyPredInfo(BasicBlock* bb);
- BasicBlock* NeedsVisit(BasicBlock* bb);
- BasicBlock* NextUnvisitedSuccessor(BasicBlock* bb);
- void MarkPreOrder(BasicBlock* bb);
- void RecordDFSOrders(BasicBlock* bb);
- void ComputeDFSOrders();
- void ComputeDefBlockMatrix();
- void ComputeDomPostOrderTraversal(BasicBlock* bb);
- void ComputeDominators();
- void InsertPhiNodes();
- void DoDFSPreOrderSSARename(BasicBlock* block);
- void SetConstant(int32_t ssa_reg, int value);
- void SetConstantWide(int ssa_reg, int64_t value);
- int GetSSAUseCount(int s_reg);
- bool BasicBlockOpt(BasicBlock* bb);
- bool EliminateNullChecks(BasicBlock* bb);
- bool NullCheckEliminationInit(BasicBlock* bb);
- bool BuildExtendedBBList(struct BasicBlock* bb);
- bool FillDefBlockMatrix(BasicBlock* bb);
- bool InitializeDominationInfo(BasicBlock* bb);
- bool ComputeblockIDom(BasicBlock* bb);
- bool ComputeBlockDominators(BasicBlock* bb);
- bool SetDominators(BasicBlock* bb);
- bool ComputeBlockLiveIns(BasicBlock* bb);
- bool InsertPhiNodeOperands(BasicBlock* bb);
- bool ComputeDominanceFrontier(BasicBlock* bb);
- bool DoConstantPropogation(BasicBlock* bb);
- bool CountChecks(BasicBlock* bb);
- bool CombineBlocks(BasicBlock* bb);
+ BasicBlock* FindBlock(unsigned int code_offset, bool split, bool create,
+ BasicBlock** immed_pred_block_p);
+ void ProcessTryCatchBlocks();
+ BasicBlock* ProcessCanBranch(BasicBlock* cur_block, MIR* insn, int cur_offset, int width,
+ int flags, const uint16_t* code_ptr, const uint16_t* code_end);
+ void ProcessCanSwitch(BasicBlock* cur_block, MIR* insn, int cur_offset, int width, int flags);
+ BasicBlock* ProcessCanThrow(BasicBlock* cur_block, MIR* insn, int cur_offset, int width,
+ int flags, ArenaBitVector* try_block_addr, const uint16_t* code_ptr,
+ const uint16_t* code_end);
+ int AddNewSReg(int v_reg);
+ void HandleSSAUse(int* uses, int dalvik_reg, int reg_index);
+ void HandleSSADef(int* defs, int dalvik_reg, int reg_index);
+ void DataFlowSSAFormat35C(MIR* mir);
+ void DataFlowSSAFormat3RC(MIR* mir);
+ bool FindLocalLiveIn(BasicBlock* bb);
+ bool ClearVisitedFlag(struct BasicBlock* bb);
+ bool CountUses(struct BasicBlock* bb);
+ bool InferTypeAndSize(BasicBlock* bb);
+ bool VerifyPredInfo(BasicBlock* bb);
+ BasicBlock* NeedsVisit(BasicBlock* bb);
+ BasicBlock* NextUnvisitedSuccessor(BasicBlock* bb);
+ void MarkPreOrder(BasicBlock* bb);
+ void RecordDFSOrders(BasicBlock* bb);
+ void ComputeDFSOrders();
+ void ComputeDefBlockMatrix();
+ void ComputeDomPostOrderTraversal(BasicBlock* bb);
+ void ComputeDominators();
+ void InsertPhiNodes();
+ void DoDFSPreOrderSSARename(BasicBlock* block);
+ void SetConstant(int32_t ssa_reg, int value);
+ void SetConstantWide(int ssa_reg, int64_t value);
+ int GetSSAUseCount(int s_reg);
+ bool BasicBlockOpt(BasicBlock* bb);
+ bool EliminateNullChecks(BasicBlock* bb);
+ bool NullCheckEliminationInit(BasicBlock* bb);
+ bool BuildExtendedBBList(struct BasicBlock* bb);
+ bool FillDefBlockMatrix(BasicBlock* bb);
+ bool InitializeDominationInfo(BasicBlock* bb);
+ bool ComputeblockIDom(BasicBlock* bb);
+ bool ComputeBlockDominators(BasicBlock* bb);
+ bool SetDominators(BasicBlock* bb);
+ bool ComputeBlockLiveIns(BasicBlock* bb);
+ bool InsertPhiNodeOperands(BasicBlock* bb);
+ bool ComputeDominanceFrontier(BasicBlock* bb);
+ bool DoConstantPropogation(BasicBlock* bb);
+ bool CountChecks(BasicBlock* bb);
+ bool CombineBlocks(BasicBlock* bb);
- CompilationUnit* cu_;
- GrowableList* ssa_base_vregs_;
- GrowableList* ssa_subscripts_;
- GrowableList* ssa_strings_;
- // Map original Dalvik virtual reg i to the current SSA name.
- int* vreg_to_ssa_map_; // length == method->registers_size
- int* ssa_last_defs_; // length == method->registers_size
- ArenaBitVector* is_constant_v_; // length == num_ssa_reg
- int* constant_values_; // length == num_ssa_reg
- // Use counts of ssa names.
- GrowableList use_counts_; // Weighted by nesting depth
- GrowableList raw_use_counts_; // Not weighted
- int num_reachable_blocks_;
- GrowableList dfs_order_;
- GrowableList dfs_post_order_;
- GrowableList dom_post_order_traversal_;
- int* i_dom_list_;
- ArenaBitVector** def_block_matrix_; // num_dalvik_register x num_blocks.
- ArenaBitVector* temp_block_v_;
- ArenaBitVector* temp_dalvik_register_v_;
- ArenaBitVector* temp_ssa_register_v_; // num_ssa_regs.
- static const int kInvalidEntry = -1;
- GrowableList block_list_;
- ArenaBitVector* try_block_addr_;
- BasicBlock* entry_block_;
- BasicBlock* exit_block_;
- BasicBlock* cur_block_;
- int num_blocks_;
- const DexFile::CodeItem* current_code_item_;
- SafeMap<unsigned int, BasicBlock*> block_map_; // FindBlock lookup cache.
- std::vector<DexCompilationUnit*> m_units_; // List of methods included in this graph
- typedef std::pair<int, int> MIRLocation; // Insert point, (m_unit_ index, offset)
- std::vector<MIRLocation> method_stack_; // Include stack
- int current_method_;
- int current_offset_;
- int def_count_; // Used to estimate size of ssa name storage.
- int* opcode_count_; // Dex opcode coverage stats.
- int num_ssa_regs_; // Number of names following SSA transformation.
- std::vector<BasicBlock*> extended_basic_blocks_; // Heads of block "traces".
+ CompilationUnit* const cu_;
+ GrowableList* ssa_base_vregs_;
+ GrowableList* ssa_subscripts_;
+ GrowableList* ssa_strings_;
+ // Map original Dalvik virtual reg i to the current SSA name.
+ int* vreg_to_ssa_map_; // length == method->registers_size
+ int* ssa_last_defs_; // length == method->registers_size
+ ArenaBitVector* is_constant_v_; // length == num_ssa_reg
+ int* constant_values_; // length == num_ssa_reg
+ // Use counts of ssa names.
+ GrowableList use_counts_; // Weighted by nesting depth
+ GrowableList raw_use_counts_; // Not weighted
+ int num_reachable_blocks_;
+ GrowableList dfs_order_;
+ GrowableList dfs_post_order_;
+ GrowableList dom_post_order_traversal_;
+ int* i_dom_list_;
+ ArenaBitVector** def_block_matrix_; // num_dalvik_register x num_blocks.
+ ArenaBitVector* temp_block_v_;
+ ArenaBitVector* temp_dalvik_register_v_;
+ ArenaBitVector* temp_ssa_register_v_; // num_ssa_regs.
+ static const int kInvalidEntry = -1;
+ GrowableList block_list_;
+ ArenaBitVector* try_block_addr_;
+ BasicBlock* entry_block_;
+ BasicBlock* exit_block_;
+ BasicBlock* cur_block_;
+ int num_blocks_;
+ const DexFile::CodeItem* current_code_item_;
+ SafeMap<unsigned int, BasicBlock*> block_map_; // FindBlock lookup cache.
+ std::vector<DexCompilationUnit*> m_units_; // List of methods included in this graph
+ typedef std::pair<int, int> MIRLocation; // Insert point, (m_unit_ index, offset)
+ std::vector<MIRLocation> method_stack_; // Include stack
+ int current_method_;
+ int current_offset_;
+ int def_count_; // Used to estimate size of ssa name storage.
+ int* opcode_count_; // Dex opcode coverage stats.
+ int num_ssa_regs_; // Number of names following SSA transformation.
+ std::vector<BasicBlock*> extended_basic_blocks_; // Heads of block "traces".
};
} // namespace art