blob: d325f5c035f573f14db63968d3122b85e56bcebc [file] [log] [blame]
buzbeee88dfbf2012-03-05 11:19:57 -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 "X86LIR.h"
19#include "../Ralloc.h"
20
21#include <string>
22
23namespace art {
24
25/* For dumping instructions */
Ian Rogersb5d09b22012-03-06 22:14:17 -080026static const char* x86RegName[] = {
buzbeee88dfbf2012-03-05 11:19:57 -080027 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
28 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
29};
30
Ian Rogersb5d09b22012-03-06 22:14:17 -080031static const char* x86CondName[] = {
32 "O",
33 "NO",
34 "B/NAE/C",
35 "NB/AE/NC",
36 "Z/EQ",
37 "NZ/NE",
38 "BE/NA",
39 "NBE/A",
40 "S",
41 "NS",
42 "P/PE",
43 "NP/PO",
44 "L/NGE",
45 "NL/GE",
46 "LE/NG",
47 "NLE/G"
48};
49
buzbeee88dfbf2012-03-05 11:19:57 -080050/*
51 * Interpret a format string and build a string no longer than size
Ian Rogers7caad772012-03-30 01:07:54 -070052 * See format key in Assemble.cc.
buzbeee88dfbf2012-03-05 11:19:57 -080053 */
Ian Rogersb5d09b22012-03-06 22:14:17 -080054std::string buildInsnString(const char *fmt, LIR *lir, unsigned char* baseAddr) {
55 std::string buf;
56 size_t i = 0;
57 size_t fmt_len = strlen(fmt);
Elliott Hughesb25c3f62012-03-26 16:35:06 -070058 while (i < fmt_len) {
Ian Rogersb5d09b22012-03-06 22:14:17 -080059 if (fmt[i] != '!') {
60 buf += fmt[i];
61 i++;
62 } else {
63 i++;
64 DCHECK_LT(i, fmt_len);
65 char operand_number_ch = fmt[i];
66 i++;
67 if (operand_number_ch == '!') {
68 buf += "!";
69 } else {
70 int operand_number = operand_number_ch - '0';
71 DCHECK_LT(operand_number, 6); // Expect upto 6 LIR operands.
72 DCHECK_LT(i, fmt_len);
73 int operand = lir->operands[operand_number];
Elliott Hughesb25c3f62012-03-26 16:35:06 -070074 switch (fmt[i]) {
Ian Rogersb3ab25b2012-03-19 01:12:01 -070075 case 'c':
76 DCHECK_LT(static_cast<size_t>(operand), sizeof(x86CondName));
77 buf += x86CondName[operand];
78 break;
Ian Rogersb5d09b22012-03-06 22:14:17 -080079 case 'd':
80 buf += StringPrintf("%d", operand);
81 break;
Ian Rogers7caad772012-03-30 01:07:54 -070082 case 'p': {
83 SwitchTable *tabRec = reinterpret_cast<SwitchTable*>(operand);
84 buf += StringPrintf("0x%08x", tabRec->offset);
85 break;
86 }
Ian Rogersb5d09b22012-03-06 22:14:17 -080087 case 'r':
88 if (FPREG(operand) || DOUBLEREG(operand)) {
89 int fp_reg = operand & FP_REG_MASK;
90 buf += StringPrintf("xmm%d", fp_reg);
buzbeee88dfbf2012-03-05 11:19:57 -080091 } else {
Ian Rogersb5d09b22012-03-06 22:14:17 -080092 DCHECK_LT(static_cast<size_t>(operand), sizeof(x86RegName));
93 buf += x86RegName[operand];
buzbeee88dfbf2012-03-05 11:19:57 -080094 }
Ian Rogersb5d09b22012-03-06 22:14:17 -080095 break;
Ian Rogersb3ab25b2012-03-19 01:12:01 -070096 case 't':
97 buf += StringPrintf("0x%08x (L%p)",
Elliott Hughesdeaac402012-03-27 13:49:44 -070098 reinterpret_cast<uint32_t>(baseAddr) + lir->offset + operand,
Ian Rogersb3ab25b2012-03-19 01:12:01 -070099 lir->target);
Ian Rogersb5d09b22012-03-06 22:14:17 -0800100 break;
101 default:
102 buf += StringPrintf("DecodeError '%c'", fmt[i]);
103 break;
buzbeee88dfbf2012-03-05 11:19:57 -0800104 }
Ian Rogersb5d09b22012-03-06 22:14:17 -0800105 i++;
106 }
buzbeee88dfbf2012-03-05 11:19:57 -0800107 }
Ian Rogersb5d09b22012-03-06 22:14:17 -0800108 }
109 return buf;
buzbeee88dfbf2012-03-05 11:19:57 -0800110}
111
112void oatDumpResourceMask(LIR *lir, u8 mask, const char *prefix)
113{
buzbeee88dfbf2012-03-05 11:19:57 -0800114 char buf[256];
115 buf[0] = 0;
buzbeea7678db2012-03-05 15:35:46 -0800116 LIR *x86LIR = (LIR *) lir;
buzbeee88dfbf2012-03-05 11:19:57 -0800117
118 if (mask == ENCODE_ALL) {
119 strcpy(buf, "all");
120 } else {
121 char num[8];
122 int i;
123
124 for (i = 0; i < kRegEnd; i++) {
125 if (mask & (1ULL << i)) {
126 sprintf(num, "%d ", i);
127 strcat(buf, num);
128 }
129 }
130
131 if (mask & ENCODE_CCODE) {
132 strcat(buf, "cc ");
133 }
buzbeee88dfbf2012-03-05 11:19:57 -0800134 /* Memory bits */
buzbeea7678db2012-03-05 15:35:46 -0800135 if (x86LIR && (mask & ENCODE_DALVIK_REG)) {
136 sprintf(buf + strlen(buf), "dr%d%s", x86LIR->aliasInfo & 0xffff,
137 (x86LIR->aliasInfo & 0x80000000) ? "(+1)" : "");
buzbeee88dfbf2012-03-05 11:19:57 -0800138 }
139 if (mask & ENCODE_LITERAL) {
140 strcat(buf, "lit ");
141 }
142
143 if (mask & ENCODE_HEAP_REF) {
144 strcat(buf, "heap ");
145 }
146 if (mask & ENCODE_MUST_NOT_ALIAS) {
147 strcat(buf, "noalias ");
148 }
149 }
150 if (buf[0]) {
151 LOG(INFO) << prefix << ": " << buf;
152 }
buzbeee88dfbf2012-03-05 11:19:57 -0800153}
154
155} // namespace art