26#define DEBUG_TYPE "hexagon-abs"
31 "Number of Load instructions converted to absolute-set form");
33 "Number of Store instructions converted to absolute-set form");
54 return "Hexagon Generate Load/Store Set Absolute Address Instruction";
67 static bool isValidIndexedStore(
int &Opcode,
int &NewOpcode);
71char HexagonGenMemAbsolute::ID = 0;
74 "Hexagon Generate Load/Store Set Absolute Address Instruction",
78 if (skipFunction(Fn.getFunction()))
82 MRI = &Fn.getRegInfo();
83 TRI = Fn.getRegInfo().getTargetRegisterInfo();
86 getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
90 MBBb != MBBe; ++MBBb) {
96 int Opc =
MI->getOpcode();
97 if (Opc != Hexagon::CONST32 && Opc != Hexagon::A2_tfrsi)
104 unsigned DstReg = MO.
getReg();
105 if (
MRI->use_nodbg_empty(DstReg))
109 use_iterator NextUseMI =
MRI->use_nodbg_begin(DstReg);
116 if (!IsLoad && !isValidIndexedStore(NextOpc, NewOpc))
122 unsigned BaseRegPos, ImmPos, RegPos;
125 RegPos = IsLoad ? 0 : 2;
127 bool IsGlobal =
MI->getOperand(1).isGlobal();
128 if (!
MI->getOperand(1).isImm() && !IsGlobal)
134 TII->getMemOperandWithOffset(*NextMI, BaseOp,
Offset, Scalable,
TRI);
137 if (!BaseOp || !BaseOp->
isReg())
143 unsigned BaseReg = BaseOp->
getReg();
144 if ((DstReg != BaseReg) || (
Offset != 0))
152 unsigned LoadStoreReg = MO0.
getReg();
156 if (LoadStoreReg == BaseReg)
162 bool Dominates =
true;
163 unsigned Counter = 0;
164 for (use_iterator
I = NextUseMI, E =
MRI->use_nodbg_end();
I != E; ++
I) {
170 if ((!Dominates) || (Counter < 3))
176 dbgs() <<
"Found a pair of instructions for absolute-set "
177 << (IsLoad ?
"load" :
"store") <<
"\n";
184 ++HexagonNumLoadAbsConversions;
186 TII->get(NewOpc), LoadStoreReg)
189 ++HexagonNumStoreAbsConversions;
191 TII->get(NewOpc), DstReg);
217bool HexagonGenMemAbsolute::isValidIndexedLoad(
int &Opc,
int &NewOpc) {
221 case Hexagon::L2_loadrb_io:
222 NewOpc = Hexagon::L4_loadrb_ap;
224 case Hexagon::L2_loadrh_io:
225 NewOpc = Hexagon::L4_loadrh_ap;
227 case Hexagon::L2_loadri_io:
228 NewOpc = Hexagon::L4_loadri_ap;
230 case Hexagon::L2_loadrd_io:
231 NewOpc = Hexagon::L4_loadrd_ap;
233 case Hexagon::L2_loadruh_io:
234 NewOpc = Hexagon::L4_loadruh_ap;
236 case Hexagon::L2_loadrub_io:
237 NewOpc = Hexagon::L4_loadrub_ap;
246bool HexagonGenMemAbsolute::isValidIndexedStore(
int &Opc,
int &NewOpc) {
250 case Hexagon::S2_storerd_io:
251 NewOpc = Hexagon::S4_storerd_ap;
253 case Hexagon::S2_storeri_io:
254 NewOpc = Hexagon::S4_storeri_ap;
256 case Hexagon::S2_storerh_io:
257 NewOpc = Hexagon::S4_storerh_ap;
259 case Hexagon::S2_storerb_io:
260 NewOpc = Hexagon::S4_storerb_ap;
274 return new HexagonGenMemAbsolute();
unsigned const MachineRegisterInfo * MRI
const HexagonInstrInfo * TII
static bool isValidIndexedLoad(const LoadSDNode *LD)
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
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.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
FunctionPass class - This class is used to implement most global optimizations.
bool getBaseAndOffsetPosition(const MachineInstr &MI, unsigned &BasePos, unsigned &OffsetPos) const override
For instructions with a base and offset, return the position of the base register and offset operands...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
unsigned getTargetFlags() const
Register getReg() const
getReg - Returns the register number.
int64_t getOffset() const
Return the offset from the symbol in this operand.
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
A global registry used in conjunction with static constructors to make pluggable components (like tar...
StringRef - Represent a constant reference to a string, i.e.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ Define
Register definition.
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.
void initializeHexagonGenMemAbsolutePass(PassRegistry &Registry)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createHexagonGenMemAbsolute()