LLVM  10.0.0svn
Macros | Typedefs | Functions | Variables
CodeExtractor.cpp File Reference
#include "llvm/Transforms/Utils/CodeExtractor.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Pass.h"
#include "llvm/Support/BlockFrequency.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include <cassert>
#include <cstdint>
#include <iterator>
#include <map>
#include <set>
#include <utility>
#include <vector>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "code-extractor"
 

Typedefs

using ProfileCount = Function::ProfileCount
 

Functions

static bool isBlockValidForExtraction (const BasicBlock &BB, const SetVector< BasicBlock *> &Result, bool AllowVarArgs, bool AllowAlloca)
 Test whether a block is valid for extraction. More...
 
static SetVector< BasicBlock * > buildExtractionBlockSet (ArrayRef< BasicBlock *> BBs, DominatorTree *DT, bool AllowVarArgs, bool AllowAlloca)
 Build a set of blocks to extract if the input blocks are viable. More...
 
static bool definedInRegion (const SetVector< BasicBlock *> &Blocks, Value *V)
 definedInRegion - Return true if the specified value is defined in the extracted region. More...
 
static bool definedInCaller (const SetVector< BasicBlock *> &Blocks, Value *V)
 definedInCaller - Return true if the specified value is defined in the function being code extracted, but not in the region being extracted. More...
 
static BasicBlockgetCommonExitBlock (const SetVector< BasicBlock *> &Blocks)
 
static void eraseLifetimeMarkersOnInputs (const SetVector< BasicBlock *> &Blocks, const SetVector< Value *> &SunkAllocas, SetVector< Value *> &LifetimesStart)
 Erase lifetime.start markers which reference inputs to the extraction region, and insert the referenced memory into LifetimesStart. More...
 
static void insertLifetimeMarkersSurroundingCall (Module *M, ArrayRef< Value *> LifetimesStart, ArrayRef< Value *> LifetimesEnd, CallInst *TheCall)
 Insert lifetime start/end markers surrounding the call to the new function for objects defined in the caller. More...
 

Variables

static cl::opt< boolAggregateArgsOpt ("aggregate-extracted-args", cl::Hidden, cl::desc("Aggregate arguments to code-extracted functions"))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "code-extractor"

Definition at line 74 of file CodeExtractor.cpp.

Typedef Documentation

◆ ProfileCount

Definition at line 72 of file CodeExtractor.cpp.

Function Documentation

◆ buildExtractionBlockSet()

static SetVector<BasicBlock *> buildExtractionBlockSet ( ArrayRef< BasicBlock *>  BBs,
DominatorTree DT,
bool  AllowVarArgs,
bool  AllowAlloca 
)
static

Build a set of blocks to extract if the input blocks are viable.

Definition at line 196 of file CodeExtractor.cpp.

References assert(), llvm::dbgs(), llvm::ArrayRef< T >::empty(), isBlockValidForExtraction(), llvm::DominatorTree::isReachableFromEntry(), LLVM_DEBUG, llvm_unreachable, and llvm::predecessors().

◆ definedInCaller()

static bool definedInCaller ( const SetVector< BasicBlock *> &  Blocks,
Value V 
)
static

definedInCaller - Return true if the specified value is defined in the function being code extracted, but not in the region being extracted.

These values must be passed in as live-ins to the function.

Definition at line 277 of file CodeExtractor.cpp.

References llvm::SetVector< T, Vector, Set >::count(), and I.

Referenced by llvm::CodeExtractor::findInputsOutputs().

◆ definedInRegion()

static bool definedInRegion ( const SetVector< BasicBlock *> &  Blocks,
Value V 
)
static

definedInRegion - Return true if the specified value is defined in the extracted region.

Definition at line 267 of file CodeExtractor.cpp.

References llvm::SetVector< T, Vector, Set >::count(), and I.

Referenced by llvm::CodeExtractor::findAllocas(), llvm::CodeExtractor::findInputsOutputs(), and llvm::CodeExtractor::findOrCreateBlockForHoisting().

◆ eraseLifetimeMarkersOnInputs()

static void eraseLifetimeMarkersOnInputs ( const SetVector< BasicBlock *> &  Blocks,
const SetVector< Value *> &  SunkAllocas,
SetVector< Value *> &  LifetimesStart 
)
static

Erase lifetime.start markers which reference inputs to the extraction region, and insert the referenced memory into LifetimesStart.

The extraction region is defined by a set of blocks (Blocks), and a set of allocas which will be moved from the caller function into the extracted function (SunkAllocas).

Definition at line 924 of file CodeExtractor.cpp.

Referenced by llvm::CodeExtractor::extractCodeRegion().

◆ getCommonExitBlock()

static BasicBlock* getCommonExitBlock ( const SetVector< BasicBlock *> &  Blocks)
static

◆ insertLifetimeMarkersSurroundingCall()

static void insertLifetimeMarkersSurroundingCall ( Module M,
ArrayRef< Value *>  LifetimesStart,
ArrayRef< Value *>  LifetimesEnd,
CallInst TheCall 
)
static

Insert lifetime start/end markers surrounding the call to the new function for objects defined in the caller.

Definition at line 950 of file CodeExtractor.cpp.

References llvm::SwitchInst::addCase(), llvm::Function::addParamAttr(), llvm::CallBase::addParamAttr(), llvm::Function::arg_begin(), llvm::Function::arg_end(), assert(), Context, llvm::BasicBlock::Create(), llvm::GetElementPtrInst::Create(), llvm::CallInst::Create(), llvm::ReturnInst::Create(), llvm::BranchInst::Create(), llvm::SwitchInst::Create(), llvm::CastInst::CreatePointerCast(), llvm::dyn_cast(), E, llvm::ArrayRef< T >::empty(), llvm::Instruction::eraseFromParent(), llvm::BasicBlock::front(), llvm::Function::front(), GEP, llvm::ConstantInt::get(), llvm::StructType::get(), llvm::DataLayout::getAllocaAddrSpace(), llvm::Function::getBasicBlockList(), llvm::SwitchInst::getCondition(), llvm::Function::getContext(), llvm::Module::getContext(), llvm::Value::getContext(), llvm::Module::getDataLayout(), llvm::Instruction::getDebugLoc(), llvm::Intrinsic::getDeclaration(), llvm::Function::getEntryBlock(), llvm::Instruction::getFunction(), getFunction(), llvm::BasicBlock::getInstList(), llvm::Type::getInt16Ty(), llvm::Type::getInt1Ty(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::Type::getInt8PtrTy(), getName(), llvm::Value::getName(), llvm::Constant::getNullValue(), llvm::Instruction::getNumSuccessors(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), getParent(), llvm::Function::getReturnType(), llvm::ConstantInt::getSigned(), llvm::Function::getSubprogram(), llvm::Instruction::getSuccessor(), llvm::SwitchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), getType(), llvm::Value::getType(), llvm::BranchProbability::getZero(), I, llvm::Instruction::insertBefore(), llvm::Type::isVoidTy(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::iplist_impl< IntrusiveListT, TraitsT >::push_back(), llvm::iplist_impl< IntrusiveListT, TraitsT >::remove(), llvm::SwitchInst::removeCase(), llvm::User::replaceUsesOfWith(), llvm::SwitchInst::setCondition(), llvm::Instruction::setDebugLoc(), llvm::SwitchInst::setDefaultDest(), llvm::BranchProbabilityInfo::setEdgeProbability(), llvm::Instruction::setMetadata(), llvm::Instruction::setSuccessor(), SI, llvm::SmallVectorBase::size(), llvm::AssumptionCache::unregisterAssumption(), and Users.

Referenced by llvm::CodeExtractor::extractCodeRegion().

◆ isBlockValidForExtraction()

static bool isBlockValidForExtraction ( const BasicBlock BB,
const SetVector< BasicBlock *> &  Result,
bool  AllowVarArgs,
bool  AllowAlloca 
)
static

Variable Documentation

◆ AggregateArgsOpt

cl::opt<bool> AggregateArgsOpt("aggregate-extracted-args", cl::Hidden, cl::desc("Aggregate arguments to code-extracted functions"))
static