xref: /aosp_15_r20/art/runtime/verifier/instruction_flags.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
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 
17 #ifndef ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
18 #define ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
19 
20 #include <stdint.h>
21 #include <string>
22 
23 #include "base/macros.h"
24 
25 namespace art HIDDEN {
26 namespace verifier {
27 
28 class InstructionFlags final {
29  public:
InstructionFlags()30   InstructionFlags() : flags_(0) {}
31 
SetIsOpcode()32   void SetIsOpcode() {
33     flags_ |= 1 << kOpcode;
34   }
ClearIsOpcode()35   void ClearIsOpcode() {
36     flags_ &= ~(1 << kOpcode);
37   }
IsOpcode()38   bool IsOpcode() const {
39     return (flags_ & (1 << kOpcode)) != 0;
40   }
41 
SetInTry()42   void SetInTry() {
43     flags_ |= 1 << kInTry;
44   }
ClearInTry()45   void ClearInTry() {
46     flags_ &= ~(1 << kInTry);
47   }
IsInTry()48   bool IsInTry() const {
49     return (flags_ & (1 << kInTry)) != 0;
50   }
51 
SetBranchTarget()52   void SetBranchTarget() {
53     flags_ |= 1 << kBranchTarget;
54   }
ClearBranchTarget()55   void ClearBranchTarget() {
56     flags_ &= ~(1 << kBranchTarget);
57   }
IsBranchTarget()58   bool IsBranchTarget() const {
59     return (flags_ & (1 << kBranchTarget)) != 0;
60   }
61 
SetVisited()62   void SetVisited() {
63     flags_ |= 1 << kVisited;
64   }
ClearVisited()65   void ClearVisited() {
66     flags_ &= ~(1 << kVisited);
67   }
IsVisited()68   bool IsVisited() const {
69     return (flags_ & (1 << kVisited)) != 0;
70   }
71 
SetChanged()72   void SetChanged() {
73     flags_ |= 1 << kChanged;
74   }
ClearChanged()75   void ClearChanged() {
76     flags_ &= ~(1 << kChanged);
77   }
IsChanged()78   bool IsChanged() const {
79     return (flags_ & (1 << kChanged)) != 0;
80   }
81 
IsVisitedOrChanged()82   bool IsVisitedOrChanged() const {
83     return IsVisited() || IsChanged();
84   }
85 
SetReturn()86   void SetReturn() {
87     flags_ |= 1 << kReturn;
88   }
ClearReturn()89   void ClearReturn() {
90     flags_ &= ~(1 << kReturn);
91   }
IsReturn()92   bool IsReturn() const {
93     return (flags_ & (1 << kReturn)) != 0;
94   }
95 
96   std::string ToString() const;
97 
Equals(const InstructionFlags & other)98   bool Equals(const InstructionFlags& other) const {
99     return flags_ == other.flags_;
100   }
101 
102  private:
103   enum {
104     // The instruction has been visited and unless IsChanged() verified.
105     kVisited = 0,
106     // Register type information flowing into the instruction changed and so the instruction must be
107     // reprocessed.
108     kChanged = 1,
109     // The item at this location is an opcode.
110     kOpcode = 2,
111     // Instruction is contained within a try region.
112     kInTry = 3,
113     // Instruction is the target of a branch (ie the start of a basic block).
114     kBranchTarget = 4,
115     // A return instruction.
116     kReturn = 5,
117   };
118   uint8_t flags_;
119 };
120 
121 static_assert(sizeof(InstructionFlags) == sizeof(uint8_t),
122               "Size of InstructionFlags not equal to uint8_t");
123 
124 }  // namespace verifier
125 }  // namespace art
126 
127 #endif  // ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
128