xueliang.zhong | c239a2b | 2017-04-27 15:31:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "load_store_analysis.h" |
| 18 | |
| 19 | namespace art { |
| 20 | |
| 21 | // A cap for the number of heap locations to prevent pathological time/space consumption. |
| 22 | // The number of heap locations for most of the methods stays below this threshold. |
| 23 | constexpr size_t kMaxNumberOfHeapLocations = 32; |
| 24 | |
| 25 | void LoadStoreAnalysis::Run() { |
| 26 | for (HBasicBlock* block : graph_->GetReversePostOrder()) { |
| 27 | heap_location_collector_.VisitBasicBlock(block); |
| 28 | } |
| 29 | |
| 30 | if (heap_location_collector_.GetNumberOfHeapLocations() > kMaxNumberOfHeapLocations) { |
| 31 | // Bail out if there are too many heap locations to deal with. |
| 32 | heap_location_collector_.CleanUp(); |
| 33 | return; |
| 34 | } |
| 35 | if (!heap_location_collector_.HasHeapStores()) { |
| 36 | // Without heap stores, this pass would act mostly as GVN on heap accesses. |
| 37 | heap_location_collector_.CleanUp(); |
| 38 | return; |
| 39 | } |
| 40 | if (heap_location_collector_.HasVolatile() || heap_location_collector_.HasMonitorOps()) { |
| 41 | // Don't do load/store elimination if the method has volatile field accesses or |
| 42 | // monitor operations, for now. |
| 43 | // TODO: do it right. |
| 44 | heap_location_collector_.CleanUp(); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | heap_location_collector_.BuildAliasingMatrix(); |
| 49 | } |
| 50 | |
| 51 | } // namespace art |