Make use of specific Kryo targeting in Clang

Clang supports specific CPU targeting and optimization
for Kryo.

This switches us to using the specific Kryo targeting
when Clang is used. For other compilers, we fallback
to cortex-a57 targeting.

Also, move the replaceFirst function to a shared location.

Bug: 36728278

Test: Built and booted sailfish, ran bionic unit tests and art tests.
Test: Disassembled libc.so before this change and after and looked at
Test: the differences. Mostly the results were the order of instructions
Test: changing.
Test: Verified with the clang person (srhines) that our clang has this support
Test: and that it appears to be mostly instruction scheduling changes.

Change-Id: I4ee73d8bcc1e4f5eccb162c18937811fe199b16f
Signed-off-by: Alex Naidis <alex.naidis@linux.com>
diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go
index 60245d0..f387ddf 100644
--- a/cc/config/arm64_device.go
+++ b/cc/config/arm64_device.go
@@ -77,8 +77,8 @@
 			"-mcpu=cortex-a53",
 		},
 		"kryo": []string{
-			// Use the cortex-a57 cpu since no compiler supports
-			// Kryo as a CPU target yet.
+			// Use the cortex-a57 cpu since some compilers
+			// don't support a Kryo specific target yet.
 			"-mcpu=cortex-a57",
 		},
 	}
@@ -97,6 +97,9 @@
 		"kryo",
 		"denver64")
 
+	// Clang supports specific Kryo targeting
+	replaceFirst(arm64ClangCpuVariantCflags["kryo"], "-mcpu=cortex-a57", "-mcpu=kryo")
+
 	pctx.StaticVariable("arm64GccVersion", arm64GccVersion)
 
 	pctx.SourcePathVariable("Arm64GccRoot",
diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go
index b02c390..d144c03 100644
--- a/cc/config/arm_device.go
+++ b/cc/config/arm_device.go
@@ -167,14 +167,6 @@
 		"kryo",
 		"denver")
 
-	replaceFirst := func(slice []string, from, to string) {
-		if slice[0] != from {
-			panic(fmt.Errorf("Expected %q, found %q", from, to))
-		}
-
-		slice[0] = to
-	}
-
 	replaceFirst(armClangCpuVariantCflags["krait"], "-mcpu=cortex-a15", "-mcpu=krait")
 	armClangCpuVariantCflags["krait"] = append(armClangCpuVariantCflags["krait"], "-mfpu=neon-vfpv4")
 
diff --git a/cc/config/global.go b/cc/config/global.go
index 50c7c98..272a4b6 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -15,6 +15,7 @@
 package config
 
 import (
+	"fmt"
 	"strings"
 
 	"android/soong/android"
@@ -176,3 +177,10 @@
 func VndkLibraries() []string {
 	return []string{}
 }
+
+func replaceFirst(slice []string, from, to string) {
+	if slice[0] != from {
+		panic(fmt.Errorf("Expected %q, found %q", from, to))
+	}
+	slice[0] = to
+}