26 #define DEBUG_TYPE "optimize-mips-pic-call"
30 cl::desc(
"Load target address from GOT"),
40 typedef std::pair<unsigned, unsigned> CntRegP;
45 AllocatorTy> ScopedHTType;
51 bool isVisited()
const;
52 void preVisit(ScopedHTType &ScopedHT);
57 ScopedHTType::ScopeTy *HTScope;
64 StringRef getPassName()
const override {
return "Mips OptimizePICCall"; }
75 bool visitNode(MBBInfo &MBBI);
83 ValueType &Val)
const;
87 unsigned getCount(ValueType Entry);
91 unsigned getReg(ValueType Entry);
94 void incCntAndSetReg(ValueType Entry,
unsigned Reg);
96 ScopedHTType ScopedHT;
135 unsigned SrcReg = I->getOperand(0).getReg();
136 unsigned DstReg =
getRegTy(SrcReg, MF) ==
MVT::i32 ? Mips::T9 : Mips::T9_64;
137 BuildMI(*MBB, I, I->getDebugLoc(), TII.
get(TargetOpcode::COPY), DstReg)
139 I->getOperand(0).setReg(DstReg);
149 unsigned Reg = Ty ==
MVT::i32 ? Mips::GP : Mips::GP_64;
166 bool MBBInfo::isVisited()
const {
return HTScope; }
168 void MBBInfo::preVisit(ScopedHTType &ScopedHT) {
169 HTScope =
new ScopedHTType::ScopeTy(ScopedHT);
172 void MBBInfo::postVisit() {
178 if (static_cast<const MipsSubtarget &>(F.
getSubtarget()).inMips16Mode())
183 bool Changed =
false;
187 while (!WorkList.empty()) {
188 MBBInfo &MBBI = WorkList.back();
192 if (MBBI.isVisited()) {
199 MBBI.preVisit(ScopedHT);
200 Changed |= visitNode(MBBI);
202 const std::vector<MachineDomTreeNode *> &Children = Node->
getChildren();
203 WorkList.append(Children.begin(), Children.end());
209 bool OptimizePICCall::visitNode(MBBInfo &MBBI) {
210 bool Changed =
false;
219 if (!isCallViaRegister(*
I, Reg, Entry))
223 unsigned N = getCount(Entry);
239 incCntAndSetReg(Entry, Reg);
247 bool OptimizePICCall::isCallViaRegister(
MachineInstr &
MI,
unsigned &Reg,
284 unsigned OptimizePICCall::getCount(
ValueType Entry) {
285 return ScopedHT.lookup(Entry).first;
289 unsigned Reg = ScopedHT.lookup(Entry).second;
294 void OptimizePICCall::incCntAndSetReg(
ValueType Entry,
unsigned Reg) {
295 CntRegP
P = ScopedHT.lookup(Entry);
296 ScopedHT.insert(Entry, std::make_pair(P.first + 1, Reg));
301 return new OptimizePICCall();
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
MachineDomTreeNode * getRootNode() const
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.
static void setCallTargetReg(MachineBasicBlock *MBB, MachineBasicBlock::iterator I)
Do the following transformation:
const std::vector< DomTreeNodeBase * > & getChildren() const
AnalysisUsage & addRequired()
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
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.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
RecyclingAllocator - This class wraps an Allocator, adding the functionality of recycling deleted obj...
unsigned getNumOperands() const
Access to explicit operands of the instruction.
void RemoveOperand(unsigned i)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
vt_iterator legalclasstypes_begin(const TargetRegisterClass &RC) const
Loop over all of the value types that can be represented by values.
Base class for the actual dominator tree node.
const MachineBasicBlock * getParent() 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.
vt_iterator legalclasstypes_end(const TargetRegisterClass &RC) const
initializer< Ty > init(const Ty &Val)
unsigned getTargetFlags() const
MO_GOT_CALL - Represents the offset into the global offset table at which the address of a call site ...
unsigned const MachineRegisterInfo * MRI
FunctionPass * createMipsOptimizePICCallPass()
Return an OptimizeCall object.
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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...
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
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...
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)
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static std::vector< std::string > Flags
Representation of each machine instruction.
static void eraseGPOpnd(MachineInstr &MI)
Search MI's operands for register GP and erase it.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
bool isCall(QueryType Type=AnyInBundle) const
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
static MVT::SimpleValueType getRegTy(unsigned Reg, MachineFunction &MF)
Return type of register Reg.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.