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 {
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   }
SetCompileTimeInfoPoint()61   void SetCompileTimeInfoPoint() {
62     flags_ |= 1 << kCompileTimeInfoPoint;
63   }
ClearCompileTimeInfoPoint()64   void ClearCompileTimeInfoPoint() {
65     flags_ &= ~(1 << kCompileTimeInfoPoint);
66   }
IsCompileTimeInfoPoint()67   bool IsCompileTimeInfoPoint() const {
68     return (flags_ & (1 << kCompileTimeInfoPoint)) != 0;
69   }
70 
SetVisited()71   void SetVisited() {
72     flags_ |= 1 << kVisited;
73   }
ClearVisited()74   void ClearVisited() {
75     flags_ &= ~(1 << kVisited);
76   }
IsVisited()77   bool IsVisited() const {
78     return (flags_ & (1 << kVisited)) != 0;
79   }
80 
SetChanged()81   void SetChanged() {
82     flags_ |= 1 << kChanged;
83   }
ClearChanged()84   void ClearChanged() {
85     flags_ &= ~(1 << kChanged);
86   }
IsChanged()87   bool IsChanged() const {
88     return (flags_ & (1 << kChanged)) != 0;
89   }
90 
IsVisitedOrChanged()91   bool IsVisitedOrChanged() const {
92     return IsVisited() || IsChanged();
93   }
94 
SetReturn()95   void SetReturn() {
96     flags_ |= 1 << kReturn;
97   }
ClearReturn()98   void ClearReturn() {
99     flags_ &= ~(1 << kReturn);
100   }
IsReturn()101   bool IsReturn() const {
102     return (flags_ & (1 << kReturn)) != 0;
103   }
104 
105   std::string ToString() const;
106 
107  private:
108   enum {
109     // The instruction has been visited and unless IsChanged() verified.
110     kVisited = 0,
111     // Register type information flowing into the instruction changed and so the instruction must be
112     // reprocessed.
113     kChanged = 1,
114     // The item at this location is an opcode.
115     kOpcode = 2,
116     // Instruction is contained within a try region.
117     kInTry = 3,
118     // Instruction is the target of a branch (ie the start of a basic block).
119     kBranchTarget = 4,
120     // Location of interest to the compiler for GC maps and verifier based method sharpening.
121     kCompileTimeInfoPoint = 5,
122     // A return instruction.
123     kReturn = 6,
124   };
125   uint8_t flags_;
126 };
127 
128 static_assert(sizeof(InstructionFlags) == sizeof(uint8_t),
129               "Size of InstructionFlags not equal to uint8_t");
130 
131 }  // namespace verifier
132 }  // namespace art
133 
134 #endif  // ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
135