Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 1 | /* |
| 2 | * TCG Backend Data: load-store optimization only. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to deal |
| 6 | * in the Software without restriction, including without limitation the rights |
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | * copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | * THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifdef CONFIG_SOFTMMU |
| 24 | #define TCG_MAX_QEMU_LDST 640 |
| 25 | |
| 26 | typedef struct TCGLabelQemuLdst { |
Richard Henderson | 9c53889 | 2014-09-02 13:59:47 -0700 | [diff] [blame] | 27 | bool is_ld; /* qemu_ld: true, qemu_st: false */ |
| 28 | TCGMemOp opc; |
| 29 | TCGType type; /* result type of a load */ |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 30 | TCGReg addrlo_reg; /* reg index for low word of guest virtual addr */ |
| 31 | TCGReg addrhi_reg; /* reg index for high word of guest virtual addr */ |
| 32 | TCGReg datalo_reg; /* reg index for low word to be loaded or stored */ |
| 33 | TCGReg datahi_reg; /* reg index for high word to be loaded or stored */ |
| 34 | int mem_index; /* soft MMU memory index */ |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 35 | tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st IR */ |
| 36 | tcg_insn_unit *label_ptr[2]; /* label pointers to be updated */ |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 37 | } TCGLabelQemuLdst; |
| 38 | |
| 39 | typedef struct TCGBackendData { |
| 40 | int nb_ldst_labels; |
| 41 | TCGLabelQemuLdst ldst_labels[TCG_MAX_QEMU_LDST]; |
| 42 | } TCGBackendData; |
| 43 | |
| 44 | |
| 45 | /* |
| 46 | * Initialize TB backend data at the beginning of the TB. |
| 47 | */ |
| 48 | |
| 49 | static inline void tcg_out_tb_init(TCGContext *s) |
| 50 | { |
| 51 | s->be->nb_ldst_labels = 0; |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Generate TB finalization at the end of block |
| 56 | */ |
| 57 | |
| 58 | static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l); |
| 59 | static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l); |
| 60 | |
| 61 | static void tcg_out_tb_finalize(TCGContext *s) |
| 62 | { |
| 63 | TCGLabelQemuLdst *lb = s->be->ldst_labels; |
| 64 | int i, n = s->be->nb_ldst_labels; |
| 65 | |
| 66 | /* qemu_ld/st slow paths */ |
| 67 | for (i = 0; i < n; i++) { |
| 68 | if (lb[i].is_ld) { |
| 69 | tcg_out_qemu_ld_slow_path(s, lb + i); |
| 70 | } else { |
| 71 | tcg_out_qemu_st_slow_path(s, lb + i); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Allocate a new TCGLabelQemuLdst entry. |
| 78 | */ |
| 79 | |
| 80 | static inline TCGLabelQemuLdst *new_ldst_label(TCGContext *s) |
| 81 | { |
| 82 | TCGBackendData *be = s->be; |
| 83 | int n = be->nb_ldst_labels; |
| 84 | |
| 85 | assert(n < TCG_MAX_QEMU_LDST); |
| 86 | be->nb_ldst_labels = n + 1; |
| 87 | return &be->ldst_labels[n]; |
| 88 | } |
| 89 | #else |
| 90 | #include "tcg-be-null.h" |
| 91 | #endif /* CONFIG_SOFTMMU */ |