Fix host build with llvm16

Use "arch" instead of "target" so that the options handle both
device and host builds.

Move RegionPrinter.cpp to debug build to fix link issues with
vulkan.pastel.debug.

Bug: b/242184599
Test: lunch aosp_cf_x86_64_phone-userdebug
Test: m vulkan.pastel
Test: m vulkan.pastel.debug
Test: lunch aosp_cf_arm64_phone-userdebug
Test: m vulkan.pastel
Test: m vulkan.pastel.debug
Test: presubmit on aosp/2592045
Change-Id: Ia7194a8cfa96721d51dd24ae784ec108f41b96a9
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/71688
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Geoff Lang <geofflang@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
Presubmit-Ready: Jason Macnak <natsu@google.com>
Tested-by: Jason Macnak <natsu@google.com>
diff --git a/third_party/llvm-16.0/Android.bp b/third_party/llvm-16.0/Android.bp
index 8e68f12..202fbcf 100644
--- a/third_party/llvm-16.0/Android.bp
+++ b/third_party/llvm-16.0/Android.bp
@@ -1096,10 +1096,9 @@
         "llvm/lib/Support/BLAKE3/blake3_portable.c",
     ],
 
-    target: {
-        android_arm: {
+    arch: {
+        arm: {
             srcs: [
-                "llvm/lib/Analysis/RegionPrinter.cpp",
                 "llvm/lib/CodeGen/MultiHazardRecognizer.cpp",
                 "llvm/lib/MC/ConstantPools.cpp",
                 "llvm/lib/MC/MCInstrInfo.cpp",
@@ -1172,9 +1171,8 @@
                 "llvm/lib/Transforms/IPO/BarrierNoopPass.cpp",
             ],
         },
-        android_arm64: {
+        arm64: {
             srcs: [
-                "llvm/lib/Analysis/RegionPrinter.cpp",
                 "llvm/lib/CodeGen/MultiHazardRecognizer.cpp",
                 "llvm/lib/MC/ConstantPools.cpp",
                 "llvm/lib/MC/MCInstrInfo.cpp",
@@ -1255,7 +1253,7 @@
                 "llvm/lib/Transforms/IPO/BarrierNoopPass.cpp",
             ],
         },
-        android_riscv64: {
+        riscv64: {
             srcs: [
                 "llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp",
                 "llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp",
@@ -1302,7 +1300,7 @@
                 "llvm/lib/Target/RISCV/TargetInfo/RISCVTargetInfo.cpp",
             ],
         },
-        android_x86: {
+        x86: {
             srcs: [
                 "llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp",
                 "llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp",
@@ -1388,7 +1386,7 @@
                 "llvm/lib/Target/X86/X86WinEHState.cpp",
             ],
         },
-        android_x86_64: {
+        x86_64: {
             srcs: [
                 "llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp",
                 "llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp",
@@ -1530,4 +1528,8 @@
     cflags: [
         "-UNDEBUG",
     ],
+
+    srcs: [
+        "llvm/lib/Analysis/RegionPrinter.cpp",
+    ],
 }
diff --git a/third_party/llvm-16.0/BUILD.gn b/third_party/llvm-16.0/BUILD.gn
index c11e7a3..19c0f4b 100644
--- a/third_party/llvm-16.0/BUILD.gn
+++ b/third_party/llvm-16.0/BUILD.gn
@@ -1272,7 +1272,6 @@
 
 swiftshader_llvm_source_set("swiftshader_llvm_aarch64") {
   sources = [
-    "llvm/lib/Analysis/RegionPrinter.cpp",
     "llvm/lib/CodeGen/MultiHazardRecognizer.cpp",
     "llvm/lib/MC/ConstantPools.cpp",
     "llvm/lib/MC/MCInstrInfo.cpp",
@@ -1356,7 +1355,6 @@
 
 swiftshader_llvm_source_set("swiftshader_llvm_arm") {
   sources = [
-    "llvm/lib/Analysis/RegionPrinter.cpp",
     "llvm/lib/CodeGen/MultiHazardRecognizer.cpp",
     "llvm/lib/MC/ConstantPools.cpp",
     "llvm/lib/MC/MCInstrInfo.cpp",
diff --git a/third_party/llvm-16.0/CMakeLists.txt b/third_party/llvm-16.0/CMakeLists.txt
index feb9fbb..b949e04 100644
--- a/third_party/llvm-16.0/CMakeLists.txt
+++ b/third_party/llvm-16.0/CMakeLists.txt
@@ -1242,7 +1242,6 @@
     )
 elseif(ARCH STREQUAL "aarch64")
     list(APPEND LLVM_LIST
-        ${LLVM_DIR}/lib/Analysis/RegionPrinter.cpp
         ${LLVM_DIR}/lib/CodeGen/MultiHazardRecognizer.cpp
         ${LLVM_DIR}/lib/MC/ConstantPools.cpp
         ${LLVM_DIR}/lib/MC/MCInstrInfo.cpp
@@ -1324,7 +1323,6 @@
     )
 elseif(ARCH STREQUAL "arm")
     list(APPEND LLVM_LIST
-        ${LLVM_DIR}/lib/Analysis/RegionPrinter.cpp
         ${LLVM_DIR}/lib/CodeGen/MultiHazardRecognizer.cpp
         ${LLVM_DIR}/lib/MC/ConstantPools.cpp
         ${LLVM_DIR}/lib/MC/MCInstrInfo.cpp
diff --git a/third_party/llvm-16.0/scripts/generate_build_files.py b/third_party/llvm-16.0/scripts/generate_build_files.py
index d0f410b..f6ca772 100755
--- a/third_party/llvm-16.0/scripts/generate_build_files.py
+++ b/third_party/llvm-16.0/scripts/generate_build_files.py
@@ -359,8 +359,11 @@
 files_llvm = exclude_files_with_prefixes(all_files, prefixes_of_files_not_needed_by_llvm)
 files_llvm.extend(files_to_add_back_for_llvm)
 
-files_to_add_back_for_llvm_arm = [
+files_llvm_debug = [
     "/lib/Analysis/RegionPrinter.cpp",
+]
+
+files_to_add_back_for_llvm_arm = [
     "/lib/CodeGen/MultiHazardRecognizer.cpp",
     "/lib/MC/ConstantPools.cpp",
     "/lib/MC/MCInstrInfo.cpp",
@@ -407,6 +410,7 @@
 android_bp_template_data = {
     'generated_file_comment' : "// " + generated_file_comment,
     'files_llvm' : format_file_list_for_android_bp(files_llvm, indent=2),
+    'files_llvm_debug': format_file_list_for_android_bp(files_llvm_debug, indent=2),
     'files_x86' : format_file_list_for_android_bp(files_x86, indent=4),
     'files_AArch64' : format_file_list_for_android_bp(files_AArch64, indent=4),
     'files_ARM' : format_file_list_for_android_bp(files_ARM, indent=4),
diff --git a/third_party/llvm-16.0/scripts/template_Android.bp b/third_party/llvm-16.0/scripts/template_Android.bp
index d015db9..00b674b 100644
--- a/third_party/llvm-16.0/scripts/template_Android.bp
+++ b/third_party/llvm-16.0/scripts/template_Android.bp
@@ -23,28 +23,28 @@
 %$%files_llvm
     ],
 
-    target: {
-        android_arm: {
+    arch: {
+        arm: {
             srcs: [
 %$%files_ARM
             ],
         },
-        android_arm64: {
+        arm64: {
             srcs: [
 %$%files_AArch64
             ],
         },
-        android_riscv64: {
+        riscv64: {
             srcs: [
 %$%files_RISCV
             ],
         },
-        android_x86: {
+        x86: {
             srcs: [
 %$%files_x86
             ],
         },
-        android_x86_64: {
+        x86_64: {
             srcs: [
 %$%files_x86
             ],
@@ -105,4 +105,8 @@
     cflags: [
         "-UNDEBUG",
     ],
+
+    srcs: [
+%$%files_llvm_debug
+    ],
 }