Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:43

0001 //===- Local.h - Functions to perform local transformations -----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This family of functions perform various local transformations to the
0010 // program.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
0015 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
0016 
0017 #include "llvm/ADT/ArrayRef.h"
0018 #include "llvm/IR/Dominators.h"
0019 #include "llvm/Support/CommandLine.h"
0020 #include "llvm/Transforms/Utils/SimplifyCFGOptions.h"
0021 #include "llvm/Transforms/Utils/ValueMapper.h"
0022 #include <cstdint>
0023 
0024 namespace llvm {
0025 
0026 class DataLayout;
0027 class Value;
0028 class WeakTrackingVH;
0029 class WeakVH;
0030 template <typename T> class SmallVectorImpl;
0031 class AAResults;
0032 class AllocaInst;
0033 class AssumptionCache;
0034 class BasicBlock;
0035 class BranchInst;
0036 class CallBase;
0037 class CallInst;
0038 class DbgVariableIntrinsic;
0039 class DIBuilder;
0040 class DomTreeUpdater;
0041 class Function;
0042 class Instruction;
0043 class InvokeInst;
0044 class LoadInst;
0045 class MDNode;
0046 class MemorySSAUpdater;
0047 class PHINode;
0048 class StoreInst;
0049 class TargetLibraryInfo;
0050 class TargetTransformInfo;
0051 
0052 //===----------------------------------------------------------------------===//
0053 //  Local constant propagation.
0054 //
0055 
0056 /// If a terminator instruction is predicated on a constant value, convert it
0057 /// into an unconditional branch to the constant destination.
0058 /// This is a nontrivial operation because the successors of this basic block
0059 /// must have their PHI nodes updated.
0060 /// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
0061 /// conditions and indirectbr addresses this might make dead if
0062 /// DeleteDeadConditions is true.
0063 bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
0064                             const TargetLibraryInfo *TLI = nullptr,
0065                             DomTreeUpdater *DTU = nullptr);
0066 
0067 //===----------------------------------------------------------------------===//
0068 //  Local dead code elimination.
0069 //
0070 
0071 /// Return true if the result produced by the instruction is not used, and the
0072 /// instruction will return. Certain side-effecting instructions are also
0073 /// considered dead if there are no uses of the instruction.
0074 bool isInstructionTriviallyDead(Instruction *I,
0075                                 const TargetLibraryInfo *TLI = nullptr);
0076 
0077 /// Return true if the result produced by the instruction would have no side
0078 /// effects if it was not used. This is equivalent to checking whether
0079 /// isInstructionTriviallyDead would be true if the use count was 0.
0080 bool wouldInstructionBeTriviallyDead(const Instruction *I,
0081                                      const TargetLibraryInfo *TLI = nullptr);
0082 
0083 /// Return true if the result produced by the instruction has no side effects on
0084 /// any paths other than where it is used. This is less conservative than
0085 /// wouldInstructionBeTriviallyDead which is based on the assumption
0086 /// that the use count will be 0. An example usage of this API is for
0087 /// identifying instructions that can be sunk down to use(s).
0088 bool wouldInstructionBeTriviallyDeadOnUnusedPaths(
0089     Instruction *I, const TargetLibraryInfo *TLI = nullptr);
0090 
0091 /// If the specified value is a trivially dead instruction, delete it.
0092 /// If that makes any of its operands trivially dead, delete them too,
0093 /// recursively. Return true if any instructions were deleted.
0094 bool RecursivelyDeleteTriviallyDeadInstructions(
0095     Value *V, const TargetLibraryInfo *TLI = nullptr,
0096     MemorySSAUpdater *MSSAU = nullptr,
0097     std::function<void(Value *)> AboutToDeleteCallback =
0098         std::function<void(Value *)>());
0099 
0100 /// Delete all of the instructions in `DeadInsts`, and all other instructions
0101 /// that deleting these in turn causes to be trivially dead.
0102 ///
0103 /// The initial instructions in the provided vector must all have empty use
0104 /// lists and satisfy `isInstructionTriviallyDead`.
0105 ///
0106 /// `DeadInsts` will be used as scratch storage for this routine and will be
0107 /// empty afterward.
0108 void RecursivelyDeleteTriviallyDeadInstructions(
0109     SmallVectorImpl<WeakTrackingVH> &DeadInsts,
0110     const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr,
0111     std::function<void(Value *)> AboutToDeleteCallback =
0112         std::function<void(Value *)>());
0113 
0114 /// Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow
0115 /// instructions that are not trivially dead. These will be ignored.
0116 /// Returns true if any changes were made, i.e. any instructions trivially dead
0117 /// were found and deleted.
0118 bool RecursivelyDeleteTriviallyDeadInstructionsPermissive(
0119     SmallVectorImpl<WeakTrackingVH> &DeadInsts,
0120     const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr,
0121     std::function<void(Value *)> AboutToDeleteCallback =
0122         std::function<void(Value *)>());
0123 
0124 /// If the specified value is an effectively dead PHI node, due to being a
0125 /// def-use chain of single-use nodes that either forms a cycle or is terminated
0126 /// by a trivially dead instruction, delete it. If that makes any of its
0127 /// operands trivially dead, delete them too, recursively. Return true if a
0128 /// change was made.
0129 bool RecursivelyDeleteDeadPHINode(PHINode *PN,
0130                                   const TargetLibraryInfo *TLI = nullptr,
0131                                   MemorySSAUpdater *MSSAU = nullptr);
0132 
0133 /// Scan the specified basic block and try to simplify any instructions in it
0134 /// and recursively delete dead instructions.
0135 ///
0136 /// This returns true if it changed the code, note that it can delete
0137 /// instructions in other blocks as well in this block.
0138 bool SimplifyInstructionsInBlock(BasicBlock *BB,
0139                                  const TargetLibraryInfo *TLI = nullptr);
0140 
0141 /// Replace all the uses of an SSA value in @llvm.dbg intrinsics with
0142 /// undef. This is useful for signaling that a variable, e.g. has been
0143 /// found dead and hence it's unavailable at a given program point.
0144 /// Returns true if the dbg values have been changed.
0145 bool replaceDbgUsesWithUndef(Instruction *I);
0146 
0147 //===----------------------------------------------------------------------===//
0148 //  Control Flow Graph Restructuring.
0149 //
0150 
0151 /// BB is a block with one predecessor and its predecessor is known to have one
0152 /// successor (BB!). Eliminate the edge between them, moving the instructions in
0153 /// the predecessor into BB. This deletes the predecessor block.
0154 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
0155 
0156 /// BB is known to contain an unconditional branch, and contains no instructions
0157 /// other than PHI nodes, potential debug intrinsics and the branch. If
0158 /// possible, eliminate BB by rewriting all the predecessors to branch to the
0159 /// successor block and return true. If we can't transform, return false.
0160 bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
0161                                              DomTreeUpdater *DTU = nullptr);
0162 
0163 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
0164 /// to be clever about PHI nodes which differ only in the order of the incoming
0165 /// values, but instcombine orders them so it usually won't matter.
0166 ///
0167 /// This overload removes the duplicate PHI nodes directly.
0168 bool EliminateDuplicatePHINodes(BasicBlock *BB);
0169 
0170 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
0171 /// to be clever about PHI nodes which differ only in the order of the incoming
0172 /// values, but instcombine orders them so it usually won't matter.
0173 ///
0174 /// This overload collects the PHI nodes to be removed into the ToRemove set.
0175 bool EliminateDuplicatePHINodes(BasicBlock *BB,
0176                                 SmallPtrSetImpl<PHINode *> &ToRemove);
0177 
0178 /// This function is used to do simplification of a CFG.  For example, it
0179 /// adjusts branches to branches to eliminate the extra hop, it eliminates
0180 /// unreachable basic blocks, and does other peephole optimization of the CFG.
0181 /// It returns true if a modification was made, possibly deleting the basic
0182 /// block that was pointed to. LoopHeaders is an optional input parameter
0183 /// providing the set of loop headers that SimplifyCFG should not eliminate.
0184 extern cl::opt<bool> RequireAndPreserveDomTree;
0185 bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
0186                  DomTreeUpdater *DTU = nullptr,
0187                  const SimplifyCFGOptions &Options = {},
0188                  ArrayRef<WeakVH> LoopHeaders = {});
0189 
0190 /// This function is used to flatten a CFG. For example, it uses parallel-and
0191 /// and parallel-or mode to collapse if-conditions and merge if-regions with
0192 /// identical statements.
0193 bool FlattenCFG(BasicBlock *BB, AAResults *AA = nullptr);
0194 
0195 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
0196 /// branches to us and one of our successors, fold the setcc into the
0197 /// predecessor and use logical operations to pick the right destination.
0198 bool foldBranchToCommonDest(BranchInst *BI, llvm::DomTreeUpdater *DTU = nullptr,
0199                             MemorySSAUpdater *MSSAU = nullptr,
0200                             const TargetTransformInfo *TTI = nullptr,
0201                             unsigned BonusInstThreshold = 1);
0202 
0203 /// This function takes a virtual register computed by an Instruction and
0204 /// replaces it with a slot in the stack frame, allocated via alloca.
0205 /// This allows the CFG to be changed around without fear of invalidating the
0206 /// SSA information for the value. It returns the pointer to the alloca inserted
0207 /// to create a stack slot for X.
0208 AllocaInst *DemoteRegToStack(Instruction &X,
0209                              bool VolatileLoads = false,
0210                              std::optional<BasicBlock::iterator> AllocaPoint = std::nullopt);
0211 
0212 /// This function takes a virtual register computed by a phi node and replaces
0213 /// it with a slot in the stack frame, allocated via alloca. The phi node is
0214 /// deleted and it returns the pointer to the alloca inserted.
0215 AllocaInst *DemotePHIToStack(PHINode *P, std::optional<BasicBlock::iterator> AllocaPoint = std::nullopt);
0216 
0217 /// If the specified pointer points to an object that we control, try to modify
0218 /// the object's alignment to PrefAlign. Returns a minimum known alignment of
0219 /// the value after the operation, which may be lower than PrefAlign.
0220 ///
0221 /// Increating value alignment isn't often possible though. If alignment is
0222 /// important, a more reliable approach is to simply align all global variables
0223 /// and allocation instructions to their preferred alignment from the beginning.
0224 Align tryEnforceAlignment(Value *V, Align PrefAlign, const DataLayout &DL);
0225 
0226 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
0227 /// the owning object can be modified and has an alignment less than \p
0228 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
0229 /// cannot be increased, the known alignment of the value is returned.
0230 ///
0231 /// It is not always possible to modify the alignment of the underlying object,
0232 /// so if alignment is important, a more reliable approach is to simply align
0233 /// all global variables and allocation instructions to their preferred
0234 /// alignment from the beginning.
0235 Align getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign,
0236                                  const DataLayout &DL,
0237                                  const Instruction *CxtI = nullptr,
0238                                  AssumptionCache *AC = nullptr,
0239                                  const DominatorTree *DT = nullptr);
0240 
0241 /// Try to infer an alignment for the specified pointer.
0242 inline Align getKnownAlignment(Value *V, const DataLayout &DL,
0243                                const Instruction *CxtI = nullptr,
0244                                AssumptionCache *AC = nullptr,
0245                                const DominatorTree *DT = nullptr) {
0246   return getOrEnforceKnownAlignment(V, MaybeAlign(), DL, CxtI, AC, DT);
0247 }
0248 
0249 /// Create a call that matches the invoke \p II in terms of arguments,
0250 /// attributes, debug information, etc. The call is not placed in a block and it
0251 /// will not have a name. The invoke instruction is not removed, nor are the
0252 /// uses replaced by the new call.
0253 CallInst *createCallMatchingInvoke(InvokeInst *II);
0254 
0255 /// This function converts the specified invoke into a normal call.
0256 CallInst *changeToCall(InvokeInst *II, DomTreeUpdater *DTU = nullptr);
0257 
0258 ///===---------------------------------------------------------------------===//
0259 ///  Dbg Intrinsic utilities
0260 ///
0261 
0262 /// Creates and inserts a dbg_value record intrinsic before a store
0263 /// that has an associated llvm.dbg.value intrinsic.
0264 void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI,
0265                                 DIBuilder &Builder);
0266 
0267 /// Creates and inserts an llvm.dbg.value intrinsic before a store
0268 /// that has an associated llvm.dbg.value intrinsic.
0269 void InsertDebugValueAtStoreLoc(DbgVariableIntrinsic *DII, StoreInst *SI,
0270                                 DIBuilder &Builder);
0271 
0272 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
0273 /// that has an associated llvm.dbg.declare intrinsic.
0274 void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
0275                                      StoreInst *SI, DIBuilder &Builder);
0276 void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, StoreInst *SI,
0277                                      DIBuilder &Builder);
0278 
0279 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
0280 /// that has an associated llvm.dbg.declare intrinsic.
0281 void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
0282                                      LoadInst *LI, DIBuilder &Builder);
0283 void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, LoadInst *LI,
0284                                      DIBuilder &Builder);
0285 
0286 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
0287 /// llvm.dbg.declare intrinsic.
0288 void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
0289                                      PHINode *LI, DIBuilder &Builder);
0290 void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, PHINode *LI,
0291                                      DIBuilder &Builder);
0292 
0293 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
0294 /// llvm.dbg.value intrinsics.
0295 bool LowerDbgDeclare(Function &F);
0296 
0297 /// Propagate dbg.value intrinsics through the newly inserted PHIs.
0298 void insertDebugValuesForPHIs(BasicBlock *BB,
0299                               SmallVectorImpl<PHINode *> &InsertedPHIs);
0300 
0301 /// Replaces llvm.dbg.declare instruction when the address it
0302 /// describes is replaced with a new value. If Deref is true, an
0303 /// additional DW_OP_deref is prepended to the expression. If Offset
0304 /// is non-zero, a constant displacement is added to the expression
0305 /// (between the optional Deref operations). Offset can be negative.
0306 bool replaceDbgDeclare(Value *Address, Value *NewAddress, DIBuilder &Builder,
0307                        uint8_t DIExprFlags, int Offset);
0308 
0309 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
0310 /// is replaced with a new value. If Offset is non-zero, a constant displacement
0311 /// is added to the expression (after the mandatory Deref). Offset can be
0312 /// negative. New llvm.dbg.value instructions are inserted at the locations of
0313 /// the instructions they replace.
0314 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
0315                               DIBuilder &Builder, int Offset = 0);
0316 
0317 /// Assuming the instruction \p I is going to be deleted, attempt to salvage
0318 /// debug users of \p I by writing the effect of \p I in a DIExpression. If it
0319 /// cannot be salvaged changes its debug uses to undef.
0320 void salvageDebugInfo(Instruction &I);
0321 
0322 /// Implementation of salvageDebugInfo, applying only to instructions in
0323 /// \p Insns, rather than all debug users from findDbgUsers( \p I).
0324 /// Mark undef if salvaging cannot be completed.
0325 void salvageDebugInfoForDbgValues(Instruction &I,
0326                                   ArrayRef<DbgVariableIntrinsic *> Insns,
0327                                   ArrayRef<DbgVariableRecord *> DPInsns);
0328 
0329 /// Given an instruction \p I and DIExpression \p DIExpr operating on
0330 /// it, append the effects of \p I to the DIExpression operand list
0331 /// \p Ops, or return \p nullptr if it cannot be salvaged.
0332 /// \p CurrentLocOps is the number of SSA values referenced by the
0333 /// incoming \p Ops.  \return the first non-constant operand
0334 /// implicitly referred to by Ops. If \p I references more than one
0335 /// non-constant operand, any additional operands are added to
0336 /// \p AdditionalValues.
0337 ///
0338 /// \example
0339 ////
0340 ///   I = add %a, i32 1
0341 ///
0342 ///   Return = %a
0343 ///   Ops = llvm::dwarf::DW_OP_lit1 llvm::dwarf::DW_OP_add
0344 ///
0345 ///   I = add %a, %b
0346 ///
0347 ///   Return = %a
0348 ///   Ops = llvm::dwarf::DW_OP_LLVM_arg0 llvm::dwarf::DW_OP_add
0349 ///   AdditionalValues = %b
0350 Value *salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
0351                             SmallVectorImpl<uint64_t> &Ops,
0352                             SmallVectorImpl<Value *> &AdditionalValues);
0353 
0354 /// Point debug users of \p From to \p To or salvage them. Use this function
0355 /// only when replacing all uses of \p From with \p To, with a guarantee that
0356 /// \p From is going to be deleted.
0357 ///
0358 /// Follow these rules to prevent use-before-def of \p To:
0359 ///   . If \p To is a linked Instruction, set \p DomPoint to \p To.
0360 ///   . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
0361 ///     \p To will be inserted after.
0362 ///   . If \p To is not an Instruction (e.g a Constant), the choice of
0363 ///     \p DomPoint is arbitrary. Pick \p From for simplicity.
0364 ///
0365 /// If a debug user cannot be preserved without reordering variable updates or
0366 /// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
0367 /// or deleted. Returns true if any debug users were updated.
0368 bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint,
0369                            DominatorTree &DT);
0370 
0371 /// If a terminator in an unreachable basic block has an operand of type
0372 /// Instruction, transform it into poison. Return true if any operands
0373 /// are changed to poison. Original Values prior to being changed to poison
0374 /// are returned in \p PoisonedValues.
0375 bool handleUnreachableTerminator(Instruction *I,
0376                                  SmallVectorImpl<Value *> &PoisonedValues);
0377 
0378 /// Remove all instructions from a basic block other than its terminator
0379 /// and any present EH pad instructions. Returns a pair where the first element
0380 /// is the number of instructions (excluding debug info intrinsics) that have
0381 /// been removed, and the second element is the number of debug info intrinsics
0382 /// that have been removed.
0383 std::pair<unsigned, unsigned>
0384 removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB);
0385 
0386 /// Insert an unreachable instruction before the specified
0387 /// instruction, making it and the rest of the code in the block dead.
0388 unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA = false,
0389                              DomTreeUpdater *DTU = nullptr,
0390                              MemorySSAUpdater *MSSAU = nullptr);
0391 
0392 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
0393 /// block.  This also splits the basic block where CI is located, because
0394 /// InvokeInst is a terminator instruction.  Returns the newly split basic
0395 /// block.
0396 BasicBlock *changeToInvokeAndSplitBasicBlock(CallInst *CI,
0397                                              BasicBlock *UnwindEdge,
0398                                              DomTreeUpdater *DTU = nullptr);
0399 
0400 /// Replace 'BB's terminator with one that does not have an unwind successor
0401 /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
0402 /// successor. Returns the instruction that replaced the original terminator,
0403 /// which might be a call in case the original terminator was an invoke.
0404 ///
0405 /// \param BB  Block whose terminator will be replaced.  Its terminator must
0406 ///            have an unwind successor.
0407 Instruction *removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
0408 
0409 /// Remove all blocks that can not be reached from the function's entry.
0410 ///
0411 /// Returns true if any basic block was removed.
0412 bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU = nullptr,
0413                              MemorySSAUpdater *MSSAU = nullptr);
0414 
0415 /// Combine the metadata of two instructions so that K can replace J. This
0416 /// specifically handles the case of CSE-like transformations. Some
0417 /// metadata can only be kept if K dominates J. For this to be correct,
0418 /// K cannot be hoisted.
0419 ///
0420 /// Unknown metadata is removed.
0421 void combineMetadataForCSE(Instruction *K, const Instruction *J,
0422                            bool DoesKMove);
0423 
0424 /// Combine metadata of two instructions, where instruction J is a memory
0425 /// access that has been merged into K. This will intersect alias-analysis
0426 /// metadata, while preserving other known metadata.
0427 void combineAAMetadata(Instruction *K, const Instruction *J);
0428 
0429 /// Copy the metadata from the source instruction to the destination (the
0430 /// replacement for the source instruction).
0431 void copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source);
0432 
0433 /// Patch the replacement so that it is not more restrictive than the value
0434 /// being replaced. It assumes that the replacement does not get moved from
0435 /// its original position.
0436 void patchReplacementInstruction(Instruction *I, Value *Repl);
0437 
0438 // Replace each use of 'From' with 'To', if that use does not belong to basic
0439 // block where 'From' is defined. Returns the number of replacements made.
0440 unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
0441 
0442 /// Replace each use of 'From' with 'To' if that use is dominated by
0443 /// the given edge.  Returns the number of replacements made.
0444 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
0445                                   const BasicBlockEdge &Edge);
0446 /// Replace each use of 'From' with 'To' if that use is dominated by
0447 /// the end of the given BasicBlock. Returns the number of replacements made.
0448 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
0449                                   const BasicBlock *BB);
0450 /// Replace each use of 'From' with 'To' if that use is dominated by
0451 /// the given edge and the callback ShouldReplace returns true. Returns the
0452 /// number of replacements made.
0453 unsigned replaceDominatedUsesWithIf(
0454     Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge,
0455     function_ref<bool(const Use &U, const Value *To)> ShouldReplace);
0456 /// Replace each use of 'From' with 'To' if that use is dominated by
0457 /// the end of the given BasicBlock and the callback ShouldReplace returns true.
0458 /// Returns the number of replacements made.
0459 unsigned replaceDominatedUsesWithIf(
0460     Value *From, Value *To, DominatorTree &DT, const BasicBlock *BB,
0461     function_ref<bool(const Use &U, const Value *To)> ShouldReplace);
0462 
0463 /// Return true if this call calls a gc leaf function.
0464 ///
0465 /// A leaf function is a function that does not safepoint the thread during its
0466 /// execution.  During a call or invoke to such a function, the callers stack
0467 /// does not have to be made parseable.
0468 ///
0469 /// Most passes can and should ignore this information, and it is only used
0470 /// during lowering by the GC infrastructure.
0471 bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI);
0472 
0473 /// Copy a nonnull metadata node to a new load instruction.
0474 ///
0475 /// This handles mapping it to range metadata if the new load is an integer
0476 /// load instead of a pointer load.
0477 void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
0478 
0479 /// Copy a range metadata node to a new load instruction.
0480 ///
0481 /// This handles mapping it to nonnull metadata if the new load is a pointer
0482 /// load instead of an integer load and the range doesn't cover null.
0483 void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
0484                        LoadInst &NewLI);
0485 
0486 /// Remove the debug intrinsic instructions for the given instruction.
0487 void dropDebugUsers(Instruction &I);
0488 
0489 /// Hoist all of the instructions in the \p IfBlock to the dominant block
0490 /// \p DomBlock, by moving its instructions to the insertion point \p InsertPt.
0491 ///
0492 /// The moved instructions receive the insertion point debug location values
0493 /// (DILocations) and their debug intrinsic instructions are removed.
0494 void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,
0495                               BasicBlock *BB);
0496 
0497 /// Given a constant, create a debug information expression.
0498 DIExpression *getExpressionForConstant(DIBuilder &DIB, const Constant &C,
0499                                        Type &Ty);
0500 
0501 /// Remap the operands of the debug records attached to \p Inst, and the
0502 /// operands of \p Inst itself if it's a debug intrinsic.
0503 void remapDebugVariable(ValueToValueMapTy &Mapping, Instruction *Inst);
0504 
0505 //===----------------------------------------------------------------------===//
0506 //  Intrinsic pattern matching
0507 //
0508 
0509 /// Try to match a bswap or bitreverse idiom.
0510 ///
0511 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
0512 /// instructions are returned in \c InsertedInsts. They will all have been added
0513 /// to a basic block.
0514 ///
0515 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
0516 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
0517 /// to BW / 4 nodes to be searched, so is significantly faster.
0518 ///
0519 /// This function returns true on a successful match or false otherwise.
0520 bool recognizeBSwapOrBitReverseIdiom(
0521     Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
0522     SmallVectorImpl<Instruction *> &InsertedInsts);
0523 
0524 //===----------------------------------------------------------------------===//
0525 //  Sanitizer utilities
0526 //
0527 
0528 /// Given a CallInst, check if it calls a string function known to CodeGen,
0529 /// and mark it with NoBuiltin if so.  To be used by sanitizers that intend
0530 /// to intercept string functions and want to avoid converting them to target
0531 /// specific instructions.
0532 void maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI,
0533                                             const TargetLibraryInfo *TLI);
0534 
0535 //===----------------------------------------------------------------------===//
0536 //  Transform predicates
0537 //
0538 
0539 /// Given an instruction, is it legal to set operand OpIdx to a non-constant
0540 /// value?
0541 bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
0542 
0543 //===----------------------------------------------------------------------===//
0544 //  Value helper functions
0545 //
0546 
0547 /// Invert the given true/false value, possibly reusing an existing copy.
0548 Value *invertCondition(Value *Condition);
0549 
0550 
0551 //===----------------------------------------------------------------------===//
0552 //  Assorted
0553 //
0554 
0555 /// If we can infer one attribute from another on the declaration of a
0556 /// function, explicitly materialize the maximal set in the IR.
0557 bool inferAttributesFromOthers(Function &F);
0558 
0559 } // end namespace llvm
0560 
0561 #endif // LLVM_TRANSFORMS_UTILS_LOCAL_H