41#ifndef LLVM_TRANSFORMS_IPO_IROUTLINER_H
42#define LLVM_TRANSFORMS_IPO_IROUTLINER_H
204 : getTTI(GTTI), getIRSI(GIRSI), getORE(GORE) {
208 static_cast<unsigned>(-1));
210 static_cast<unsigned>(-2));
220 unsigned doOutline(
Module &M);
241 pruneIncompatibleRegions(std::vector<IRSimilarityCandidate> &CandidateVec,
253 unsigned FunctionNameSuffix);
312 std::vector<Function *> &FuncsToRemove,
313 unsigned &OutlinedFunctionNum);
326 void fillOverallFunction(
329 std::vector<Function *> &FuncsToRemove);
333 bool OutlineFromLinkODRs =
false;
338 bool CostModel =
true;
370 struct InstructionAllowed :
public InstVisitor<InstructionAllowed, bool> {
371 InstructionAllowed() =
default;
373 bool visitBranchInst(
BranchInst &BI) {
return EnableBranches; }
374 bool visitPHINode(PHINode &PN) {
return EnableBranches; }
376 bool visitAllocaInst(AllocaInst &AI) {
return false; }
380 bool visitVAArgInst(VAArgInst &VI) {
return false; }
383 bool visitLandingPadInst(LandingPadInst &LPI) {
return false; }
384 bool visitFuncletPadInst(FuncletPadInst &FPI) {
return false; }
388 bool visitDbgInfoIntrinsic(DbgInfoIntrinsic &DII) {
return true; }
391 bool IntrinsicInst(IntrinsicInst &
II) {
return EnableIntrinsics; }
394 bool visitCallInst(CallInst &CI) {
404 if (CI.canReturnTwice())
413 if (CI.hasFnAttr(Attribute::NoMerge))
424 if (IsTailCC && !EnableMustTailCalls)
426 if (CI.isMustTailCall() && !EnableMustTailCalls)
430 if (CI.isMustTailCall() && !IsTailCC)
437 bool visitFreezeInst(FreezeInst &CI) {
return false; }
439 bool visitInvokeInst(InvokeInst &
II) {
return false; }
441 bool visitCallBrInst(CallBrInst &CBI) {
return false; }
443 bool visitTerminator(Instruction &
I) {
return false; }
444 bool visitInstruction(Instruction &
I) {
return true; }
448 bool EnableBranches =
false;
452 bool EnableIndirectCalls =
true;
456 bool EnableIntrinsics =
false;
459 bool EnableMustTailCalls =
false;
463 InstructionAllowed InstructionClassifier;
static bool IsIndirectCall(const MachineInstr *MI)
This header defines various interfaces for pass management in LLVM.
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
uint64_t IntrinsicInst * II
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
This class represents a function call, abstracting a target machine's calling convention.
Implements a dense probed hash-table based set.
Pass to outline similar regions.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
IROutliner(function_ref< TargetTransformInfo &(Function &)> GTTI, function_ref< IRSimilarityIdentifier &(Module &)> GIRSI, function_ref< OptimizationRemarkEmitter &(Function &)> GORE)
This is a class that wraps a range of IRInstructionData from one point to another in the vector of IR...
This class puts all the pieces of the IRInstructionData, IRInstructionMapper, IRSimilarityCandidate t...
Base class for instruction visitors.
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
CallingConv Namespace - This namespace contains an enum with a value for the well-known calling conve...
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
The OutlinableGroup holds all the overarching information for outlining a set of regions that are str...
An information struct used to provide DenseMap with the various necessary components for a given valu...
This provides the utilities for hashing an Instruction to an unsigned integer.
The OutlinableRegion holds all the information for a specific region, or sequence of instructions.
CallInst * Call
The call site of the extracted region.
CodeExtractor * CE
Used to create an outlined function.
InstructionCost getBenefit(TargetTransformInfo &TTI)
Get the size of the code removed from the region.
DenseMap< unsigned, Constant * > AggArgToConstant
Mapping of the argument number in the deduplicated function to a given constant, which is used when c...
DenseMap< unsigned, unsigned > AggArgToExtracted
BasicBlock * FollowBB
The BasicBlock that is after the start of the region BasicBlock, only defined when the region has bee...
unsigned OutputBlockNum
The corresponding BasicBlock with the appropriate stores for this OutlinableRegion in the overall fun...
IRInstructionData * NewFront
If this region is outlined, the front and back IRInstructionData could potentially become invalidated...
SmallVector< unsigned, 4 > GVNStores
The global value numbers that are used as outputs for this section.
bool CandidateSplit
Flag for whether we have split out the IRSimilarityCanidate.
bool IgnoreRegion
Flag for whether we should not consider this region for extraction.
bool ChangedArgOrder
Marks whether we need to change the order of the arguments when mapping the old extracted function ca...
void splitCandidate()
For the contained region, split the parent BasicBlock at the starting and ending instructions of the ...
Value * findCorrespondingValueIn(const OutlinableRegion &Other, Value *V)
Find a corresponding value for V in similar OutlinableRegion Other.
DenseMap< unsigned, unsigned > ExtractedArgToAgg
Mapping the extracted argument number to the argument number in the overall function.
BasicBlock * findCorrespondingBlockIn(const OutlinableRegion &Other, BasicBlock *BB)
Find a corresponding BasicBlock for BB in similar OutlinableRegion Other.
BasicBlock * PrevBB
The BasicBlock that is before the start of the region BasicBlock, only defined when the region has be...
BasicBlock * EndBB
The BasicBlock that contains the ending instruction of the region.
IRSimilarityCandidate * Candidate
Describes the region of code.
unsigned NumExtractedInputs
The number of extracted inputs from the CodeExtractor.
DenseMap< Value *, BasicBlock * > PHIBlocks
The PHIBlocks with their corresponding return block based on the return value as the key.
DenseMap< Value *, Value * > RemappedArguments
Values in the outlined functions will often be replaced by arguments.
OutlinableGroup * Parent
The Outlinable Group that contains this region and structurally similar regions to this region.
OutlinableRegion(IRSimilarityCandidate &C, OutlinableGroup &Group)
Function * ExtractedFunction
The function for the extracted region.
bool EndsInBranch
Marks whether this region ends in a branch, there is special handling required for the following basi...
BasicBlock * StartBB
The BasicBlock that contains the starting instruction of the region.
IRInstructionData * NewBack
void reattachCandidate()
For the contained region, reattach the BasicBlock at the starting and ending instructions of the cont...
A CRTP mix-in to automatically provide informational APIs needed for passes.