blob: e67067cddef6e5689d6c28bf3a9e43180927c31f [file] [log] [blame]
Ian Rogers7b3ddd22013-02-21 15:19:52 -08001/*
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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
18#define ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
Ian Rogers7b3ddd22013-02-21 15:19:52 -080019
Ian Rogers7b3ddd22013-02-21 15:19:52 -080020#include <stdint.h>
21#include <string>
22
Ian Rogers7b078e82014-09-10 14:44:24 -070023#include "base/macros.h"
Ian Rogers576ca0c2014-06-06 15:58:22 -070024
Ian Rogers7b3ddd22013-02-21 15:19:52 -080025namespace art {
26namespace verifier {
27
Ian Rogers7b078e82014-09-10 14:44:24 -070028class InstructionFlags FINAL {
Ian Rogers7b3ddd22013-02-21 15:19:52 -080029 public:
Ian Rogers7b078e82014-09-10 14:44:24 -070030 InstructionFlags() : flags_(0) {}
Ian Rogers7b3ddd22013-02-21 15:19:52 -080031
Ian Rogers7b078e82014-09-10 14:44:24 -070032 void SetIsOpcode() {
33 flags_ |= 1 << kOpcode;
Ian Rogers7b3ddd22013-02-21 15:19:52 -080034 }
Ian Rogers7b078e82014-09-10 14:44:24 -070035 void ClearIsOpcode() {
36 flags_ &= ~(1 << kOpcode);
Ian Rogers7b3ddd22013-02-21 15:19:52 -080037 }
38 bool IsOpcode() const {
Ian Rogers7b078e82014-09-10 14:44:24 -070039 return (flags_ & (1 << kOpcode)) != 0;
Ian Rogers7b3ddd22013-02-21 15:19:52 -080040 }
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 Asal02c42232013-04-30 12:09:45 -070061 void SetCompileTimeInfoPoint() {
62 flags_ |= 1 << kCompileTimeInfoPoint;
Ian Rogers7b3ddd22013-02-21 15:19:52 -080063 }
Sameer Abu Asal02c42232013-04-30 12:09:45 -070064 void ClearCompileTimeInfoPoint() {
65 flags_ &= ~(1 << kCompileTimeInfoPoint);
Ian Rogers7b3ddd22013-02-21 15:19:52 -080066 }
Sameer Abu Asal02c42232013-04-30 12:09:45 -070067 bool IsCompileTimeInfoPoint() const {
68 return (flags_ & (1 << kCompileTimeInfoPoint)) != 0;
Ian Rogers7b3ddd22013-02-21 15:19:52 -080069 }
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 Rogersb8c78592013-07-25 23:52:52 +000095 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 Rogers7b3ddd22013-02-21 15:19:52 -0800110 std::string ToString() const;
111
112 private:
113 enum {
Ian Rogers6d376ae2013-07-23 15:12:40 -0700114 // 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 Rogers7b078e82014-09-10 14:44:24 -0700119 // The item at this location is an opcode.
120 kOpcode = 2,
Ian Rogers6d376ae2013-07-23 15:12:40 -0700121 // Instruction is contained within a try region.
Ian Rogers7b078e82014-09-10 14:44:24 -0700122 kInTry = 3,
Ian Rogers6d376ae2013-07-23 15:12:40 -0700123 // Instruction is the target of a branch (ie the start of a basic block).
Ian Rogers7b078e82014-09-10 14:44:24 -0700124 kBranchTarget = 4,
Ian Rogers6d376ae2013-07-23 15:12:40 -0700125 // Location of interest to the compiler for GC maps and verifier based method sharpening.
Ian Rogers7b078e82014-09-10 14:44:24 -0700126 kCompileTimeInfoPoint = 5,
Ian Rogersb8c78592013-07-25 23:52:52 +0000127 // A return instruction.
Ian Rogers7b078e82014-09-10 14:44:24 -0700128 kReturn = 6,
Ian Rogers7b3ddd22013-02-21 15:19:52 -0800129 };
Ian Rogers7b3ddd22013-02-21 15:19:52 -0800130 uint8_t flags_;
131};
132
Andreas Gampe575e78c2014-11-03 23:41:03 -0800133static_assert(sizeof(InstructionFlags) == sizeof(uint8_t),
134 "Size of InstructionFlags not equal to uint8_t");
Ian Rogers7b078e82014-09-10 14:44:24 -0700135
Ian Rogers7b3ddd22013-02-21 15:19:52 -0800136} // namespace verifier
137} // namespace art
138
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700139#endif // ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_