15 #define GET_INSTRMAP_INFO 31 #define OPTADDRMODE_DESC "ARC load/store address mode" 32 #define OPTADDRMODE_NAME "arc-addr-mode" 33 #define DEBUG_TYPE "arc-addr-mode" 100 void changeToAddrMode(
MachineInstr &Ldst,
unsigned NewOpcode,
153 assert(InstBB != MBB &&
"Instruction found in empty MBB");
172 unsigned BasePos, OffPos;
182 bool ARCOptAddrMode::noUseOfAddBeforeLoadOrStore(
const MachineInstr *
Add,
191 unsigned BasePos, OffsetPos;
194 if (!AII->getBaseAndOffsetPosition(Ldst, BasePos, OffsetPos)) {
202 assert(Base.
isReg() &&
"Base operand must be register");
203 if (!Offset.
isImm()) {
215 if (Offset.
getImm() != 0) {
220 for (
auto &Add :
MRI->use_nodbg_instructions(B)) {
228 MachineInstr *MoveTo = canJoinInstructions(&Ldst, &Add, &Uses);
237 if (MDT->dominates(Last, First))
std::swap(First, Last);
238 dbgs() <<
"[ABAW] Instructions " << *First <<
" and " << *Last
244 if (MoveTo == &Add) {
249 Result = Result->getNextNode();
251 fixPastUses(Uses, B, Incr);
253 int NewOpcode = ARC::getPostIncOpcode(Ldst.
getOpcode());
254 assert(NewOpcode > 0 &&
"No postincrement form found");
256 changeToAddrMode(Ldst, NewOpcode, NewBaseReg, Add.
getOperand(2));
267 assert(Ldst && Add &&
"NULL instruction passed");
271 if (MDT->dominates(Ldst, Add))
273 else if (!MDT->dominates(Add, Ldst))
278 unsigned BasePos, OffPos;
280 if (!AII->getBaseAndOffsetPosition(*Ldst, BasePos, OffPos)) {
283 <<
"[canJoinInstructions] Cannot determine base/offset position\n");
298 LLVM_DEBUG(
dbgs() <<
"[canJoinInstructions] Store uses result of Add\n");
306 if (&
MI == Ldst || &
MI == Add)
308 if (&
MI != Add && MDT->dominates(Ldst, &
MI))
310 else if (!MDT->dominates(&
MI, Ldst))
312 if (MDT->dominates(Add, &
MI))
323 if (noUseOfAddBeforeLoadOrStore(First, Last)) {
325 LLVM_DEBUG(
dbgs() <<
"[canJoinInstructions] Can sink Add down to Ldst\n");
326 }
else if (canHoistLoadStoreTo(Ldst, Add)) {
328 LLVM_DEBUG(
dbgs() <<
"[canJoinInstructions] Can hoist Ldst to Add\n");
335 LLVM_DEBUG(
dbgs() <<
"[canJoinInstructions] Can hoist Add to Ldst\n");
338 *Uses = (Result == Ldst) ? UsesAfterLdst : UsesAfterAdd;
345 assert(Incr.
isImm() &&
"Expected immediate increment");
346 int64_t NewOffset = Incr.
getImm();
356 LLVM_DEBUG(
dbgs() <<
"Instruction cannot handle displacement " << -NewOffset
364 unsigned NewBase, int64_t NewOffset) {
368 unsigned BasePos, OffPos;
372 "New offset won't fit into ADD instr");
375 }
else if (AII->getBaseAndOffsetPosition(*
MI, BasePos, OffPos)) {
377 assert(MO.
isImm() &&
"expected immediate operand");
380 "New offset won't fit into LD/ST");
384 MI->getOperand(BasePos).setReg(NewBase);
385 MI->getOperand(OffPos).setImm(NewOffset);
396 for (;
MI != ME &&
MI != End; ++
MI) {
397 if (
MI->isDebugValue())
399 if (
MI->mayStore() ||
MI->isCall() ||
MI->isInlineAsm() ||
400 MI->hasUnmodeledSideEffects())
402 if (IsStore &&
MI->mayLoad())
407 if (!
O.isReg() || !
O.isUse())
410 if (!OpDef || !MDT->dominates(OpDef, To))
427 for (;
MI != ME &&
MI != End; ++
MI) {
428 if (
MI->isDebugValue())
430 if (
MI->mayStore() ||
MI->isCall() ||
MI->isInlineAsm() ||
431 MI->hasUnmodeledSideEffects())
433 if (IsStore &&
MI->mayLoad())
435 if (ValReg &&
MI->readsVirtualRegister(ValReg))
441 void ARCOptAddrMode::changeToAddrMode(
MachineInstr &Ldst,
unsigned NewOpcode,
445 unsigned BasePos, OffPos;
447 AII->getBaseAndOffsetPosition(Ldst, BasePos, OffPos);
459 Ldst.
setDesc(AST->getInstrInfo()->get(NewOpcode));
469 bool Changed =
false;
471 if (
MI->isDebugValue())
473 if (!
MI->mayLoad() && !
MI->mayStore())
475 if (ARC::getPostIncOpcode(
MI->getOpcode()) < 0)
494 MDT = &getAnalysis<MachineDominatorTree>();
496 bool Changed =
false;
498 Changed |= processBasicBlock(MBB);
const_iterator end(StringRef path)
Get end iterator over path.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
MachineBasicBlock * getMBB() const
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
This class represents lattice values for constants.
iterator_range< mop_iterator > explicit_operands()
void push_back(const T &Elt)
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
static bool isStackSlot(unsigned Reg)
isStackSlot - Sometimes it is useful the be able to store a non-negative frame index in a variable th...
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
static bool isLoadStoreThatCanHandleDisplacement(const TargetInstrInfo *TII, const MachineInstr &MI, int64_t Disp)
use_nodbg_iterator use_nodbg_begin(unsigned RegNo) const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
static false bool isValidLoadStoreOffset(int64_t Off)
static use_nodbg_iterator use_nodbg_end()
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
virtual bool getBaseAndOffsetPosition(const MachineInstr &MI, unsigned &BasePos, unsigned &OffsetPos) const
Return true if the instruction contains a base register and offset.
reverse_iterator rbegin()
const ARCInstrInfo * getInstrInfo() const override
TargetInstrInfo - Interface to description of machine instruction set.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
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.
FunctionPass * createARCOptAddrMode()
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
Promote Memory to Register
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.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
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.
INITIALIZE_PASS_BEGIN(ARCOptAddrMode, OPTADDRMODE_NAME, OPTADDRMODE_DESC, false, false) INITIALIZE_PASS_END(ARCOptAddrMode
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static bool isAddConstantOp(const MachineInstr &MI, int64_t &Amount)
static MachineOperand CreateImm(int64_t Val)
static bool isValidIncrementOffset(int64_t Off)
MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it. ...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
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.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
void initializeARCOptAddrModePass(PassRegistry &)
static bool dominatesAllUsesOf(const MachineInstr *MI, unsigned VReg, MachineDominatorTree *MDT, MachineRegisterInfo *MRI)
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
void RemoveOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Wrapper class representing virtual and physical registers.