ART: Clean up arm64 kNumberOfXRegisters usage.

Avoid undefined behavior for arm64 stemming from 1u << 32 in
loops with upper bound kNumberOfXRegisters.

Create iterators for enumerating bits in an integer either
from high to low or from low to high and use them for
<arch>Context::FillCalleeSaves() on all architectures.

Refactor runtime/utils.{h,cc} by moving all bit-fiddling
functions to runtime/base/bit_utils.{h,cc} (together with
the new bit iterators) and all time-related functions to
runtime/base/time_utils.{h,cc}. Improve test coverage and
fix some corner cases for the bit-fiddling functions.

Bug: 13925192
Change-Id: I704884dab15b41ecf7a1c47d397ab1c3fc7ee0f7
diff --git a/compiler/compiled_method.h b/compiler/compiled_method.h
index 480d021..45a62bc 100644
--- a/compiler/compiled_method.h
+++ b/compiler/compiled_method.h
@@ -22,8 +22,8 @@
 #include <vector>
 
 #include "arch/instruction_set.h"
+#include "base/bit_utils.h"
 #include "method_reference.h"
-#include "utils.h"
 #include "utils/array_ref.h"
 #include "utils/swap_space.h"
 
diff --git a/compiler/compiler.cc b/compiler/compiler.cc
index 5e8ec1e..223affa 100644
--- a/compiler/compiler.cc
+++ b/compiler/compiler.cc
@@ -20,6 +20,7 @@
 #include "dex/quick/quick_compiler_factory.h"
 #include "driver/compiler_driver.h"
 #include "optimizing/optimizing_compiler.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/compiler_ir.cc b/compiler/dex/compiler_ir.cc
index 7fc1b03..6e1853b 100644
--- a/compiler/dex/compiler_ir.cc
+++ b/compiler/dex/compiler_ir.cc
@@ -22,6 +22,7 @@
 #include "dex/quick/mir_to_lir.h"
 #include "driver/compiler_driver.h"
 #include "mir_graph.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/compiler_ir.h b/compiler/dex/compiler_ir.h
index dceea24..d28df1d 100644
--- a/compiler/dex/compiler_ir.h
+++ b/compiler/dex/compiler_ir.h
@@ -21,6 +21,7 @@
 #include <string>
 #include <vector>
 
+#include "arch/instruction_set.h"
 #include "base/arena_allocator.h"
 #include "base/scoped_arena_allocator.h"
 #include "base/timing_logger.h"
@@ -31,6 +32,7 @@
 
 class ClassLinker;
 class CompilerDriver;
+class DexFile;
 class Mir2Lir;
 class MIRGraph;
 
diff --git a/compiler/dex/local_value_numbering.cc b/compiler/dex/local_value_numbering.cc
index cc9dbe4..38f7d1e 100644
--- a/compiler/dex/local_value_numbering.cc
+++ b/compiler/dex/local_value_numbering.cc
@@ -16,9 +16,11 @@
 
 #include "local_value_numbering.h"
 
+#include "base/bit_utils.h"
 #include "global_value_numbering.h"
 #include "mir_field_info.h"
 #include "mir_graph.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/local_value_numbering.h b/compiler/dex/local_value_numbering.h
index 67fb647..dff5e27 100644
--- a/compiler/dex/local_value_numbering.h
+++ b/compiler/dex/local_value_numbering.h
@@ -106,8 +106,7 @@
   }
 
   void SetOperandValueImpl(uint16_t s_reg, uint16_t value, SregValueMap* map) {
-    DCHECK_EQ(map->count(s_reg), 0u) << PrettyMethod(gvn_->cu_->method_idx, *gvn_->cu_->dex_file)
-        << " LVN id: " << id_ << ", s_reg: " << s_reg;
+    DCHECK_EQ(map->count(s_reg), 0u);
     map->Put(s_reg, value);
   }
 
diff --git a/compiler/dex/mir_analysis.cc b/compiler/dex/mir_analysis.cc
index 9099e8a..1cff8dc 100644
--- a/compiler/dex/mir_analysis.cc
+++ b/compiler/dex/mir_analysis.cc
@@ -30,6 +30,7 @@
 #include "driver/compiler_driver.h"
 #include "driver/compiler_options.h"
 #include "driver/dex_compilation_unit.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/mir_graph.cc b/compiler/dex/mir_graph.cc
index 1871f07..9fa5148 100644
--- a/compiler/dex/mir_graph.cc
+++ b/compiler/dex/mir_graph.cc
@@ -35,6 +35,7 @@
 #include "leb128.h"
 #include "pass_driver_me_post_opt.h"
 #include "stack.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/mir_graph.h b/compiler/dex/mir_graph.h
index 7385a8b..f038397 100644
--- a/compiler/dex/mir_graph.h
+++ b/compiler/dex/mir_graph.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 
 #include "base/arena_containers.h"
+#include "base/bit_utils.h"
 #include "base/scoped_arena_containers.h"
 #include "dex_file.h"
 #include "dex_instruction.h"
diff --git a/compiler/dex/mir_optimization.cc b/compiler/dex/mir_optimization.cc
index 217dbee..7679db8 100644
--- a/compiler/dex/mir_optimization.cc
+++ b/compiler/dex/mir_optimization.cc
@@ -31,6 +31,7 @@
 #include "quick/dex_file_to_method_inliner_map.h"
 #include "stack.h"
 #include "type_inference.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/quick/arm/call_arm.cc b/compiler/dex/quick/arm/call_arm.cc
index 2b2d6af..822ea21 100644
--- a/compiler/dex/quick/arm/call_arm.cc
+++ b/compiler/dex/quick/arm/call_arm.cc
@@ -19,6 +19,7 @@
 #include "codegen_arm.h"
 
 #include "arm_lir.h"
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "dex/mir_graph.h"
 #include "dex/quick/dex_file_to_method_inliner_map.h"
@@ -29,7 +30,6 @@
 #include "mirror/art_method.h"
 #include "mirror/object_array-inl.h"
 #include "entrypoints/quick/quick_entrypoints.h"
-#include "utils.h"
 #include "utils/dex_cache_arrays_layout-inl.h"
 
 namespace art {
diff --git a/compiler/dex/quick/arm/int_arm.cc b/compiler/dex/quick/arm/int_arm.cc
index 7598e50..7de8e55 100644
--- a/compiler/dex/quick/arm/int_arm.cc
+++ b/compiler/dex/quick/arm/int_arm.cc
@@ -20,6 +20,7 @@
 
 #include "arch/instruction_set_features.h"
 #include "arm_lir.h"
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "dex/compiler_ir.h"
 #include "dex/mir_graph.h"
@@ -28,7 +29,6 @@
 #include "driver/compiler_driver.h"
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "mirror/array-inl.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/quick/arm64/fp_arm64.cc b/compiler/dex/quick/arm64/fp_arm64.cc
index 49b15fe..3b88021 100644
--- a/compiler/dex/quick/arm64/fp_arm64.cc
+++ b/compiler/dex/quick/arm64/fp_arm64.cc
@@ -20,7 +20,6 @@
 #include "base/logging.h"
 #include "dex/mir_graph.h"
 #include "dex/quick/mir_to_lir-inl.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/quick/arm64/int_arm64.cc b/compiler/dex/quick/arm64/int_arm64.cc
index 9340d01..08aa5d2 100644
--- a/compiler/dex/quick/arm64/int_arm64.cc
+++ b/compiler/dex/quick/arm64/int_arm64.cc
@@ -20,6 +20,7 @@
 
 #include "arch/instruction_set_features.h"
 #include "arm64_lir.h"
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "dex/compiler_ir.h"
 #include "dex/mir_graph.h"
@@ -28,7 +29,6 @@
 #include "driver/compiler_driver.h"
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "mirror/array-inl.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/quick/gen_common.cc b/compiler/dex/quick/gen_common.cc
index 0592c74..63f83f9 100644
--- a/compiler/dex/quick/gen_common.cc
+++ b/compiler/dex/quick/gen_common.cc
@@ -19,6 +19,7 @@
 #include <functional>
 
 #include "arch/arm/instruction_set_features_arm.h"
+#include "base/bit_utils.h"
 #include "base/macros.h"
 #include "dex/compiler_ir.h"
 #include "dex/mir_graph.h"
@@ -30,7 +31,6 @@
 #include "mirror/object_array-inl.h"
 #include "mirror/object-inl.h"
 #include "mirror/object_reference.h"
-#include "utils.h"
 #include "utils/dex_cache_arrays_layout-inl.h"
 #include "verifier/method_verifier.h"
 
diff --git a/compiler/dex/quick/mir_to_lir-inl.h b/compiler/dex/quick/mir_to_lir-inl.h
index 280dbbe..767fe25 100644
--- a/compiler/dex/quick/mir_to_lir-inl.h
+++ b/compiler/dex/quick/mir_to_lir-inl.h
@@ -21,6 +21,7 @@
 
 #include "base/logging.h"
 #include "dex/compiler_ir.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/quick/mir_to_lir.h b/compiler/dex/quick/mir_to_lir.h
index 4fdc728..d54616f 100644
--- a/compiler/dex/quick/mir_to_lir.h
+++ b/compiler/dex/quick/mir_to_lir.h
@@ -31,6 +31,7 @@
 #include "invoke_type.h"
 #include "lazy_debug_frame_opcode_writer.h"
 #include "leb128.h"
+#include "primitive.h"
 #include "safe_map.h"
 #include "utils/array_ref.h"
 #include "utils/dex_cache_arrays_layout.h"
diff --git a/compiler/dex/quick/resource_mask.cc b/compiler/dex/quick/resource_mask.cc
index 57e8af3..817a69a 100644
--- a/compiler/dex/quick/resource_mask.cc
+++ b/compiler/dex/quick/resource_mask.cc
@@ -18,9 +18,9 @@
 
 #include "resource_mask.h"
 
+#include "base/bit_utils.h"
 #include "base/arena_allocator.h"
 #include "base/logging.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/quick/x86/assemble_x86.cc b/compiler/dex/quick/x86/assemble_x86.cc
index 8467b71..12523ac 100644
--- a/compiler/dex/quick/x86/assemble_x86.cc
+++ b/compiler/dex/quick/x86/assemble_x86.cc
@@ -16,10 +16,12 @@
 
 #include "codegen_x86.h"
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "dex/compiler_ir.h"
 #include "dex/quick/mir_to_lir.h"
 #include "oat.h"
+#include "utils.h"
 #include "x86_lir.h"
 
 namespace art {
diff --git a/compiler/dex/quick/x86/int_x86.cc b/compiler/dex/quick/x86/int_x86.cc
index 943bfc0..9bbb5f8 100755
--- a/compiler/dex/quick/x86/int_x86.cc
+++ b/compiler/dex/quick/x86/int_x86.cc
@@ -18,12 +18,12 @@
 
 #include "codegen_x86.h"
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "dex/quick/mir_to_lir-inl.h"
 #include "dex/reg_storage_eq.h"
 #include "mirror/art_method.h"
 #include "mirror/array-inl.h"
-#include "utils.h"
 #include "x86_lir.h"
 
 namespace art {
diff --git a/compiler/dex/type_inference.cc b/compiler/dex/type_inference.cc
index 19d591b..cd6467f 100644
--- a/compiler/dex/type_inference.cc
+++ b/compiler/dex/type_inference.cc
@@ -25,6 +25,7 @@
 #include "mir_field_info.h"
 #include "mir_graph.h"
 #include "mir_method_info.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dex/type_inference.h b/compiler/dex/type_inference.h
index c9b29bf..85f79af 100644
--- a/compiler/dex/type_inference.h
+++ b/compiler/dex/type_inference.h
@@ -17,6 +17,7 @@
 #ifndef ART_COMPILER_DEX_TYPE_INFERENCE_H_
 #define ART_COMPILER_DEX_TYPE_INFERENCE_H_
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "base/arena_object.h"
 #include "base/scoped_arena_containers.h"
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 5dc93ce..4945a91 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -29,6 +29,7 @@
 
 #include "art_field-inl.h"
 #include "base/stl_util.h"
+#include "base/time_utils.h"
 #include "base/timing_logger.h"
 #include "class_linker-inl.h"
 #include "compiled_class.h"
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 2b0985a..2cc2409 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -24,6 +24,7 @@
 
 #include "arch/instruction_set.h"
 #include "base/arena_allocator.h"
+#include "base/bit_utils.h"
 #include "base/mutex.h"
 #include "base/timing_logger.h"
 #include "class_reference.h"
@@ -41,7 +42,6 @@
 #include "utils/dedupe_set.h"
 #include "utils/dex_cache_arrays_layout.h"
 #include "utils/swap_space.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/dwarf/debug_frame_opcode_writer.h b/compiler/dwarf/debug_frame_opcode_writer.h
index 4112c84..d8077d5 100644
--- a/compiler/dwarf/debug_frame_opcode_writer.h
+++ b/compiler/dwarf/debug_frame_opcode_writer.h
@@ -17,10 +17,10 @@
 #ifndef ART_COMPILER_DWARF_DEBUG_FRAME_OPCODE_WRITER_H_
 #define ART_COMPILER_DWARF_DEBUG_FRAME_OPCODE_WRITER_H_
 
+#include "base/bit_utils.h"
 #include "dwarf/dwarf_constants.h"
 #include "dwarf/register.h"
 #include "dwarf/writer.h"
-#include "utils.h"
 
 namespace art {
 namespace dwarf {
diff --git a/compiler/dwarf/dwarf_test.h b/compiler/dwarf/dwarf_test.h
index 3afb5ea..f819c49 100644
--- a/compiler/dwarf/dwarf_test.h
+++ b/compiler/dwarf/dwarf_test.h
@@ -25,7 +25,6 @@
 #include <string>
 #include <sys/types.h>
 
-#include "utils.h"
 #include "base/unix_file/fd_file.h"
 #include "common_runtime_test.h"
 #include "elf_builder.h"
diff --git a/compiler/dwarf/writer.h b/compiler/dwarf/writer.h
index 3b9c558..e703aee 100644
--- a/compiler/dwarf/writer.h
+++ b/compiler/dwarf/writer.h
@@ -18,9 +18,9 @@
 #define ART_COMPILER_DWARF_WRITER_H_
 
 #include <vector>
-#include "leb128.h"
+#include "base/bit_utils.h"
 #include "base/logging.h"
-#include "utils.h"
+#include "leb128.h"
 
 namespace art {
 namespace dwarf {
diff --git a/compiler/elf_builder.h b/compiler/elf_builder.h
index 972bd08..8a63a48 100644
--- a/compiler/elf_builder.h
+++ b/compiler/elf_builder.h
@@ -20,6 +20,7 @@
 #include <vector>
 
 #include "arch/instruction_set.h"
+#include "base/bit_utils.h"
 #include "base/unix_file/fd_file.h"
 #include "buffered_output_stream.h"
 #include "elf_utils.h"
diff --git a/compiler/elf_writer_debug.cc b/compiler/elf_writer_debug.cc
index f4df6c1..c68bbc0 100644
--- a/compiler/elf_writer_debug.cc
+++ b/compiler/elf_writer_debug.cc
@@ -25,6 +25,7 @@
 #include "dwarf/headers.h"
 #include "dwarf/register.h"
 #include "oat_writer.h"
+#include "utils.h"
 
 namespace art {
 namespace dwarf {
diff --git a/compiler/gc_map_builder.h b/compiler/gc_map_builder.h
index 4c36ef7..45e3fc5 100644
--- a/compiler/gc_map_builder.h
+++ b/compiler/gc_map_builder.h
@@ -19,8 +19,8 @@
 
 #include <vector>
 
+#include "base/bit_utils.h"
 #include "gc_map.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/image_writer.h b/compiler/image_writer.h
index c0cffa5..5921732 100644
--- a/compiler/image_writer.h
+++ b/compiler/image_writer.h
@@ -26,6 +26,7 @@
 #include <string>
 #include <ostream>
 
+#include "base/bit_utils.h"
 #include "base/macros.h"
 #include "driver/compiler_driver.h"
 #include "gc/space/space.h"
@@ -35,7 +36,6 @@
 #include "os.h"
 #include "safe_map.h"
 #include "gc/space/space.h"
-#include "utils.h"
 
 namespace art {
 
@@ -136,7 +136,7 @@
 
   friend std::ostream& operator<<(std::ostream& stream, const Bin& bin);
 
-  static constexpr size_t kBinBits = MinimumBitsToStore(kBinMirrorCount - 1);
+  static constexpr size_t kBinBits = MinimumBitsToStore<uint32_t>(kBinMirrorCount - 1);
   // uint32 = typeof(lockword_)
   static constexpr size_t kBinShift = BitSizeOf<uint32_t>() - kBinBits;
   // 111000.....0
diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc
index 7c400ee..7ed7097 100644
--- a/compiler/jit/jit_compiler.cc
+++ b/compiler/jit/jit_compiler.cc
@@ -18,6 +18,7 @@
 
 #include "arch/instruction_set.h"
 #include "arch/instruction_set_features.h"
+#include "base/time_utils.h"
 #include "base/timing_logger.h"
 #include "compiler_callbacks.h"
 #include "dex/pass_manager.h"
diff --git a/compiler/jni/quick/arm64/calling_convention_arm64.cc b/compiler/jni/quick/arm64/calling_convention_arm64.cc
index a6caff1..4344c90 100644
--- a/compiler/jni/quick/arm64/calling_convention_arm64.cc
+++ b/compiler/jni/quick/arm64/calling_convention_arm64.cc
@@ -158,7 +158,8 @@
                                                      const char* shorty)
     : JniCallingConvention(is_static, is_synchronized, shorty, kFramePointerSize) {
   uint32_t core_spill_mask = CoreSpillMask();
-  for (int x_reg = 0; x_reg < kNumberOfXRegisters; ++x_reg) {
+  DCHECK_EQ(XZR, kNumberOfXRegisters - 1);  // Exclude XZR from the loop (avoid 1 << 32).
+  for (int x_reg = 0; x_reg < kNumberOfXRegisters - 1; ++x_reg) {
     if (((1 << x_reg) & core_spill_mask) != 0) {
       callee_save_regs_.push_back(
           Arm64ManagedRegister::FromXRegister(static_cast<XRegister>(x_reg)));
diff --git a/compiler/jni/quick/calling_convention.cc b/compiler/jni/quick/calling_convention.cc
index 436fc0c..2e146c4 100644
--- a/compiler/jni/quick/calling_convention.cc
+++ b/compiler/jni/quick/calling_convention.cc
@@ -23,7 +23,6 @@
 #include "jni/quick/mips64/calling_convention_mips64.h"
 #include "jni/quick/x86/calling_convention_x86.h"
 #include "jni/quick/x86_64/calling_convention_x86_64.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/jni/quick/x86/calling_convention_x86.cc b/compiler/jni/quick/x86/calling_convention_x86.cc
index 8a45f0c..499dd7c 100644
--- a/compiler/jni/quick/x86/calling_convention_x86.cc
+++ b/compiler/jni/quick/x86/calling_convention_x86.cc
@@ -19,7 +19,6 @@
 #include "base/logging.h"
 #include "handle_scope-inl.h"
 #include "utils/x86/managed_register_x86.h"
-#include "utils.h"
 
 namespace art {
 namespace x86 {
diff --git a/compiler/jni/quick/x86_64/calling_convention_x86_64.cc b/compiler/jni/quick/x86_64/calling_convention_x86_64.cc
index bbdf1fe..7e92d12 100644
--- a/compiler/jni/quick/x86_64/calling_convention_x86_64.cc
+++ b/compiler/jni/quick/x86_64/calling_convention_x86_64.cc
@@ -16,10 +16,10 @@
 
 #include "calling_convention_x86_64.h"
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "handle_scope-inl.h"
 #include "utils/x86_64/managed_register_x86_64.h"
-#include "utils.h"
 
 namespace art {
 namespace x86_64 {
diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc
index 1c76630..5f8023d 100644
--- a/compiler/optimizing/code_generator_arm.cc
+++ b/compiler/optimizing/code_generator_arm.cc
@@ -494,11 +494,6 @@
         assembler_(codegen->GetAssembler()),
         codegen_(codegen) {}
 
-static uint32_t LeastSignificantBit(uint32_t mask) {
-  // ffs starts at 1.
-  return ffs(mask) - 1;
-}
-
 void CodeGeneratorARM::ComputeSpillMask() {
   core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
   // Save one extra register for baseline. Note that on thumb2, there is no easy
@@ -2222,7 +2217,7 @@
   Register dividend = locations->InAt(0).AsRegister<Register>();
   Register temp = locations->GetTemp(0).AsRegister<Register>();
   int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
-  int32_t abs_imm = std::abs(imm);
+  uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
   DCHECK(IsPowerOfTwo(abs_imm));
   int ctz_imm = CTZ(abs_imm);
 
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index b6d99ab..ced60cd 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -1738,7 +1738,7 @@
   Register out = OutputRegister(instruction);
   Register dividend = InputRegisterAt(instruction, 0);
   int64_t imm = Int64FromConstant(second.GetConstant());
-  int64_t abs_imm = std::abs(imm);
+  uint64_t abs_imm = static_cast<uint64_t>(std::abs(imm));
   DCHECK(IsPowerOfTwo(abs_imm));
   int ctz_imm = CTZ(abs_imm);
 
diff --git a/compiler/optimizing/intrinsics.cc b/compiler/optimizing/intrinsics.cc
index 43fe374..9e18f11 100644
--- a/compiler/optimizing/intrinsics.cc
+++ b/compiler/optimizing/intrinsics.cc
@@ -22,6 +22,7 @@
 #include "invoke_type.h"
 #include "nodes.h"
 #include "quick/inline_method_analyser.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 47da9cc..91daeb7 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -19,6 +19,7 @@
 #include "code_generator.h"
 #include "ssa_builder.h"
 #include "base/bit_vector-inl.h"
+#include "base/bit_utils.h"
 #include "utils/growable_array.h"
 #include "scoped_thread_state_change.h"
 
diff --git a/compiler/optimizing/parallel_move_resolver.h b/compiler/optimizing/parallel_move_resolver.h
index e89417d..9ede910 100644
--- a/compiler/optimizing/parallel_move_resolver.h
+++ b/compiler/optimizing/parallel_move_resolver.h
@@ -20,6 +20,7 @@
 #include "base/value_object.h"
 #include "utils/growable_array.h"
 #include "locations.h"
+#include "primitive.h"
 
 namespace art {
 
diff --git a/compiler/optimizing/register_allocator.h b/compiler/optimizing/register_allocator.h
index 6d5bfc3..c29fe75 100644
--- a/compiler/optimizing/register_allocator.h
+++ b/compiler/optimizing/register_allocator.h
@@ -17,6 +17,7 @@
 #ifndef ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATOR_H_
 #define ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATOR_H_
 
+#include "arch/instruction_set.h"
 #include "base/macros.h"
 #include "primitive.h"
 #include "utils/growable_array.h"
diff --git a/compiler/utils/arm/assembler_arm.cc b/compiler/utils/arm/assembler_arm.cc
index eca6f5a..0cd5c8b 100644
--- a/compiler/utils/arm/assembler_arm.cc
+++ b/compiler/utils/arm/assembler_arm.cc
@@ -16,11 +16,11 @@
 
 #include "assembler_arm.h"
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "offsets.h"
 #include "thread.h"
-#include "utils.h"
 
 namespace art {
 namespace arm {
diff --git a/compiler/utils/arm/assembler_arm.h b/compiler/utils/arm/assembler_arm.h
index dee8287..e2c2e27 100644
--- a/compiler/utils/arm/assembler_arm.h
+++ b/compiler/utils/arm/assembler_arm.h
@@ -19,13 +19,13 @@
 
 #include <vector>
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "base/value_object.h"
 #include "constants_arm.h"
 #include "utils/arm/managed_register_arm.h"
 #include "utils/assembler.h"
 #include "offsets.h"
-#include "utils.h"
 
 namespace art {
 namespace arm {
diff --git a/compiler/utils/arm/assembler_arm32.cc b/compiler/utils/arm/assembler_arm32.cc
index 6e165fc..cdf62bf 100644
--- a/compiler/utils/arm/assembler_arm32.cc
+++ b/compiler/utils/arm/assembler_arm32.cc
@@ -16,11 +16,11 @@
 
 #include "assembler_arm32.h"
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "offsets.h"
 #include "thread.h"
-#include "utils.h"
 
 namespace art {
 namespace arm {
diff --git a/compiler/utils/arm/assembler_arm32.h b/compiler/utils/arm/assembler_arm32.h
index 55ec7b4..82fed50 100644
--- a/compiler/utils/arm/assembler_arm32.h
+++ b/compiler/utils/arm/assembler_arm32.h
@@ -24,7 +24,6 @@
 #include "utils/arm/managed_register_arm.h"
 #include "utils/arm/assembler_arm.h"
 #include "offsets.h"
-#include "utils.h"
 
 namespace art {
 namespace arm {
diff --git a/compiler/utils/arm/assembler_thumb2.cc b/compiler/utils/arm/assembler_thumb2.cc
index 75f2b77..ab83f95 100644
--- a/compiler/utils/arm/assembler_thumb2.cc
+++ b/compiler/utils/arm/assembler_thumb2.cc
@@ -16,11 +16,11 @@
 
 #include "assembler_thumb2.h"
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "offsets.h"
 #include "thread.h"
-#include "utils.h"
 
 namespace art {
 namespace arm {
diff --git a/compiler/utils/arm/assembler_thumb2.h b/compiler/utils/arm/assembler_thumb2.h
index 90d489f..2da8ee2 100644
--- a/compiler/utils/arm/assembler_thumb2.h
+++ b/compiler/utils/arm/assembler_thumb2.h
@@ -24,7 +24,6 @@
 #include "utils/arm/managed_register_arm.h"
 #include "utils/arm/assembler_arm.h"
 #include "offsets.h"
-#include "utils.h"
 
 namespace art {
 namespace arm {
diff --git a/compiler/utils/arm64/assembler_arm64.cc b/compiler/utils/arm64/assembler_arm64.cc
index 98702a2..3ee79a1 100644
--- a/compiler/utils/arm64/assembler_arm64.cc
+++ b/compiler/utils/arm64/assembler_arm64.cc
@@ -19,7 +19,6 @@
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "offsets.h"
 #include "thread.h"
-#include "utils.h"
 
 using namespace vixl;  // NOLINT(build/namespaces)
 
diff --git a/compiler/utils/arm64/assembler_arm64.h b/compiler/utils/arm64/assembler_arm64.h
index e47b531..b1b66ed 100644
--- a/compiler/utils/arm64/assembler_arm64.h
+++ b/compiler/utils/arm64/assembler_arm64.h
@@ -26,7 +26,6 @@
 #include "utils/arm64/managed_register_arm64.h"
 #include "utils/assembler.h"
 #include "offsets.h"
-#include "utils.h"
 
 // TODO: make vixl clean wrt -Wshadow.
 #pragma GCC diagnostic push
diff --git a/compiler/utils/arm64/managed_register_arm64.h b/compiler/utils/arm64/managed_register_arm64.h
index 62c1d4d..dbcd8c5 100644
--- a/compiler/utils/arm64/managed_register_arm64.h
+++ b/compiler/utils/arm64/managed_register_arm64.h
@@ -117,8 +117,7 @@
 
   bool IsSRegister() const {
     CHECK(IsValidManagedRegister());
-    const int test = id_ - (kNumberOfXRegIds + kNumberOfWRegIds +
-                            kNumberOfDRegIds);
+    const int test = id_ - (kNumberOfXRegIds + kNumberOfWRegIds + kNumberOfDRegIds);
     return (0 <= test) && (test < kNumberOfSRegIds);
   }
 
diff --git a/compiler/utils/assembler_test_base.h b/compiler/utils/assembler_test_base.h
index 3341151..574051a 100644
--- a/compiler/utils/assembler_test_base.h
+++ b/compiler/utils/assembler_test_base.h
@@ -17,14 +17,15 @@
 #ifndef ART_COMPILER_UTILS_ASSEMBLER_TEST_BASE_H_
 #define ART_COMPILER_UTILS_ASSEMBLER_TEST_BASE_H_
 
-#include "common_runtime_test.h"  // For ScratchFile
-
 #include <cstdio>
 #include <cstdlib>
 #include <fstream>
 #include <iterator>
 #include <sys/stat.h>
 
+#include "common_runtime_test.h"  // For ScratchFile
+#include "utils.h"
+
 namespace art {
 
 // If you want to take a look at the differences between the ART assembler and GCC, set this flag
diff --git a/compiler/utils/dedupe_set.h b/compiler/utils/dedupe_set.h
index a9a5781..8cdb180 100644
--- a/compiler/utils/dedupe_set.h
+++ b/compiler/utils/dedupe_set.h
@@ -26,6 +26,7 @@
 #include "base/mutex.h"
 #include "base/stl_util.h"
 #include "base/stringprintf.h"
+#include "base/time_utils.h"
 #include "utils/swap_space.h"
 
 namespace art {
diff --git a/compiler/utils/dex_cache_arrays_layout-inl.h b/compiler/utils/dex_cache_arrays_layout-inl.h
index 2c50c96..a71eece 100644
--- a/compiler/utils/dex_cache_arrays_layout-inl.h
+++ b/compiler/utils/dex_cache_arrays_layout-inl.h
@@ -19,11 +19,11 @@
 
 #include "dex_cache_arrays_layout.h"
 
+#include "base/bit_utils.h"
 #include "base/logging.h"
 #include "globals.h"
 #include "mirror/array-inl.h"
 #include "primitive.h"
-#include "utils.h"
 
 namespace mirror {
 class ArtMethod;
diff --git a/compiler/utils/mips/assembler_mips.cc b/compiler/utils/mips/assembler_mips.cc
index 709a911..e769489 100644
--- a/compiler/utils/mips/assembler_mips.cc
+++ b/compiler/utils/mips/assembler_mips.cc
@@ -16,6 +16,7 @@
 
 #include "assembler_mips.h"
 
+#include "base/bit_utils.h"
 #include "base/casts.h"
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "memory_region.h"
diff --git a/compiler/utils/mips/assembler_mips.h b/compiler/utils/mips/assembler_mips.h
index d4acf03..34713e1 100644
--- a/compiler/utils/mips/assembler_mips.h
+++ b/compiler/utils/mips/assembler_mips.h
@@ -25,7 +25,6 @@
 #include "managed_register_mips.h"
 #include "utils/assembler.h"
 #include "offsets.h"
-#include "utils.h"
 
 namespace art {
 namespace mips {
diff --git a/compiler/utils/mips64/assembler_mips64.cc b/compiler/utils/mips64/assembler_mips64.cc
index 5e9653d..b95e436 100644
--- a/compiler/utils/mips64/assembler_mips64.cc
+++ b/compiler/utils/mips64/assembler_mips64.cc
@@ -16,6 +16,7 @@
 
 #include "assembler_mips64.h"
 
+#include "base/bit_utils.h"
 #include "base/casts.h"
 #include "entrypoints/quick/quick_entrypoints.h"
 #include "memory_region.h"
@@ -116,7 +117,7 @@
 
 int32_t Mips64Assembler::EncodeBranchOffset(int offset, int32_t inst, bool is_jump) {
   CHECK_ALIGNED(offset, 4);
-  CHECK(IsInt(POPCOUNT(kBranchOffsetMask), offset)) << offset;
+  CHECK(IsInt<POPCOUNT(kBranchOffsetMask)>(offset)) << offset;
 
   // Properly preserve only the bits supported in the instruction.
   offset >>= 2;
diff --git a/compiler/utils/mips64/assembler_mips64.h b/compiler/utils/mips64/assembler_mips64.h
index 2d7c661..95ba967 100644
--- a/compiler/utils/mips64/assembler_mips64.h
+++ b/compiler/utils/mips64/assembler_mips64.h
@@ -25,7 +25,6 @@
 #include "managed_register_mips64.h"
 #include "utils/assembler.h"
 #include "offsets.h"
-#include "utils.h"
 
 namespace art {
 namespace mips64 {
diff --git a/compiler/utils/swap_space.h b/compiler/utils/swap_space.h
index 1f8f5da..691df4a 100644
--- a/compiler/utils/swap_space.h
+++ b/compiler/utils/swap_space.h
@@ -28,7 +28,6 @@
 #include "base/macros.h"
 #include "base/mutex.h"
 #include "mem_map.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/utils/test_dex_file_builder.h b/compiler/utils/test_dex_file_builder.h
index ab039aa..b1d7b4c 100644
--- a/compiler/utils/test_dex_file_builder.h
+++ b/compiler/utils/test_dex_file_builder.h
@@ -22,8 +22,9 @@
 #include <map>
 #include <vector>
 
+#include "base/bit_utils.h"
+#include "base/logging.h"
 #include "dex_file.h"
-#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/utils/test_dex_file_builder_test.cc b/compiler/utils/test_dex_file_builder_test.cc
index ee6e35d..7a424a2 100644
--- a/compiler/utils/test_dex_file_builder_test.cc
+++ b/compiler/utils/test_dex_file_builder_test.cc
@@ -18,6 +18,7 @@
 
 #include "dex_file-inl.h"
 #include "gtest/gtest.h"
+#include "utils.h"
 
 namespace art {
 
diff --git a/compiler/utils/x86/assembler_x86.h b/compiler/utils/x86/assembler_x86.h
index 136b0cb..5319dac 100644
--- a/compiler/utils/x86/assembler_x86.h
+++ b/compiler/utils/x86/assembler_x86.h
@@ -18,13 +18,13 @@
 #define ART_COMPILER_UTILS_X86_ASSEMBLER_X86_H_
 
 #include <vector>
+#include "base/bit_utils.h"
 #include "base/macros.h"
 #include "constants_x86.h"
 #include "globals.h"
 #include "managed_register_x86.h"
 #include "offsets.h"
 #include "utils/assembler.h"
-#include "utils.h"
 
 namespace art {
 namespace x86 {
diff --git a/compiler/utils/x86_64/assembler_x86_64.h b/compiler/utils/x86_64/assembler_x86_64.h
index 162714a..7daf994 100644
--- a/compiler/utils/x86_64/assembler_x86_64.h
+++ b/compiler/utils/x86_64/assembler_x86_64.h
@@ -18,13 +18,14 @@
 #define ART_COMPILER_UTILS_X86_64_ASSEMBLER_X86_64_H_
 
 #include <vector>
+
+#include "base/bit_utils.h"
 #include "base/macros.h"
 #include "constants_x86_64.h"
 #include "globals.h"
 #include "managed_register_x86_64.h"
 #include "offsets.h"
 #include "utils/assembler.h"
-#include "utils.h"
 
 namespace art {
 namespace x86_64 {
diff --git a/compiler/utils/x86_64/assembler_x86_64_test.cc b/compiler/utils/x86_64/assembler_x86_64_test.cc
index 0be4d63..dcffe35 100644
--- a/compiler/utils/x86_64/assembler_x86_64_test.cc
+++ b/compiler/utils/x86_64/assembler_x86_64_test.cc
@@ -20,9 +20,9 @@
 #include <map>
 #include <random>
 
+#include "base/bit_utils.h"
 #include "base/stl_util.h"
 #include "utils/assembler_test.h"
-#include "utils.h"
 
 namespace art {