| 1 | // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #ifndef RUNTIME_VM_COMPILER_API_DEOPT_ID_H_ |
| 6 | #define RUNTIME_VM_COMPILER_API_DEOPT_ID_H_ |
| 7 | |
| 8 | #include "platform/allocation.h" |
| 9 | |
| 10 | namespace dart { |
| 11 | |
| 12 | // Deoptimization Id logic. |
| 13 | // |
| 14 | // Deoptimization ids are used to refer to deoptimization points, at which |
| 15 | // control can enter unoptimized code from the optimized version of the code. |
| 16 | // |
| 17 | // Note: any instruction that does a call has two deoptimization points, |
| 18 | // one before the call and one after the call - so that we could deoptimize |
| 19 | // to either before or after the call depending on whether the same call |
| 20 | // already occured in the optimized code (and potentially produced |
| 21 | // observable side-effects) or not. |
| 22 | // |
| 23 | // To simplify implementation we always allocate two deopt ids (one for before |
| 24 | // point and one for the after point). |
| 25 | class DeoptId : public AllStatic { |
| 26 | public: |
| 27 | static constexpr intptr_t kNone = -1; |
| 28 | |
| 29 | static inline intptr_t Next(intptr_t deopt_id) { return deopt_id + kStep; } |
| 30 | |
| 31 | static inline intptr_t ToDeoptAfter(intptr_t deopt_id) { |
| 32 | ASSERT(IsDeoptBefore(deopt_id)); |
| 33 | return deopt_id + kAfterOffset; |
| 34 | } |
| 35 | |
| 36 | static inline bool IsDeoptBefore(intptr_t deopt_id) { |
| 37 | return (deopt_id % kStep) == kBeforeOffset; |
| 38 | } |
| 39 | |
| 40 | static inline bool IsDeoptAfter(intptr_t deopt_id) { |
| 41 | return (deopt_id % kStep) == kAfterOffset; |
| 42 | } |
| 43 | |
| 44 | private: |
| 45 | static constexpr intptr_t kStep = 2; |
| 46 | static constexpr intptr_t kBeforeOffset = 0; |
| 47 | static constexpr intptr_t kAfterOffset = 1; |
| 48 | }; |
| 49 | |
| 50 | } // namespace dart |
| 51 | |
| 52 | #endif // RUNTIME_VM_COMPILER_API_DEOPT_ID_H_ |
| 53 | |