#include "LoongArch.h"
#include "LoongArchMachineFunctionInfo.h"
#include "LoongArchSubtarget.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
usingnamespacellvm;
#define DEBUG_TYPE …
#define LOONGARCH_OPT_W_INSTRS_NAME …
STATISTIC(NumRemovedSExtW, "Number of removed sign-extensions");
STATISTIC(NumTransformedToWInstrs,
"Number of instructions transformed to W-ops");
static cl::opt<bool>
DisableSExtWRemoval("loongarch-disable-sextw-removal",
cl::desc("Disable removal of sign-extend insn"),
cl::init(false), cl::Hidden);
static cl::opt<bool>
DisableCvtToDSuffix("loongarch-disable-cvt-to-d-suffix",
cl::desc("Disable convert to D suffix"),
cl::init(false), cl::Hidden);
namespace {
class LoongArchOptWInstrs : public MachineFunctionPass { … };
}
char LoongArchOptWInstrs::ID = …;
INITIALIZE_PASS(…)
FunctionPass *llvm::createLoongArchOptWInstrsPass() { … }
static bool hasAllNBitUsers(const MachineInstr &OrigMI,
const LoongArchSubtarget &ST,
const MachineRegisterInfo &MRI, unsigned OrigBits) { … }
static bool hasAllWUsers(const MachineInstr &OrigMI,
const LoongArchSubtarget &ST,
const MachineRegisterInfo &MRI) { … }
static bool isSignExtendingOpW(const MachineInstr &MI,
const MachineRegisterInfo &MRI, unsigned OpNo) { … }
static bool isSignExtendedW(Register SrcReg, const LoongArchSubtarget &ST,
const MachineRegisterInfo &MRI,
SmallPtrSetImpl<MachineInstr *> &FixableDef) { … }
static unsigned getWOp(unsigned Opcode) { … }
bool LoongArchOptWInstrs::removeSExtWInstrs(MachineFunction &MF,
const LoongArchInstrInfo &TII,
const LoongArchSubtarget &ST,
MachineRegisterInfo &MRI) { … }
bool LoongArchOptWInstrs::convertToDSuffixes(MachineFunction &MF,
const LoongArchInstrInfo &TII,
const LoongArchSubtarget &ST,
MachineRegisterInfo &MRI) { … }
bool LoongArchOptWInstrs::convertToWSuffixes(MachineFunction &MF,
const LoongArchInstrInfo &TII,
const LoongArchSubtarget &ST,
MachineRegisterInfo &MRI) { … }
bool LoongArchOptWInstrs::runOnMachineFunction(MachineFunction &MF) { … }