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");
44 StringRef getPassName()
const override {
45 return "Hexagon Generate Load/Store Set Absolute Address Instruction";
48 void getAnalysisUsage(AnalysisUsage &AU)
const override {
58 static bool isValidIndexedStore(
int &Opcode,
int &NewOpcode);
62char HexagonGenMemAbsolute::ID = 0;
65 "Hexagon Generate Load/Store Set Absolute Address Instruction",
69 if (skipFunction(Fn.getFunction()))
73 MRI = &Fn.getRegInfo();
76 getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
84 int Opc =
MI->getOpcode();
85 if (
Opc != Hexagon::CONST32 &&
Opc != Hexagon::A2_tfrsi)
92 unsigned DstReg = MO.
getReg();
93 if (MRI->use_nodbg_empty(DstReg))
97 use_iterator NextUseMI = MRI->use_nodbg_begin(DstReg);
104 if (!IsLoad && !isValidIndexedStore(NextOpc, NewOpc))
110 unsigned BaseRegPos, ImmPos, RegPos;
111 if (!
TII->getBaseAndOffsetPosition(*NextMI, BaseRegPos, ImmPos))
113 RegPos = IsLoad ? 0 : 2;
115 bool IsGlobal =
MI->getOperand(1).isGlobal();
116 if (!
MI->getOperand(1).isImm() && !IsGlobal)
122 TII->getMemOperandWithOffset(*NextMI, BaseOp,
Offset, Scalable);
125 if (!BaseOp || !BaseOp->
isReg())
131 unsigned BaseReg = BaseOp->
getReg();
132 if ((DstReg != BaseReg) || (
Offset != 0))
140 unsigned LoadStoreReg = MO0.
getReg();
144 if (LoadStoreReg == BaseReg)
150 bool Dominates =
true;
151 unsigned Counter = 0;
152 for (use_iterator
I = NextUseMI,
E = MRI->use_nodbg_end();
I !=
E; ++
I) {
154 if (!MDT.dominates(NextMI,
I->getParent()))
158 if ((!Dominates) || (Counter < 3))
164 dbgs() <<
"Found a pair of instructions for absolute-set "
165 << (IsLoad ?
"load" :
"store") <<
"\n";
172 ++HexagonNumLoadAbsConversions;
174 TII->get(NewOpc), LoadStoreReg)
177 ++HexagonNumStoreAbsConversions;
179 TII->get(NewOpc), DstReg);
205bool HexagonGenMemAbsolute::isValidIndexedLoad(
int &
Opc,
int &NewOpc) {
209 case Hexagon::L2_loadrb_io:
210 NewOpc = Hexagon::L4_loadrb_ap;
212 case Hexagon::L2_loadrh_io:
213 NewOpc = Hexagon::L4_loadrh_ap;
215 case Hexagon::L2_loadri_io:
216 NewOpc = Hexagon::L4_loadri_ap;
218 case Hexagon::L2_loadrd_io:
219 NewOpc = Hexagon::L4_loadrd_ap;
221 case Hexagon::L2_loadruh_io:
222 NewOpc = Hexagon::L4_loadruh_ap;
224 case Hexagon::L2_loadrub_io:
225 NewOpc = Hexagon::L4_loadrub_ap;
234bool HexagonGenMemAbsolute::isValidIndexedStore(
int &
Opc,
int &NewOpc) {
238 case Hexagon::S2_storerd_io:
239 NewOpc = Hexagon::S4_storerd_ap;
241 case Hexagon::S2_storeri_io:
242 NewOpc = Hexagon::S4_storeri_ap;
244 case Hexagon::S2_storerh_io:
245 NewOpc = Hexagon::S4_storerh_ap;
247 case Hexagon::S2_storerb_io:
248 NewOpc = Hexagon::S4_storerb_ap;
262 return new HexagonGenMemAbsolute();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
static bool isValidIndexedLoad(const LoadSDNode *LD)
#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)
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.
const HexagonInstrInfo * getInstrInfo() const override
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineInstrBundleIterator< MachineInstr > iterator
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
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 MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
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
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.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
defusechain_iterator< true, false, true, true, false > use_nodbg_iterator
use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the specified register,...
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.
@ Define
Register definition.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createHexagonGenMemAbsolute()