43#define DEBUG_TYPE "optimize-mips-pic-call"
47 cl::desc(
"Load target address from GOT"),
57using CntRegP = std::pair<unsigned, unsigned>;
68 bool isVisited()
const;
69 void preVisit(ScopedHTType &ScopedHT);
74 ScopedHTType::ScopeTy *HTScope;
92 bool visitNode(MBBInfo &
MBBI);
111 void incCntAndSetReg(
ValueType Entry,
unsigned Reg);
113 ScopedHTType ScopedHT;
120char OptimizePICCall::ID = 0;
124 if (
MI.getNumOperands() == 0)
139 assert(
TRI.legalclasstypes_end(*RC) -
TRI.legalclasstypes_begin(*RC) == 1);
140 return *
TRI.legalclasstypes_begin(*RC);
153 Register SrcReg =
I->getOperand(0).getReg();
154 unsigned DstReg =
getRegTy(SrcReg, MF) == MVT::i32 ? Mips::T9 : Mips::T9_64;
155 BuildMI(*
MBB,
I,
I->getDebugLoc(),
TII.get(TargetOpcode::COPY), DstReg)
157 I->getOperand(0).setReg(DstReg);
167 unsigned Reg = Ty == MVT::i32 ? Mips::GP : Mips::GP_64;
169 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I) {
184bool MBBInfo::isVisited()
const {
return HTScope; }
186void MBBInfo::preVisit(ScopedHTType &ScopedHT) {
187 HTScope =
new ScopedHTType::ScopeTy(ScopedHT);
190void MBBInfo::postVisit() {
201 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
202 bool Changed =
false;
206 while (!WorkList.empty()) {
211 if (
MBBI.isVisited()) {
218 MBBI.preVisit(ScopedHT);
219 Changed |= visitNode(
MBBI);
221 WorkList.append(
Node->begin(),
Node->end());
227bool OptimizePICCall::visitNode(MBBInfo &
MBBI) {
228 bool Changed =
false;
237 if (!isCallViaRegister(*
I, Reg, Entry))
241 unsigned N = getCount(Entry);
257 incCntAndSetReg(Entry, Reg);
265bool OptimizePICCall::isCallViaRegister(
MachineInstr &
MI,
unsigned &Reg,
302unsigned OptimizePICCall::getCount(
ValueType Entry) {
303 return ScopedHT.lookup(Entry).first;
306unsigned OptimizePICCall::getReg(
ValueType Entry) {
307 unsigned Reg = ScopedHT.lookup(Entry).second;
312void OptimizePICCall::incCntAndSetReg(
ValueType Entry,
unsigned Reg) {
313 CntRegP
P = ScopedHT.lookup(Entry);
314 ScopedHT.insert(Entry, std::make_pair(
P.first + 1, Reg));
319 return new OptimizePICCall();
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder MachineInstrBuilder & DefMI
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file defines the BumpPtrAllocator interface.
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static cl::opt< bool > LoadTargetFromGOT("mips-load-target-from-got", cl::init(true), cl::desc("Load target address from GOT"), cl::Hidden)
static void setCallTargetReg(MachineBasicBlock *MBB, MachineBasicBlock::iterator I)
Do the following transformation:
static void eraseGPOpnd(MachineInstr &MI)
Search MI's operands for register GP and erase it.
static MachineOperand * getCallTargetRegOpnd(MachineInstr &MI)
Return the first MachineOperand of MI if it is a used virtual register.
static cl::opt< bool > EraseGPOpnd("mips-erase-gp-opnd", cl::init(true), cl::desc("Erase GP Operand"), cl::Hidden)
static MVT::SimpleValueType getRegTy(unsigned Reg, MachineFunction &MF)
Return type of register Reg.
This file defines the PointerUnion class, which is a discriminated union of pointer types.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
Base class for the actual dominator tree node.
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
FunctionPass class - This class is used to implement most global optimizations.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Analysis pass which computes a MachineDominatorTree.
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getNumOperands() const
Retuns the total number of operands.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void setReg(Register Reg)
Change the register this operand corresponds to.
unsigned getTargetFlags() const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
bool inMips16Mode() const
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
RecyclingAllocator - This class wraps an Allocator, adding the functionality of recycling deleted obj...
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ MO_GOT_CALL
MO_GOT_CALL - Represents the offset into the global offset table at which the address of a call site ...
Reg
All possible values of the reg field in the ModR/M byte.
initializer< Ty > init(const Ty &Val)
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.
FunctionPass * createMipsOptimizePICCallPass()
Return an OptimizeCall object.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
An information struct used to provide DenseMap with the various necessary components for a given valu...