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 #ifndef ART_COMPILER_OPTIMIZING_INTRINSICS_X86_H_
18 #define ART_COMPILER_OPTIMIZING_INTRINSICS_X86_H_
19 
20 #include "base/macros.h"
21 #include "intrinsics.h"
22 #include "intrinsics_list.h"
23 
24 namespace art HIDDEN {
25 
26 class ArenaAllocator;
27 class HInvokeStaticOrDirect;
28 class HInvokeVirtual;
29 
30 namespace x86 {
31 
32 class CodeGeneratorX86;
33 class X86Assembler;
34 
35 class IntrinsicLocationsBuilderX86 final : public IntrinsicVisitor {
36  public:
37   explicit IntrinsicLocationsBuilderX86(CodeGeneratorX86* codegen);
38 
39   // Define visitor methods.
40 
41 #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions, ...) \
42   void Visit ## Name(HInvoke* invoke) override;
43   ART_INTRINSICS_WITH_HINVOKE_LIST(OPTIMIZING_INTRINSICS)
44 #undef OPTIMIZING_INTRINSICS
45 
46   // Check whether an invoke is an intrinsic, and if so, create a location summary. Returns whether
47   // a corresponding LocationSummary with the intrinsified_ flag set was generated and attached to
48   // the invoke.
49   bool TryDispatch(HInvoke* invoke);
50 
51  private:
52   ArenaAllocator* const allocator_;
53   CodeGeneratorX86* const codegen_;
54 
55   DISALLOW_COPY_AND_ASSIGN(IntrinsicLocationsBuilderX86);
56 };
57 
58 class IntrinsicCodeGeneratorX86 final : public IntrinsicVisitor {
59  public:
IntrinsicCodeGeneratorX86(CodeGeneratorX86 * codegen)60   explicit IntrinsicCodeGeneratorX86(CodeGeneratorX86* codegen) : codegen_(codegen) {}
61 
62   // Define visitor methods.
63 
64 #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions, ...) \
65   void Visit ## Name(HInvoke* invoke) override;
66   ART_INTRINSICS_WITH_HINVOKE_LIST(OPTIMIZING_INTRINSICS)
67 #undef OPTIMIZING_INTRINSICS
68 
69  private:
70   X86Assembler* GetAssembler();
71 
72   ArenaAllocator* GetAllocator();
73 
74   void HandleValueOf(HInvoke* invoke,
75                      const IntrinsicVisitor::ValueOfInfo& info,
76                      DataType::Type type);
77 
78   CodeGeneratorX86* const codegen_;
79 
80   DISALLOW_COPY_AND_ASSIGN(IntrinsicCodeGeneratorX86);
81 };
82 
83 }  // namespace x86
84 }  // namespace art
85 
86 #endif  // ART_COMPILER_OPTIMIZING_INTRINSICS_X86_H_
87