117 using namespace llvm;
119 #define DEBUG_TYPE "aarch64-collect-loh" 122 "Number of simplifiable ADRP dominate by another");
123 STATISTIC(NumADDToSTR,
"Number of simplifiable STR reachable by ADD");
124 STATISTIC(NumLDRToSTR,
"Number of simplifiable STR reachable by LDR");
125 STATISTIC(NumADDToLDR,
"Number of simplifiable LDR reachable by ADD");
126 STATISTIC(NumLDRToLDR,
"Number of simplifiable LDR reachable by LDR");
127 STATISTIC(NumADRPToLDR,
"Number of simplifiable LDR reachable by ADRP");
128 STATISTIC(NumADRSimpleCandidate,
"Number of simplifiable ADRP + ADD");
130 #define AARCH64_COLLECT_LOH_NAME "AArch64 Collect Linker Optimization Hint (LOH)" 162 switch (MI.getOperand(2).getType()) {
182 case AArch64::ADDXri:
183 return canAddBePartOfLOH(MI);
184 case AArch64::LDRXui:
185 case AArch64::LDRWui:
202 case AArch64::STRBBui:
203 case AArch64::STRHHui:
204 case AArch64::STRBui:
205 case AArch64::STRHui:
206 case AArch64::STRWui:
207 case AArch64::STRXui:
208 case AArch64::STRSui:
209 case AArch64::STRDui:
210 case AArch64::STRQui:
226 case AArch64::LDRSBWui:
227 case AArch64::LDRSBXui:
228 case AArch64::LDRSHWui:
229 case AArch64::LDRSHXui:
230 case AArch64::LDRSWui:
231 case AArch64::LDRBui:
232 case AArch64::LDRHui:
233 case AArch64::LDRWui:
234 case AArch64::LDRXui:
235 case AArch64::LDRSui:
236 case AArch64::LDRDui:
237 case AArch64::LDRQui:
247 case AArch64::LDRSWui:
248 case AArch64::LDRWui:
249 case AArch64::LDRXui:
250 case AArch64::LDRSui:
251 case AArch64::LDRDui:
252 case AArch64::LDRQui:
261 static_assert(AArch64::X28 - AArch64::X0 + 3 == N_GPR_REGS,
"Number of GPRs");
262 static_assert(AArch64::W30 - AArch64::W0 + 1 == N_GPR_REGS,
"Number of GPRs");
263 if (AArch64::X0 <= Reg && Reg <= AArch64::X28)
264 return Reg - AArch64::X0;
265 if (AArch64::W0 <= Reg && Reg <= AArch64::W30)
266 return Reg - AArch64::W0;
269 if (Reg == AArch64::FP)
271 if (Reg == AArch64::LR)
313 }
else if (MI.
getOpcode() == AArch64::ADDXri) {
317 }
else if ((MI.
getOpcode() == AArch64::LDRXui ||
341 if (&DefInfo != &OpInfo) {
350 if (MI.
getOpcode() == AArch64::ADDXri && canAddBePartOfLOH(MI)) {
365 "Expect LDRXui or LDRWui");
367 "Expected GOT relocation");
388 <<
'\t' << MI <<
'\t' << *Info.
LastADRP);
390 ++NumADRPSimpleCandidate;
398 <<
'\t' << MI <<
'\t' << *Info.
MI0);
400 ++NumADRSimpleCandidate;
405 <<
'\t' << MI <<
'\t' << *Info.
MI0);
412 <<
'\t' << MI <<
'\t' << *Info.
MI1 <<
'\t' 418 if (Info.
MI1 !=
nullptr) {
420 <<
'\t' << MI <<
'\t' << *Info.
MI1 <<
'\t' 428 <<
'\t' << MI <<
'\t' << *Info.
MI1 <<
'\t' 435 <<
'\t' << MI <<
'\t' << *Info.
MI1 <<
'\t' 442 <<
'\t' << MI <<
'\t' << *Info.
MI0);
466 if (MO.isRegMask()) {
467 const uint32_t *RegMask = MO.getRegMask();
474 if (!MO.isReg() || !MO.isDef())
485 if (!MO.isReg() || !MO.readsReg())
495 if (!UsesSeen.
count(Idx)) {
506 LLVM_DEBUG(
dbgs() <<
"********** AArch64 Collect LOH **********\n" 507 <<
"Looking in function " << MF.
getName() <<
'\n');
513 memset(LOHInfos, 0,
sizeof(LOHInfos));
516 for (
const auto &LI : Succ->liveins()) {
519 LOHInfos[RegIdx].OneUser =
true;
526 unsigned Opcode =
MI.getOpcode();
528 case AArch64::ADDXri:
529 case AArch64::LDRXui:
530 case AArch64::LDRWui:
538 if (DefIdx >= 0 && OpIdx >= 0 &&
561 return new AArch64CollectLOH();
unsigned getTargetFlags() const
static void handleNormalInst(const MachineInstr &MI, LOHInfo *LOHInfos)
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
This class represents lattice values for constants.
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
Address of indexed Jump Table for switch.
const MachineInstr * LastADRP
Last ADRP in same register.
Adrp _v -> Add _v -> Ldr.
STATISTIC(NumFunctions, "Total number of functions")
iterator_range< mop_iterator > operands()
iterator_range< succ_iterator > successors()
FunctionPass * createAArch64CollectLOHPass()
Adrp _v -> Ldr _v -> Ldr.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
static bool isCandidateLoad(const MachineInstr &MI)
Check whether the given instruction can be the end of a LOH chain involving a load.
static int mapRegToGPRIndex(MCPhysReg Reg)
Map register number to index from 0-30.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static const unsigned N_GPR_REGS
Number of GPR registers traked by mapRegToGPRIndex()
State tracked per register.
MO_GOT - This flag indicates that a symbol operand represents the address of the GOT entry for the sy...
INITIALIZE_PASS(AArch64CollectLOH, "aarch64-collect-loh", AARCH64_COLLECT_LOH_NAME, false, false) static bool canAddBePartOfLOH(const MachineInstr &MI)
static bool isCandidateStore(const MachineInstr &MI, const MachineOperand &MO)
Check whether the given instruction can the end of a LOH chain involving a store. ...
Analysis containing CSE Info
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
static void handleRegMaskClobber(const uint32_t *RegMask, MCPhysReg Reg, LOHInfo *LOHInfos)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
static bool handleMiddleInst(const MachineInstr &MI, LOHInfo &DefInfo, LOHInfo &OpInfo)
Update state Info given that MI is possibly the middle instruction of an LOH involving 3 instructions...
Address of a global value.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool MultiUsers
Found multiple users.
bool OneUser
Found exactly one user (yet).
Represent the analysis usage information of a pass.
MCLOHType
Linker Optimization Hint Type.
Address of a basic block.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static void handleClobber(LOHInfo &Info)
Update state Info given the tracked register is clobbered.
Adrp _v -> Add _v -> Str.
MachineOperand class - Representation of each machine instruction operand.
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.
static bool clobbersPhysReg(const uint32_t *RegMask, unsigned PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool IsCandidate
Possible LOH candidate.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
static void handleUse(const MachineInstr &MI, const MachineOperand &MO, LOHInfo &Info)
Update state Info given MI uses the tracked register.
MCLOHType Type
"Best" type of LOH possible.
Adrp xY, _v1 -> Adrp xY, _v2.
Adrp _v -> Ldr _v -> Str.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static bool canDefBePartOfLOH(const MachineInstr &MI)
Answer the following question: Can Def be one of the definition involved in a part of a LOH...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MachineInstr * MI0
First instruction involved in the LOH.
void addLOHDirective(MCLOHType Kind, MILOHArgs Args)
Add a LOH directive of this Kind and this Args.
static bool supportLoadFromLiteral(const MachineInstr &MI)
Check whether the given instruction can load a litteral.
const MachineInstr * MI1
Second instruction involved in the LOH (if any).
StringRef - Represent a constant reference to a string, i.e.
static void handleADRP(const MachineInstr &MI, AArch64FunctionInfo &AFI, LOHInfo &Info)
Update state when seeing and ADRP instruction.
Address of indexed Constant in Constant Pool.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
#define AARCH64_COLLECT_LOH_NAME
Properties which a MachineFunction may have at a given point in time.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.