29class MemIntrinsicPlugin :
public InstVisitor<MemIntrinsicPlugin> {
31 TargetLibraryInfo &TLI;
32 std::vector<CandidateInfo> *Candidates;
37 MemIntrinsicPlugin(Function &Fn, TargetLibraryInfo &TLI)
38 :
F(Fn), TLI(TLI), Candidates(nullptr) {}
40 void run(std::vector<CandidateInfo> &Cs) {
45 void visitMemIntrinsic(MemIntrinsic &
MI) {
48 if (isa<ConstantInt>(Length))
53 Candidates->emplace_back(CandidateInfo{
Length, InsertPt, AnnotatedInst});
55 void visitCallInst(CallInst &CI) {
56 if (!MemOPOptMemcmpBcmp)
63 (Func == LibFunc_memcmp || Func == LibFunc_bcmp)) {
66 if (isa<ConstantInt>(Length))
70 Candidates->emplace_back(CandidateInfo{
Length, InsertPt, AnnotatedInst});
76class IndirectCallPromotionPlugin {
82 IndirectCallPromotionPlugin(Function &Fn, TargetLibraryInfo &TLI) :
F(Fn) {}
84 void run(std::vector<CandidateInfo> &Candidates) {
86 for (Instruction *
I : Result) {
90 Candidates.emplace_back(CandidateInfo{
Callee, InsertPt, AnnotatedInst});
96class VTableProfilingPlugin {
102 VTableProfilingPlugin(Function &Fn, TargetLibraryInfo &TLI) :
F(Fn) {}
104 void run(std::vector<CandidateInfo> &Candidates) {
106 for (Instruction *
I : Result) {
111 while (InsertPt && (dyn_cast<PHINode>(InsertPt) || InsertPt->
isEHPad()))
116 if (InsertPt ==
nullptr)
120 Candidates.emplace_back(CandidateInfo{
I, InsertPt, AnnotatedInst});
128#define VP_PLUGIN_LIST \
129 MemIntrinsicPlugin, IndirectCallPromotionPlugin, VTableProfilingPlugin
void visit(MachineFunction &MF, MachineBasicBlock &Start, std::function< void(MachineBasicBlock *)> op)
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Value * getArgOperand(unsigned i) const
Base class for instruction visitors.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
NodeAddr< FuncNode * > Func
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
std::vector< CallBase * > findIndirectCalls(Function &F)
cl::opt< bool > MemOPOptMemcmpBcmp("pgo-memop-optimize-memcmp-bcmp", cl::init(true), cl::Hidden, cl::desc("Size-specialize memcmp and bcmp calls"))
std::vector< Instruction * > findVTableAddrs(Function &F)