LLVM 20.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/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... | |
Namespaces | |
namespace | std |
Implement std::hash so that hash_code can be used in STL containers. | |
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 42 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 85 of file AssignmentTrackingAnalysis.cpp.
|
static |
Definition at line 2767 of file AssignmentTrackingAnalysis.cpp.
References findVarsWithStackSlot(), 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.
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 2151 of file AssignmentTrackingAnalysis.cpp.
References FunctionVarLocsBuilder::addSingleLocVar(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::at::calculateFragmentIntersect(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains(), DynCastToDbgDeclare(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::filterDbgVars(), fullyContains(), llvm::at::getAssignmentMarkers(), llvm::Function::getDataLayout(), llvm::DbgRecord::getDebugLoc(), llvm::at::getDVRAssignmentMarkers(), llvm::DbgVariableRecord::getExpression(), llvm::DebugVariable::getInlinedAt(), FunctionVarLocsBuilder::getNumVariables(), llvm::DbgVariableRecord::getRawLocation(), getUntaggedStoreAssignmentInfo(), llvm::DebugVariable::getVariable(), I, Info, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), FunctionVarLocsBuilder::insertVariable(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
DbgAssignIntrinsic * CastToDbgAssign | ( | DbgVariableIntrinsic * | DVI | ) |
Definition at line 1515 of file AssignmentTrackingAnalysis.cpp.
DbgVariableRecord * CastToDbgAssign | ( | DbgVariableRecord * | DVR | ) |
Definition at line 1519 of file AssignmentTrackingAnalysis.cpp.
References assert(), and llvm::DbgVariableRecord::isDbgAssign().
DbgDeclareInst * DynCastToDbgDeclare | ( | DbgVariableIntrinsic * | DVI | ) |
Definition at line 2125 of file AssignmentTrackingAnalysis.cpp.
Referenced by buildOverlapMapAndRecordDeclares().
DbgVariableRecord * DynCastToDbgDeclare | ( | DbgVariableRecord * | DVR | ) |
Definition at line 2129 of file AssignmentTrackingAnalysis.cpp.
References llvm::DbgVariableRecord::isDbgDeclare().
|
static |
Definition at line 2747 of file AssignmentTrackingAnalysis.cpp.
References llvm::at::getAssignmentMarkers(), 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 2098 of file AssignmentTrackingAnalysis.cpp.
Referenced by buildOverlapMapAndRecordDeclares().
|
static |
Definition at line 329 of file AssignmentTrackingAnalysis.cpp.
References llvm::Instruction::getDebugLoc(), llvm::DebugLoc::getInlinedAt(), and llvm::DbgVariableIntrinsic::getVariable().
Referenced by removeRedundantDbgLocsUsingBackwardScan().
|
static |
Definition at line 332 of file AssignmentTrackingAnalysis.cpp.
References llvm::DebugVariable::getInlinedAt(), and llvm::DebugVariable::getVariable().
|
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 1453 of file AssignmentTrackingAnalysis.cpp.
References I.
|
static |
Definition at line 1457 of file AssignmentTrackingAnalysis.cpp.
References llvm::DbgAssignIntrinsic::getAssignID().
|
static |
Definition at line 1461 of file AssignmentTrackingAnalysis.cpp.
References assert(), llvm::DbgVariableRecord::getAssignID(), and llvm::DbgVariableRecord::isDbgAssign().
VarLocInsertPt getNextNode | ( | const DbgRecord * | DVR | ) |
Definition at line 1497 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 1503 of file AssignmentTrackingAnalysis.cpp.
References llvm::Instruction::getDbgRecordRange(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), and llvm::Instruction::hasDbgRecords().
VarLocInsertPt getNextNode | ( | VarLocInsertPt | InsertPt | ) |
Definition at line 1509 of file AssignmentTrackingAnalysis.cpp.
References getNextNode().
|
static |
Definition at line 2113 of file AssignmentTrackingAnalysis.cpp.
References llvm::at::getAssignmentInfo(), I, and MI.
Referenced by buildOverlapMapAndRecordDeclares().
Definition at line 1843 of file AssignmentTrackingAnalysis.cpp.
References F.
Definition at line 1483 of file AssignmentTrackingAnalysis.cpp.
References llvm_unreachable.
|
static |
Definition at line 2733 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 2491 of file AssignmentTrackingAnalysis.cpp.
References llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::divideCeil(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::DbgVariableFragmentInfo::endInBits(), 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(), llvm::DbgVariableFragmentInfo::startInBits(), 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 2589 of file AssignmentTrackingAnalysis.cpp.
References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::filterDbgVars(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::DebugVariable::getVariable(), FunctionVarLocsBuilder::getVariable(), FunctionVarLocsBuilder::getWedge(), I, llvm::SmallVectorTemplateBase< T, bool >::push_back(), and FunctionVarLocsBuilder::setWedge().
Referenced by removeRedundantDbgLocs().
|
static |
Definition at line 2648 of file AssignmentTrackingAnalysis.cpp.
References A, llvm::any_of(), assert(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::filterDbgVars(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::DebugVariable::getVariable(), FunctionVarLocsBuilder::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 336 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 llvm::DIExpression::append(), DL, End, 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().