-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC][KeyInstr] Add Atom Group (re)mapping #133479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Add: mapAtomInstance - map the atom group number to a new group. RemapSourceAtom - apply the mapped atom group number to this instruction. Modify: CloneBasicBlock - Call mapAtomInstance on cloned instruction's DebugLocs if MapAtoms is true (default). Setting to false could lead to a degraded debugging experience. See code comment. Optimisations like loop unroll that duplicate instructions need to remap source atom groups so that each duplicated source construct instance is considered distinct when determining is_stmt locations. This commit adds the remapping functionality and a unittest.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#include "llvm/Analysis/AssumptionCache.h" | ||
#include "llvm/Analysis/InlineCost.h" | ||
#include "llvm/IR/BasicBlock.h" | ||
#include "llvm/IR/DebugLoc.h" | ||
#include "llvm/IR/ValueHandle.h" | ||
#include "llvm/Transforms/Utils/ValueMapper.h" | ||
#include <functional> | ||
|
@@ -117,9 +118,21 @@ struct ClonedCodeInfo { | |
/// If you would like to collect additional information about the cloned | ||
/// function, you can specify a ClonedCodeInfo object with the optional fifth | ||
/// parameter. | ||
/// | ||
/// Set \p MapAtoms to false to skip mapping source atoms for later remapping. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO "source-location atoms" to make it even clearer that this is a debugging feature. Also IMO it's better to discuss when this flag is necessary instead of when it's not necessary, as it'll enlighten the reader what it's for. AFAIUI, something like "Must be true when you duplicate a code path and a source line is intended to appear twice in the generated instructions. Can be set to false if you are transplanting code from one place to another". |
||
/// Incorrectly setting false may harm the debugging experience. It's safe to | ||
/// set false if the cloned basic block is destined for a different function or | ||
/// if the original block is deleted. Setting true (default) is always safe | ||
/// (correct) but sometimes unecessary; this option reduces the compile-time | ||
/// impact of Key Instruction in such cases. | ||
BasicBlock *CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, | ||
const Twine &NameSuffix = "", Function *F = nullptr, | ||
ClonedCodeInfo *CodeInfo = nullptr); | ||
ClonedCodeInfo *CodeInfo = nullptr, | ||
bool MapAtoms = true); | ||
|
||
/// Mark a cloned instruction as a new instance so that its source loc can | ||
/// be updated when remapped. | ||
void mapAtomInstance(const DebugLoc &DL, ValueToValueMapTy &VMap); | ||
|
||
/// Return a copy of the specified function and add it to that | ||
/// function's module. Also, any references specified in the VMap are changed | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -105,6 +105,13 @@ enum RemapFlags { | |||||||||
/// Any global values not in value map are mapped to null instead of mapping | ||||||||||
/// to self. Illegal if RF_IgnoreMissingLocals is also set. | ||||||||||
RF_NullMapMissingGlobalValues = 8, | ||||||||||
|
||||||||||
/// Do not remap atom instances. Only safe if to do this if the cloned | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO needs "source location atom" instead of just "atom" to ensure the random reader knows it's about debug-info. |
||||||||||
/// instructions being remapped are inserted into a new function, or an | ||||||||||
/// existing function where the inlined-at fields are updated. If in doubt, | ||||||||||
/// don't use this flag. It's used for compiler performance reasons rather | ||||||||||
/// than correctness. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO suggesting that it's not related to correctness is misleading, because the presence/absence of the flag can lead to correctness issues. Better to just avoid saying that and say something else as suggested. |
||||||||||
RF_DoNotRemapAtoms = 16, | ||||||||||
}; | ||||||||||
|
||||||||||
inline RemapFlags operator|(RemapFlags LHS, RemapFlags RHS) { | ||||||||||
|
@@ -284,6 +291,9 @@ inline void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, | |||||||||
.remapInstruction(*I); | ||||||||||
} | ||||||||||
|
||||||||||
/// Remap source atom. Called by RemapInstruction. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO too terse; needs some purpose and context. |
||||||||||
void RemapSourceAtom(Instruction *I, ValueToValueMapTy &VM); | ||||||||||
|
||||||||||
/// Remap the Values used in the DbgRecord \a DR using the value map \a | ||||||||||
/// VM. | ||||||||||
inline void RemapDbgRecord(Module *M, DbgRecord *DR, ValueToValueMapTy &VM, | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using SmallDenseMap simply to reduce the initial allocations in the non-debug-info codepath?