42#define DEBUG_TYPE "optimize-mips-pic-call"
47using CntRegP = std::pair<unsigned, unsigned>;
58 bool isVisited()
const;
59 void preVisit(ScopedHTType &
ScopedHT);
64 ScopedHTType::ScopeTy *HTScope;
71 StringRef getPassName()
const override {
return "Mips OptimizePICCall"; }
82 bool visitNode(MBBInfo &
MBBI);
110char OptimizePICCall::ID = 0;
114 if (
MI.getNumOperands() == 0)
129 assert(
TRI.legalclasstypes_end(*RC) -
TRI.legalclasstypes_begin(*RC) == 1);
130 return *
TRI.legalclasstypes_begin(*RC);
143 Register SrcReg =
I->getOperand(0).getReg();
145 9,
getRegTy(SrcReg, MF) != MVT::i32);
146 BuildMI(*
MBB,
I,
I->getDebugLoc(),
TII.get(TargetOpcode::COPY), DstReg)
148 I->getOperand(0).setReg(DstReg);
153 if (!CLOpts.erase_gp_opnd)
158 unsigned Reg = Ty == MVT::i32 ? Mips::GP : Mips::GP_64;
160 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I) {
175bool MBBInfo::isVisited()
const {
return HTScope; }
177void MBBInfo::preVisit(ScopedHTType &
ScopedHT) {
178 HTScope =
new ScopedHTType::ScopeTy(
ScopedHT);
181void MBBInfo::postVisit() {
187 if (
F.getSubtarget<MipsSubtarget>().inMips16Mode())
191 MachineDominatorTree *MDT =
192 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
197 while (!WorkList.empty()) {
202 if (
MBBI.isVisited()) {
212 WorkList.append(
Node->begin(),
Node->end());
218bool OptimizePICCall::visitNode(MBBInfo &
MBBI) {
220 MachineBasicBlock *
MBB =
MBBI.getNode()->getBlock();
222 const MipsOptions &CLOpts = STI.
getCLOpts();
226 MachineOperand *GPDef =
nullptr;
234 if (isCallViaRegister(*
I,
Reg, Entry)) {
236 unsigned N = getCount(Entry);
242 if (
N >= 2 && !CLOpts.load_target_from_got)
253 incCntAndSetReg(Entry,
Reg);
258 if (MachineOperand *Def =
I->findRegisterDefOperand(Mips::GP, &
TRI))
260 else if (
I->readsRegister(Mips::GP, &
TRI))
267bool OptimizePICCall::isCallViaRegister(MachineInstr &
MI,
unsigned &
Reg,
281 MachineRegisterInfo &MRI =
MI.getParent()->getParent()->getRegInfo();
304unsigned OptimizePICCall::getCount(
ValueType Entry) {
308unsigned OptimizePICCall::getReg(
ValueType Entry) {
314void OptimizePICCall::incCntAndSetReg(
ValueType Entry,
unsigned Reg) {
321 return new OptimizePICCall();
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
ScopedHashTable< Value *, Align, DenseMapInfo< Value * >, BumpPtrAllocator > ScopedHT
Register const TargetRegisterInfo * TRI
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static void setCallTargetReg(MachineBasicBlock *MBB, MachineBasicBlock::iterator I)
Do the following transformation:
static MachineOperand * getCallTargetRegOpnd(MachineInstr &MI)
Return the first MachineOperand of MI if it is a used virtual register.
static MVT::SimpleValueType getRegTy(unsigned Reg, MachineFunction &MF)
Return type of register Reg.
static bool eraseGPOpnd(const MipsOptions &CLOpts, MachineInstr &MI)
Search MI's operands for register GP and erase it.
This file defines the PointerUnion class, which is a discriminated union of pointer types.
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
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.
Wrapper class representing physical registers. Should be passed by value.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
Analysis pass which computes a MachineDominatorTree.
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.
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, RegState Flags={}, 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 setIsDead(bool Val=true)
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
unsigned getTargetFlags() const
Register getReg() const
getReg - Returns the register number.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI LLVM_READONLY MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
const MipsOptions & getCLOpts() const
const MipsRegisterInfo * getRegisterInfo() const override
A discriminated union of two or more pointer types, with the discriminator in the low bits of the poi...
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.
void insert(const K &Key, const V &Val)
V lookup(const K &Key) const
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 TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
NodeAddr< DefNode * > Def
NodeAddr< NodeBase * > Node
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.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
MCRegisterClass TargetRegisterClass
An information struct used to provide DenseMap with the various necessary components for a given valu...