diff options
author | 2014-04-11 12:28:11 +0100 | |
---|---|---|
committer | 2014-05-09 15:38:54 +0100 | |
commit | 69f08baaa4b70ce32a258f3da43cf12f2a034696 (patch) | |
tree | 33f8b5a6675ef8b3b1755fa8e88f6b7dae33b857 | |
parent | 18694f430b1e499954e5e4fcdbd6ac07a07763ae (diff) |
Clean up ScopedArenaAllocatorAdapter.
Make the adapter equality-comparable, define aliases for
containers using the adapter and use those aliases.
Fix DebugStackIndirectTopRefImpl assignment.
Change-Id: I689aa8a93d169f63a659dec5040567d7b1343277
-rw-r--r-- | compiler/dex/local_value_numbering.h | 17 | ||||
-rw-r--r-- | compiler/dex/mir_analysis.cc | 8 | ||||
-rw-r--r-- | compiler/dex/mir_optimization.cc | 7 | ||||
-rw-r--r-- | compiler/utils/debug_stack.h | 2 | ||||
-rw-r--r-- | compiler/utils/scoped_arena_allocator.h | 16 | ||||
-rw-r--r-- | compiler/utils/scoped_arena_containers.h | 40 |
6 files changed, 71 insertions, 19 deletions
diff --git a/compiler/dex/local_value_numbering.h b/compiler/dex/local_value_numbering.h index 535b613ba1..6d67afb862 100644 --- a/compiler/dex/local_value_numbering.h +++ b/compiler/dex/local_value_numbering.h @@ -20,6 +20,7 @@ #include "compiler_internals.h" #include "UniquePtr.h" #include "utils/scoped_arena_allocator.h" +#include "utils/scoped_arena_containers.h" #define NO_VALUE 0xffff #define ARRAY_REF 0xfffe @@ -75,20 +76,16 @@ class LocalValueNumbering { }; // Key is s_reg, value is value name. - typedef SafeMap<uint16_t, uint16_t, std::less<uint16_t>, - ScopedArenaAllocatorAdapter<std::pair<uint16_t, uint16_t> > > SregValueMap; + typedef ScopedArenaSafeMap<uint16_t, uint16_t> SregValueMap; // Key is concatenation of opcode, operand1, operand2 and modifier, value is value name. - typedef SafeMap<uint64_t, uint16_t, std::less<uint64_t>, - ScopedArenaAllocatorAdapter<std::pair<uint64_t, uint16_t> > > ValueMap; + typedef ScopedArenaSafeMap<uint64_t, uint16_t> ValueMap; // Key represents a memory address, value is generation. - typedef SafeMap<MemoryVersionKey, uint16_t, MemoryVersionKeyComparator, - ScopedArenaAllocatorAdapter<std::pair<MemoryVersionKey, uint16_t> > > MemoryVersionMap; + typedef ScopedArenaSafeMap<MemoryVersionKey, uint16_t, MemoryVersionKeyComparator + > MemoryVersionMap; // Maps field key to field id for resolved fields. - typedef SafeMap<FieldReference, uint32_t, FieldReferenceComparator, - ScopedArenaAllocatorAdapter<std::pair<FieldReference, uint16_t> > > FieldIndexMap; + typedef ScopedArenaSafeMap<FieldReference, uint32_t, FieldReferenceComparator> FieldIndexMap; // A set of value names. - typedef std::set<uint16_t, std::less<uint16_t>, - ScopedArenaAllocatorAdapter<uint16_t> > ValueNameSet; + typedef ScopedArenaSet<uint16_t> ValueNameSet; public: static LocalValueNumbering* Create(CompilationUnit* cu) { diff --git a/compiler/dex/mir_analysis.cc b/compiler/dex/mir_analysis.cc index 200795e535..c3b5a2585f 100644 --- a/compiler/dex/mir_analysis.cc +++ b/compiler/dex/mir_analysis.cc @@ -24,6 +24,7 @@ #include "dex/quick/dex_file_to_method_inliner_map.h" #include "driver/compiler_options.h" #include "UniquePtr.h" +#include "utils/scoped_arena_containers.h" namespace art { @@ -1205,17 +1206,16 @@ void MIRGraph::DoCacheMethodLoweringInfo() { MethodReferenceComparator devirt_cmp; }; - // Map invoke key (see MapEntry) to lowering info index. - typedef std::set<MapEntry, MapEntryComparator, ScopedArenaAllocatorAdapter<MapEntry> > InvokeMap; - ScopedArenaAllocator allocator(&cu_->arena_stack); // All INVOKE instructions take 3 code units and there must also be a RETURN. uint32_t max_refs = (current_code_item_->insns_size_in_code_units_ - 1u) / 3u; + // Map invoke key (see MapEntry) to lowering info index and vice versa. // The invoke_map and sequential entries are essentially equivalent to Boost.MultiIndex's // multi_index_container with one ordered index and one sequential index. - InvokeMap invoke_map(MapEntryComparator(), allocator.Adapter()); + ScopedArenaSet<MapEntry, MapEntryComparator> invoke_map(MapEntryComparator(), + allocator.Adapter()); const MapEntry** sequential_entries = reinterpret_cast<const MapEntry**>( allocator.Alloc(max_refs * sizeof(sequential_entries[0]), kArenaAllocMisc)); diff --git a/compiler/dex/mir_optimization.cc b/compiler/dex/mir_optimization.cc index 413b4e0f75..8e8a593192 100644 --- a/compiler/dex/mir_optimization.cc +++ b/compiler/dex/mir_optimization.cc @@ -19,6 +19,7 @@ #include "dataflow_iterator-inl.h" #include "dex/quick/dex_file_method_inliner.h" #include "dex/quick/dex_file_to_method_inliner_map.h" +#include "utils/scoped_arena_containers.h" namespace art { @@ -964,11 +965,9 @@ bool MIRGraph::EliminateClassInitChecksGate() { } }; - typedef std::set<MapEntry, MapEntryComparator, ScopedArenaAllocatorAdapter<MapEntry> > - ClassToIndexMap; - ScopedArenaAllocator allocator(&cu_->arena_stack); - ClassToIndexMap class_to_index_map(MapEntryComparator(), allocator.Adapter()); + ScopedArenaSet<MapEntry, MapEntryComparator> class_to_index_map(MapEntryComparator(), + allocator.Adapter()); // First, find all SGET/SPUTs that may need class initialization checks, record INVOKE_STATICs. AllNodesIterator iter(this); diff --git a/compiler/utils/debug_stack.h b/compiler/utils/debug_stack.h index 2e02b438b9..1bb0624187 100644 --- a/compiler/utils/debug_stack.h +++ b/compiler/utils/debug_stack.h @@ -118,7 +118,7 @@ class DebugStackIndirectTopRefImpl { CheckTop(); } DebugStackIndirectTopRefImpl& operator=(const DebugStackIndirectTopRefImpl& other) { - CHECK(ref_ == other->ref_); + CHECK(ref_ == other.ref_); CheckTop(); return *this; } diff --git a/compiler/utils/scoped_arena_allocator.h b/compiler/utils/scoped_arena_allocator.h index d5b003ca4d..c090062db5 100644 --- a/compiler/utils/scoped_arena_allocator.h +++ b/compiler/utils/scoped_arena_allocator.h @@ -235,8 +235,24 @@ class ScopedArenaAllocatorAdapter : private DebugStackReference, private DebugSt template <typename U> friend class ScopedArenaAllocatorAdapter; + + template <typename U> + friend bool operator==(const ScopedArenaAllocatorAdapter<U>& lhs, + const ScopedArenaAllocatorAdapter<U>& rhs); }; +template <typename T> +inline bool operator==(const ScopedArenaAllocatorAdapter<T>& lhs, + const ScopedArenaAllocatorAdapter<T>& rhs) { + return lhs.arena_stack_ == rhs.arena_stack_; +} + +template <typename T> +inline bool operator!=(const ScopedArenaAllocatorAdapter<T>& lhs, + const ScopedArenaAllocatorAdapter<T>& rhs) { + return !(lhs == rhs); +} + inline ScopedArenaAllocatorAdapter<void> ScopedArenaAllocator::Adapter() { return ScopedArenaAllocatorAdapter<void>(this); } diff --git a/compiler/utils/scoped_arena_containers.h b/compiler/utils/scoped_arena_containers.h new file mode 100644 index 0000000000..c6fefde7c7 --- /dev/null +++ b/compiler/utils/scoped_arena_containers.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_COMPILER_UTILS_SCOPED_ARENA_CONTAINERS_H_ +#define ART_COMPILER_UTILS_SCOPED_ARENA_CONTAINERS_H_ + +#include <vector> +#include <set> + +#include "utils/scoped_arena_allocator.h" +#include "safe_map.h" + +namespace art { + +template <typename T> +using ScopedArenaVector = std::vector<T, ScopedArenaAllocatorAdapter<T> >; + +template <typename T, typename Comparator = std::less<T> > +using ScopedArenaSet = std::set<T, Comparator, ScopedArenaAllocatorAdapter<T> >; + +template <typename K, typename V, typename Comparator = std::less<K> > +using ScopedArenaSafeMap = + SafeMap<K, V, Comparator, ScopedArenaAllocatorAdapter<std::pair<const K, V> > >; + +} // namespace art + +#endif // ART_COMPILER_UTILS_SCOPED_ARENA_CONTAINERS_H_ |