Path: blob/main/contrib/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.h
35294 views
//===- RISCVMatInt.h - Immediate materialisation ---------------*- C++ -*--===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_MATINT_H9#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_MATINT_H1011#include "llvm/ADT/SmallVector.h"12#include "llvm/MC/MCRegister.h"13#include "llvm/MC/MCSubtargetInfo.h"14#include <cstdint>1516namespace llvm {17class APInt;1819namespace RISCVMatInt {2021enum OpndKind {22RegImm, // ADDI/ADDIW/SLLI/SRLI/BSETI/BCLRI23Imm, // LUI24RegReg, // SH1ADD/SH2ADD/SH3ADD25RegX0, // ADD_UW26};2728class Inst {29unsigned Opc;30int32_t Imm; // The largest value we need to store is 20 bits.3132public:33Inst(unsigned Opc, int64_t I) : Opc(Opc), Imm(I) {34assert(I == Imm && "truncated");35}3637unsigned getOpcode() const { return Opc; }38int64_t getImm() const { return Imm; }3940OpndKind getOpndKind() const;41};42using InstSeq = SmallVector<Inst, 8>;4344// Helper to generate an instruction sequence that will materialise the given45// immediate value into a register. A sequence of instructions represented by a46// simple struct is produced rather than directly emitting the instructions in47// order to allow this helper to be used from both the MC layer and during48// instruction selection.49InstSeq generateInstSeq(int64_t Val, const MCSubtargetInfo &STI);5051// Helper to generate the generateInstSeq instruction sequence using MCInsts52void generateMCInstSeq(int64_t Val, const MCSubtargetInfo &STI,53MCRegister DestReg, SmallVectorImpl<MCInst> &Insts);5455// Helper to generate an instruction sequence that can materialize the given56// immediate value into a register using an additional temporary register. This57// handles cases where the constant can be generated by (ADD (SLLI X, C), X) or58// (ADD_UW (SLLI X, C) X). The sequence to generate X is returned. ShiftAmt is59// provides the SLLI and AddOpc indicates ADD or ADD_UW.60InstSeq generateTwoRegInstSeq(int64_t Val, const MCSubtargetInfo &STI,61unsigned &ShiftAmt, unsigned &AddOpc);6263// Helper to estimate the number of instructions required to materialise the64// given immediate value into a register. This estimate does not account for65// `Val` possibly fitting into an immediate, and so may over-estimate.66//67// This will attempt to produce instructions to materialise `Val` as an68// `Size`-bit immediate.69//70// If CompressionCost is true it will use a different cost calculation if RVC is71// enabled. This should be used to compare two different sequences to determine72// which is more compressible.73//74// If FreeZeroes is true, it will be assumed free to materialize any75// XLen-sized chunks that are 0. This is appropriate to use in instances when76// the zero register can be used, e.g. when estimating the cost of77// materializing a value used by a particular operation.78int getIntMatCost(const APInt &Val, unsigned Size, const MCSubtargetInfo &STI,79bool CompressionCost = false, bool FreeZeroes = false);80} // namespace RISCVMatInt81} // namespace llvm82#endif838485