Improve sharpening for read barrier image HLoadClass

Handle MarkInBoot image for LoadKind::kReferrersClass. This reduces
read barriers for the boot image if the referring class is in
the boot image.

Only really helps CC case, TODO avoid doing the work for non CC?

ARM64 CC baker boot.oat: 48006064 -> 47916736

Bug: 29516974

Test: test-art-host CC baker

Change-Id: Ibfa0cf0a3b888ad0e53c2d95a38e330b79e7443c
diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc
index b8e1379..e64c005 100644
--- a/compiler/optimizing/sharpening.cc
+++ b/compiler/optimizing/sharpening.cc
@@ -157,20 +157,11 @@
 }
 
 void HSharpening::ProcessLoadClass(HLoadClass* load_class) {
-  if (load_class->NeedsAccessCheck()) {
-    // We need to call the runtime anyway, so we simply get the class as that call's return value.
-    return;
-  }
-  if (load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) {
-    // Loading from the ArtMethod* is the most efficient retrieval.
-    // TODO: This may not actually be true for all architectures and
-    // locations of target classes. The additional register pressure
-    // for using the ArtMethod* should be considered.
-    return;
-  }
-
-  DCHECK_EQ(load_class->GetLoadKind(), HLoadClass::LoadKind::kDexCacheViaMethod);
+  DCHECK(load_class->GetLoadKind() == HLoadClass::LoadKind::kDexCacheViaMethod ||
+         load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass)
+      << load_class->GetLoadKind();
   DCHECK(!load_class->IsInDexCache()) << "HLoadClass should not be optimized before sharpening.";
+  DCHECK(!load_class->IsInBootImage()) << "HLoadClass should not be optimized before sharpening.";
 
   const DexFile& dex_file = load_class->GetDexFile();
   uint32_t type_index = load_class->GetTypeIndex();
@@ -242,13 +233,28 @@
       }
     }
   }
-  if (is_in_dex_cache) {
-    load_class->MarkInDexCache();
-  }
+
   if (is_in_boot_image) {
     load_class->MarkInBootImage();
   }
 
+  if (load_class->NeedsAccessCheck()) {
+    // We need to call the runtime anyway, so we simply get the class as that call's return value.
+    return;
+  }
+
+  if (load_class->GetLoadKind() == HLoadClass::LoadKind::kReferrersClass) {
+    // Loading from the ArtMethod* is the most efficient retrieval in code size.
+    // TODO: This may not actually be true for all architectures and
+    // locations of target classes. The additional register pressure
+    // for using the ArtMethod* should be considered.
+    return;
+  }
+
+  if (is_in_dex_cache) {
+    load_class->MarkInDexCache();
+  }
+
   HLoadClass::LoadKind load_kind = codegen_->GetSupportedLoadClassKind(desired_load_kind);
   switch (load_kind) {
     case HLoadClass::LoadKind::kBootImageLinkTimeAddress: