49#define DEBUG_TYPE "aarch64-simd-scalar"
55 cl::desc(
"Force use of AdvSIMD scalar instructions everywhere"),
58STATISTIC(NumScalarInsnsUsed,
"Number of scalar instructions used");
59STATISTIC(NumCopiesDeleted,
"Number of cross-class copies deleted");
60STATISTIC(NumCopiesInserted,
"Number of cross-class copies inserted");
62#define AARCH64_ADVSIMD_NAME "AdvSIMD Scalar Operation Optimization"
65class AArch64AdvSIMDScalarImpl {
101char AArch64AdvSIMDScalarLegacy::ID = 0;
110 const bool Changed = AArch64AdvSIMDScalarImpl().run(MF);
124 return AArch64::GPR64RegClass.contains(
Reg);
132 (MRI->
getRegClass(
Reg)->hasSuperClassEq(&AArch64::FPR128RegClass) &&
133 SubReg == AArch64::dsub);
135 return (AArch64::FPR64RegClass.
contains(
Reg) && SubReg == 0) ||
136 (AArch64::FPR128RegClass.contains(
Reg) && SubReg == AArch64::dsub);
146 if (
MI->getOpcode() == AArch64::FMOVDXr ||
147 MI->getOpcode() == AArch64::FMOVXDr)
148 return &
MI->getOperand(1);
151 if (
MI->getOpcode() == AArch64::UMOVvi64 &&
MI->getOperand(2).getImm() == 0) {
152 SubReg = AArch64::dsub;
153 return &
MI->getOperand(1);
157 if (
MI->getOpcode() == AArch64::COPY) {
158 if (
isFPR64(
MI->getOperand(0).getReg(),
MI->getOperand(0).getSubReg(),
160 isGPR64(
MI->getOperand(1).getReg(),
MI->getOperand(1).getSubReg(), MRI))
161 return &
MI->getOperand(1);
162 if (
isGPR64(
MI->getOperand(0).getReg(),
MI->getOperand(0).getSubReg(),
164 isFPR64(
MI->getOperand(1).getReg(),
MI->getOperand(1).getSubReg(),
166 SubReg =
MI->getOperand(1).getSubReg();
167 return &
MI->getOperand(1);
183 case AArch64::ADDXrr:
184 return AArch64::ADDv1i64;
185 case AArch64::SUBXrr:
186 return AArch64::SUBv1i64;
187 case AArch64::ANDXrr:
188 return AArch64::ANDv8i8;
189 case AArch64::EORXrr:
190 return AArch64::EORv8i8;
191 case AArch64::ORRXrr:
192 return AArch64::ORRv8i8;
199 unsigned Opc =
MI.getOpcode();
206bool AArch64AdvSIMDScalarImpl::isProfitableToTransform(
215 unsigned NumNewCopies = 3;
216 unsigned NumRemovableCopies = 0;
218 Register OrigSrc0 =
MI.getOperand(1).getReg();
219 Register OrigSrc1 =
MI.getOperand(2).getReg();
233 ++NumRemovableCopies;
245 ++NumRemovableCopies;
254 bool AllUsesAreCopies =
true;
261 ++NumRemovableCopies;
267 else if (
Use->getOpcode() == AArch64::INSERT_SUBREG ||
268 Use->getOpcode() == AArch64::INSvi64gpr)
271 AllUsesAreCopies =
false;
275 if (AllUsesAreCopies)
280 if (NumNewCopies <= NumRemovableCopies)
289 unsigned Dst,
unsigned Src,
bool IsKill) {
291 TII->get(AArch64::COPY), Dst)
301void AArch64AdvSIMDScalarImpl::transformInstruction(MachineInstr &
MI) {
304 MachineBasicBlock *
MBB =
MI.getParent();
305 unsigned OldOpc =
MI.getOpcode();
307 assert(OldOpc != NewOpc &&
"transform an instruction to itself?!");
310 Register OrigSrc0 =
MI.getOperand(1).getReg();
311 Register OrigSrc1 =
MI.getOperand(2).getReg();
312 unsigned Src0 = 0, SubReg0;
313 unsigned Src1 = 0, SubReg1;
314 bool KillSrc0 =
false, KillSrc1 =
false;
324 KillSrc0 = MOSrc0->
isKill();
328 assert(MOSrc0 &&
"Can't delete copy w/o a valid original source!");
329 Def->eraseFromParent();
343 KillSrc1 = MOSrc1->
isKill();
347 assert(MOSrc1 &&
"Can't delete copy w/o a valid original source!");
348 Def->eraseFromParent();
386 MI.eraseFromParent();
388 ++NumScalarInsnsUsed;
392bool AArch64AdvSIMDScalarImpl::processMachineBasicBlock(
393 MachineBasicBlock *
MBB) {
397 transformInstruction(
MI);
405bool AArch64AdvSIMDScalarLegacy::runOnMachineFunction(MachineFunction &MF) {
409 return AArch64AdvSIMDScalarImpl().run(MF);
412bool AArch64AdvSIMDScalarImpl::run(MachineFunction &MF) {
420 for (MachineBasicBlock &
MBB : MF)
421 if (processMachineBasicBlock(&
MBB))
429 return new AArch64AdvSIMDScalarLegacy();
static cl::opt< bool > TransformAll("aarch64-a57-fp-load-balancing-force-all", cl::desc("Always modify dest registers regardless of color"), cl::init(false), cl::Hidden)
#define AARCH64_ADVSIMD_NAME
static MachineInstr * insertCopy(const TargetInstrInfo *TII, MachineInstr &MI, unsigned Dst, unsigned Src, bool IsKill)
static cl::opt< bool > TransformAll("aarch64-simd-scalar-force-all", cl::desc("Force use of AdvSIMD scalar instructions everywhere"), cl::init(false), cl::Hidden)
static bool isTransformable(const MachineInstr &MI)
static unsigned getTransformOpcode(unsigned Opc)
static bool isGPR64(unsigned Reg, unsigned SubReg, const MachineRegisterInfo *MRI)
static bool isFPR64(unsigned Reg, unsigned SubReg, const MachineRegisterInfo *MRI)
static MachineOperand * getSrcFromCopy(MachineInstr *MI, const MachineRegisterInfo *MRI, unsigned &SubReg)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
static bool isProfitableToTransform(const Loop &L, const BranchInst *BI)
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
void setIsKill(bool Val=true)
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
defusechain_instr_iterator< true, false, true, true > use_instr_nodbg_iterator
use_instr_nodbg_iterator/use_instr_nodbg_begin/use_instr_nodbg_end - Walk all uses of the specified r...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static def_instr_iterator def_instr_end()
defusechain_instr_iterator< false, true, false, true > def_instr_iterator
def_instr_iterator/def_instr_begin/def_instr_end - Walk all defs of the specified register,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
def_instr_iterator def_instr_begin(Register RegNo) const
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
use_instr_nodbg_iterator use_instr_nodbg_begin(Register RegNo) const
static use_instr_nodbg_iterator use_instr_nodbg_end()
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
static constexpr bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
virtual const TargetInstrInfo * getInstrInfo() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
NodeAddr< DefNode * > Def
NodeAddr< UseNode * > Use
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr RegState getKillRegState(bool B)
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createAArch64AdvSIMDScalar()