LLVM: lib/Transforms/Utils/CodeExtractor.cpp File Reference (original) (raw)

Go to the source code of this file.

Macros
#define DEBUG_TYPE "code-extractor"
Functions
static bool isBlockValidForExtraction (const BasicBlock &BB, const SetVector< BasicBlock * > &Result, bool AllowVarArgs, bool AllowAlloca)
Test whether a block is valid for extraction.
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.
static bool isAlignmentPreservedForAddrCast (const Triple &TargetTriple)
isAlignmentPreservedForAddrCast - Return true if the cast operation for specified target preserves original alignment
static bool definedInRegion (const SetVector< BasicBlock * > &Blocks, Value *V)
definedInRegion - Return true if the specified value is defined in the extracted region.
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.
static BasicBlock * getCommonExitBlock (const SetVector< BasicBlock * > &Blocks)
static void applyFirstDebugLoc (Function *oldFunction, ArrayRef< BasicBlock * > Blocks, Instruction *BranchI)
If the original function has debug info, we have to add a debug location to the new branch instruction from the artificial entry block.
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.
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.
static void eraseDebugIntrinsicsWithNonLocalRefs (Function &F)
Erase debug info intrinsics which refer to values in F but aren't in F.
static void fixupDebugInfoPostExtraction (Function &OldFunc, Function &NewFunc, CallInst &TheCall, const SetVector< Value * > &Inputs, ArrayRef< Value * > NewValues)
Fix up the debug info in the old and new functions.

DEBUG_TYPE

#define DEBUG_TYPE "code-extractor"

applyFirstDebugLoc()

buildExtractionBlockSet()

definedInCaller()

definedInRegion()

eraseDebugIntrinsicsWithNonLocalRefs()

void eraseDebugIntrinsicsWithNonLocalRefs ( Function & F) static

eraseLifetimeMarkersOnInputs()

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 1091 of file CodeExtractor.cpp.

References llvm::SetVector< T, Vector, Set, N >::count(), definedInRegion(), llvm::dyn_cast(), I, II, llvm::SetVector< T, Vector, Set, N >::insert(), and llvm::make_early_inc_range().

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

fixupDebugInfoPostExtraction()

Fix up the debug info in the old and new functions.

Following changes are done.

  1. If a debug record points to a value that has been replaced, update the record to use the new value.
  2. If an Input value that has been replaced was used as a location of a debug record in the Parent function, then materealize a similar record in the new function.
  3. Point line locations and debug intrinsics to the new subprogram scope
  4. Remove intrinsics which point to values outside of the new function.

Definition at line 1238 of file CodeExtractor.cpp.

References llvm::any_of(), assert(), llvm::cast(), llvm::DILocalScope::cloneScopeForSubprogram(), llvm::DIBuilder::createAutoVariable(), llvm::DIBuilder::createExpression(), llvm::DIBuilder::createFunction(), llvm::DIBuilder::createSubroutineType(), DL, llvm::dyn_cast(), llvm::dyn_cast_or_null(), eraseDebugIntrinsicsWithNonLocalRefs(), llvm::DIBuilder::finalizeSubprogram(), llvm::findDbgUsers(), llvm::MDNode::get(), llvm::DbgVariableRecord::getAddress(), llvm::DILabel::getColumn(), llvm::Function::getContext(), llvm::DILabel::getCoroSuspendIdx(), llvm::DbgRecord::getDebugLoc(), llvm::Instruction::getDebugLoc(), llvm::Function::getEntryBlock(), llvm::DILabel::getFile(), llvm::DIScope::getFile(), llvm::Function::getFunction(), llvm::DebugLoc::getInlinedAt(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::DILabel::getLine(), llvm::DILabel::getName(), llvm::DIScope::getName(), llvm::Value::getName(), llvm::DIBuilder::getOrCreateTypeArray(), llvm::GlobalValue::getParent(), llvm::DILabel::getScope(), llvm::Function::getSubprogram(), llvm::BasicBlock::getTerminator(), llvm::DbgVariableRecord::getVariable(), I, llvm::DIBuilder::insertDbgValueIntrinsic(), llvm::DIBuilder::insertDeclare(), instructions, llvm::isa(), llvm::DILabel::isArtificial(), llvm::DbgVariableRecord::isDbgAssign(), llvm::DbgVariableRecord::location_ops(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::at::remapAssignID(), llvm::DebugLoc::replaceInlinedAtSubprogram(), llvm::Instruction::setDebugLoc(), llvm::Function::setSubprogram(), llvm::DbgVariableRecord::setVariable(), llvm::stripDebugInfo(), llvm::updateLoopMetadataDebugLocations(), and llvm::zip_equal().

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

getCommonExitBlock()

insertLifetimeMarkersSurroundingCall()

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

Definition at line 1116 of file CodeExtractor.cpp.

References assert(), llvm::cast(), llvm::CallInst::Create(), llvm::ArrayRef< T >::empty(), getFunction(), llvm::Instruction::getFunction(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Intrinsic::getOrInsertDeclaration(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), and llvm::isa().

isAlignmentPreservedForAddrCast()

isBlockValidForExtraction()

Test whether a block is valid for extraction.

Definition at line 83 of file CodeExtractor.cpp.

References llvm::BasicBlock::begin(), llvm::cast(), llvm::dyn_cast(), E(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::BasicBlock::end(), F, getParent(), llvm::BasicBlock::hasAddressTaken(), I, II, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::isa(), llvm::make_pointer_range(), llvm::User::operands(), llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by buildExtractionBlockSet().

AggregateArgsOpt

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