intrinsics.h revision 7c3952f423b8213083d60596a5f0bf4237ca3f7b
171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe/*
271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * Copyright (C) 2015 The Android Open Source Project
371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe *
471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License");
571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * you may not use this file except in compliance with the License.
671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * You may obtain a copy of the License at
771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe *
871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe *      http://www.apache.org/licenses/LICENSE-2.0
971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe *
1071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * Unless required by applicable law or agreed to in writing, software
1171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS,
1271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * See the License for the specific language governing permissions and
1471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe * limitations under the License.
1571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe */
1671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
1771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#ifndef ART_COMPILER_OPTIMIZING_INTRINSICS_H_
1871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#define ART_COMPILER_OPTIMIZING_INTRINSICS_H_
1971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
2071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#include "nodes.h"
2171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#include "optimization.h"
2271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
2371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampenamespace art {
2471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
2571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampeclass CompilerDriver;
2671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampeclass DexFile;
2771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
2871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe// Recognize intrinsics from HInvoke nodes.
2971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampeclass IntrinsicsRecognizer : public HOptimization {
3071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe public:
3171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  IntrinsicsRecognizer(HGraph* graph, const DexFile* dex_file, CompilerDriver* driver)
327c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe      : HOptimization(graph, true, kIntrinsicsRecognizerPassName),
3371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe        dex_file_(dex_file), driver_(driver) {}
3471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
3571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  void Run() OVERRIDE;
3671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
377c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe  static constexpr const char* kIntrinsicsRecognizerPassName = "intrinsics_recognition";
387c3952f423b8213083d60596a5f0bf4237ca3f7bAndreas Gampe
3971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe private:
4071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  const DexFile* dex_file_;
4171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  CompilerDriver* driver_;
4271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
4371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  DISALLOW_COPY_AND_ASSIGN(IntrinsicsRecognizer);
4471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe};
4571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
4671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampeclass IntrinsicVisitor : public ValueObject {
4771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe public:
4871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  virtual ~IntrinsicVisitor() {}
4971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
5071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  // Dispatch logic.
5171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
5271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  void Dispatch(HInvoke* invoke) {
5371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe    switch (invoke->GetIntrinsic()) {
5471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe      case Intrinsics::kNone:
5571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe        return;
5671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#define OPTIMIZING_INTRINSICS(Name, IsStatic) \
5771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe      case Intrinsics::k ## Name:             \
5871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe        Visit ## Name(invoke);                \
5971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe        return;
6071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#include "intrinsics_list.h"
6171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas GampeINTRINSICS_LIST(OPTIMIZING_INTRINSICS)
6271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#undef INTRINSICS_LIST
6371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#undef OPTIMIZING_INTRINSICS
6471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
6571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe      // Do not put a default case. That way the compiler will complain if we missed a case.
6671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe    }
6771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  }
6871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
6971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  // Define visitor methods.
7071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
7171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#define OPTIMIZING_INTRINSICS(Name, IsStatic)                    \
7271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  virtual void Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \
7371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  }
7471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#include "intrinsics_list.h"
7571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas GampeINTRINSICS_LIST(OPTIMIZING_INTRINSICS)
7671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#undef INTRINSICS_LIST
7771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#undef OPTIMIZING_INTRINSICS
7871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
7971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe protected:
8071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  IntrinsicVisitor() {}
8171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
8271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe private:
8371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  DISALLOW_COPY_AND_ASSIGN(IntrinsicVisitor);
8471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe};
8571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
8671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe}  // namespace art
8771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
8871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe#endif  // ART_COMPILER_OPTIMIZING_INTRINSICS_H_
89