Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_ |
| 18 | #define ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_ |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 19 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | #include <string> |
| 22 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 23 | #include "base/macros.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 24 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 25 | namespace art { |
| 26 | namespace verifier { |
| 27 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 28 | class InstructionFlags FINAL { |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 29 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 30 | InstructionFlags() : flags_(0) {} |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 31 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 32 | void SetIsOpcode() { |
| 33 | flags_ |= 1 << kOpcode; |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 34 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 35 | void ClearIsOpcode() { |
| 36 | flags_ &= ~(1 << kOpcode); |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 37 | } |
| 38 | bool IsOpcode() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 39 | return (flags_ & (1 << kOpcode)) != 0; |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void SetInTry() { |
| 43 | flags_ |= 1 << kInTry; |
| 44 | } |
| 45 | void ClearInTry() { |
| 46 | flags_ &= ~(1 << kInTry); |
| 47 | } |
| 48 | bool IsInTry() const { |
| 49 | return (flags_ & (1 << kInTry)) != 0; |
| 50 | } |
| 51 | |
| 52 | void SetBranchTarget() { |
| 53 | flags_ |= 1 << kBranchTarget; |
| 54 | } |
| 55 | void ClearBranchTarget() { |
| 56 | flags_ &= ~(1 << kBranchTarget); |
| 57 | } |
| 58 | bool IsBranchTarget() const { |
| 59 | return (flags_ & (1 << kBranchTarget)) != 0; |
| 60 | } |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 61 | void SetCompileTimeInfoPoint() { |
| 62 | flags_ |= 1 << kCompileTimeInfoPoint; |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 63 | } |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 64 | void ClearCompileTimeInfoPoint() { |
| 65 | flags_ &= ~(1 << kCompileTimeInfoPoint); |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 66 | } |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 67 | bool IsCompileTimeInfoPoint() const { |
| 68 | return (flags_ & (1 << kCompileTimeInfoPoint)) != 0; |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void SetVisited() { |
| 72 | flags_ |= 1 << kVisited; |
| 73 | } |
| 74 | void ClearVisited() { |
| 75 | flags_ &= ~(1 << kVisited); |
| 76 | } |
| 77 | bool IsVisited() const { |
| 78 | return (flags_ & (1 << kVisited)) != 0; |
| 79 | } |
| 80 | |
| 81 | void SetChanged() { |
| 82 | flags_ |= 1 << kChanged; |
| 83 | } |
| 84 | void ClearChanged() { |
| 85 | flags_ &= ~(1 << kChanged); |
| 86 | } |
| 87 | bool IsChanged() const { |
| 88 | return (flags_ & (1 << kChanged)) != 0; |
| 89 | } |
| 90 | |
| 91 | bool IsVisitedOrChanged() const { |
| 92 | return IsVisited() || IsChanged(); |
| 93 | } |
| 94 | |
Ian Rogers | b8c7859 | 2013-07-25 23:52:52 +0000 | [diff] [blame] | 95 | void SetReturn() { |
| 96 | flags_ |= 1 << kReturn; |
| 97 | } |
| 98 | void ClearReturn() { |
| 99 | flags_ &= ~(1 << kReturn); |
| 100 | } |
| 101 | bool IsReturn() const { |
| 102 | return (flags_ & (1 << kReturn)) != 0; |
| 103 | } |
| 104 | |
| 105 | void SetCompileTimeInfoPointAndReturn() { |
| 106 | SetCompileTimeInfoPoint(); |
| 107 | SetReturn(); |
| 108 | } |
| 109 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 110 | std::string ToString() const; |
| 111 | |
| 112 | private: |
| 113 | enum { |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 114 | // The instruction has been visited and unless IsChanged() verified. |
| 115 | kVisited = 0, |
| 116 | // Register type information flowing into the instruction changed and so the instruction must be |
| 117 | // reprocessed. |
| 118 | kChanged = 1, |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 119 | // The item at this location is an opcode. |
| 120 | kOpcode = 2, |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 121 | // Instruction is contained within a try region. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 122 | kInTry = 3, |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 123 | // Instruction is the target of a branch (ie the start of a basic block). |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 124 | kBranchTarget = 4, |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 125 | // Location of interest to the compiler for GC maps and verifier based method sharpening. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 126 | kCompileTimeInfoPoint = 5, |
Ian Rogers | b8c7859 | 2013-07-25 23:52:52 +0000 | [diff] [blame] | 127 | // A return instruction. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 128 | kReturn = 6, |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 129 | }; |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 130 | uint8_t flags_; |
| 131 | }; |
| 132 | |
Andreas Gampe | 575e78c | 2014-11-03 23:41:03 -0800 | [diff] [blame] | 133 | static_assert(sizeof(InstructionFlags) == sizeof(uint8_t), |
| 134 | "Size of InstructionFlags not equal to uint8_t"); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 135 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 136 | } // namespace verifier |
| 137 | } // namespace art |
| 138 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 139 | #endif // ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_ |