45 #define DEBUG_TYPE "optimize-mips-pic-call" 49 cl::desc(
"Load target address from GOT"),
59 using CntRegP = std::pair<unsigned, unsigned>;
70 bool isVisited()
const;
71 void preVisit(ScopedHTType &ScopedHT);
76 ScopedHTType::ScopeTy *HTScope;
83 StringRef getPassName()
const override {
return "Mips OptimizePICCall"; }
94 bool visitNode(MBBInfo &MBBI);
102 ValueType &Val)
const;
106 unsigned getCount(ValueType Entry);
110 unsigned getReg(ValueType Entry);
113 void incCntAndSetReg(ValueType Entry,
unsigned Reg);
115 ScopedHTType ScopedHT;
156 unsigned SrcReg = I->getOperand(0).getReg();
157 unsigned DstReg =
getRegTy(SrcReg, MF) ==
MVT::i32 ? Mips::T9 : Mips::T9_64;
158 BuildMI(*MBB, I, I->getDebugLoc(), TII.
get(TargetOpcode::COPY), DstReg)
160 I->getOperand(0).setReg(DstReg);
170 unsigned Reg = Ty ==
MVT::i32 ? Mips::GP : Mips::GP_64;
187 bool MBBInfo::isVisited()
const {
return HTScope; }
189 void MBBInfo::preVisit(ScopedHTType &ScopedHT) {
190 HTScope =
new ScopedHTType::ScopeTy(ScopedHT);
193 void MBBInfo::postVisit() {
199 if (static_cast<const MipsSubtarget &>(F.
getSubtarget()).inMips16Mode())
204 bool Changed =
false;
208 while (!WorkList.
empty()) {
209 MBBInfo &MBBI = WorkList.
back();
213 if (MBBI.isVisited()) {
220 MBBI.preVisit(ScopedHT);
221 Changed |= visitNode(MBBI);
223 const std::vector<MachineDomTreeNode *> &Children = Node->
getChildren();
224 WorkList.
append(Children.begin(), Children.end());
230 bool OptimizePICCall::visitNode(MBBInfo &MBBI) {
231 bool Changed =
false;
240 if (!isCallViaRegister(*
I, Reg, Entry))
244 unsigned N = getCount(Entry);
260 incCntAndSetReg(Entry, Reg);
305 unsigned OptimizePICCall::getCount(
ValueType Entry) {
306 return ScopedHT.lookup(Entry).first;
310 unsigned Reg = ScopedHT.lookup(Entry).second;
315 void OptimizePICCall::incCntAndSetReg(
ValueType Entry,
unsigned Reg) {
316 CntRegP
P = ScopedHT.lookup(Entry);
317 ScopedHT.insert(Entry, std::make_pair(P.first + 1, Reg));
322 return new OptimizePICCall();
unsigned getTargetFlags() const
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
bool isCall(QueryType Type=AnyInBundle) const
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
This class represents lattice values for constants.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
static MachineOperand * getCallTargetRegOpnd(MachineInstr &MI)
Return the first MachineOperand of MI if it is a used virtual register.
unsigned const TargetRegisterInfo * TRI
static void setCallTargetReg(MachineBasicBlock *MBB, MachineBasicBlock::iterator I)
Do the following transformation:
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
AnalysisUsage & addRequired()
vt_iterator legalclasstypes_end(const TargetRegisterClass &RC) const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Retuns the total number of operands.
RecyclingAllocator - This class wraps an Allocator, adding the functionality of recycling deleted obj...
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
Base class for the actual dominator tree node.
const std::vector< DomTreeNodeBase * > & getChildren() const
virtual const TargetInstrInfo * getInstrInfo() const
TargetInstrInfo - Interface to description of machine instruction set.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
MO_GOT_CALL - Represents the offset into the global offset table at which the address of a call site ...
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 * createMipsOptimizePICCallPass()
Return an OptimizeCall object.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
FunctionPass class - This class is used to implement most global optimizations.
static cl::opt< bool > LoadTargetFromGOT("mips-load-target-from-got", cl::init(true), cl::desc("Load target address from GOT"), cl::Hidden)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
MachineDomTreeNode * getRootNode() const
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...
MachineInstrBuilder MachineInstrBuilder & DefMI
static cl::opt< bool > EraseGPOpnd("mips-erase-gp-opnd", cl::init(true), cl::desc("Erase GP Operand"), cl::Hidden)
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
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.
static void eraseGPOpnd(MachineInstr &MI)
Search MI's operands for register GP and erase it.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
LLVM_NODISCARD bool empty() const
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void setReg(unsigned Reg)
Change the register this operand corresponds to.
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 MVT::SimpleValueType getRegTy(unsigned Reg, MachineFunction &MF)
Return type of register Reg.
StringRef - Represent a constant reference to a string, i.e.
void RemoveOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
const MachineOperand & getOperand(unsigned i) const
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...
vt_iterator legalclasstypes_begin(const TargetRegisterClass &RC) const
Loop over all of the value types that can be represented by values in the given register class...