003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/include/llvm/Transforms/Utils
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
include
/
llvm
/
Transforms
/
Utils
/
📁
..
📄
AMDGPUEmitPrintf.h
(864 B)
📄
ASanStackFrameLayout.h
(3.51 KB)
📄
AddDiscriminators.h
(1.04 KB)
📄
AssumeBundleBuilder.h
(2.29 KB)
📄
BasicBlockUtils.h
(20.81 KB)
📄
BreakCriticalEdges.h
(1.16 KB)
📄
BuildLibCalls.h
(9.67 KB)
📄
BypassSlowDivision.h
(2.55 KB)
📄
CallGraphUpdater.h
(3.84 KB)
📄
CallPromotionUtils.h
(3.41 KB)
📄
CanonicalizeAliases.h
(998 B)
📄
CanonicalizeFreezeInLoops.h
(1.15 KB)
📄
Cloning.h
(12.34 KB)
📄
CodeExtractor.h
(9.58 KB)
📄
CodeMoverUtils.h
(2.85 KB)
📄
CtorUtils.h
(1021 B)
📄
Debugify.h
(3.36 KB)
📄
EntryExitInstrumenter.h
(1.16 KB)
📄
EscapeEnumerator.h
(1.56 KB)
📄
Evaluator.h
(4.69 KB)
📄
FunctionComparator.h
(17.12 KB)
📄
FunctionImportUtils.h
(5.73 KB)
📄
GlobalStatus.h
(2.97 KB)
📄
GuardUtils.h
(1.92 KB)
📄
ImportedFunctionsInliningStatistics.h
(4.35 KB)
📄
InjectTLIMappings.h
(1.27 KB)
📄
IntegerDivision.h
(2.88 KB)
📄
LCSSA.h
(1.56 KB)
📄
LibCallsShrinkWrap.h
(908 B)
📄
Local.h
(24.77 KB)
📄
LoopRotationUtils.h
(1.54 KB)
📄
LoopSimplify.h
(2.85 KB)
📄
LoopUtils.h
(21.25 KB)
📄
LoopVersioning.h
(5.87 KB)
📄
LowerInvoke.h
(1.08 KB)
📄
LowerMemIntrinsics.h
(2.14 KB)
📄
Mem2Reg.h
(921 B)
📄
MisExpect.h
(1.81 KB)
📄
ModuleUtils.h
(5.04 KB)
📄
NameAnonGlobals.h
(1.03 KB)
📄
PredicateInfo.h
(7.76 KB)
📄
PromoteMemToReg.h
(1.57 KB)
📄
SSAUpdater.h
(6.12 KB)
📄
SSAUpdaterBulk.h
(3.18 KB)
📄
SSAUpdaterImpl.h
(15.75 KB)
📄
SanitizerStats.h
(1.53 KB)
📄
ScalarEvolutionExpander.h
(17.87 KB)
📄
SimplifyIndVar.h
(2.12 KB)
📄
SimplifyLibCalls.h
(10.85 KB)
📄
SizeOpts.h
(4.84 KB)
📄
SplitModule.h
(1.53 KB)
📄
SymbolRewriter.h
(5.02 KB)
📄
UnifyFunctionExitNodes.h
(1.83 KB)
📄
UniqueInternalLinkageNames.h
(1.07 KB)
📄
UnrollLoop.h
(6.05 KB)
📄
VNCoercion.h
(4.99 KB)
📄
ValueMapper.h
(11.67 KB)
Editing: CodeExtractor.h
//===- Transform/Utils/CodeExtractor.h - Code extraction util ---*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // A utility to support extracting code from one function into its own // stand-alone function. // //===----------------------------------------------------------------------===// #ifndef LLVM_TRANSFORMS_UTILS_CODEEXTRACTOR_H #define LLVM_TRANSFORMS_UTILS_CODEEXTRACTOR_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include <limits> namespace llvm { class AllocaInst; class BasicBlock; class BlockFrequency; class BlockFrequencyInfo; class BranchProbabilityInfo; class AssumptionCache; class CallInst; class DominatorTree; class Function; class Instruction; class Loop; class Module; class Type; class Value; /// A cache for the CodeExtractor analysis. The operation \ref /// CodeExtractor::extractCodeRegion is guaranteed not to invalidate this /// object. This object should conservatively be considered invalid if any /// other mutating operations on the IR occur. /// /// Constructing this object is O(n) in the size of the function. class CodeExtractorAnalysisCache { /// The allocas in the function. SmallVector<AllocaInst *, 16> Allocas; /// Base memory addresses of load/store instructions, grouped by block. DenseMap<BasicBlock *, DenseSet<Value *>> BaseMemAddrs; /// Blocks which contain instructions which may have unknown side-effects /// on memory. DenseSet<BasicBlock *> SideEffectingBlocks; void findSideEffectInfoForBlock(BasicBlock &BB); public: CodeExtractorAnalysisCache(Function &F); /// Get the allocas in the function at the time the analysis was created. /// Note that some of these allocas may no longer be present in the function, /// due to \ref CodeExtractor::extractCodeRegion. ArrayRef<AllocaInst *> getAllocas() const { return Allocas; } /// Check whether \p BB contains an instruction thought to load from, store /// to, or otherwise clobber the alloca \p Addr. bool doesBlockContainClobberOfAddr(BasicBlock &BB, AllocaInst *Addr) const; }; /// Utility class for extracting code into a new function. /// /// This utility provides a simple interface for extracting some sequence of /// code into its own function, replacing it with a call to that function. It /// also provides various methods to query about the nature and result of /// such a transformation. /// /// The rough algorithm used is: /// 1) Find both the inputs and outputs for the extracted region. /// 2) Pass the inputs as arguments, remapping them within the extracted /// function to arguments. /// 3) Add allocas for any scalar outputs, adding all of the outputs' allocas /// as arguments, and inserting stores to the arguments for any scalars. class CodeExtractor { using ValueSet = SetVector<Value *>; // Various bits of state computed on construction. DominatorTree *const DT; const bool AggregateArgs; BlockFrequencyInfo *BFI; BranchProbabilityInfo *BPI; AssumptionCache *AC; // If true, varargs functions can be extracted. bool AllowVarArgs; // Bits of intermediate state computed at various phases of extraction. SetVector<BasicBlock *> Blocks; unsigned NumExitBlocks = std::numeric_limits<unsigned>::max(); Type *RetTy; // Suffix to use when creating extracted function (appended to the original // function name + "."). If empty, the default is to use the entry block // label, if non-empty, otherwise "extracted". std::string Suffix; public: /// Create a code extractor for a sequence of blocks. /// /// Given a sequence of basic blocks where the first block in the sequence /// dominates the rest, prepare a code extractor object for pulling this /// sequence out into its new function. When a DominatorTree is also given, /// extra checking and transformations are enabled. If AllowVarArgs is true, /// vararg functions can be extracted. This is safe, if all vararg handling /// code is extracted, including vastart. If AllowAlloca is true, then /// extraction of blocks containing alloca instructions would be possible, /// however code extractor won't validate whether extraction is legal. CodeExtractor(ArrayRef<BasicBlock *> BBs, DominatorTree *DT = nullptr, bool AggregateArgs = false, BlockFrequencyInfo *BFI = nullptr, BranchProbabilityInfo *BPI = nullptr, AssumptionCache *AC = nullptr, bool AllowVarArgs = false, bool AllowAlloca = false, std::string Suffix = ""); /// Create a code extractor for a loop body. /// /// Behaves just like the generic code sequence constructor, but uses the /// block sequence of the loop. CodeExtractor(DominatorTree &DT, Loop &L, bool AggregateArgs = false, BlockFrequencyInfo *BFI = nullptr, BranchProbabilityInfo *BPI = nullptr, AssumptionCache *AC = nullptr, std::string Suffix = ""); /// Perform the extraction, returning the new function. /// /// Returns zero when called on a CodeExtractor instance where isEligible /// returns false. Function *extractCodeRegion(const CodeExtractorAnalysisCache &CEAC); /// Verify that assumption cache isn't stale after a region is extracted. /// Returns true when verifier finds errors. AssumptionCache is passed as /// parameter to make this function stateless. static bool verifyAssumptionCache(const Function &OldFunc, const Function &NewFunc, AssumptionCache *AC); /// Test whether this code extractor is eligible. /// /// Based on the blocks used when constructing the code extractor, /// determine whether it is eligible for extraction. /// /// Checks that varargs handling (with vastart and vaend) is only done in /// the outlined blocks. bool isEligible() const; /// Compute the set of input values and output values for the code. /// /// These can be used either when performing the extraction or to evaluate /// the expected size of a call to the extracted function. Note that this /// work cannot be cached between the two as once we decide to extract /// a code sequence, that sequence is modified, including changing these /// sets, before extraction occurs. These modifications won't have any /// significant impact on the cost however. void findInputsOutputs(ValueSet &Inputs, ValueSet &Outputs, const ValueSet &Allocas) const; /// Check if life time marker nodes can be hoisted/sunk into the outline /// region. /// /// Returns true if it is safe to do the code motion. bool isLegalToShrinkwrapLifetimeMarkers(const CodeExtractorAnalysisCache &CEAC, Instruction *AllocaAddr) const; /// Find the set of allocas whose life ranges are contained within the /// outlined region. /// /// Allocas which have life_time markers contained in the outlined region /// should be pushed to the outlined function. The address bitcasts that /// are used by the lifetime markers are also candidates for shrink- /// wrapping. The instructions that need to be sunk are collected in /// 'Allocas'. void findAllocas(const CodeExtractorAnalysisCache &CEAC, ValueSet &SinkCands, ValueSet &HoistCands, BasicBlock *&ExitBlock) const; /// Find or create a block within the outline region for placing hoisted /// code. /// /// CommonExitBlock is block outside the outline region. It is the common /// successor of blocks inside the region. If there exists a single block /// inside the region that is the predecessor of CommonExitBlock, that block /// will be returned. Otherwise CommonExitBlock will be split and the /// original block will be added to the outline region. BasicBlock *findOrCreateBlockForHoisting(BasicBlock *CommonExitBlock); private: struct LifetimeMarkerInfo { bool SinkLifeStart = false; bool HoistLifeEnd = false; Instruction *LifeStart = nullptr; Instruction *LifeEnd = nullptr; }; LifetimeMarkerInfo getLifetimeMarkers(const CodeExtractorAnalysisCache &CEAC, Instruction *Addr, BasicBlock *ExitBlock) const; void severSplitPHINodesOfEntry(BasicBlock *&Header); void severSplitPHINodesOfExits(const SmallPtrSetImpl<BasicBlock *> &Exits); void splitReturnBlocks(); Function *constructFunction(const ValueSet &inputs, const ValueSet &outputs, BasicBlock *header, BasicBlock *newRootNode, BasicBlock *newHeader, Function *oldFunction, Module *M); void moveCodeToFunction(Function *newFunction); void calculateNewCallTerminatorWeights( BasicBlock *CodeReplacer, DenseMap<BasicBlock *, BlockFrequency> &ExitWeights, BranchProbabilityInfo *BPI); CallInst *emitCallAndSwitchStatement(Function *newFunction, BasicBlock *newHeader, ValueSet &inputs, ValueSet &outputs); }; } // end namespace llvm #endif // LLVM_TRANSFORMS_UTILS_CODEEXTRACTOR_H
Upload File
Create Folder