10b57cec5SDimitry Andric //===-- X86InstrFoldTables.h - X86 Instruction Folding Tables ---*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file contains the interface to query the X86 memory folding tables. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_X86_X86INSTRFOLDTABLES_H 140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_X86_X86INSTRFOLDTABLES_H 150b57cec5SDimitry Andric 16*5ffd83dbSDimitry Andric #include <cstdint> 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric namespace llvm { 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric enum { 210b57cec5SDimitry Andric // Select which memory operand is being unfolded. 228bcb0991SDimitry Andric // (stored in bits 0 - 2) 230b57cec5SDimitry Andric TB_INDEX_0 = 0, 240b57cec5SDimitry Andric TB_INDEX_1 = 1, 250b57cec5SDimitry Andric TB_INDEX_2 = 2, 260b57cec5SDimitry Andric TB_INDEX_3 = 3, 270b57cec5SDimitry Andric TB_INDEX_4 = 4, 288bcb0991SDimitry Andric TB_INDEX_MASK = 0x7, 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric // Do not insert the reverse map (MemOp -> RegOp) into the table. 310b57cec5SDimitry Andric // This may be needed because there is a many -> one mapping. 328bcb0991SDimitry Andric TB_NO_REVERSE = 1 << 3, 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric // Do not insert the forward map (RegOp -> MemOp) into the table. 350b57cec5SDimitry Andric // This is needed for Native Client, which prohibits branch 360b57cec5SDimitry Andric // instructions from using a memory operand. 378bcb0991SDimitry Andric TB_NO_FORWARD = 1 << 4, 380b57cec5SDimitry Andric 398bcb0991SDimitry Andric TB_FOLDED_LOAD = 1 << 5, 408bcb0991SDimitry Andric TB_FOLDED_STORE = 1 << 6, 418bcb0991SDimitry Andric TB_FOLDED_BCAST = 1 << 7, 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric // Minimum alignment required for load/store. 448bcb0991SDimitry Andric // Used for RegOp->MemOp conversion. Encoded as Log2(Align) + 1 to allow 0 458bcb0991SDimitry Andric // to mean align of 0. 468bcb0991SDimitry Andric // (stored in bits 8 - 11) 470b57cec5SDimitry Andric TB_ALIGN_SHIFT = 8, 480b57cec5SDimitry Andric TB_ALIGN_NONE = 0 << TB_ALIGN_SHIFT, 498bcb0991SDimitry Andric TB_ALIGN_16 = 5 << TB_ALIGN_SHIFT, 508bcb0991SDimitry Andric TB_ALIGN_32 = 6 << TB_ALIGN_SHIFT, 518bcb0991SDimitry Andric TB_ALIGN_64 = 7 << TB_ALIGN_SHIFT, 528bcb0991SDimitry Andric TB_ALIGN_MASK = 0xf << TB_ALIGN_SHIFT, 538bcb0991SDimitry Andric 548bcb0991SDimitry Andric // Broadcast type. 558bcb0991SDimitry Andric // (stored in bits 12 - 13) 568bcb0991SDimitry Andric TB_BCAST_TYPE_SHIFT = 12, 578bcb0991SDimitry Andric TB_BCAST_D = 0 << TB_BCAST_TYPE_SHIFT, 588bcb0991SDimitry Andric TB_BCAST_Q = 1 << TB_BCAST_TYPE_SHIFT, 598bcb0991SDimitry Andric TB_BCAST_SS = 2 << TB_BCAST_TYPE_SHIFT, 608bcb0991SDimitry Andric TB_BCAST_SD = 3 << TB_BCAST_TYPE_SHIFT, 618bcb0991SDimitry Andric TB_BCAST_MASK = 0x3 << TB_BCAST_TYPE_SHIFT, 628bcb0991SDimitry Andric 638bcb0991SDimitry Andric // Unused bits 14-15 640b57cec5SDimitry Andric }; 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric // This struct is used for both the folding and unfold tables. They KeyOp 670b57cec5SDimitry Andric // is used to determine the sorting order. 680b57cec5SDimitry Andric struct X86MemoryFoldTableEntry { 690b57cec5SDimitry Andric uint16_t KeyOp; 700b57cec5SDimitry Andric uint16_t DstOp; 710b57cec5SDimitry Andric uint16_t Flags; 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric bool operator<(const X86MemoryFoldTableEntry &RHS) const { 740b57cec5SDimitry Andric return KeyOp < RHS.KeyOp; 750b57cec5SDimitry Andric } 760b57cec5SDimitry Andric bool operator==(const X86MemoryFoldTableEntry &RHS) const { 770b57cec5SDimitry Andric return KeyOp == RHS.KeyOp; 780b57cec5SDimitry Andric } 790b57cec5SDimitry Andric friend bool operator<(const X86MemoryFoldTableEntry &TE, unsigned Opcode) { 800b57cec5SDimitry Andric return TE.KeyOp < Opcode; 810b57cec5SDimitry Andric } 820b57cec5SDimitry Andric }; 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric // Look up the memory folding table entry for folding a load and a store into 850b57cec5SDimitry Andric // operand 0. 860b57cec5SDimitry Andric const X86MemoryFoldTableEntry *lookupTwoAddrFoldTable(unsigned RegOp); 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric // Look up the memory folding table entry for folding a load or store with 890b57cec5SDimitry Andric // operand OpNum. 900b57cec5SDimitry Andric const X86MemoryFoldTableEntry *lookupFoldTable(unsigned RegOp, unsigned OpNum); 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric // Look up the memory unfolding table entry for this instruction. 930b57cec5SDimitry Andric const X86MemoryFoldTableEntry *lookupUnfoldTable(unsigned MemOp); 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric } // namespace llvm 960b57cec5SDimitry Andric 970b57cec5SDimitry Andric #endif 98