49 #define DEBUG_TYPE "aarch64-simd-scalar" 55 cl::desc(
"Force use of AdvSIMD scalar instructions everywhere"),
58 STATISTIC(NumScalarInsnsUsed,
"Number of scalar instructions used");
59 STATISTIC(NumCopiesDeleted,
"Number of cross-class copies deleted");
60 STATISTIC(NumCopiesInserted,
"Number of cross-class copies inserted");
62 #define AARCH64_ADVSIMD_NAME "AdvSIMD Scalar Operation Optimization" 110 return AArch64::GPR64RegClass.contains(Reg);
119 SubReg == AArch64::dsub);
121 return (AArch64::FPR64RegClass.
contains(Reg) && SubReg == 0) ||
122 (AArch64::FPR128RegClass.
contains(Reg) && SubReg == AArch64::dsub);
132 if (MI->
getOpcode() == AArch64::FMOVDXr ||
138 SubReg = AArch64::dsub;
169 case AArch64::ADDXrr:
170 return AArch64::ADDv1i64;
171 case AArch64::SUBXrr:
172 return AArch64::SUBv1i64;
173 case AArch64::ANDXrr:
174 return AArch64::ANDv8i8;
175 case AArch64::EORXrr:
176 return AArch64::EORv8i8;
177 case AArch64::ORRXrr:
178 return AArch64::ORRv8i8;
192 bool AArch64AdvSIMDScalar::isProfitableToTransform(
201 unsigned NumNewCopies = 3;
202 unsigned NumRemovableCopies = 0;
208 if (!
MRI->def_empty(OrigSrc0)) {
210 MRI->def_instr_begin(OrigSrc0);
211 assert(std::next(Def) ==
MRI->def_instr_end() &&
"Multiple def in SSA!");
218 if (MOSrc0 &&
MRI->hasOneNonDBGUse(OrigSrc0))
219 ++NumRemovableCopies;
221 if (!
MRI->def_empty(OrigSrc1)) {
223 MRI->def_instr_begin(OrigSrc1);
224 assert(std::next(Def) ==
MRI->def_instr_end() &&
"Multiple def in SSA!");
230 if (MOSrc1 &&
MRI->hasOneNonDBGUse(OrigSrc1))
231 ++NumRemovableCopies;
240 bool AllUsesAreCopies =
true;
242 Use =
MRI->use_instr_nodbg_begin(Dst),
243 E =
MRI->use_instr_nodbg_end();
247 ++NumRemovableCopies;
253 else if (
Use->getOpcode() == AArch64::INSERT_SUBREG ||
254 Use->getOpcode() == AArch64::INSvi64gpr)
257 AllUsesAreCopies =
false;
261 if (AllUsesAreCopies)
266 if (NumNewCopies <= NumRemovableCopies)
275 unsigned Dst,
unsigned Src,
bool IsKill) {
277 TII->
get(AArch64::COPY), Dst)
287 void AArch64AdvSIMDScalar::transformInstruction(
MachineInstr &MI) {
293 assert(OldOpc != NewOpc &&
"transform an instruction to itself?!");
298 unsigned Src0 = 0, SubReg0;
299 unsigned Src1 = 0, SubReg1;
300 bool KillSrc0 =
false, KillSrc1 =
false;
301 if (!
MRI->def_empty(OrigSrc0)) {
303 MRI->def_instr_begin(OrigSrc0);
304 assert(std::next(Def) ==
MRI->def_instr_end() &&
"Multiple def in SSA!");
309 Src0 = MOSrc0->getReg();
310 KillSrc0 = MOSrc0->isKill();
312 MOSrc0->setIsKill(
false);
313 if (
MRI->hasOneNonDBGUse(OrigSrc0)) {
314 assert(MOSrc0 &&
"Can't delete copy w/o a valid original source!");
320 if (!
MRI->def_empty(OrigSrc1)) {
322 MRI->def_instr_begin(OrigSrc1);
323 assert(std::next(Def) ==
MRI->def_instr_end() &&
"Multiple def in SSA!");
328 Src1 = MOSrc1->getReg();
329 KillSrc1 = MOSrc1->isKill();
331 MOSrc1->setIsKill(
false);
332 if (
MRI->hasOneNonDBGUse(OrigSrc1)) {
333 assert(MOSrc1 &&
"Can't delete copy w/o a valid original source!");
343 Src0 =
MRI->createVirtualRegister(&AArch64::FPR64RegClass);
349 Src1 =
MRI->createVirtualRegister(&AArch64::FPR64RegClass);
357 Register Dst =
MRI->createVirtualRegister(&AArch64::FPR64RegClass);
374 ++NumScalarInsnsUsed;
379 bool Changed =
false;
382 if (isProfitableToTransform(MI)) {
383 transformInstruction(MI);
392 bool Changed =
false;
403 if (processMachineBasicBlock(&*
I))
411 return new AArch64AdvSIMDScalar();
static MachineInstr * insertCopy(const TargetInstrInfo *TII, MachineInstr &MI, unsigned Dst, unsigned Src, bool IsKill)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getSubReg() const
#define AARCH64_ADVSIMD_NAME
STATISTIC(NumFunctions, "Total number of functions")
static bool isTransformable(const MachineInstr &MI)
static MachineOperand * getSrcFromCopy(MachineInstr *MI, const MachineRegisterInfo *MRI, unsigned &SubReg)
return AArch64::GPR64RegClass contains(Reg)
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static bool isFPR64(unsigned Reg, unsigned SubReg, const MachineRegisterInfo *MRI)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
INITIALIZE_PASS(AArch64AdvSIMDScalar, "aarch64-simd-scalar", AARCH64_ADVSIMD_NAME, false, false) static bool isGPR64(unsigned Reg
A Use represents the edge between a Value definition and its users.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
defusechain_iterator - This class provides iterator support for machine operands in the function that...
virtual const TargetInstrInfo * getInstrInfo() const
unsigned getKillRegState(bool B)
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
unsigned const MachineRegisterInfo * MRI
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static cl::opt< bool > TransformAll("aarch64-simd-scalar-force-all", cl::desc("Force use of AdvSIMD scalar instructions everywhere"), cl::init(false), cl::Hidden)
Represent the analysis usage information of a pass.
FunctionPass * createAArch64AdvSIMDScalar()
static unsigned getTransformOpcode(unsigned Opc)
FunctionPass class - This class is used to implement most global optimizations.
Iterator for intrusive lists based on ilist_node.
MachineOperand class - Representation of each machine instruction operand.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static 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.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Wrapper class representing virtual and physical registers.
void initializeAArch64AdvSIMDScalarPass(PassRegistry &)