LLVM 22.0.0git
|
#include "llvm/CodeGen/AssignmentTrackingAnalysis.h"
#include "LiveDebugValues/LiveDebugValues.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/UniqueVector.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugProgramInstruction.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/PrintPasses.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include <assert.h>
#include <cstdint>
#include <optional>
#include <queue>
#include <sstream>
#include <unordered_map>
Go to the source code of this file.
Classes | |
struct | llvm::DenseMapInfo< VariableID > |
struct | std::hash< VarLocInsertPt > |
class | FunctionVarLocsBuilder |
Helper class to build FunctionVarLocs, since that class isn't easy to modify. More... |
Macros | |
#define | DEBUG_TYPE "debug-ata" |
Typedefs | |
using | VarLocInsertPt = PointerUnion<const Instruction *, const DbgRecord *> |
using | DebugAggregate = std::pair<const DILocalVariable *, const DILocation *> |
A whole (unfragmented) source variable. |
Variables | |
static cl::opt< unsigned > | MaxNumBlocks ("debug-ata-max-blocks", cl::init(10000), cl::desc("Maximum num basic blocks before debug info dropped"), cl::Hidden) |
static cl::opt< bool > | EnableMemLocFragFill ("mem-loc-frag-fill", cl::init(true), cl::Hidden) |
Option for debugging the pass, determines if the memory location fragment filling happens after generating the variable locations. | |
static cl::opt< bool > | PrintResults ("print-debug-ata", cl::init(false), cl::Hidden) |
Print the results of the analysis. Respects -filter-print-funcs. | |
static cl::opt< cl::boolOrDefault > | CoalesceAdjacentFragmentsOpt ("debug-ata-coalesce-frags", cl::Hidden) |
Coalesce adjacent dbg locs describing memory locations that have contiguous fragments. |
#define DEBUG_TYPE "debug-ata" |
Definition at line 43 of file AssignmentTrackingAnalysis.cpp.
using DebugAggregate = std::pair<const DILocalVariable *, const DILocation *> |
A whole (unfragmented) source variable.
Definition at line 328 of file AssignmentTrackingAnalysis.cpp.
using VarLocInsertPt = PointerUnion<const Instruction *, const DbgRecord *> |
Definition at line 86 of file AssignmentTrackingAnalysis.cpp.
|
static |
Definition at line 2734 of file AssignmentTrackingAnalysis.cpp.
References Changed, findVarsWithStackSlot(), Pass, removeRedundantDbgLocs(), and shouldCoalesceFragments().
Referenced by llvm::DebugAssignmentTrackingAnalysis::run(), and llvm::AssignmentTrackingAnalysis::runOnFunction().
|
static |
Build a map of {Variable x: Variables y} where all variable fragments contained within the variable fragment x are in set y.
This means that y does not contain all overlaps because partial overlaps are excluded.
While we're iterating over the function, add single location defs for dbg.declares to FnVarLocs
.
Variables that are interesting to this pass in are added to FnVarLocs->Variables first. TrackedVariablesVectorSize is set to the ID of the last interesting variable plus 1, meaning variables with ID 1 (inclusive) to TrackedVariablesVectorSize (exclusive) are interesting. The subsequent variables are either stack homed or fully promoted.
Finally, populate UntaggedStoreVars with a mapping of untagged stores to the stored-to variable fragments, and UnknownStoreVars with a mapping of untagged unknown stores to the stored-to variable aggregates.
These tasks are bundled together to reduce the number of times we need to iterate over the function as they can be achieved together in one pass.
Definition at line 2117 of file AssignmentTrackingAnalysis.cpp.
References FunctionVarLocsBuilder::addSingleLocVar(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::at::calculateFragmentIntersect(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::filterDbgVars(), fullyContains(), llvm::Function::getDataLayout(), llvm::DbgRecord::getDebugLoc(), llvm::at::getDVRAssignmentMarkers(), llvm::DbgVariableRecord::getExpression(), llvm::DebugVariable::getInlinedAt(), FunctionVarLocsBuilder::getNumVariables(), llvm::DbgVariableRecord::getRawLocation(), getUnknownStore(), getUntaggedStoreAssignmentInfo(), llvm::DebugVariable::getVariable(), I, Info, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), FunctionVarLocsBuilder::insertVariable(), llvm::Next, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
|
static |
Definition at line 2717 of file AssignmentTrackingAnalysis.cpp.
References llvm::DbgRecord::getDebugLoc(), llvm::at::getDVRAssignmentMarkers(), llvm::DebugLoc::getInlinedAt(), llvm::DbgVariableRecord::getVariable(), and I.
Referenced by analyzeFunction().
|
static |
Return true if A fully contains B.
Definition at line 2051 of file AssignmentTrackingAnalysis.cpp.
Referenced by buildOverlapMapAndRecordDeclares().
|
static |
Definition at line 329 of file AssignmentTrackingAnalysis.cpp.
References llvm::DebugVariable::getInlinedAt(), and llvm::DebugVariable::getVariable().
Referenced by removeRedundantDbgLocsUsingBackwardScan().
|
static |
Extract the offset used in DIExpr
.
Returns std::nullopt if the expression doesn't explicitly describe a memory location with DW_OP_deref or if the expression is too complex to interpret.
Definition at line 286 of file AssignmentTrackingAnalysis.cpp.
References llvm::dwarf::DW_OP_LLVM_fragment, llvm::DIExpression::getElements(), llvm::DIExpression::getNumElements(), and llvm::Offset.
|
static |
Definition at line 1426 of file AssignmentTrackingAnalysis.cpp.
References llvm::cast(), and I.
|
static |
Definition at line 1430 of file AssignmentTrackingAnalysis.cpp.
References assert(), llvm::DbgVariableRecord::getAssignID(), and llvm::DbgVariableRecord::isDbgAssign().
VarLocInsertPt getNextNode | ( | const DbgRecord * | DVR | ) |
Definition at line 1466 of file AssignmentTrackingAnalysis.cpp.
References llvm::DbgMarker::getDbgRecordRange(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::DbgRecord::getMarker(), and llvm::DbgMarker::MarkedInstr.
Referenced by getNextNode().
VarLocInsertPt getNextNode | ( | const Instruction * | Inst | ) |
Definition at line 1472 of file AssignmentTrackingAnalysis.cpp.
References llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), and llvm::Next.
VarLocInsertPt getNextNode | ( | VarLocInsertPt | InsertPt | ) |
Definition at line 1478 of file AssignmentTrackingAnalysis.cpp.
References llvm::cast(), getNextNode(), and llvm::isa().
AllocaInst * getUnknownStore | ( | const Instruction & | I, |
const DataLayout & | Layout ) |
Definition at line 2078 of file AssignmentTrackingAnalysis.cpp.
References llvm::sampleprof::Base, llvm::dyn_cast(), llvm::DataLayout::getIndexTypeSizeInBits(), I, II, and llvm::Offset.
Referenced by buildOverlapMapAndRecordDeclares().
|
static |
Definition at line 2066 of file AssignmentTrackingAnalysis.cpp.
References llvm::dyn_cast(), llvm::at::getAssignmentInfo(), I, and MI.
Referenced by buildOverlapMapAndRecordDeclares().
|
static |
Definition at line 1830 of file AssignmentTrackingAnalysis.cpp.
References F.
Definition at line 1452 of file AssignmentTrackingAnalysis.cpp.
References llvm_unreachable.
|
static |
Definition at line 2703 of file AssignmentTrackingAnalysis.cpp.
References llvm::dbgs(), llvm::Value::getName(), llvm::BasicBlock::isEntryBlock(), LLVM_DEBUG, removeRedundantDbgLocsUsingBackwardScan(), removeRedundantDbgLocsUsingForwardScan(), and removeUndefDbgLocsFromEntryBlock().
Referenced by analyzeFunction().
|
static |
Remove redundant definitions within sequences of consecutive location defs.
This is done using a backward scan to keep the last def describing a specific variable/fragment.
This implements removeRedundantDbgInstrsUsingBackwardScan from lib/Transforms/Utils/BasicBlockUtils.cpp for locations described with FunctionVarLocsBuilder instead of with intrinsics.
Definition at line 2464 of file AssignmentTrackingAnalysis.cpp.
References llvm::SmallVectorTemplateCommon< T, typename >::begin(), Changed, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::divideCeil(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::filterDbgVars(), llvm::BitVector::find_first_unset_in(), getAggregate(), FunctionVarLocsBuilder::getVariable(), FunctionVarLocsBuilder::getWedge(), I, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::reverse(), llvm::BitVector::set(), FunctionVarLocsBuilder::setWedge(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().
Referenced by removeRedundantDbgLocs().
|
static |
Remove redundant location defs using a forward scan.
This can remove a location definition that is redundant due to indicating that a variable has the same value as is already being indicated by an earlier def.
This implements removeRedundantDbgInstrsUsingForwardScan from lib/Transforms/Utils/BasicBlockUtils.cpp for locations described with FunctionVarLocsBuilder instead of with intrinsics
Definition at line 2560 of file AssignmentTrackingAnalysis.cpp.
References Changed, llvm::filterDbgVars(), FunctionVarLocsBuilder::getVariable(), llvm::DebugVariable::getVariable(), FunctionVarLocsBuilder::getWedge(), I, llvm::InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key, llvm::SmallVectorTemplateBase< T, bool >::push_back(), FunctionVarLocsBuilder::setWedge(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().
Referenced by removeRedundantDbgLocs().
|
static |
Definition at line 2619 of file AssignmentTrackingAnalysis.cpp.
References A(), llvm::any_of(), assert(), Changed, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::filterDbgVars(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), FunctionVarLocsBuilder::getVariable(), llvm::DebugVariable::getVariable(), FunctionVarLocsBuilder::getWedge(), I, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::BasicBlock::isEntryBlock(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and FunctionVarLocsBuilder::setWedge().
Referenced by removeRedundantDbgLocs().
Definition at line 333 of file AssignmentTrackingAnalysis.cpp.
References llvm::cl::BOU_FALSE, llvm::cl::BOU_TRUE, llvm::cl::BOU_UNSET, CoalesceAdjacentFragmentsOpt, llvm::debuginfoShouldUseDebugInstrRef(), F, and llvm_unreachable.
Referenced by analyzeFunction().
STATISTIC | ( | NumDefsRemoved | , |
"Number of dbg locs removed" | ) |
STATISTIC | ( | NumDefsScanned | , |
"Number of dbg locs that get scanned for removal" | ) |
STATISTIC | ( | NumWedgesChanged | , |
"Number of dbg wedges changed" | ) |
STATISTIC | ( | NumWedgesScanned | , |
"Number of dbg wedges scanned" | ) |
|
static |
Walk backwards along constant GEPs and bitcasts to the base storage from Start
as far as possible.
Prepend \Expression with the offset and append it with a DW_OP_deref that haes been implicit until now. Returns the walked-to value and modified expression.
Definition at line 267 of file AssignmentTrackingAnalysis.cpp.
References AbstractManglingParser< Derived, Alloc >::Ops, llvm::DIExpression::append(), DL, llvm::APInt::getBoolValue(), llvm::APInt::getZExtValue(), and llvm::DIExpression::prependOpcodes().
|
static |
Coalesce adjacent dbg locs describing memory locations that have contiguous fragments.
This reduces the cost of LiveDebugValues which does SSA construction for each explicitly stated variable fragment.
Referenced by shouldCoalesceFragments().
|
static |
Option for debugging the pass, determines if the memory location fragment filling happens after generating the variable locations.
|
static |
|
static |
Print the results of the analysis. Respects -filter-print-funcs.
Referenced by llvm::AssignmentTrackingAnalysis::runOnFunction().