25#define DEBUG_TYPE "hexagon-abs"
30 "Number of Load instructions converted to absolute-set form");
32 "Number of Store instructions converted to absolute-set form");
53 return "Hexagon Generate Load/Store Set Absolute Address Instruction";
66 static bool isValidIndexedStore(
int &Opcode,
int &NewOpcode);
70char HexagonGenMemAbsolute::ID = 0;
73 "Hexagon Generate Load/Store Set Absolute Address Instruction",
77 if (skipFunction(Fn.getFunction()))
81 MRI = &Fn.getRegInfo();
82 TRI = Fn.getRegInfo().getTargetRegisterInfo();
85 getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
93 int Opc =
MI->getOpcode();
94 if (Opc != Hexagon::CONST32 && Opc != Hexagon::A2_tfrsi)
101 unsigned DstReg = MO.
getReg();
102 if (
MRI->use_nodbg_empty(DstReg))
106 use_iterator NextUseMI =
MRI->use_nodbg_begin(DstReg);
113 if (!IsLoad && !isValidIndexedStore(NextOpc, NewOpc))
119 unsigned BaseRegPos, ImmPos, RegPos;
122 RegPos = IsLoad ? 0 : 2;
124 bool IsGlobal =
MI->getOperand(1).isGlobal();
125 if (!
MI->getOperand(1).isImm() && !IsGlobal)
131 TII->getMemOperandWithOffset(*NextMI, BaseOp,
Offset, Scalable,
TRI);
134 if (!BaseOp || !BaseOp->
isReg())
140 unsigned BaseReg = BaseOp->
getReg();
141 if ((DstReg != BaseReg) || (
Offset != 0))
149 unsigned LoadStoreReg = MO0.
getReg();
153 if (LoadStoreReg == BaseReg)
159 bool Dominates =
true;
160 unsigned Counter = 0;
161 for (use_iterator
I = NextUseMI, E =
MRI->use_nodbg_end();
I != E; ++
I) {
167 if ((!Dominates) || (Counter < 3))
173 dbgs() <<
"Found a pair of instructions for absolute-set "
174 << (IsLoad ?
"load" :
"store") <<
"\n";
181 ++HexagonNumLoadAbsConversions;
183 TII->get(NewOpc), LoadStoreReg)
186 ++HexagonNumStoreAbsConversions;
188 TII->get(NewOpc), DstReg);
214bool HexagonGenMemAbsolute::isValidIndexedLoad(
int &Opc,
int &NewOpc) {
218 case Hexagon::L2_loadrb_io:
219 NewOpc = Hexagon::L4_loadrb_ap;
221 case Hexagon::L2_loadrh_io:
222 NewOpc = Hexagon::L4_loadrh_ap;
224 case Hexagon::L2_loadri_io:
225 NewOpc = Hexagon::L4_loadri_ap;
227 case Hexagon::L2_loadrd_io:
228 NewOpc = Hexagon::L4_loadrd_ap;
230 case Hexagon::L2_loadruh_io:
231 NewOpc = Hexagon::L4_loadruh_ap;
233 case Hexagon::L2_loadrub_io:
234 NewOpc = Hexagon::L4_loadrub_ap;
243bool HexagonGenMemAbsolute::isValidIndexedStore(
int &Opc,
int &NewOpc) {
247 case Hexagon::S2_storerd_io:
248 NewOpc = Hexagon::S4_storerd_ap;
250 case Hexagon::S2_storeri_io:
251 NewOpc = Hexagon::S4_storeri_ap;
253 case Hexagon::S2_storerh_io:
254 NewOpc = Hexagon::S4_storerh_ap;
256 case Hexagon::S2_storerb_io:
257 NewOpc = Hexagon::S4_storerb_ap;
271 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 MachineInstr *A, const MachineInstr *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()