xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86InstrFoldTables.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===-- X86InstrFoldTables.h - X86 Instruction Folding Tables ---*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // This file contains the interface to query the X86 memory folding tables.
10*0b57cec5SDimitry Andric //
11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_X86_X86INSTRFOLDTABLES_H
14*0b57cec5SDimitry Andric #define LLVM_LIB_TARGET_X86_X86INSTRFOLDTABLES_H
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric #include "llvm/Support/DataTypes.h"
17*0b57cec5SDimitry Andric 
18*0b57cec5SDimitry Andric namespace llvm {
19*0b57cec5SDimitry Andric 
20*0b57cec5SDimitry Andric enum {
21*0b57cec5SDimitry Andric   // Select which memory operand is being unfolded.
22*0b57cec5SDimitry Andric   // (stored in bits 0 - 3)
23*0b57cec5SDimitry Andric   TB_INDEX_0    = 0,
24*0b57cec5SDimitry Andric   TB_INDEX_1    = 1,
25*0b57cec5SDimitry Andric   TB_INDEX_2    = 2,
26*0b57cec5SDimitry Andric   TB_INDEX_3    = 3,
27*0b57cec5SDimitry Andric   TB_INDEX_4    = 4,
28*0b57cec5SDimitry Andric   TB_INDEX_MASK = 0xf,
29*0b57cec5SDimitry Andric 
30*0b57cec5SDimitry Andric   // Do not insert the reverse map (MemOp -> RegOp) into the table.
31*0b57cec5SDimitry Andric   // This may be needed because there is a many -> one mapping.
32*0b57cec5SDimitry Andric   TB_NO_REVERSE   = 1 << 4,
33*0b57cec5SDimitry Andric 
34*0b57cec5SDimitry Andric   // Do not insert the forward map (RegOp -> MemOp) into the table.
35*0b57cec5SDimitry Andric   // This is needed for Native Client, which prohibits branch
36*0b57cec5SDimitry Andric   // instructions from using a memory operand.
37*0b57cec5SDimitry Andric   TB_NO_FORWARD   = 1 << 5,
38*0b57cec5SDimitry Andric 
39*0b57cec5SDimitry Andric   TB_FOLDED_LOAD  = 1 << 6,
40*0b57cec5SDimitry Andric   TB_FOLDED_STORE = 1 << 7,
41*0b57cec5SDimitry Andric 
42*0b57cec5SDimitry Andric   // Minimum alignment required for load/store.
43*0b57cec5SDimitry Andric   // Used for RegOp->MemOp conversion.
44*0b57cec5SDimitry Andric   // (stored in bits 8 - 15)
45*0b57cec5SDimitry Andric   TB_ALIGN_SHIFT = 8,
46*0b57cec5SDimitry Andric   TB_ALIGN_NONE  =    0 << TB_ALIGN_SHIFT,
47*0b57cec5SDimitry Andric   TB_ALIGN_16    =   16 << TB_ALIGN_SHIFT,
48*0b57cec5SDimitry Andric   TB_ALIGN_32    =   32 << TB_ALIGN_SHIFT,
49*0b57cec5SDimitry Andric   TB_ALIGN_64    =   64 << TB_ALIGN_SHIFT,
50*0b57cec5SDimitry Andric   TB_ALIGN_MASK  = 0xff << TB_ALIGN_SHIFT
51*0b57cec5SDimitry Andric };
52*0b57cec5SDimitry Andric 
53*0b57cec5SDimitry Andric // This struct is used for both the folding and unfold tables. They KeyOp
54*0b57cec5SDimitry Andric // is used to determine the sorting order.
55*0b57cec5SDimitry Andric struct X86MemoryFoldTableEntry {
56*0b57cec5SDimitry Andric   uint16_t KeyOp;
57*0b57cec5SDimitry Andric   uint16_t DstOp;
58*0b57cec5SDimitry Andric   uint16_t Flags;
59*0b57cec5SDimitry Andric 
60*0b57cec5SDimitry Andric   bool operator<(const X86MemoryFoldTableEntry &RHS) const {
61*0b57cec5SDimitry Andric     return KeyOp < RHS.KeyOp;
62*0b57cec5SDimitry Andric   }
63*0b57cec5SDimitry Andric   bool operator==(const X86MemoryFoldTableEntry &RHS) const {
64*0b57cec5SDimitry Andric     return KeyOp == RHS.KeyOp;
65*0b57cec5SDimitry Andric   }
66*0b57cec5SDimitry Andric   friend bool operator<(const X86MemoryFoldTableEntry &TE, unsigned Opcode) {
67*0b57cec5SDimitry Andric     return TE.KeyOp < Opcode;
68*0b57cec5SDimitry Andric   }
69*0b57cec5SDimitry Andric };
70*0b57cec5SDimitry Andric 
71*0b57cec5SDimitry Andric // Look up the memory folding table entry for folding a load and a store into
72*0b57cec5SDimitry Andric // operand 0.
73*0b57cec5SDimitry Andric const X86MemoryFoldTableEntry *lookupTwoAddrFoldTable(unsigned RegOp);
74*0b57cec5SDimitry Andric 
75*0b57cec5SDimitry Andric // Look up the memory folding table entry for folding a load or store with
76*0b57cec5SDimitry Andric // operand OpNum.
77*0b57cec5SDimitry Andric const X86MemoryFoldTableEntry *lookupFoldTable(unsigned RegOp, unsigned OpNum);
78*0b57cec5SDimitry Andric 
79*0b57cec5SDimitry Andric // Look up the memory unfolding table entry for this instruction.
80*0b57cec5SDimitry Andric const X86MemoryFoldTableEntry *lookupUnfoldTable(unsigned MemOp);
81*0b57cec5SDimitry Andric 
82*0b57cec5SDimitry Andric } // namespace llvm
83*0b57cec5SDimitry Andric 
84*0b57cec5SDimitry Andric #endif
85