llvm/llvm/lib/Target/X86/X86FixupVectorConstants.cpp

//===-- X86FixupVectorConstants.cpp - optimize constant generation  -------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file examines all full size vector constant pool loads and attempts to
// replace them with smaller constant pool entries, including:
// * Converting AVX512 memory-fold instructions to their broadcast-fold form.
// * Using vzload scalar loads.
// * Broadcasting of full width loads.
// * Sign/Zero extension of full width loads.
//
//===----------------------------------------------------------------------===//

#include "X86.h"
#include "X86InstrFoldTables.h"
#include "X86InstrInfo.h"
#include "X86Subtarget.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/MachineConstantPool.h"

usingnamespacellvm;

#define DEBUG_TYPE

STATISTIC(NumInstChanges, "Number of instructions changes");

namespace {
class X86FixupVectorConstantsPass : public MachineFunctionPass {};
} // end anonymous namespace

char X86FixupVectorConstantsPass::ID =;

INITIALIZE_PASS()

FunctionPass *llvm::createX86FixupVectorConstants() {}

/// Normally, we only allow poison in vector splats. However, as this is part
/// of the backend, and working with the DAG representation, which currently
/// only natively represents undef values, we need to accept undefs here.
static Constant *getSplatValueAllowUndef(const ConstantVector *C) {}

// Attempt to extract the full width of bits data from the constant.
static std::optional<APInt> extractConstantBits(const Constant *C) {}

static std::optional<APInt> extractConstantBits(const Constant *C,
                                                unsigned NumBits) {}

// Attempt to compute the splat width of bits data by normalizing the splat to
// remove undefs.
static std::optional<APInt> getSplatableConstant(const Constant *C,
                                                 unsigned SplatBitWidth) {}

// Split raw bits into a constant vector of elements of a specific bit width.
// NOTE: We don't always bother converting to scalars if the vector length is 1.
static Constant *rebuildConstant(LLVMContext &Ctx, Type *SclTy,
                                 const APInt &Bits, unsigned NumSclBits) {}

// Attempt to rebuild a normalized splat vector constant of the requested splat
// width, built up of potentially smaller scalar values.
static Constant *rebuildSplatCst(const Constant *C, unsigned /*NumBits*/,
                                 unsigned /*NumElts*/, unsigned SplatBitWidth) {}

static Constant *rebuildZeroUpperCst(const Constant *C, unsigned NumBits,
                                     unsigned /*NumElts*/,
                                     unsigned ScalarBitWidth) {}

static Constant *rebuildExtCst(const Constant *C, bool IsSExt,
                               unsigned NumBits, unsigned NumElts,
                               unsigned SrcEltBitWidth) {}
static Constant *rebuildSExtCst(const Constant *C, unsigned NumBits,
                                unsigned NumElts, unsigned SrcEltBitWidth) {}
static Constant *rebuildZExtCst(const Constant *C, unsigned NumBits,
                                unsigned NumElts, unsigned SrcEltBitWidth) {}

bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
                                                     MachineBasicBlock &MBB,
                                                     MachineInstr &MI) {}

bool X86FixupVectorConstantsPass::runOnMachineFunction(MachineFunction &MF) {}