45#define DEBUG_TYPE "optimize-mips-pic-call"
50using CntRegP = std::pair<unsigned, unsigned>;
61 bool isVisited()
const;
62 void preVisit(ScopedHTType &
ScopedHT);
67 ScopedHTType::ScopeTy *HTScope;
74 StringRef getPassName()
const override {
return "Mips OptimizePICCall"; }
90char MipsOptimizePICCallLegacy::ID = 0;
94 if (
MI.getNumOperands() == 0)
109 assert(
TRI.legalclasstypes_end(*RC) -
TRI.legalclasstypes_begin(*RC) == 1);
110 return *
TRI.legalclasstypes_begin(*RC);
123 Register SrcReg =
I->getOperand(0).getReg();
125 9,
getRegTy(SrcReg, MF) != MVT::i32);
126 BuildMI(*
MBB,
I,
I->getDebugLoc(),
TII.get(TargetOpcode::COPY), DstReg)
128 I->getOperand(0).setReg(DstReg);
133 if (!CLOpts.erase_gp_opnd)
140 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I) {
155bool MBBInfo::isVisited()
const {
return HTScope; }
157void MBBInfo::preVisit(ScopedHTType &
ScopedHT) {
158 HTScope =
new ScopedHTType::ScopeTy(
ScopedHT);
161void MBBInfo::postVisit() {
168 return ScopedHT.lookup(Entry).first;
183 ScopedHT.insert(Entry, std::make_pair(
P.first + 1,
Reg));
211 if (!
DefMI->mayLoad() ||
DefMI->getNumOperands() < 3)
214 unsigned Flags =
DefMI->getOperand(2).getTargetFlags();
221 Val = (*
DefMI->memoperands_begin())->getValue();
223 Val = (*
DefMI->memoperands_begin())->getPseudoValue();
232 const MipsOptions &CLOpts = STI.
getCLOpts();
252 if (
N >= 2 && !CLOpts.load_target_from_got)
291 while (!WorkList.
empty()) {
296 if (
MBBI.isVisited()) {
314 return new MipsOptimizePICCallLegacy();
317bool MipsOptimizePICCallLegacy::runOnMachineFunction(
MachineFunction &MF) {
319 return &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
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 bool isCallViaRegister(MachineInstr &MI, unsigned &Reg, ValueType &Val)
Test if MI jumps to a function via a register.
static void incCntAndSetReg(ValueType Entry, unsigned Reg, ScopedHTType &ScopedHT)
Update ScopedHT.
static bool visitNode(MBBInfo &MBBI, ScopedHTType &ScopedHT)
Visit MBB.
static MVT::SimpleValueType getRegTy(unsigned Reg, MachineFunction &MF)
Return type of register Reg.
static bool optimizePICCallsInFunction(MachineFunction &F, function_ref< MachineDominatorTree *()> GetMDT)
static unsigned getCount(ValueType Entry, ScopedHTType &ScopedHT)
Return the number of instructions that dominate the current instruction and load the function address...
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.
MachineRegisterInfo & MRI
This file defines the SmallVector class.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
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.
MachineInstrBundleIterator< MachineInstr > iterator
Analysis pass which computes a MachineDominatorTree.
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.
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.
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.
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.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
bool inMips16Mode() const
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...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
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 append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
An efficient, type-erasing, non-owning reference to a callable.
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr MCPhysReg GP_64
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createMipsOptimizePICCallLegacyPass()
Return an OptimizeCall object.
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...