blob: 29cc8efcc3204f22baf6773eaf8a9dbdf6ee0555 [file] [log] [blame]
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001/*
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_H_
18#define ART_COMPILER_OPTIMIZING_INTRINSICS_H_
19
20#include "nodes.h"
21#include "optimization.h"
22
23namespace art {
24
25class CompilerDriver;
26class DexFile;
27
28// Recognize intrinsics from HInvoke nodes.
29class IntrinsicsRecognizer : public HOptimization {
30 public:
31 IntrinsicsRecognizer(HGraph* graph, const DexFile* dex_file, CompilerDriver* driver)
32 : HOptimization(graph, true, "intrinsics_recognition"),
33 dex_file_(dex_file), driver_(driver) {}
34
35 void Run() OVERRIDE;
36
37 private:
38 const DexFile* dex_file_;
39 CompilerDriver* driver_;
40
41 DISALLOW_COPY_AND_ASSIGN(IntrinsicsRecognizer);
42};
43
44class IntrinsicVisitor : public ValueObject {
45 public:
46 virtual ~IntrinsicVisitor() {}
47
48 // Dispatch logic.
49
50 void Dispatch(HInvoke* invoke) {
51 switch (invoke->GetIntrinsic()) {
52 case Intrinsics::kNone:
53 return;
54#define OPTIMIZING_INTRINSICS(Name, IsStatic) \
55 case Intrinsics::k ## Name: \
56 Visit ## Name(invoke); \
57 return;
58#include "intrinsics_list.h"
59INTRINSICS_LIST(OPTIMIZING_INTRINSICS)
60#undef INTRINSICS_LIST
61#undef OPTIMIZING_INTRINSICS
62
63 // Do not put a default case. That way the compiler will complain if we missed a case.
64 }
65 }
66
67 // Define visitor methods.
68
69#define OPTIMIZING_INTRINSICS(Name, IsStatic) \
70 virtual void Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \
71 }
72#include "intrinsics_list.h"
73INTRINSICS_LIST(OPTIMIZING_INTRINSICS)
74#undef INTRINSICS_LIST
75#undef OPTIMIZING_INTRINSICS
76
77 protected:
78 IntrinsicVisitor() {}
79
80 private:
81 DISALLOW_COPY_AND_ASSIGN(IntrinsicVisitor);
82};
83
84} // namespace art
85
86#endif // ART_COMPILER_OPTIMIZING_INTRINSICS_H_