Path: blob/main/contrib/llvm-project/llvm/lib/Target/Lanai/LanaiInstrInfo.h
35271 views
//===- LanaiInstrInfo.h - Lanai Instruction Information ---------*- 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//===----------------------------------------------------------------------===//7//8// This file contains the Lanai implementation of the TargetInstrInfo class.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H13#define LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H1415#include "LanaiRegisterInfo.h"16#include "MCTargetDesc/LanaiMCTargetDesc.h"17#include "llvm/CodeGen/TargetInstrInfo.h"1819#define GET_INSTRINFO_HEADER20#include "LanaiGenInstrInfo.inc"2122namespace llvm {2324class LanaiInstrInfo : public LanaiGenInstrInfo {25const LanaiRegisterInfo RegisterInfo;2627public:28LanaiInstrInfo();2930// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As31// such, whenever a client has an instance of instruction info, it should32// always be able to get register info as well (through this method).33virtual const LanaiRegisterInfo &getRegisterInfo() const {34return RegisterInfo;35}3637bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa,38const MachineInstr &MIb) const override;3940Register isLoadFromStackSlot(const MachineInstr &MI,41int &FrameIndex) const override;4243Register isLoadFromStackSlotPostFE(const MachineInstr &MI,44int &FrameIndex) const override;4546Register isStoreToStackSlot(const MachineInstr &MI,47int &FrameIndex) const override;4849void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position,50const DebugLoc &DL, MCRegister DestinationRegister,51MCRegister SourceRegister, bool KillSource) const override;5253void storeRegToStackSlot(MachineBasicBlock &MBB,54MachineBasicBlock::iterator Position,55Register SourceRegister, bool IsKill, int FrameIndex,56const TargetRegisterClass *RegisterClass,57const TargetRegisterInfo *RegisterInfo,58Register VReg) const override;5960void loadRegFromStackSlot(MachineBasicBlock &MBB,61MachineBasicBlock::iterator Position,62Register DestinationRegister, int FrameIndex,63const TargetRegisterClass *RegisterClass,64const TargetRegisterInfo *RegisterInfo,65Register VReg) const override;6667bool expandPostRAPseudo(MachineInstr &MI) const override;6869bool getMemOperandsWithOffsetWidth(70const MachineInstr &LdSt,71SmallVectorImpl<const MachineOperand *> &BaseOps, int64_t &Offset,72bool &OffsetIsScalable, LocationSize &Width,73const TargetRegisterInfo *TRI) const override;7475bool getMemOperandWithOffsetWidth(const MachineInstr &LdSt,76const MachineOperand *&BaseOp,77int64_t &Offset, LocationSize &Width,78const TargetRegisterInfo *TRI) const;7980std::pair<unsigned, unsigned>81decomposeMachineOperandsTargetFlags(unsigned TF) const override;8283ArrayRef<std::pair<unsigned, const char *>>84getSerializableDirectMachineOperandTargetFlags() const override;8586bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TrueBlock,87MachineBasicBlock *&FalseBlock,88SmallVectorImpl<MachineOperand> &Condition,89bool AllowModify) const override;9091unsigned removeBranch(MachineBasicBlock &MBB,92int *BytesRemoved = nullptr) const override;9394// For a comparison instruction, return the source registers in SrcReg and95// SrcReg2 if having two register operands, and the value it compares against96// in CmpValue. Return true if the comparison instruction can be analyzed.97bool analyzeCompare(const MachineInstr &MI, Register &SrcReg,98Register &SrcReg2, int64_t &CmpMask,99int64_t &CmpValue) const override;100101// See if the comparison instruction can be converted into something more102// efficient. E.g., on Lanai register-register instructions can set the flag103// register, obviating the need for a separate compare.104bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,105Register SrcReg2, int64_t CmpMask, int64_t CmpValue,106const MachineRegisterInfo *MRI) const override;107108// Analyze the given select instruction, returning true if it cannot be109// understood. It is assumed that MI->isSelect() is true.110//111// When successful, return the controlling condition and the operands that112// determine the true and false result values.113//114// Result = SELECT Cond, TrueOp, FalseOp115//116// Lanai can optimize certain select instructions, for example by predicating117// the instruction defining one of the operands and sets Optimizable to true.118bool analyzeSelect(const MachineInstr &MI,119SmallVectorImpl<MachineOperand> &Cond, unsigned &TrueOp,120unsigned &FalseOp, bool &Optimizable) const override;121122// Given a select instruction that was understood by analyzeSelect and123// returned Optimizable = true, attempt to optimize MI by merging it with one124// of its operands. Returns NULL on failure.125//126// When successful, returns the new select instruction. The client is127// responsible for deleting MI.128//129// If both sides of the select can be optimized, the TrueOp is modifed.130// PreferFalse is not used.131MachineInstr *optimizeSelect(MachineInstr &MI,132SmallPtrSetImpl<MachineInstr *> &SeenMIs,133bool PreferFalse) const override;134135bool reverseBranchCondition(136SmallVectorImpl<MachineOperand> &Condition) const override;137138unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TrueBlock,139MachineBasicBlock *FalseBlock,140ArrayRef<MachineOperand> Condition,141const DebugLoc &DL,142int *BytesAdded = nullptr) const override;143};144145static inline bool isSPLSOpcode(unsigned Opcode) {146switch (Opcode) {147case Lanai::LDBs_RI:148case Lanai::LDBz_RI:149case Lanai::LDHs_RI:150case Lanai::LDHz_RI:151case Lanai::STB_RI:152case Lanai::STH_RI:153return true;154default:155return false;156}157}158159static inline bool isRMOpcode(unsigned Opcode) {160switch (Opcode) {161case Lanai::LDW_RI:162case Lanai::SW_RI:163return true;164default:165return false;166}167}168169static inline bool isRRMOpcode(unsigned Opcode) {170switch (Opcode) {171case Lanai::LDBs_RR:172case Lanai::LDBz_RR:173case Lanai::LDHs_RR:174case Lanai::LDHz_RR:175case Lanai::LDWz_RR:176case Lanai::LDW_RR:177case Lanai::STB_RR:178case Lanai::STH_RR:179case Lanai::SW_RR:180return true;181default:182return false;183}184}185186} // namespace llvm187188#endif // LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H189190191