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