• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 public class Main {
18 
assertIntEquals(int expected, int result)19   public static void assertIntEquals(int expected, int result) {
20     if (expected != result) {
21       throw new Error("Expected: " + expected + ", found: " + result);
22     }
23   }
24 
25   // This function always returns 1.
$opt$noinline$function_call(int arg)26   public static int $opt$noinline$function_call(int arg) {
27     return 1 % arg;
28   }
29 
30   //                               | registers available to | regexp
31   //                               | the register allocator |
32   // ------------------------------|------------------------|-----------------
33   // ARM64 callee-saved registers  | [x20-x29]              | x2[0-9]
34   // ARM callee-saved registers    | [r5-r8,r10,r11]        | r([5-8]|10|11)
35   // X86 callee-saved registers    | [ebp,esi,edi]          | e(bp|si|di)
36   // X86_64 callee-saved registers | [rbx,rbp,r12-15]       | r(bx|bp|1[2-5])
37 
38   /**
39    * Check that a value live across a function call is allocated in a callee
40    * saved register.
41    */
42 
43   /// CHECK-START-ARM:   int Main.$opt$LiveInCall(int) register (after)
44   /// CHECK-DAG:   <<Arg:i\d+>>     ParameterValue
45   /// CHECK-DAG:   <<Const1:i\d+>>  IntConstant 1
46   /// CHECK:       <<t1:i\d+>>      Add [<<Arg>>,<<Const1>>] {{.*->r([5-8]|10|11)}}
47   /// CHECK:       <<t2:i\d+>>      InvokeStaticOrDirect
48   /// CHECK:                        Sub [<<t1>>,<<t2>>]
49   /// CHECK:                        Return
50 
51   /// CHECK-START-ARM64: int Main.$opt$LiveInCall(int) register (after)
52   /// CHECK-DAG:   <<Arg:i\d+>>     ParameterValue
53   /// CHECK-DAG:   <<Const1:i\d+>>  IntConstant 1
54   /// CHECK:       <<t1:i\d+>>      Add [<<Arg>>,<<Const1>>] {{.*->x2[0-9]}}
55   /// CHECK:       <<t2:i\d+>>      InvokeStaticOrDirect
56   /// CHECK:                        Sub [<<t1>>,<<t2>>]
57   /// CHECK:                        Return
58 
59   /// CHECK-START-X86: int Main.$opt$LiveInCall(int) register (after)
60   /// CHECK-DAG:   <<Arg:i\d+>>     ParameterValue
61   /// CHECK-DAG:   <<Const1:i\d+>>  IntConstant 1
62   /// CHECK:       <<t1:i\d+>>      Add [<<Arg>>,<<Const1>>] {{.*->e(bp|si|di)}}
63   /// CHECK:       <<t2:i\d+>>      InvokeStaticOrDirect
64   /// CHECK:                        Sub [<<t1>>,<<t2>>]
65   /// CHECK:                        Return
66 
67   /// CHECK-START-X86_64: int Main.$opt$LiveInCall(int) register (after)
68   /// CHECK-DAG:   <<Arg:i\d+>>     ParameterValue
69   /// CHECK-DAG:   <<Const1:i\d+>>  IntConstant 1
70   /// CHECK:       <<t1:i\d+>>      Add [<<Arg>>,<<Const1>>] {{.*->r(bx|bp|1[2-5])}}
71   /// CHECK:       <<t2:i\d+>>      InvokeStaticOrDirect
72   /// CHECK:                        Sub [<<t1>>,<<t2>>]
73   /// CHECK:                        Return
74 
$opt$LiveInCall(int arg)75   public static int $opt$LiveInCall(int arg) {
76     int t1 = arg + 1;
77     int t2 = $opt$noinline$function_call(arg);
78     return t1 - t2;
79   }
80 
main(String[] args)81   public static void main(String[] args) {
82     int arg = 123;
83     assertIntEquals($opt$LiveInCall(arg), arg);
84   }
85 }
86