1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef BERBERIS_HEAVY_OPTIMIZER_RISCV64_HEAVY_OPTIMIZE_REGION_H_
18 #define BERBERIS_HEAVY_OPTIMIZER_RISCV64_HEAVY_OPTIMIZE_REGION_H_
19 
20 #include <cstdint>
21 #include <tuple>
22 
23 #include "berberis/assembler/machine_code.h"
24 #include "berberis/guest_state/guest_addr.h"
25 
26 namespace berberis {
27 
28 struct HeavyOptimizeParams {
29   // Generally we don't expect too long regions, since we break at unconditional branches, including
30   // function calls and returns. But some applications end up having more than 1000 insns in region
31   // (b/197703128), which results in huge memory consumption by translator's data structures
32   // (specifically by LivenessAnalyzer). Regions longer than 200 are quite rare and there is a lot
33   // of room for optimzations within this range. Thus this limitation has very little to no impact
34   // on the generated code quality.
35   size_t max_number_of_instructions = 200;
36 };
37 
38 std::tuple<GuestAddr, bool, size_t> HeavyOptimizeRegion(
39     GuestAddr pc,
40     MachineCode* machine_code,
41     const HeavyOptimizeParams& params = HeavyOptimizeParams());
42 
43 }  // namespace berberis
44 
45 #endif /* BERBERIS_HEAVY_OPTIMIZER_RISCV64_HEAVY_OPTIMIZE_REGION_H_ */
46