blob: 7bf7a651ab1ec4d19f707b2704d616a20c5b0c82 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
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 */
16
Ian Rogerse77493c2014-08-20 15:08:45 -070017#include "base/bit_vector-inl.h"
buzbeeeaf09bc2012-11-15 14:51:41 -080018#include "compiler_internals.h"
Ian Rogers8d3a1172013-06-04 01:13:28 -070019#include "dataflow_iterator-inl.h"
Vladimir Markoc9360ce2014-06-05 20:09:47 +010020#include "utils/scoped_arena_containers.h"
buzbee67bf8852011-08-17 17:51:35 -070021
buzbee1fd33462013-03-25 13:40:45 -070022#define NOTVISITED (-1)
23
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080024namespace art {
25
buzbeea5abf702013-04-12 14:39:29 -070026void MIRGraph::ClearAllVisitedFlags() {
buzbee56c71782013-09-05 17:13:19 -070027 AllNodesIterator iter(this);
buzbeea5abf702013-04-12 14:39:29 -070028 for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
29 bb->visited = false;
30 }
31}
32
buzbee311ca162013-02-28 15:56:43 -080033BasicBlock* MIRGraph::NeedsVisit(BasicBlock* bb) {
buzbeee5f01222012-06-14 15:19:35 -070034 if (bb != NULL) {
35 if (bb->visited || bb->hidden) {
36 bb = NULL;
37 }
38 }
39 return bb;
40}
41
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070042BasicBlock* MIRGraph::NextUnvisitedSuccessor(BasicBlock* bb) {
buzbee0d829482013-10-11 15:24:55 -070043 BasicBlock* res = NeedsVisit(GetBasicBlock(bb->fall_through));
buzbeee5f01222012-06-14 15:19:35 -070044 if (res == NULL) {
buzbee0d829482013-10-11 15:24:55 -070045 res = NeedsVisit(GetBasicBlock(bb->taken));
buzbeee5f01222012-06-14 15:19:35 -070046 if (res == NULL) {
buzbee0d829482013-10-11 15:24:55 -070047 if (bb->successor_block_list_type != kNotUsed) {
48 GrowableArray<SuccessorBlockInfo*>::Iterator iterator(bb->successor_blocks);
buzbeee5f01222012-06-14 15:19:35 -070049 while (true) {
buzbee862a7602013-04-05 10:58:54 -070050 SuccessorBlockInfo *sbi = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -070051 if (sbi == NULL) {
52 break;
53 }
buzbee0d829482013-10-11 15:24:55 -070054 res = NeedsVisit(GetBasicBlock(sbi->block));
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -070055 if (res != NULL) {
56 break;
57 }
buzbeee5f01222012-06-14 15:19:35 -070058 }
59 }
60 }
61 }
62 return res;
63}
64
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070065void MIRGraph::MarkPreOrder(BasicBlock* block) {
buzbeee5f01222012-06-14 15:19:35 -070066 block->visited = true;
buzbeefa57c472012-11-21 12:06:18 -080067 /* Enqueue the pre_order block id */
buzbee0d829482013-10-11 15:24:55 -070068 if (block->id != NullBasicBlockId) {
69 dfs_order_->Insert(block->id);
70 }
buzbeee5f01222012-06-14 15:19:35 -070071}
72
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070073void MIRGraph::RecordDFSOrders(BasicBlock* block) {
Vladimir Markoc9360ce2014-06-05 20:09:47 +010074 DCHECK(temp_scoped_alloc_.get() != nullptr);
75 ScopedArenaVector<BasicBlock*> succ(temp_scoped_alloc_->Adapter());
buzbee311ca162013-02-28 15:56:43 -080076 MarkPreOrder(block);
buzbeee5f01222012-06-14 15:19:35 -070077 succ.push_back(block);
78 while (!succ.empty()) {
79 BasicBlock* curr = succ.back();
buzbeefa57c472012-11-21 12:06:18 -080080 BasicBlock* next_successor = NextUnvisitedSuccessor(curr);
81 if (next_successor != NULL) {
buzbee311ca162013-02-28 15:56:43 -080082 MarkPreOrder(next_successor);
buzbeefa57c472012-11-21 12:06:18 -080083 succ.push_back(next_successor);
buzbeee5f01222012-06-14 15:19:35 -070084 continue;
85 }
buzbee862a7602013-04-05 10:58:54 -070086 curr->dfs_id = dfs_post_order_->Size();
buzbee0d829482013-10-11 15:24:55 -070087 if (curr->id != NullBasicBlockId) {
88 dfs_post_order_->Insert(curr->id);
89 }
buzbeee5f01222012-06-14 15:19:35 -070090 succ.pop_back();
91 }
92}
93
buzbee5b537102012-01-17 17:33:47 -080094/* Sort the blocks by the Depth-First-Search */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070095void MIRGraph::ComputeDFSOrders() {
buzbeefa57c472012-11-21 12:06:18 -080096 /* Initialize or reset the DFS pre_order list */
buzbee862a7602013-04-05 10:58:54 -070097 if (dfs_order_ == NULL) {
buzbee0d829482013-10-11 15:24:55 -070098 dfs_order_ = new (arena_) GrowableArray<BasicBlockId>(arena_, GetNumBlocks(),
99 kGrowableArrayDfsOrder);
Bill Buzbeea114add2012-05-03 15:00:40 -0700100 } else {
101 /* Just reset the used length on the counter */
buzbee862a7602013-04-05 10:58:54 -0700102 dfs_order_->Reset();
Bill Buzbeea114add2012-05-03 15:00:40 -0700103 }
buzbee67bf8852011-08-17 17:51:35 -0700104
buzbeefa57c472012-11-21 12:06:18 -0800105 /* Initialize or reset the DFS post_order list */
buzbee862a7602013-04-05 10:58:54 -0700106 if (dfs_post_order_ == NULL) {
buzbee0d829482013-10-11 15:24:55 -0700107 dfs_post_order_ = new (arena_) GrowableArray<BasicBlockId>(arena_, GetNumBlocks(),
108 kGrowableArrayDfsPostOrder);
Bill Buzbeea114add2012-05-03 15:00:40 -0700109 } else {
110 /* Just reset the used length on the counter */
buzbee862a7602013-04-05 10:58:54 -0700111 dfs_post_order_->Reset();
Bill Buzbeea114add2012-05-03 15:00:40 -0700112 }
buzbee5b537102012-01-17 17:33:47 -0800113
buzbeee5f01222012-06-14 15:19:35 -0700114 // Reset visited flags from all nodes
buzbeea5abf702013-04-12 14:39:29 -0700115 ClearAllVisitedFlags();
116
buzbeee5f01222012-06-14 15:19:35 -0700117 // Record dfs orders
buzbee311ca162013-02-28 15:56:43 -0800118 RecordDFSOrders(GetEntryBlock());
buzbeee5f01222012-06-14 15:19:35 -0700119
buzbee862a7602013-04-05 10:58:54 -0700120 num_reachable_blocks_ = dfs_order_->Size();
Andreas Gampe44395962014-06-13 13:44:40 -0700121
122 if (num_reachable_blocks_ != num_blocks_) {
123 // Hide all unreachable blocks.
124 AllNodesIterator iter(this);
125 for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
126 if (!bb->visited) {
127 bb->Hide(cu_);
128 }
129 }
130 }
buzbee67bf8852011-08-17 17:51:35 -0700131}
132
133/*
134 * Mark block bit on the per-Dalvik register vector to denote that Dalvik
135 * register idx is defined in BasicBlock bb.
136 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700137bool MIRGraph::FillDefBlockMatrix(BasicBlock* bb) {
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700138 if (bb->data_flow_info == NULL) {
139 return false;
140 }
buzbee67bf8852011-08-17 17:51:35 -0700141
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100142 for (uint32_t idx : bb->data_flow_info->def_v->Indexes()) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700143 /* Block bb defines register idx */
buzbee862a7602013-04-05 10:58:54 -0700144 def_block_matrix_[idx]->SetBit(bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700145 }
146 return true;
buzbee67bf8852011-08-17 17:51:35 -0700147}
148
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700149void MIRGraph::ComputeDefBlockMatrix() {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700150 int num_registers = GetNumOfCodeAndTempVRs();
151 /* Allocate num_registers bit vector pointers */
buzbee311ca162013-02-28 15:56:43 -0800152 def_block_matrix_ = static_cast<ArenaBitVector**>
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700153 (arena_->Alloc(sizeof(ArenaBitVector *) * num_registers,
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000154 kArenaAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -0700155 int i;
buzbee67bf8852011-08-17 17:51:35 -0700156
buzbeefa57c472012-11-21 12:06:18 -0800157 /* Initialize num_register vectors with num_blocks bits each */
158 for (i = 0; i < num_registers; i++) {
buzbee862a7602013-04-05 10:58:54 -0700159 def_block_matrix_[i] =
160 new (arena_) ArenaBitVector(arena_, GetNumBlocks(), false, kBitMapBMatrix);
Bill Buzbeea114add2012-05-03 15:00:40 -0700161 }
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700162
buzbee56c71782013-09-05 17:13:19 -0700163 AllNodesIterator iter(this);
buzbee311ca162013-02-28 15:56:43 -0800164 for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
165 FindLocalLiveIn(bb);
166 }
buzbee56c71782013-09-05 17:13:19 -0700167 AllNodesIterator iter2(this);
buzbee311ca162013-02-28 15:56:43 -0800168 for (BasicBlock* bb = iter2.Next(); bb != NULL; bb = iter2.Next()) {
169 FillDefBlockMatrix(bb);
170 }
buzbee67bf8852011-08-17 17:51:35 -0700171
Bill Buzbeea114add2012-05-03 15:00:40 -0700172 /*
173 * Also set the incoming parameters as defs in the entry block.
174 * Only need to handle the parameters for the outer method.
175 */
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700176 int num_regs = GetNumOfCodeVRs();
177 int in_reg = GetFirstInVR();
buzbeefa57c472012-11-21 12:06:18 -0800178 for (; in_reg < num_regs; in_reg++) {
buzbee862a7602013-04-05 10:58:54 -0700179 def_block_matrix_[in_reg]->SetBit(GetEntryBlock()->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700180 }
buzbee67bf8852011-08-17 17:51:35 -0700181}
182
buzbeea5abf702013-04-12 14:39:29 -0700183void MIRGraph::ComputeDomPostOrderTraversal(BasicBlock* bb) {
Jean Christophe Beyler4896d7b2014-05-01 15:36:22 -0700184 if (dom_post_order_traversal_ == NULL || max_num_reachable_blocks_ < num_reachable_blocks_) {
185 // First time or too small - create the array.
buzbeea5abf702013-04-12 14:39:29 -0700186 dom_post_order_traversal_ =
buzbee0d829482013-10-11 15:24:55 -0700187 new (arena_) GrowableArray<BasicBlockId>(arena_, num_reachable_blocks_,
buzbeea5abf702013-04-12 14:39:29 -0700188 kGrowableArrayDomPostOrderTraversal);
189 } else {
190 dom_post_order_traversal_->Reset();
Bill Buzbeea114add2012-05-03 15:00:40 -0700191 }
buzbeea5abf702013-04-12 14:39:29 -0700192 ClearAllVisitedFlags();
Vladimir Markoc9360ce2014-06-05 20:09:47 +0100193 DCHECK(temp_scoped_alloc_.get() != nullptr);
194 ScopedArenaVector<std::pair<BasicBlock*, ArenaBitVector::IndexIterator>> work_stack(
195 temp_scoped_alloc_->Adapter());
buzbeea5abf702013-04-12 14:39:29 -0700196 bb->visited = true;
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100197 work_stack.push_back(std::make_pair(bb, bb->i_dominated->Indexes().begin()));
buzbeea5abf702013-04-12 14:39:29 -0700198 while (!work_stack.empty()) {
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100199 std::pair<BasicBlock*, ArenaBitVector::IndexIterator>* curr = &work_stack.back();
200 BasicBlock* curr_bb = curr->first;
201 ArenaBitVector::IndexIterator* curr_idom_iter = &curr->second;
202 while (!curr_idom_iter->Done() && (NeedsVisit(GetBasicBlock(**curr_idom_iter)) == nullptr)) {
203 ++*curr_idom_iter;
buzbeea5abf702013-04-12 14:39:29 -0700204 }
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100205 // NOTE: work_stack.push_back()/pop_back() invalidate curr and curr_idom_iter.
206 if (!curr_idom_iter->Done()) {
207 BasicBlock* new_bb = GetBasicBlock(**curr_idom_iter);
208 ++*curr_idom_iter;
buzbeea5abf702013-04-12 14:39:29 -0700209 new_bb->visited = true;
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100210 work_stack.push_back(std::make_pair(new_bb, new_bb->i_dominated->Indexes().begin()));
buzbeea5abf702013-04-12 14:39:29 -0700211 } else {
212 // no successor/next
buzbee0d829482013-10-11 15:24:55 -0700213 if (curr_bb->id != NullBasicBlockId) {
214 dom_post_order_traversal_->Insert(curr_bb->id);
215 }
buzbeea5abf702013-04-12 14:39:29 -0700216 work_stack.pop_back();
buzbee67bf8852011-08-17 17:51:35 -0700217
buzbeea5abf702013-04-12 14:39:29 -0700218 /* hacky loop detection */
buzbee0d829482013-10-11 15:24:55 -0700219 if ((curr_bb->taken != NullBasicBlockId) && curr_bb->dominators->IsBitSet(curr_bb->taken)) {
Bill Buzbee0b1191c2013-10-28 22:11:59 +0000220 curr_bb->nesting_depth++;
buzbeea5abf702013-04-12 14:39:29 -0700221 attributes_ |= METHOD_HAS_LOOP;
222 }
223 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700224 }
buzbee67bf8852011-08-17 17:51:35 -0700225}
226
buzbee311ca162013-02-28 15:56:43 -0800227void MIRGraph::CheckForDominanceFrontier(BasicBlock* dom_bb,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700228 const BasicBlock* succ_bb) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700229 /*
230 * TODO - evaluate whether phi will ever need to be inserted into exit
231 * blocks.
232 */
buzbee0d829482013-10-11 15:24:55 -0700233 if (succ_bb->i_dom != dom_bb->id &&
buzbeefa57c472012-11-21 12:06:18 -0800234 succ_bb->block_type == kDalvikByteCode &&
235 succ_bb->hidden == false) {
buzbee862a7602013-04-05 10:58:54 -0700236 dom_bb->dom_frontier->SetBit(succ_bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700237 }
buzbee67bf8852011-08-17 17:51:35 -0700238}
239
240/* Worker function to compute the dominance frontier */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700241bool MIRGraph::ComputeDominanceFrontier(BasicBlock* bb) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700242 /* Calculate DF_local */
buzbee0d829482013-10-11 15:24:55 -0700243 if (bb->taken != NullBasicBlockId) {
244 CheckForDominanceFrontier(bb, GetBasicBlock(bb->taken));
Bill Buzbeea114add2012-05-03 15:00:40 -0700245 }
buzbee0d829482013-10-11 15:24:55 -0700246 if (bb->fall_through != NullBasicBlockId) {
247 CheckForDominanceFrontier(bb, GetBasicBlock(bb->fall_through));
Bill Buzbeea114add2012-05-03 15:00:40 -0700248 }
buzbee0d829482013-10-11 15:24:55 -0700249 if (bb->successor_block_list_type != kNotUsed) {
250 GrowableArray<SuccessorBlockInfo*>::Iterator iterator(bb->successor_blocks);
Bill Buzbeea114add2012-05-03 15:00:40 -0700251 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700252 SuccessorBlockInfo *successor_block_info = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700253 if (successor_block_info == NULL) {
254 break;
255 }
buzbee0d829482013-10-11 15:24:55 -0700256 BasicBlock* succ_bb = GetBasicBlock(successor_block_info->block);
buzbee311ca162013-02-28 15:56:43 -0800257 CheckForDominanceFrontier(bb, succ_bb);
Bill Buzbeea114add2012-05-03 15:00:40 -0700258 }
259 }
buzbee67bf8852011-08-17 17:51:35 -0700260
Bill Buzbeea114add2012-05-03 15:00:40 -0700261 /* Calculate DF_up */
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100262 for (uint32_t dominated_idx : bb->i_dominated->Indexes()) {
Jean Christophe Beyler2469e602014-05-06 20:36:55 -0700263 BasicBlock* dominated_bb = GetBasicBlock(dominated_idx);
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100264 for (uint32_t df_up_block_idx : dominated_bb->dom_frontier->Indexes()) {
Jean Christophe Beyler2469e602014-05-06 20:36:55 -0700265 BasicBlock* df_up_block = GetBasicBlock(df_up_block_idx);
buzbee311ca162013-02-28 15:56:43 -0800266 CheckForDominanceFrontier(bb, df_up_block);
buzbee67bf8852011-08-17 17:51:35 -0700267 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700268 }
buzbee67bf8852011-08-17 17:51:35 -0700269
Bill Buzbeea114add2012-05-03 15:00:40 -0700270 return true;
buzbee67bf8852011-08-17 17:51:35 -0700271}
272
273/* Worker function for initializing domination-related data structures */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700274void MIRGraph::InitializeDominationInfo(BasicBlock* bb) {
buzbee311ca162013-02-28 15:56:43 -0800275 int num_total_blocks = GetBasicBlockListCount();
buzbee67bf8852011-08-17 17:51:35 -0700276
Brian Carlstromdf629502013-07-17 22:39:56 -0700277 if (bb->dominators == NULL) {
buzbee862a7602013-04-05 10:58:54 -0700278 bb->dominators = new (arena_) ArenaBitVector(arena_, num_total_blocks,
279 false /* expandable */, kBitMapDominators);
280 bb->i_dominated = new (arena_) ArenaBitVector(arena_, num_total_blocks,
281 false /* expandable */, kBitMapIDominated);
282 bb->dom_frontier = new (arena_) ArenaBitVector(arena_, num_total_blocks,
283 false /* expandable */, kBitMapDomFrontier);
Bill Buzbeea114add2012-05-03 15:00:40 -0700284 } else {
buzbee862a7602013-04-05 10:58:54 -0700285 bb->dominators->ClearAllBits();
286 bb->i_dominated->ClearAllBits();
287 bb->dom_frontier->ClearAllBits();
Bill Buzbeea114add2012-05-03 15:00:40 -0700288 }
289 /* Set all bits in the dominator vector */
buzbee862a7602013-04-05 10:58:54 -0700290 bb->dominators->SetInitialBits(num_total_blocks);
buzbee67bf8852011-08-17 17:51:35 -0700291
buzbee862a7602013-04-05 10:58:54 -0700292 return;
buzbee67bf8852011-08-17 17:51:35 -0700293}
294
buzbee5b537102012-01-17 17:33:47 -0800295/*
buzbeefa57c472012-11-21 12:06:18 -0800296 * Walk through the ordered i_dom list until we reach common parent.
297 * Given the ordering of i_dom_list, this common parent represents the
buzbee5b537102012-01-17 17:33:47 -0800298 * last element of the intersection of block1 and block2 dominators.
299 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700300int MIRGraph::FindCommonParent(int block1, int block2) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700301 while (block1 != block2) {
302 while (block1 < block2) {
buzbee311ca162013-02-28 15:56:43 -0800303 block1 = i_dom_list_[block1];
Bill Buzbeea114add2012-05-03 15:00:40 -0700304 DCHECK_NE(block1, NOTVISITED);
buzbee5b537102012-01-17 17:33:47 -0800305 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700306 while (block2 < block1) {
buzbee311ca162013-02-28 15:56:43 -0800307 block2 = i_dom_list_[block2];
Bill Buzbeea114add2012-05-03 15:00:40 -0700308 DCHECK_NE(block2, NOTVISITED);
309 }
310 }
311 return block1;
buzbee5b537102012-01-17 17:33:47 -0800312}
313
314/* Worker function to compute each block's immediate dominator */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700315bool MIRGraph::ComputeblockIDom(BasicBlock* bb) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700316 /* Special-case entry block */
buzbee0d829482013-10-11 15:24:55 -0700317 if ((bb->id == NullBasicBlockId) || (bb == GetEntryBlock())) {
buzbee5b537102012-01-17 17:33:47 -0800318 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -0700319 }
320
321 /* Iterate through the predecessors */
buzbee0d829482013-10-11 15:24:55 -0700322 GrowableArray<BasicBlockId>::Iterator iter(bb->predecessors);
Bill Buzbeea114add2012-05-03 15:00:40 -0700323
324 /* Find the first processed predecessor */
buzbee862a7602013-04-05 10:58:54 -0700325 int idom = -1;
Bill Buzbeea114add2012-05-03 15:00:40 -0700326 while (true) {
buzbee0d829482013-10-11 15:24:55 -0700327 BasicBlock* pred_bb = GetBasicBlock(iter.Next());
buzbeefa57c472012-11-21 12:06:18 -0800328 CHECK(pred_bb != NULL);
buzbee311ca162013-02-28 15:56:43 -0800329 if (i_dom_list_[pred_bb->dfs_id] != NOTVISITED) {
buzbeefa57c472012-11-21 12:06:18 -0800330 idom = pred_bb->dfs_id;
Bill Buzbeea114add2012-05-03 15:00:40 -0700331 break;
332 }
333 }
334
335 /* Scan the rest of the predecessors */
336 while (true) {
buzbee0d829482013-10-11 15:24:55 -0700337 BasicBlock* pred_bb = GetBasicBlock(iter.Next());
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700338 if (!pred_bb) {
339 break;
340 }
buzbee311ca162013-02-28 15:56:43 -0800341 if (i_dom_list_[pred_bb->dfs_id] == NOTVISITED) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700342 continue;
343 } else {
buzbee311ca162013-02-28 15:56:43 -0800344 idom = FindCommonParent(pred_bb->dfs_id, idom);
Bill Buzbeea114add2012-05-03 15:00:40 -0700345 }
346 }
347
348 DCHECK_NE(idom, NOTVISITED);
349
350 /* Did something change? */
buzbee311ca162013-02-28 15:56:43 -0800351 if (i_dom_list_[bb->dfs_id] != idom) {
352 i_dom_list_[bb->dfs_id] = idom;
Bill Buzbeea114add2012-05-03 15:00:40 -0700353 return true;
354 }
355 return false;
buzbee5b537102012-01-17 17:33:47 -0800356}
357
358/* Worker function to compute each block's domintors */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700359bool MIRGraph::ComputeBlockDominators(BasicBlock* bb) {
buzbee311ca162013-02-28 15:56:43 -0800360 if (bb == GetEntryBlock()) {
buzbee862a7602013-04-05 10:58:54 -0700361 bb->dominators->ClearAllBits();
Bill Buzbeea114add2012-05-03 15:00:40 -0700362 } else {
buzbee0d829482013-10-11 15:24:55 -0700363 bb->dominators->Copy(GetBasicBlock(bb->i_dom)->dominators);
Bill Buzbeea114add2012-05-03 15:00:40 -0700364 }
buzbee862a7602013-04-05 10:58:54 -0700365 bb->dominators->SetBit(bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700366 return false;
buzbee5b537102012-01-17 17:33:47 -0800367}
368
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700369bool MIRGraph::SetDominators(BasicBlock* bb) {
buzbee311ca162013-02-28 15:56:43 -0800370 if (bb != GetEntryBlock()) {
371 int idom_dfs_idx = i_dom_list_[bb->dfs_id];
buzbeefa57c472012-11-21 12:06:18 -0800372 DCHECK_NE(idom_dfs_idx, NOTVISITED);
buzbee862a7602013-04-05 10:58:54 -0700373 int i_dom_idx = dfs_post_order_->Get(idom_dfs_idx);
buzbee311ca162013-02-28 15:56:43 -0800374 BasicBlock* i_dom = GetBasicBlock(i_dom_idx);
buzbee0d829482013-10-11 15:24:55 -0700375 bb->i_dom = i_dom->id;
buzbeefa57c472012-11-21 12:06:18 -0800376 /* Add bb to the i_dominated set of the immediate dominator block */
buzbee862a7602013-04-05 10:58:54 -0700377 i_dom->i_dominated->SetBit(bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700378 }
379 return false;
buzbee5b537102012-01-17 17:33:47 -0800380}
381
buzbee67bf8852011-08-17 17:51:35 -0700382/* Compute dominators, immediate dominator, and dominance fronter */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700383void MIRGraph::ComputeDominators() {
buzbee311ca162013-02-28 15:56:43 -0800384 int num_reachable_blocks = num_reachable_blocks_;
buzbee67bf8852011-08-17 17:51:35 -0700385
Bill Buzbeea114add2012-05-03 15:00:40 -0700386 /* Initialize domination-related data structures */
buzbee56c71782013-09-05 17:13:19 -0700387 PreOrderDfsIterator iter(this);
buzbee311ca162013-02-28 15:56:43 -0800388 for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
389 InitializeDominationInfo(bb);
390 }
buzbee67bf8852011-08-17 17:51:35 -0700391
Jean Christophe Beyler4896d7b2014-05-01 15:36:22 -0700392 /* Initialize & Clear i_dom_list */
393 if (max_num_reachable_blocks_ < num_reachable_blocks_) {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700394 i_dom_list_ = static_cast<int*>(arena_->Alloc(sizeof(int) * num_reachable_blocks,
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000395 kArenaAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -0700396 }
buzbeefa57c472012-11-21 12:06:18 -0800397 for (int i = 0; i < num_reachable_blocks; i++) {
buzbee311ca162013-02-28 15:56:43 -0800398 i_dom_list_[i] = NOTVISITED;
Bill Buzbeea114add2012-05-03 15:00:40 -0700399 }
buzbee5b537102012-01-17 17:33:47 -0800400
buzbeefa57c472012-11-21 12:06:18 -0800401 /* For post-order, last block is entry block. Set its i_dom to istelf */
buzbee311ca162013-02-28 15:56:43 -0800402 DCHECK_EQ(GetEntryBlock()->dfs_id, num_reachable_blocks-1);
403 i_dom_list_[GetEntryBlock()->dfs_id] = GetEntryBlock()->dfs_id;
buzbee5b537102012-01-17 17:33:47 -0800404
Bill Buzbeea114add2012-05-03 15:00:40 -0700405 /* Compute the immediate dominators */
buzbee56c71782013-09-05 17:13:19 -0700406 RepeatingReversePostOrderDfsIterator iter2(this);
buzbee311ca162013-02-28 15:56:43 -0800407 bool change = false;
408 for (BasicBlock* bb = iter2.Next(false); bb != NULL; bb = iter2.Next(change)) {
409 change = ComputeblockIDom(bb);
410 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700411
412 /* Set the dominator for the root node */
buzbee862a7602013-04-05 10:58:54 -0700413 GetEntryBlock()->dominators->ClearAllBits();
414 GetEntryBlock()->dominators->SetBit(GetEntryBlock()->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700415
buzbee0d829482013-10-11 15:24:55 -0700416 GetEntryBlock()->i_dom = 0;
Bill Buzbeea114add2012-05-03 15:00:40 -0700417
buzbee56c71782013-09-05 17:13:19 -0700418 PreOrderDfsIterator iter3(this);
buzbee311ca162013-02-28 15:56:43 -0800419 for (BasicBlock* bb = iter3.Next(); bb != NULL; bb = iter3.Next()) {
420 SetDominators(bb);
Bill Buzbeea114add2012-05-03 15:00:40 -0700421 }
buzbee67bf8852011-08-17 17:51:35 -0700422
buzbee56c71782013-09-05 17:13:19 -0700423 ReversePostOrderDfsIterator iter4(this);
buzbee311ca162013-02-28 15:56:43 -0800424 for (BasicBlock* bb = iter4.Next(); bb != NULL; bb = iter4.Next()) {
425 ComputeBlockDominators(bb);
426 }
buzbee5b537102012-01-17 17:33:47 -0800427
buzbeea5abf702013-04-12 14:39:29 -0700428 // Compute the dominance frontier for each block.
buzbee311ca162013-02-28 15:56:43 -0800429 ComputeDomPostOrderTraversal(GetEntryBlock());
buzbee56c71782013-09-05 17:13:19 -0700430 PostOrderDOMIterator iter5(this);
buzbee311ca162013-02-28 15:56:43 -0800431 for (BasicBlock* bb = iter5.Next(); bb != NULL; bb = iter5.Next()) {
432 ComputeDominanceFrontier(bb);
433 }
buzbee67bf8852011-08-17 17:51:35 -0700434}
435
436/*
437 * Perform dest U= src1 ^ ~src2
438 * This is probably not general enough to be placed in BitVector.[ch].
439 */
buzbee311ca162013-02-28 15:56:43 -0800440void MIRGraph::ComputeSuccLineIn(ArenaBitVector* dest, const ArenaBitVector* src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700441 const ArenaBitVector* src2) {
buzbee862a7602013-04-05 10:58:54 -0700442 if (dest->GetStorageSize() != src1->GetStorageSize() ||
443 dest->GetStorageSize() != src2->GetStorageSize() ||
444 dest->IsExpandable() != src1->IsExpandable() ||
445 dest->IsExpandable() != src2->IsExpandable()) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700446 LOG(FATAL) << "Incompatible set properties";
447 }
buzbee67bf8852011-08-17 17:51:35 -0700448
Bill Buzbeea114add2012-05-03 15:00:40 -0700449 unsigned int idx;
buzbee862a7602013-04-05 10:58:54 -0700450 for (idx = 0; idx < dest->GetStorageSize(); idx++) {
451 dest->GetRawStorage()[idx] |= src1->GetRawStorageWord(idx) & ~(src2->GetRawStorageWord(idx));
Bill Buzbeea114add2012-05-03 15:00:40 -0700452 }
buzbee67bf8852011-08-17 17:51:35 -0700453}
454
455/*
456 * Iterate through all successor blocks and propagate up the live-in sets.
457 * The calculated result is used for phi-node pruning - where we only need to
458 * insert a phi node if the variable is live-in to the block.
459 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700460bool MIRGraph::ComputeBlockLiveIns(BasicBlock* bb) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700461 DCHECK_EQ(temp_bit_vector_size_, cu_->mir_graph.get()->GetNumOfCodeAndTempVRs());
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100462 ArenaBitVector* temp_dalvik_register_v = temp_bit_vector_;
buzbee67bf8852011-08-17 17:51:35 -0700463
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700464 if (bb->data_flow_info == NULL) {
465 return false;
466 }
buzbee862a7602013-04-05 10:58:54 -0700467 temp_dalvik_register_v->Copy(bb->data_flow_info->live_in_v);
buzbee0d829482013-10-11 15:24:55 -0700468 BasicBlock* bb_taken = GetBasicBlock(bb->taken);
469 BasicBlock* bb_fall_through = GetBasicBlock(bb->fall_through);
470 if (bb_taken && bb_taken->data_flow_info)
471 ComputeSuccLineIn(temp_dalvik_register_v, bb_taken->data_flow_info->live_in_v,
buzbeefa57c472012-11-21 12:06:18 -0800472 bb->data_flow_info->def_v);
buzbee0d829482013-10-11 15:24:55 -0700473 if (bb_fall_through && bb_fall_through->data_flow_info)
474 ComputeSuccLineIn(temp_dalvik_register_v, bb_fall_through->data_flow_info->live_in_v,
buzbeefa57c472012-11-21 12:06:18 -0800475 bb->data_flow_info->def_v);
buzbee0d829482013-10-11 15:24:55 -0700476 if (bb->successor_block_list_type != kNotUsed) {
477 GrowableArray<SuccessorBlockInfo*>::Iterator iterator(bb->successor_blocks);
Bill Buzbeea114add2012-05-03 15:00:40 -0700478 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700479 SuccessorBlockInfo *successor_block_info = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700480 if (successor_block_info == NULL) {
481 break;
482 }
buzbee0d829482013-10-11 15:24:55 -0700483 BasicBlock* succ_bb = GetBasicBlock(successor_block_info->block);
buzbeefa57c472012-11-21 12:06:18 -0800484 if (succ_bb->data_flow_info) {
buzbee311ca162013-02-28 15:56:43 -0800485 ComputeSuccLineIn(temp_dalvik_register_v, succ_bb->data_flow_info->live_in_v,
buzbeefa57c472012-11-21 12:06:18 -0800486 bb->data_flow_info->def_v);
Bill Buzbeea114add2012-05-03 15:00:40 -0700487 }
buzbee67bf8852011-08-17 17:51:35 -0700488 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700489 }
buzbee862a7602013-04-05 10:58:54 -0700490 if (!temp_dalvik_register_v->Equal(bb->data_flow_info->live_in_v)) {
491 bb->data_flow_info->live_in_v->Copy(temp_dalvik_register_v);
Bill Buzbeea114add2012-05-03 15:00:40 -0700492 return true;
493 }
494 return false;
buzbee67bf8852011-08-17 17:51:35 -0700495}
496
497/* Insert phi nodes to for each variable to the dominance frontiers */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700498void MIRGraph::InsertPhiNodes() {
buzbeefa57c472012-11-21 12:06:18 -0800499 int dalvik_reg;
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100500 ArenaBitVector* phi_blocks = new (temp_scoped_alloc_.get()) ArenaBitVector(
501 temp_scoped_alloc_.get(), GetNumBlocks(), false, kBitMapPhi);
502 ArenaBitVector* input_blocks = new (temp_scoped_alloc_.get()) ArenaBitVector(
503 temp_scoped_alloc_.get(), GetNumBlocks(), false, kBitMapInputBlocks);
buzbee67bf8852011-08-17 17:51:35 -0700504
buzbee56c71782013-09-05 17:13:19 -0700505 RepeatingPostOrderDfsIterator iter(this);
buzbee311ca162013-02-28 15:56:43 -0800506 bool change = false;
507 for (BasicBlock* bb = iter.Next(false); bb != NULL; bb = iter.Next(change)) {
508 change = ComputeBlockLiveIns(bb);
509 }
buzbee67bf8852011-08-17 17:51:35 -0700510
Bill Buzbeea114add2012-05-03 15:00:40 -0700511 /* Iterate through each Dalvik register */
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700512 for (dalvik_reg = GetNumOfCodeAndTempVRs() - 1; dalvik_reg >= 0; dalvik_reg--) {
buzbee862a7602013-04-05 10:58:54 -0700513 input_blocks->Copy(def_block_matrix_[dalvik_reg]);
514 phi_blocks->ClearAllBits();
Bill Buzbeea114add2012-05-03 15:00:40 -0700515 do {
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100516 // TUNING: When we repeat this, we could skip indexes from the previous pass.
517 for (uint32_t idx : input_blocks->Indexes()) {
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700518 BasicBlock* def_bb = GetBasicBlock(idx);
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100519 if (def_bb->dom_frontier != nullptr) {
520 phi_blocks->Union(def_bb->dom_frontier);
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700521 }
522 }
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100523 } while (input_blocks->Union(phi_blocks));
Bill Buzbeea114add2012-05-03 15:00:40 -0700524
525 /*
buzbeefa57c472012-11-21 12:06:18 -0800526 * Insert a phi node for dalvik_reg in the phi_blocks if the Dalvik
Bill Buzbeea114add2012-05-03 15:00:40 -0700527 * register is in the live-in set.
528 */
Vladimir Markoa5b8fde2014-05-23 15:16:44 +0100529 for (uint32_t idx : phi_blocks->Indexes()) {
buzbee311ca162013-02-28 15:56:43 -0800530 BasicBlock* phi_bb = GetBasicBlock(idx);
Bill Buzbeea114add2012-05-03 15:00:40 -0700531 /* Variable will be clobbered before being used - no need for phi */
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700532 if (!phi_bb->data_flow_info->live_in_v->IsBitSet(dalvik_reg)) {
533 continue;
534 }
Jean Christophe Beyler3aa57732014-04-17 12:47:24 -0700535 MIR *phi = NewMIR();
buzbeecbd6d442012-11-17 14:11:25 -0800536 phi->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpPhi);
buzbeefa57c472012-11-21 12:06:18 -0800537 phi->dalvikInsn.vA = dalvik_reg;
538 phi->offset = phi_bb->start_offset;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700539 phi->m_unit_index = 0; // Arbitrarily assign all Phi nodes to outermost method.
Jean Christophe Beylercdacac42014-03-13 14:54:59 -0700540 phi_bb->PrependMIR(phi);
buzbee67bf8852011-08-17 17:51:35 -0700541 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700542 }
buzbee67bf8852011-08-17 17:51:35 -0700543}
544
545/*
546 * Worker function to insert phi-operands with latest SSA names from
547 * predecessor blocks
548 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700549bool MIRGraph::InsertPhiNodeOperands(BasicBlock* bb) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700550 /* Phi nodes are at the beginning of each block */
buzbee0d829482013-10-11 15:24:55 -0700551 for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
buzbeecbd6d442012-11-17 14:11:25 -0800552 if (mir->dalvikInsn.opcode != static_cast<Instruction::Code>(kMirOpPhi))
Bill Buzbeea114add2012-05-03 15:00:40 -0700553 return true;
buzbeefa57c472012-11-21 12:06:18 -0800554 int ssa_reg = mir->ssa_rep->defs[0];
555 DCHECK_GE(ssa_reg, 0); // Shouldn't see compiler temps here
buzbee311ca162013-02-28 15:56:43 -0800556 int v_reg = SRegToVReg(ssa_reg);
buzbee67bf8852011-08-17 17:51:35 -0700557
Bill Buzbeea114add2012-05-03 15:00:40 -0700558 /* Iterate through the predecessors */
buzbee0d829482013-10-11 15:24:55 -0700559 GrowableArray<BasicBlockId>::Iterator iter(bb->predecessors);
560 size_t num_uses = bb->predecessors->Size();
Jean Christophe Beyler4896d7b2014-05-01 15:36:22 -0700561 AllocateSSAUseData(mir, num_uses);
562 int* uses = mir->ssa_rep->uses;
buzbee0d829482013-10-11 15:24:55 -0700563 BasicBlockId* incoming =
564 static_cast<BasicBlockId*>(arena_->Alloc(sizeof(BasicBlockId) * num_uses,
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000565 kArenaAllocDFInfo));
buzbee0d829482013-10-11 15:24:55 -0700566 mir->meta.phi_incoming = incoming;
567 int idx = 0;
Bill Buzbeea114add2012-05-03 15:00:40 -0700568 while (true) {
buzbee0d829482013-10-11 15:24:55 -0700569 BasicBlock* pred_bb = GetBasicBlock(iter.Next());
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700570 if (!pred_bb) {
Jean Christophe Beyler4896d7b2014-05-01 15:36:22 -0700571 break;
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700572 }
Jean Christophe Beyler4896d7b2014-05-01 15:36:22 -0700573 int ssa_reg = pred_bb->data_flow_info->vreg_to_ssa_map_exit[v_reg];
buzbee0d829482013-10-11 15:24:55 -0700574 uses[idx] = ssa_reg;
575 incoming[idx] = pred_bb->id;
576 idx++;
Bill Buzbeea114add2012-05-03 15:00:40 -0700577 }
578 }
579
580 return true;
buzbee67bf8852011-08-17 17:51:35 -0700581}
582
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700583void MIRGraph::DoDFSPreOrderSSARename(BasicBlock* block) {
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700584 if (block->visited || block->hidden) {
585 return;
586 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700587 block->visited = true;
buzbeef0cde542011-09-13 14:55:02 -0700588
Bill Buzbeea114add2012-05-03 15:00:40 -0700589 /* Process this block */
buzbee311ca162013-02-28 15:56:43 -0800590 DoSSAConversion(block);
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700591 int map_size = sizeof(int) * GetNumOfCodeAndTempVRs();
buzbeef0cde542011-09-13 14:55:02 -0700592
Bill Buzbeea114add2012-05-03 15:00:40 -0700593 /* Save SSA map snapshot */
Vladimir Marko5d474472014-03-21 17:10:58 +0000594 ScopedArenaAllocator allocator(&cu_->arena_stack);
buzbee862a7602013-04-05 10:58:54 -0700595 int* saved_ssa_map =
Vladimir Marko5d474472014-03-21 17:10:58 +0000596 static_cast<int*>(allocator.Alloc(map_size, kArenaAllocDalvikToSSAMap));
buzbee311ca162013-02-28 15:56:43 -0800597 memcpy(saved_ssa_map, vreg_to_ssa_map_, map_size);
buzbeef0cde542011-09-13 14:55:02 -0700598
buzbee0d829482013-10-11 15:24:55 -0700599 if (block->fall_through != NullBasicBlockId) {
600 DoDFSPreOrderSSARename(GetBasicBlock(block->fall_through));
Bill Buzbeea114add2012-05-03 15:00:40 -0700601 /* Restore SSA map snapshot */
buzbee311ca162013-02-28 15:56:43 -0800602 memcpy(vreg_to_ssa_map_, saved_ssa_map, map_size);
Bill Buzbeea114add2012-05-03 15:00:40 -0700603 }
buzbee0d829482013-10-11 15:24:55 -0700604 if (block->taken != NullBasicBlockId) {
605 DoDFSPreOrderSSARename(GetBasicBlock(block->taken));
Bill Buzbeea114add2012-05-03 15:00:40 -0700606 /* Restore SSA map snapshot */
buzbee311ca162013-02-28 15:56:43 -0800607 memcpy(vreg_to_ssa_map_, saved_ssa_map, map_size);
Bill Buzbeea114add2012-05-03 15:00:40 -0700608 }
buzbee0d829482013-10-11 15:24:55 -0700609 if (block->successor_block_list_type != kNotUsed) {
610 GrowableArray<SuccessorBlockInfo*>::Iterator iterator(block->successor_blocks);
Bill Buzbeea114add2012-05-03 15:00:40 -0700611 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700612 SuccessorBlockInfo *successor_block_info = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700613 if (successor_block_info == NULL) {
614 break;
615 }
buzbee0d829482013-10-11 15:24:55 -0700616 BasicBlock* succ_bb = GetBasicBlock(successor_block_info->block);
buzbee311ca162013-02-28 15:56:43 -0800617 DoDFSPreOrderSSARename(succ_bb);
Bill Buzbeea114add2012-05-03 15:00:40 -0700618 /* Restore SSA map snapshot */
buzbee311ca162013-02-28 15:56:43 -0800619 memcpy(vreg_to_ssa_map_, saved_ssa_map, map_size);
buzbeef0cde542011-09-13 14:55:02 -0700620 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700621 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700622 return;
buzbeef0cde542011-09-13 14:55:02 -0700623}
624
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800625} // namespace art