Skip to content

Commit

Permalink
[RFC][X86][MemFold] Upgrade the mechanism of auto-generated Memory Fo…
Browse files Browse the repository at this point in the history
…lding Table

1. Align ManualMapSet with X86MemoryFoldTableEntry instead of using UnfoldStrategy
2. ManualMapSet able to update the existing record in auto-generated MemFold table

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D142084
  • Loading branch information
yubingex007-a11y committed Mar 20, 2023
1 parent 8d2885c commit 0666c59
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 134 deletions.
59 changes: 59 additions & 0 deletions llvm/include/llvm/Support/X86FoldTablesUtils.h
@@ -0,0 +1,59 @@
//===-- X86FoldTablesUtils.h ------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_SUPPORT_X86FOLDTABLESUTILS_H
#define LLVM_SUPPORT_X86FOLDTABLESUTILS_H

namespace {
enum {
// Select which memory operand is being unfolded.
// (stored in bits 0 - 2)
TB_INDEX_0 = 0,
TB_INDEX_1 = 1,
TB_INDEX_2 = 2,
TB_INDEX_3 = 3,
TB_INDEX_4 = 4,
TB_INDEX_MASK = 0x7,

// Do not insert the reverse map (MemOp -> RegOp) into the table.
// This may be needed because there is a many -> one mapping.
TB_NO_REVERSE = 1 << 3,

// Do not insert the forward map (RegOp -> MemOp) into the table.
// This is needed for Native Client, which prohibits branch
// instructions from using a memory operand.
TB_NO_FORWARD = 1 << 4,

TB_FOLDED_LOAD = 1 << 5,
TB_FOLDED_STORE = 1 << 6,
TB_FOLDED_BCAST = 1 << 7,

// Minimum alignment required for load/store.
// Used for RegOp->MemOp conversion. Encoded as Log2(Align) + 1 to allow 0
// to mean align of 0.
// (stored in bits 8 - 11)
TB_ALIGN_SHIFT = 8,
TB_ALIGN_NONE = 0 << TB_ALIGN_SHIFT,
TB_ALIGN_16 = 5 << TB_ALIGN_SHIFT,
TB_ALIGN_32 = 6 << TB_ALIGN_SHIFT,
TB_ALIGN_64 = 7 << TB_ALIGN_SHIFT,
TB_ALIGN_MASK = 0xf << TB_ALIGN_SHIFT,

// Broadcast type.
// (stored in bits 12 - 13)
TB_BCAST_TYPE_SHIFT = 12,
TB_BCAST_D = 0 << TB_BCAST_TYPE_SHIFT,
TB_BCAST_Q = 1 << TB_BCAST_TYPE_SHIFT,
TB_BCAST_SS = 2 << TB_BCAST_TYPE_SHIFT,
TB_BCAST_SD = 3 << TB_BCAST_TYPE_SHIFT,
TB_BCAST_MASK = 0x3 << TB_BCAST_TYPE_SHIFT,

// Unused bits 14-15
};
}
#endif // LLVM_SUPPORT_X86FOLDTABLESUTILS_H
47 changes: 1 addition & 46 deletions llvm/lib/Target/X86/X86InstrFoldTables.h
Expand Up @@ -14,55 +14,10 @@
#define LLVM_LIB_TARGET_X86_X86INSTRFOLDTABLES_H

#include <cstdint>
#include "llvm/Support/X86FoldTablesUtils.h"

namespace llvm {

enum {
// Select which memory operand is being unfolded.
// (stored in bits 0 - 2)
TB_INDEX_0 = 0,
TB_INDEX_1 = 1,
TB_INDEX_2 = 2,
TB_INDEX_3 = 3,
TB_INDEX_4 = 4,
TB_INDEX_MASK = 0x7,

// Do not insert the reverse map (MemOp -> RegOp) into the table.
// This may be needed because there is a many -> one mapping.
TB_NO_REVERSE = 1 << 3,

// Do not insert the forward map (RegOp -> MemOp) into the table.
// This is needed for Native Client, which prohibits branch
// instructions from using a memory operand.
TB_NO_FORWARD = 1 << 4,

TB_FOLDED_LOAD = 1 << 5,
TB_FOLDED_STORE = 1 << 6,
TB_FOLDED_BCAST = 1 << 7,

// Minimum alignment required for load/store.
// Used for RegOp->MemOp conversion. Encoded as Log2(Align) + 1 to allow 0
// to mean align of 0.
// (stored in bits 8 - 11)
TB_ALIGN_SHIFT = 8,
TB_ALIGN_NONE = 0 << TB_ALIGN_SHIFT,
TB_ALIGN_16 = 5 << TB_ALIGN_SHIFT,
TB_ALIGN_32 = 6 << TB_ALIGN_SHIFT,
TB_ALIGN_64 = 7 << TB_ALIGN_SHIFT,
TB_ALIGN_MASK = 0xf << TB_ALIGN_SHIFT,

// Broadcast type.
// (stored in bits 12 - 13)
TB_BCAST_TYPE_SHIFT = 12,
TB_BCAST_D = 0 << TB_BCAST_TYPE_SHIFT,
TB_BCAST_Q = 1 << TB_BCAST_TYPE_SHIFT,
TB_BCAST_SS = 2 << TB_BCAST_TYPE_SHIFT,
TB_BCAST_SD = 3 << TB_BCAST_TYPE_SHIFT,
TB_BCAST_MASK = 0x3 << TB_BCAST_TYPE_SHIFT,

// Unused bits 14-15
};

// This struct is used for both the folding and unfold tables. They KeyOp
// is used to determine the sorting order.
struct X86MemoryFoldTableEntry {
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/TableGen/x86-auto-memfold.td
@@ -0,0 +1,2 @@
// RUN: llvm-tblgen -gen-x86-fold-tables -asmwriternum=1 %p/../../lib/Target/X86/X86.td -I %p/../../include -I %p/../../lib/Target/X86/ -I %p/../../include/ -I %p/../../lib/Target/ --write-if-changed -o %t1
// RUN: cmp --ignore-initial=0:568 %p/../../lib/Target/X86/X86MemFoldTables.inc %t1

0 comments on commit 0666c59

Please sign in to comment.