130 }
131
132
133 bool LIRGenerator:: can_inline_as_constant(LIR_Const* c) const {
134 if (c->type() == T_INT) {
135 return Assembler::is_simm13(c->as_jint());
136 }
137 return false;
138 }
139
140
141 LIR_Opr LIRGenerator::safepoint_poll_register() {
142 return new_register(T_INT);
143 }
144
145
146
147 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
148 int shift, int disp, BasicType type) {
149 assert(base->is_register(), "must be");
150
151 // accumulate fixed displacements
152 if (index->is_constant()) {
153 disp += index->as_constant_ptr()->as_jint() << shift;
154 index = LIR_OprFact::illegalOpr;
155 }
156
157 if (index->is_register()) {
158 // apply the shift and accumulate the displacement
159 if (shift > 0) {
160 LIR_Opr tmp = new_pointer_register();
161 __ shift_left(index, shift, tmp);
162 index = tmp;
163 }
164 if (disp != 0) {
165 LIR_Opr tmp = new_pointer_register();
166 if (Assembler::is_simm13(disp)) {
167 __ add(tmp, LIR_OprFact::intptrConst(disp), tmp);
168 index = tmp;
169 } else {
170 __ move(LIR_OprFact::intptrConst(disp), tmp);
171 __ add(tmp, index, tmp);
172 index = tmp;
173 }
174 disp = 0;
175 }
176 } else if (disp != 0 && !Assembler::is_simm13(disp)) {
177 // index is illegal so replace it with the displacement loaded into a register
178 index = new_pointer_register();
179 __ move(LIR_OprFact::intptrConst(disp), index);
180 disp = 0;
181 }
182
183 // at this point we either have base + index or base + displacement
184 if (disp == 0) {
185 return new LIR_Address(base, index, type);
186 } else {
187 assert(Assembler::is_simm13(disp), "must be");
188 return new LIR_Address(base, disp, type);
189 }
190 }
191
192
193 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,
194 BasicType type, bool needs_card_mark) {
195 int elem_size = type2aelembytes(type);
196 int shift = exact_log2(elem_size);
197
198 LIR_Opr base_opr;
199 int offset = arrayOopDesc::base_offset_in_bytes(type);
200
201 if (index_opr->is_constant()) {
202 int i = index_opr->as_constant_ptr()->as_jint();
203 int array_offset = i * elem_size;
204 if (Assembler::is_simm13(array_offset + offset)) {
205 base_opr = array_opr;
206 offset = array_offset + offset;
207 } else {
208 base_opr = new_pointer_register();
|
130 }
131
132
133 bool LIRGenerator:: can_inline_as_constant(LIR_Const* c) const {
134 if (c->type() == T_INT) {
135 return Assembler::is_simm13(c->as_jint());
136 }
137 return false;
138 }
139
140
141 LIR_Opr LIRGenerator::safepoint_poll_register() {
142 return new_register(T_INT);
143 }
144
145
146
147 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
148 int shift, int disp, BasicType type) {
149 assert(base->is_register(), "must be");
150 intx large_disp = disp;
151
152 // accumulate fixed displacements
153 if (index->is_constant()) {
154 large_disp += (intx)(index->as_constant_ptr()->as_jint()) << shift;
155 index = LIR_OprFact::illegalOpr;
156 }
157
158 if (index->is_register()) {
159 // apply the shift and accumulate the displacement
160 if (shift > 0) {
161 LIR_Opr tmp = new_pointer_register();
162 __ shift_left(index, shift, tmp);
163 index = tmp;
164 }
165 if (large_disp != 0) {
166 LIR_Opr tmp = new_pointer_register();
167 if (Assembler::is_simm13(large_disp)) {
168 __ add(tmp, LIR_OprFact::intptrConst(large_disp), tmp);
169 index = tmp;
170 } else {
171 __ move(LIR_OprFact::intptrConst(large_disp), tmp);
172 __ add(tmp, index, tmp);
173 index = tmp;
174 }
175 large_disp = 0;
176 }
177 } else if (large_disp != 0 && !Assembler::is_simm13(large_disp)) {
178 // index is illegal so replace it with the displacement loaded into a register
179 index = new_pointer_register();
180 __ move(LIR_OprFact::intptrConst(large_disp), index);
181 large_disp = 0;
182 }
183
184 // at this point we either have base + index or base + displacement
185 if (large_disp == 0) {
186 return new LIR_Address(base, index, type);
187 } else {
188 assert(Assembler::is_simm13(large_disp), "must be");
189 return new LIR_Address(base, large_disp, type);
190 }
191 }
192
193
194 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,
195 BasicType type, bool needs_card_mark) {
196 int elem_size = type2aelembytes(type);
197 int shift = exact_log2(elem_size);
198
199 LIR_Opr base_opr;
200 int offset = arrayOopDesc::base_offset_in_bytes(type);
201
202 if (index_opr->is_constant()) {
203 int i = index_opr->as_constant_ptr()->as_jint();
204 int array_offset = i * elem_size;
205 if (Assembler::is_simm13(array_offset + offset)) {
206 base_opr = array_opr;
207 offset = array_offset + offset;
208 } else {
209 base_opr = new_pointer_register();
|