blob: f837c399ae153bd5b99c8b063eed4221330b57d8 [file] [log] [blame]
buzbeee3acd072012-02-25 17:03:10 -08001/*
2 * Copyright (C) 2012 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#include "../../CompilerInternals.h"
18#include "MipsLIR.h"
19#include "../Ralloc.h"
20
21#include <string>
22
23namespace art {
24
buzbeeb046e162012-10-30 15:48:42 -070025void setupTargetResourceMasks(CompilationUnit* cUnit, LIR* lir)
26{
27 DCHECK_EQ(cUnit->instructionSet, kMips);
28
29 // Mips-specific resource map setup here.
Bill Buzbee4b39c9f1b2012-11-08 13:32:05 -080030 int flags = EncodingMap[lir->opcode].flags;
buzbeeb046e162012-10-30 15:48:42 -070031 if (flags & REG_DEF_LR) {
Bill Buzbee4b39c9f1b2012-11-08 13:32:05 -080032 lir->defMask |= ENCODE_REG_LR;
buzbeeb046e162012-10-30 15:48:42 -070033 }
34}
35
buzbeee3acd072012-02-25 17:03:10 -080036/* For dumping instructions */
37#define MIPS_REG_COUNT 32
38static const char *mipsRegName[MIPS_REG_COUNT] = {
Bill Buzbeea114add2012-05-03 15:00:40 -070039 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
40 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
41 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
42 "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
buzbeee3acd072012-02-25 17:03:10 -080043};
44
45/*
46 * Interpret a format string and build a string no longer than size
47 * See format key in Assemble.c.
48 */
buzbee5de34942012-03-01 14:51:57 -080049std::string buildInsnString(const char *fmt, LIR *lir, unsigned char* baseAddr)
buzbeee3acd072012-02-25 17:03:10 -080050{
Bill Buzbeea114add2012-05-03 15:00:40 -070051 std::string buf;
52 int i;
53 const char *fmtEnd = &fmt[strlen(fmt)];
54 char tbuf[256];
55 char nc;
56 while (fmt < fmtEnd) {
57 int operand;
58 if (*fmt == '!') {
59 fmt++;
60 DCHECK_LT(fmt, fmtEnd);
61 nc = *fmt++;
62 if (nc=='!') {
63 strcpy(tbuf, "!");
64 } else {
65 DCHECK_LT(fmt, fmtEnd);
66 DCHECK_LT((unsigned)(nc-'0'), 4u);
67 operand = lir->operands[nc-'0'];
68 switch (*fmt++) {
69 case 'b':
70 strcpy(tbuf,"0000");
71 for (i=3; i>= 0; i--) {
72 tbuf[i] += operand & 1;
73 operand >>= 1;
74 }
75 break;
76 case 's':
77 sprintf(tbuf,"$f%d",operand & FP_REG_MASK);
78 break;
79 case 'S':
80 DCHECK_EQ(((operand & FP_REG_MASK) & 1), 0);
81 sprintf(tbuf,"$f%d",operand & FP_REG_MASK);
82 break;
83 case 'h':
84 sprintf(tbuf,"%04x", operand);
85 break;
86 case 'M':
87 case 'd':
88 sprintf(tbuf,"%d", operand);
89 break;
90 case 'D':
91 sprintf(tbuf,"%d", operand+1);
92 break;
93 case 'E':
94 sprintf(tbuf,"%d", operand*4);
95 break;
96 case 'F':
97 sprintf(tbuf,"%d", operand*2);
98 break;
99 case 't':
100 sprintf(tbuf,"0x%08x (L%p)", (int) baseAddr + lir->offset + 4 +
101 (operand << 2), lir->target);
102 break;
103 case 'T':
104 sprintf(tbuf,"0x%08x", (int) (operand << 2));
105 break;
106 case 'u': {
107 int offset_1 = lir->operands[0];
108 int offset_2 = NEXT_LIR(lir)->operands[0];
109 intptr_t target =
110 ((((intptr_t) baseAddr + lir->offset + 4) & ~3) +
111 (offset_1 << 21 >> 9) + (offset_2 << 1)) & 0xfffffffc;
112 sprintf(tbuf, "%p", (void *) target);
113 break;
114 }
buzbeee3acd072012-02-25 17:03:10 -0800115
Bill Buzbeea114add2012-05-03 15:00:40 -0700116 /* Nothing to print for BLX_2 */
117 case 'v':
118 strcpy(tbuf, "see above");
119 break;
120 case 'r':
121 DCHECK(operand >= 0 && operand < MIPS_REG_COUNT);
122 strcpy(tbuf, mipsRegName[operand]);
123 break;
124 case 'N':
125 // Placeholder for delay slot handling
126 strcpy(tbuf, "; nop");
127 break;
128 default:
129 strcpy(tbuf,"DecodeError");
130 break;
131 }
132 buf += tbuf;
133 }
134 } else {
135 buf += *fmt++;
buzbeee3acd072012-02-25 17:03:10 -0800136 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700137 }
138 return buf;
buzbeee3acd072012-02-25 17:03:10 -0800139}
140
buzbee408ad162012-06-06 16:45:18 -0700141// FIXME: need to redo resource maps for MIPS - fix this at that time
buzbeee3acd072012-02-25 17:03:10 -0800142void oatDumpResourceMask(LIR *lir, u8 mask, const char *prefix)
143{
Bill Buzbeea114add2012-05-03 15:00:40 -0700144 char buf[256];
145 buf[0] = 0;
146 LIR *mipsLIR = (LIR *) lir;
buzbeee3acd072012-02-25 17:03:10 -0800147
Bill Buzbeea114add2012-05-03 15:00:40 -0700148 if (mask == ENCODE_ALL) {
149 strcpy(buf, "all");
150 } else {
151 char num[8];
152 int i;
buzbeee3acd072012-02-25 17:03:10 -0800153
Bill Buzbee4b39c9f1b2012-11-08 13:32:05 -0800154 for (i = 0; i < kRegEnd; i++) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700155 if (mask & (1ULL << i)) {
156 sprintf(num, "%d ", i);
157 strcat(buf, num);
158 }
buzbeee3acd072012-02-25 17:03:10 -0800159 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700160
161 if (mask & ENCODE_CCODE) {
162 strcat(buf, "cc ");
buzbeee3acd072012-02-25 17:03:10 -0800163 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700164 if (mask & ENCODE_FP_STATUS) {
165 strcat(buf, "fpcc ");
166 }
167 /* Memory bits */
168 if (mipsLIR && (mask & ENCODE_DALVIK_REG)) {
169 sprintf(buf + strlen(buf), "dr%d%s", mipsLIR->aliasInfo & 0xffff,
170 (mipsLIR->aliasInfo & 0x80000000) ? "(+1)" : "");
171 }
172 if (mask & ENCODE_LITERAL) {
173 strcat(buf, "lit ");
174 }
175
176 if (mask & ENCODE_HEAP_REF) {
177 strcat(buf, "heap ");
178 }
179 if (mask & ENCODE_MUST_NOT_ALIAS) {
180 strcat(buf, "noalias ");
181 }
182 }
183 if (buf[0]) {
184 LOG(INFO) << prefix << ": " << buf;
185 }
buzbeee3acd072012-02-25 17:03:10 -0800186}
187
buzbeee3acd072012-02-25 17:03:10 -0800188} // namespace art