41#ifndef LLVM_TRANSFORMS_IPO_IROUTLINER_H
42#define LLVM_TRANSFORMS_IPO_IROUTLINER_H
53using namespace IRSimilarity;
56class TargetTransformInfo;
57class OptimizationRemarkEmitter;
204 : getTTI(GTTI), getIRSI(GIRSI), getORE(GORE) {
208 "DenseMapInfo<unsigned>'s empty key isn't -1!");
210 "DenseMapInfo<unsigned>'s tombstone key isn't -2!");
220 unsigned doOutline(
Module &M);
241 pruneIncompatibleRegions(std::vector<IRSimilarityCandidate> &CandidateVec,
253 unsigned FunctionNameSuffix);
312 std::vector<Function *> &FuncsToRemove,
313 unsigned &OutlinedFunctionNum);
317 bool OutlineFromLinkODRs =
false;
322 bool CostModel =
true;
354 struct InstructionAllowed :
public InstVisitor<InstructionAllowed, bool> {
355 InstructionAllowed() =
default;
357 bool visitBranchInst(
BranchInst &BI) {
return EnableBranches; }
358 bool visitPHINode(PHINode &PN) {
return EnableBranches; }
360 bool visitAllocaInst(AllocaInst &AI) {
return false; }
364 bool visitVAArgInst(VAArgInst &VI) {
return false; }
367 bool visitLandingPadInst(LandingPadInst &LPI) {
return false; }
368 bool visitFuncletPadInst(FuncletPadInst &FPI) {
return false; }
372 bool visitDbgInfoIntrinsic(DbgInfoIntrinsic &DII) {
return true; }
375 bool IntrinsicInst(IntrinsicInst &
II) {
return EnableIntrinsics; }
378 bool visitCallInst(CallInst &CI) {
380 bool IsIndirectCall = CI.isIndirectCall();
381 if (IsIndirectCall && !EnableIndirectCalls)
383 if (!
F && !IsIndirectCall)
388 if (CI.canReturnTwice())
401 if (IsTailCC && !EnableMustTailCalls)
403 if (CI.isMustTailCall() && !EnableMustTailCalls)
407 if (CI.isMustTailCall() && !IsTailCC)
414 bool visitFreezeInst(FreezeInst &CI) {
return false; }
416 bool visitInvokeInst(InvokeInst &
II) {
return false; }
418 bool visitCallBrInst(CallBrInst &CBI) {
return false; }
420 bool visitTerminator(Instruction &
I) {
return false; }
421 bool visitInstruction(Instruction &
I) {
return true; }
425 bool EnableBranches =
false;
429 bool EnableIndirectCalls =
true;
433 bool EnableIntrinsics =
false;
436 bool EnableMustTailCalls =
false;
440 InstructionAllowed InstructionClassifier;
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,...
Machine Check Debug Module
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A container for analyses that lazily runs them and caches their results.
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)
This class is a pass that identifies similarity in a Module, extracts instances of the similarity,...
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.
@ 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.
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.