buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace art { |
| 24 | |
| 25 | /* For dumping instructions */ |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 26 | static const char* x86RegName[] = { |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 27 | "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", |
| 28 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 29 | }; |
| 30 | |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 31 | static 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 | |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 50 | /* |
| 51 | * Interpret a format string and build a string no longer than size |
| 52 | * See format key in Assemble.c. |
| 53 | */ |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 54 | std::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 Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 58 | while (i < fmt_len) { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 59 | 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 Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 74 | switch (fmt[i]) { |
Ian Rogers | b3ab25b | 2012-03-19 01:12:01 -0700 | [diff] [blame] | 75 | case 'c': |
| 76 | DCHECK_LT(static_cast<size_t>(operand), sizeof(x86CondName)); |
| 77 | buf += x86CondName[operand]; |
| 78 | break; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 79 | case 'd': |
| 80 | buf += StringPrintf("%d", operand); |
| 81 | break; |
| 82 | case 'r': |
| 83 | if (FPREG(operand) || DOUBLEREG(operand)) { |
| 84 | int fp_reg = operand & FP_REG_MASK; |
| 85 | buf += StringPrintf("xmm%d", fp_reg); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 86 | } else { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 87 | DCHECK_LT(static_cast<size_t>(operand), sizeof(x86RegName)); |
| 88 | buf += x86RegName[operand]; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 89 | } |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 90 | break; |
Ian Rogers | b3ab25b | 2012-03-19 01:12:01 -0700 | [diff] [blame] | 91 | case 't': |
| 92 | buf += StringPrintf("0x%08x (L%p)", |
Elliott Hughes | deaac40 | 2012-03-27 13:49:44 -0700 | [diff] [blame] | 93 | reinterpret_cast<uint32_t>(baseAddr) + lir->offset + operand, |
Ian Rogers | b3ab25b | 2012-03-19 01:12:01 -0700 | [diff] [blame] | 94 | lir->target); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 95 | break; |
| 96 | default: |
| 97 | buf += StringPrintf("DecodeError '%c'", fmt[i]); |
| 98 | break; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 99 | } |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 100 | i++; |
| 101 | } |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 102 | } |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 103 | } |
| 104 | return buf; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void oatDumpResourceMask(LIR *lir, u8 mask, const char *prefix) |
| 108 | { |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 109 | char buf[256]; |
| 110 | buf[0] = 0; |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 111 | LIR *x86LIR = (LIR *) lir; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 112 | |
| 113 | if (mask == ENCODE_ALL) { |
| 114 | strcpy(buf, "all"); |
| 115 | } else { |
| 116 | char num[8]; |
| 117 | int i; |
| 118 | |
| 119 | for (i = 0; i < kRegEnd; i++) { |
| 120 | if (mask & (1ULL << i)) { |
| 121 | sprintf(num, "%d ", i); |
| 122 | strcat(buf, num); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if (mask & ENCODE_CCODE) { |
| 127 | strcat(buf, "cc "); |
| 128 | } |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 129 | /* Memory bits */ |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 130 | if (x86LIR && (mask & ENCODE_DALVIK_REG)) { |
| 131 | sprintf(buf + strlen(buf), "dr%d%s", x86LIR->aliasInfo & 0xffff, |
| 132 | (x86LIR->aliasInfo & 0x80000000) ? "(+1)" : ""); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 133 | } |
| 134 | if (mask & ENCODE_LITERAL) { |
| 135 | strcat(buf, "lit "); |
| 136 | } |
| 137 | |
| 138 | if (mask & ENCODE_HEAP_REF) { |
| 139 | strcat(buf, "heap "); |
| 140 | } |
| 141 | if (mask & ENCODE_MUST_NOT_ALIAS) { |
| 142 | strcat(buf, "noalias "); |
| 143 | } |
| 144 | } |
| 145 | if (buf[0]) { |
| 146 | LOG(INFO) << prefix << ": " << buf; |
| 147 | } |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | } // namespace art |