//
// Copyright (C) 2012 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.
//

// TODO We should really separate out those files that are actually needed for both variants of an
// architecture into its own category. Currently we just include all of the 32bit variant in the
// 64bit variant. It also might be good to allow one to compile only the 64bit variant without the
// 32bit one.

package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "art_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["art_license"],
}

art_cc_defaults {
    name: "libart-compiler-defaults",
    defaults: ["art_defaults"],
    host_supported: true,
    srcs: [
        "compiled_method.cc",
        "debug/elf_debug_writer.cc",
        "dex/inline_method_analyser.cc",
        "dex/verified_method.cc",
        "dex/verification_results.cc",
        "driver/compiled_method_storage.cc",
        "driver/compiler_options.cc",
        "driver/dex_compilation_unit.cc",
        "jit/jit_compiler.cc",
        "jit/jit_logger.cc",
        "jni/quick/calling_convention.cc",
        "jni/quick/jni_compiler.cc",
        "optimizing/block_builder.cc",
        "optimizing/block_namer.cc",
        "optimizing/bounds_check_elimination.cc",
        "optimizing/builder.cc",
        "optimizing/cha_guard_optimization.cc",
        "optimizing/code_generator.cc",
        "optimizing/code_generator_utils.cc",
        "optimizing/code_sinking.cc",
        "optimizing/constant_folding.cc",
        "optimizing/constructor_fence_redundancy_elimination.cc",
        "optimizing/data_type.cc",
        "optimizing/dead_code_elimination.cc",
        "optimizing/escape.cc",
        "optimizing/execution_subgraph.cc",
        "optimizing/graph_checker.cc",
        "optimizing/graph_visualizer.cc",
        "optimizing/gvn.cc",
        "optimizing/induction_var_analysis.cc",
        "optimizing/induction_var_range.cc",
        "optimizing/inliner.cc",
        "optimizing/instruction_builder.cc",
        "optimizing/instruction_simplifier.cc",
        "optimizing/intrinsic_objects.cc",
        "optimizing/intrinsics.cc",
        "optimizing/licm.cc",
        "optimizing/linear_order.cc",
        "optimizing/load_store_analysis.cc",
        "optimizing/load_store_elimination.cc",
        "optimizing/locations.cc",
        "optimizing/loop_analysis.cc",
        "optimizing/loop_optimization.cc",
        "optimizing/nodes.cc",
        "optimizing/optimization.cc",
        "optimizing/optimizing_compiler.cc",
        "optimizing/parallel_move_resolver.cc",
        "optimizing/prepare_for_register_allocation.cc",
        "optimizing/reference_type_propagation.cc",
        "optimizing/register_allocation_resolver.cc",
        "optimizing/register_allocator.cc",
        "optimizing/register_allocator_graph_color.cc",
        "optimizing/register_allocator_linear_scan.cc",
        "optimizing/select_generator.cc",
        "optimizing/scheduler.cc",
        "optimizing/sharpening.cc",
        "optimizing/side_effects_analysis.cc",
        "optimizing/ssa_builder.cc",
        "optimizing/ssa_liveness_analysis.cc",
        "optimizing/ssa_phi_elimination.cc",
        "optimizing/stack_map_stream.cc",
        "optimizing/superblock_cloner.cc",
        "trampolines/trampoline_compiler.cc",
        "utils/assembler.cc",
        "utils/jni_macro_assembler.cc",
        "utils/swap_space.cc",
        "compiler.cc",
    ],

    codegen: {
        arm: {
            srcs: [
                "jni/quick/arm/calling_convention_arm.cc",
                "optimizing/code_generator_arm_vixl.cc",
                "optimizing/code_generator_vector_arm_vixl.cc",
                "optimizing/critical_native_abi_fixup_arm.cc",
                "optimizing/instruction_simplifier_arm.cc",
                "optimizing/instruction_simplifier_shared.cc",
                "optimizing/intrinsics_arm_vixl.cc",
                "optimizing/nodes_shared.cc",
                "optimizing/scheduler_arm.cc",
                "utils/arm/assembler_arm_vixl.cc",
                "utils/arm/constants_arm.cc",
                "utils/arm/jni_macro_assembler_arm_vixl.cc",
                "utils/arm/managed_register_arm.cc",
            ],
        },
        arm64: {
            srcs: [
                "jni/quick/arm64/calling_convention_arm64.cc",
                "optimizing/code_generator_arm64.cc",
                "optimizing/code_generator_vector_arm64_neon.cc",
                "optimizing/code_generator_vector_arm64_sve.cc",
                "optimizing/scheduler_arm64.cc",
                "optimizing/instruction_simplifier_arm64.cc",
                "optimizing/intrinsics_arm64.cc",
                "utils/arm64/assembler_arm64.cc",
                "utils/arm64/jni_macro_assembler_arm64.cc",
                "utils/arm64/managed_register_arm64.cc",
            ],
        },
        x86: {
            srcs: [
                "jni/quick/x86/calling_convention_x86.cc",
                "optimizing/code_generator_x86.cc",
                "optimizing/code_generator_vector_x86.cc",
                "optimizing/intrinsics_x86.cc",
                "optimizing/instruction_simplifier_x86_shared.cc",
                "optimizing/instruction_simplifier_x86.cc",
                "optimizing/pc_relative_fixups_x86.cc",
                "optimizing/x86_memory_gen.cc",
                "utils/x86/assembler_x86.cc",
                "utils/x86/jni_macro_assembler_x86.cc",
                "utils/x86/managed_register_x86.cc",
            ],
        },
        x86_64: {
            srcs: [
                "jni/quick/x86_64/calling_convention_x86_64.cc",
                "optimizing/intrinsics_x86_64.cc",
                "optimizing/instruction_simplifier_x86_64.cc",
                "optimizing/code_generator_x86_64.cc",
                "optimizing/code_generator_vector_x86_64.cc",
                "utils/x86_64/assembler_x86_64.cc",
                "utils/x86_64/jni_macro_assembler_x86_64.cc",
                "utils/x86_64/managed_register_x86_64.cc",
            ],
        },
    },
    static: {
        cflags: ["-DART_STATIC_LIBART_COMPILER"],
    },
    generated_sources: ["art_compiler_operator_srcs"],
    shared_libs: [
        "libbase",
        "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib.
    ],
    header_libs: [
        "art_cmdlineparser_headers", // For compiler_options.
        "art_disassembler_headers",
        "libnativehelper_header_only",
    ],

    export_include_dirs: ["."],
}

cc_defaults {
    name: "libart-compiler_static_base_defaults",
    whole_static_libs: [
        "libbase",
    ],
}

gensrcs {
    name: "art_compiler_operator_srcs",
    cmd: "$(location generate_operator_out) art/compiler $(in) > $(out)",
    tools: ["generate_operator_out"],
    srcs: [
        "linker/linker_patch.h",
        "optimizing/locations.h",
        "optimizing/nodes.h",
        "optimizing/optimizing_compiler_stats.h",

        "utils/arm/constants_arm.h",
    ],
    output_extension: "operator_out.cc",
}

art_cc_library {
    name: "libart-compiler",
    defaults: [
        "libart-compiler-defaults",
        "dex2oat-pgo-defaults",
    ],
    codegen: {
        arm: {
            // VIXL assembly support for ARM targets.
            static: {
                whole_static_libs: [
                    "libvixl",
                ],
            },
            shared: {
                shared_libs: [
                    "libvixl",
                ],
                // Export vixl headers as they are included in this library's exported headers.
                export_shared_lib_headers: [
                    "libvixl",
                ],
            },
        },
        arm64: {
            // VIXL assembly support for ARM64 targets.
            static: {
                whole_static_libs: [
                    "libvixl",
                ],
            },
            shared: {
                shared_libs: [
                    "libvixl",
                ],
                // Export vixl headers as they are included in this library's exported headers.
                export_shared_lib_headers: [
                    "libvixl",
                ],
            },
        },
    },
    shared_libs: [
        "libart",
        "libartbase",
        "libartpalette",
        "libprofile",
        "libdexfile",
    ],
    whole_static_libs: ["libelffile"],
    runtime_libs: [
        // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load
        // `libart-disassembler.so`.
        "libart-disassembler",
    ],

    target: {
        android: {
            lto: {
                thin: true,
            },
        },
    },
    apex_available: [
        "com.android.art",
        "com.android.art.debug",
    ],
}

cc_defaults {
    name: "libart-compiler_static_defaults",
    defaults: [
        "libart-compiler_static_base_defaults",
        "libart-disassembler_static_defaults",
        "libart_static_defaults",
        "libartbase_static_defaults",
        "libdexfile_static_defaults",
        "libprofile_static_defaults",
    ],
    whole_static_libs: ["libart-compiler"],
}

art_cc_library {
    name: "libartd-compiler",
    defaults: [
        "art_debug_defaults",
        "libart-compiler-defaults",
    ],
    codegen: {
        arm: {
            // VIXL assembly support for ARM targets.
            static: {
                whole_static_libs: [
                    "libvixld",
                ],
            },
            shared: {
                shared_libs: [
                    "libvixld",
                ],
                // Export vixl headers as they are included in this library's exported headers.
                export_shared_lib_headers: [
                    "libvixld",
                ],
            },
        },
        arm64: {
            // VIXL assembly support for ARM64 targets.
            static: {
                whole_static_libs: [
                    "libvixld",
                ],
            },
            shared: {
                shared_libs: [
                    "libvixld",
                ],
                // Export vixl headers as they are included in this library's exported headers.
                export_shared_lib_headers: [
                    "libvixld",
                ],
            },
        },
    },
    shared_libs: [
        "libartbased",
        "libartd",
        "libartpalette",
        "libprofiled",
        "libdexfiled",
    ],
    whole_static_libs: ["libelffiled"],
    runtime_libs: [
        // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load
        // `libartd-disassembler.so`.
        "libartd-disassembler",
    ],

    apex_available: [
        "com.android.art.debug",
    ],
}

cc_defaults {
    name: "libartd-compiler_static_defaults",
    defaults: [
        "libart-compiler_static_base_defaults",
        "libartbased_static_defaults",
        "libartd-disassembler_static_defaults",
        "libartd_static_defaults",
        "libdexfiled_static_defaults",
        "libprofiled_static_defaults",
    ],
    whole_static_libs: ["libartd-compiler"],
}

art_cc_library {
    name: "libart-compiler-gtest",
    defaults: ["libart-gtest-defaults"],
    srcs: [
        "common_compiler_test.cc",
    ],
    shared_libs: [
        "libartd-compiler",
        "libartd-disassembler",
        "libartbase-art-gtest",
        "libart-runtime-gtest",
        "libbase",
    ],
}

art_cc_test {
    name: "art_compiler_tests",
    defaults: [
        "art_gtest_defaults",
    ],
    data: [
        ":art-gtest-jars-ExceptionHandle",
        ":art-gtest-jars-Interfaces",
        ":art-gtest-jars-MyClassNatives",
    ],
    srcs: [
        "debug/dwarf/dwarf_test.cc",
        "debug/src_map_elem_test.cc",
        "driver/compiled_method_storage_test.cc",
        "exception_test.cc",
        "jni/jni_compiler_test.cc",
        "linker/linker_patch_test.cc",
        "linker/output_stream_test.cc",
        "optimizing/bounds_check_elimination_test.cc",
        "optimizing/constant_folding_test.cc",
        "optimizing/data_type_test.cc",
        "optimizing/dead_code_elimination_test.cc",
        "optimizing/dominator_test.cc",
        "optimizing/find_loops_test.cc",
        "optimizing/graph_checker_test.cc",
        "optimizing/graph_test.cc",
        "optimizing/gvn_test.cc",
        "optimizing/induction_var_analysis_test.cc",
        "optimizing/induction_var_range_test.cc",
        "optimizing/licm_test.cc",
        "optimizing/linearize_test.cc",
        "optimizing/live_interval_test.cc",
        "optimizing/live_ranges_test.cc",
        "optimizing/liveness_test.cc",
        "optimizing/loop_optimization_test.cc",
        "optimizing/nodes_test.cc",
        "optimizing/nodes_vector_test.cc",
        "optimizing/parallel_move_test.cc",
        "optimizing/pretty_printer_test.cc",
        "optimizing/reference_type_propagation_test.cc",
        "optimizing/select_generator_test.cc",
        "optimizing/side_effects_test.cc",
        "optimizing/ssa_liveness_analysis_test.cc",
        "optimizing/ssa_test.cc",
        "optimizing/stack_map_test.cc",
        "optimizing/superblock_cloner_test.cc",
        "optimizing/suspend_check_test.cc",
        "utils/atomic_dex_ref_map_test.cc",
        "utils/dedupe_set_test.cc",
        "utils/swap_space_test.cc",

        "jni/jni_cfi_test.cc",
        "optimizing/codegen_test.cc",
        "optimizing/execution_subgraph_test.cc",
        "optimizing/load_store_analysis_test.cc",
        "optimizing/load_store_elimination_test.cc",
        "optimizing/optimizing_cfi_test.cc",
        "optimizing/scheduler_test.cc",
    ],

    codegen: {
        arm: {
            srcs: [
                "utils/arm/managed_register_arm_test.cc",
            ],
        },
        arm64: {
            srcs: [
                "utils/arm64/managed_register_arm64_test.cc",
            ],
        },
        x86: {
            srcs: [
                "utils/x86/managed_register_x86_test.cc",

                // This test is testing architecture-independent functionality,
                // but happens to use x86 codegen as part of the test.
                "optimizing/register_allocator_test.cc",
            ],
        },
        x86_64: {
            srcs: [
                // Is this test a bit-rotten copy of the x86 test? b/77951326
                // "utils/x86_64/managed_register_x86_64_test.cc",
            ],
        },
    },

    header_libs: [
        "libart_simulator_headers",
        "libnativehelper_header_only",
    ],

    shared_libs: [
        "libprofiled",
        "libartd-compiler",
        "libartd-simulator-container",
        "libvixld",

        "libbacktrace",
        "libnativeloader",
    ],

    target: {
        host: {
            shared_libs: [
                "libartd-simulator",
            ],
        },
    },
}

art_cc_test {
    name: "art_compiler_host_tests",
    device_supported: false,
    defaults: [
        "art_gtest_defaults",
    ],
    codegen: {
        arm: {
            srcs: [
                "utils/assembler_thumb_test.cc",
            ],
        },
        x86: {
            srcs: [
                "utils/x86/assembler_x86_test.cc",
            ],
        },
        x86_64: {
            srcs: [
                "utils/x86_64/assembler_x86_64_test.cc",
            ],
        },
    },
    shared_libs: [
        "libartd-compiler",
        "libvixld",
    ],
}
