LLVM 24.0.0git
Local.h
Go to the documentation of this file.
1//===- Local.h - Functions to perform local transformations -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This family of functions perform various local transformations to the
10// program.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
15#define LLVM_TRANSFORMS_UTILS_LOCAL_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/IR/Dominators.h"
23#include <cstdint>
24
25namespace llvm {
26
27class DataLayout;
28class Value;
29class WeakTrackingVH;
30class WeakVH;
31template <typename PtrType> class SmallPtrSetImpl;
32template <typename T> class SmallVectorImpl;
33class AAResults;
34class AllocaInst;
35class AssumptionCache;
36class BasicBlock;
37class CallBase;
38class CallInst;
39class CondBrInst;
40class DIBuilder;
41class DomTreeUpdater;
42class Function;
43class Instruction;
44class InvokeInst;
45class LoadInst;
46class MDNode;
48class PHINode;
49class StoreInst;
52
53//===----------------------------------------------------------------------===//
54// Local constant propagation.
55//
56
57/// If a terminator instruction is predicated on a constant value, convert it
58/// into an unconditional branch to the constant destination.
59/// This is a nontrivial operation because the successors of this basic block
60/// must have their PHI nodes updated.
61/// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
62/// conditions and indirectbr addresses this might make dead if
63/// DeleteDeadConditions is true.
65 bool DeleteDeadConditions = false,
66 const TargetLibraryInfo *TLI = nullptr,
67 DomTreeUpdater *DTU = nullptr);
68
69//===----------------------------------------------------------------------===//
70// Local dead code elimination.
71//
72
73/// Return true if the result produced by the instruction is not used, and the
74/// instruction will return. Certain side-effecting instructions are also
75/// considered dead if there are no uses of the instruction.
76LLVM_ABI bool
78 const TargetLibraryInfo *TLI = nullptr);
79
80/// Return true if the result produced by the instruction would have no side
81/// effects if it was not used. This is equivalent to checking whether
82/// isInstructionTriviallyDead would be true if the use count was 0.
83LLVM_ABI bool
85 const TargetLibraryInfo *TLI = nullptr);
86
87/// If the specified value is a trivially dead instruction, delete it.
88/// If that makes any of its operands trivially dead, delete them too,
89/// recursively. Return true if any instructions were deleted.
91 Value *V, const TargetLibraryInfo *TLI = nullptr,
92 MemorySSAUpdater *MSSAU = nullptr,
93 std::function<void(Value *)> AboutToDeleteCallback =
94 std::function<void(Value *)>());
95
96/// Delete all of the instructions in `DeadInsts`, and all other instructions
97/// that deleting these in turn causes to be trivially dead.
98///
99/// The initial instructions in the provided vector must all have empty use
100/// lists and satisfy `isInstructionTriviallyDead`.
101///
102/// `DeadInsts` will be used as scratch storage for this routine and will be
103/// empty afterward.
106 const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr,
107 std::function<void(Value *)> AboutToDeleteCallback =
108 std::function<void(Value *)>());
109
110/// Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow
111/// instructions that are not trivially dead. These will be ignored.
112/// Returns true if any changes were made, i.e. any instructions trivially dead
113/// were found and deleted.
116 const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr,
117 std::function<void(Value *)> AboutToDeleteCallback =
118 std::function<void(Value *)>());
119
120/// If the specified value is an effectively dead PHI node, due to being a
121/// def-use chain of single-use nodes that either forms a cycle or is terminated
122/// by a trivially dead instruction, delete it. If that makes any of its
123/// operands trivially dead, delete them too, recursively. Return true if a
124/// change was made.
126 PHINode *PN, const TargetLibraryInfo *TLI = nullptr,
127 MemorySSAUpdater *MSSAU = nullptr,
128 SmallPtrSetImpl<PHINode *> *KnownNonDeadPHIs = nullptr);
129
130/// Scan the specified basic block and try to simplify any instructions in it
131/// and recursively delete dead instructions.
132///
133/// This returns true if it changed the code, note that it can delete
134/// instructions in other blocks as well in this block.
135LLVM_ABI bool
137 const TargetLibraryInfo *TLI = nullptr);
138
139//===----------------------------------------------------------------------===//
140// Control Flow Graph Restructuring.
141//
142
143/// BB is a block with one predecessor and its predecessor is known to have one
144/// successor (BB!). Eliminate the edge between them, moving the instructions in
145/// the predecessor into BB. This deletes the predecessor block.
147 DomTreeUpdater *DTU = nullptr);
148
149/// BB is known to contain an unconditional branch, and contains no instructions
150/// other than PHI nodes, potential debug intrinsics and the branch. If
151/// possible, eliminate BB by rewriting all the predecessors to branch to the
152/// successor block and return true. If we can't transform, return false.
153LLVM_ABI bool
155 DomTreeUpdater *DTU = nullptr);
156
157/// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
158/// to be clever about PHI nodes which differ only in the order of the incoming
159/// values, but instcombine orders them so it usually won't matter.
160///
161/// This overload removes the duplicate PHI nodes directly.
163
164/// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
165/// to be clever about PHI nodes which differ only in the order of the incoming
166/// values, but instcombine orders them so it usually won't matter.
167///
168/// This overload collects the PHI nodes to be removed into the ToRemove set.
171
172/// This function is used to do simplification of a CFG. For example, it
173/// adjusts branches to branches to eliminate the extra hop, it eliminates
174/// unreachable basic blocks, and does other peephole optimization of the CFG.
175/// It returns true if a modification was made, possibly deleting the basic
176/// block that was pointed to. LoopHeaders is an optional input parameter
177/// providing the set of loop headers that SimplifyCFG should not eliminate.
180 DomTreeUpdater *DTU = nullptr,
181 const SimplifyCFGOptions &Options = {},
182 ArrayRef<WeakVH> LoopHeaders = {});
183
184/// This function is used to flatten a CFG. For example, it uses parallel-and
185/// and parallel-or mode to collapse if-conditions and merge if-regions with
186/// identical statements.
187LLVM_ABI bool FlattenCFG(BasicBlock *BB, AAResults *AA = nullptr);
188
189/// If this basic block is ONLY a setcc and a branch, and if a predecessor
190/// branches to us and one of our successors, fold the setcc into the
191/// predecessor and use logical operations to pick the right destination.
193 llvm::DomTreeUpdater *DTU = nullptr,
194 MemorySSAUpdater *MSSAU = nullptr,
195 const TargetTransformInfo *TTI = nullptr,
196 AssumptionCache *AC = nullptr,
197 unsigned BonusInstThreshold = 1);
198
199/// This function takes a virtual register computed by an Instruction and
200/// replaces it with a slot in the stack frame, allocated via alloca.
201/// This allows the CFG to be changed around without fear of invalidating the
202/// SSA information for the value. It returns the pointer to the alloca inserted
203/// to create a stack slot for X.
205 Instruction &X, bool VolatileLoads = false,
206 std::optional<BasicBlock::iterator> AllocaPoint = std::nullopt);
207
208/// This function takes a virtual register computed by a phi node and replaces
209/// it with a slot in the stack frame, allocated via alloca. The phi node is
210/// deleted and it returns the pointer to the alloca inserted.
212 PHINode *P, std::optional<BasicBlock::iterator> AllocaPoint = std::nullopt);
213
214/// If the specified pointer points to an object that we control, try to modify
215/// the object's alignment to PrefAlign. Returns a minimum known alignment of
216/// the value after the operation, which may be lower than PrefAlign.
217///
218/// Increating value alignment isn't often possible though. If alignment is
219/// important, a more reliable approach is to simply align all global variables
220/// and allocation instructions to their preferred alignment from the beginning.
222 const DataLayout &DL);
223
224/// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
225/// the owning object can be modified and has an alignment less than \p
226/// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
227/// cannot be increased, the known alignment of the value is returned.
228///
229/// It is not always possible to modify the alignment of the underlying object,
230/// so if alignment is important, a more reliable approach is to simply align
231/// all global variables and allocation instructions to their preferred
232/// alignment from the beginning.
234 const DataLayout &DL,
235 const Instruction *CxtI = nullptr,
236 AssumptionCache *AC = nullptr,
237 const DominatorTree *DT = nullptr);
238
239/// Try to infer an alignment for the specified pointer.
241 const Instruction *CxtI = nullptr,
242 AssumptionCache *AC = nullptr,
243 const DominatorTree *DT = nullptr) {
244 return getOrEnforceKnownAlignment(V, MaybeAlign(), DL, CxtI, AC, DT);
245}
246
247/// Create a call that matches the invoke \p II in terms of arguments,
248/// attributes, debug information, etc. The call is not placed in a block and it
249/// will not have a name. The invoke instruction is not removed, nor are the
250/// uses replaced by the new call.
251LLVM_ABI CallInst *createCallMatchingInvoke(InvokeInst *II);
252
253/// This function converts the specified invoke into a normal call.
254LLVM_ABI CallInst *changeToCall(InvokeInst *II, DomTreeUpdater *DTU = nullptr);
255
256///===---------------------------------------------------------------------===//
257/// Dbg Intrinsic utilities
258///
259
260/// Creates and inserts a dbg_value record intrinsic before a store
261/// that has an associated llvm.dbg.value intrinsic.
262LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI,
263 DIBuilder &Builder);
264
265/// Inserts a dbg.value record before a store to an alloca'd value
266/// that has an associated dbg.declare record.
267LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
268 StoreInst *SI,
269 DIBuilder &Builder);
270
271/// Inserts a dbg.value record before a load of an alloca'd value
272/// that has an associated dbg.declare record.
273LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
274 LoadInst *LI, DIBuilder &Builder);
275
276/// Inserts a dbg.value record after a phi that has an associated
277/// llvm.dbg.declare record.
278LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
279 PHINode *LI, DIBuilder &Builder);
280
281/// Lowers dbg.declare records into appropriate set of dbg.value records.
283
284/// Propagate dbg.value intrinsics through the newly inserted PHIs.
285LLVM_ABI void
286insertDebugValuesForPHIs(BasicBlock *BB,
287 SmallVectorImpl<PHINode *> &InsertedPHIs);
288
289/// Replaces dbg.declare record when the address it
290/// describes is replaced with a new value. If Deref is true, an
291/// additional DW_OP_deref is prepended to the expression. If Offset
292/// is non-zero, a constant displacement is added to the expression
293/// (between the optional Deref operations). Offset can be negative.
294LLVM_ABI bool replaceDbgDeclare(Value *Address, Value *NewAddress,
295 DIBuilder &Builder, uint8_t DIExprFlags,
296 int Offset);
297
298/// Replaces multiple dbg.value records when the alloca it describes
299/// is replaced with a new value. If Offset is non-zero, a constant displacement
300/// is added to the expression (after the mandatory Deref). Offset can be
301/// negative. New dbg.value records are inserted at the locations of
302/// the instructions they replace.
303LLVM_ABI void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
304 DIBuilder &Builder, int Offset = 0);
305
306/// Salvage debug records that use \p I before the instruction is deleted.
307/// Rewrite those uses in terms of its operands where we can, and encode the
308/// instruction's effect in the record's DIExpression. Deleting the instruction
309/// replaces any remaining debug-record uses with poison.
310LLVM_ABI void salvageDebugInfo(Instruction &I);
311
312/// Salvage only the records in \p DbgRecords instead of finding every debug
313/// user of \p I. Every record must be a debug user of the instruction.
314///
315/// Process records in order. For a dbg.assign, salvage a matching address
316/// before its variable location since replacing a variable-location operand
317/// can also replace the address. Stop when a checked variable location cannot
318/// be salvaged. A matching address counts as processed even if salvage leaves
319/// it unchanged. If nothing was processed, call setKillLocation() on every
320/// supplied record.
321LLVM_ABI void
324
325/// Given an instruction \p I and DIExpression \p DIExpr operating on
326/// it, append the effects of \p I to the DIExpression operand list
327/// \p Ops, or return \p nullptr if it cannot be salvaged.
328/// \p CurrentLocOps is the number of SSA values referenced by the
329/// incoming \p Ops. \return the first non-constant operand
330/// implicitly referred to by Ops. If \p I references more than one
331/// non-constant operand, any additional operands are added to
332/// \p AdditionalValues.
333///
334/// \example
335////
336/// I = add %a, i32 1
337///
338/// Return = %a
339/// Ops = llvm::dwarf::DW_OP_lit1 llvm::dwarf::DW_OP_add
340///
341/// I = add %a, %b
342///
343/// Return = %a
344/// Ops = llvm::dwarf::DW_OP_LLVM_arg0 llvm::dwarf::DW_OP_add
345/// AdditionalValues = %b
346LLVM_ABI Value *
347salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
348 SmallVectorImpl<uint64_t> &Ops,
349 SmallVectorImpl<Value *> &AdditionalValues);
350
351/// Point debug users of \p From to \p To or salvage them. Use this function
352/// only when replacing all uses of \p From with \p To, with a guarantee that
353/// \p From is going to be deleted.
354///
355/// Follow these rules to prevent use-before-def of \p To:
356/// . If \p To is a linked Instruction, set \p DomPoint to \p To.
357/// . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
358/// \p To will be inserted after.
359/// . If \p To is not an Instruction (e.g a Constant), the choice of
360/// \p DomPoint is arbitrary. Pick \p From for simplicity.
361///
362/// If a debug user cannot be preserved without reordering variable updates or
363/// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
364/// or deleted. Returns true if any debug users were updated.
365LLVM_ABI bool replaceAllDbgUsesWith(Instruction &From, Value &To,
366 Instruction &DomPoint, DominatorTree &DT);
367
368/// If a terminator in an unreachable basic block has an operand of type
369/// Instruction, transform it into poison. Return true if any operands
370/// are changed to poison. Original Values prior to being changed to poison
371/// are returned in \p PoisonedValues.
372LLVM_ABI bool
373handleUnreachableTerminator(Instruction *I,
374 SmallVectorImpl<Value *> &PoisonedValues);
375
376/// Remove all instructions from a basic block other than its terminator
377/// and any present EH pad instructions. Returns the number of instructions
378/// that have been removed.
380
381/// Insert an unreachable instruction before the specified
382/// instruction, making it and the rest of the code in the block dead.
383LLVM_ABI unsigned changeToUnreachable(Instruction *I,
384 bool PreserveLCSSA = false,
385 DomTreeUpdater *DTU = nullptr,
386 MemorySSAUpdater *MSSAU = nullptr);
387
388/// Convert the CallInst to InvokeInst with the specified unwind edge basic
389/// block. This also splits the basic block where CI is located, because
390/// InvokeInst is a terminator instruction. Returns the newly split basic
391/// block.
392LLVM_ABI BasicBlock *
393changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge,
394 DomTreeUpdater *DTU = nullptr);
395
396/// Replace 'BB's terminator with one that does not have an unwind successor
397/// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
398/// successor. Returns the instruction that replaced the original terminator,
399/// which might be a call in case the original terminator was an invoke.
400///
401/// \param BB Block whose terminator will be replaced. Its terminator must
402/// have an unwind successor.
403LLVM_ABI Instruction *removeUnwindEdge(BasicBlock *BB,
404 DomTreeUpdater *DTU = nullptr);
405
406/// Remove all blocks that can not be reached from the function's entry.
407/// When \p FoldInstsToUnreachable is true, it will also convert obviously
408/// unreachable instructions into unreachable (e.g, store to null).
409///
410/// Returns true if any basic block was removed or any instruction was folded.
412 DomTreeUpdater *DTU = nullptr,
413 MemorySSAUpdater *MSSAU = nullptr,
414 bool FoldInstsToUnreachable = true);
415
416/// Combine the metadata of two instructions so that K can replace J. This
417/// specifically handles the case of CSE-like transformations. Some
418/// metadata can only be kept if K dominates J. For this to be correct,
419/// K cannot be hoisted.
420///
421/// Unknown metadata is removed.
422LLVM_ABI void combineMetadataForCSE(Instruction *K, const Instruction *J,
423 bool DoesKMove);
424
425/// Combine metadata of two instructions, where instruction J is a memory
426/// access that has been merged into K. This will intersect alias-analysis
427/// metadata, while preserving other known metadata.
428LLVM_ABI void combineAAMetadata(Instruction *K, const Instruction *J);
429
430/// Copy the metadata from the source instruction to the destination (the
431/// replacement for the source instruction).
432LLVM_ABI void copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source);
433
434/// Patch the replacement so that it is not more restrictive than the value
435/// being replaced. It assumes that the replacement does not get moved from
436/// its original position.
437LLVM_ABI void patchReplacementInstruction(Instruction *I, Value *Repl);
438
439// Replace each use of 'From' with 'To', if that use does not belong to basic
440// block where 'From' is defined. Returns the number of replacements made.
441LLVM_ABI unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
442
443/// Replace each use of 'From' with 'To' if that use is dominated by
444/// the given edge. Returns the number of replacements made.
445LLVM_ABI unsigned replaceDominatedUsesWith(Value *From, Value *To,
446 DominatorTree &DT,
447 const BasicBlockEdge &Edge);
448/// Replace each use of 'From' with 'To' if that use is dominated by
449/// the end of the given BasicBlock. Returns the number of replacements made.
450LLVM_ABI unsigned replaceDominatedUsesWith(Value *From, Value *To,
451 DominatorTree &DT,
452 const BasicBlock *BB);
453/// Replace each use of 'From' with 'To' if that use is dominated by the
454/// given instruction. Returns the number of replacements made.
455LLVM_ABI unsigned replaceDominatedUsesWith(Value *From, Value *To,
456 DominatorTree &DT,
457 const Instruction *I);
458/// Replace each use of 'From' with 'To' if that use is dominated by
459/// the given edge and the callback ShouldReplace returns true. Returns the
460/// number of replacements made.
462 Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge,
463 function_ref<bool(const Use &U, const Value *To)> ShouldReplace);
464/// Replace each use of 'From' with 'To' if that use is dominated by
465/// the end of the given BasicBlock and the callback ShouldReplace returns true.
466/// Returns the number of replacements made.
468 Value *From, Value *To, DominatorTree &DT, const BasicBlock *BB,
469 function_ref<bool(const Use &U, const Value *To)> ShouldReplace);
470/// Replace each use of 'From' with 'To' if that use is dominated by
471/// the given instruction and the callback ShouldReplace returns true. Returns
472/// the number of replacements made.
474 Value *From, Value *To, DominatorTree &DT, const Instruction *I,
475 function_ref<bool(const Use &U, const Value *To)> ShouldReplace);
476
477/// Return true if this call calls a gc leaf function.
478///
479/// A leaf function is a function that does not safepoint the thread during its
480/// execution. During a call or invoke to such a function, the callers stack
481/// does not have to be made parseable.
482///
483/// Most passes can and should ignore this information, and it is only used
484/// during lowering by the GC infrastructure.
485LLVM_ABI bool callsGCLeafFunction(const CallBase *Call,
486 const TargetLibraryInfo &TLI);
487
488/// Copy a nonnull metadata node to a new load instruction.
489///
490/// This handles mapping it to range metadata if the new load is an integer
491/// load instead of a pointer load.
492LLVM_ABI void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N,
493 LoadInst &NewLI);
494
495/// Copy a range metadata node to a new load instruction.
496///
497/// This handles mapping it to nonnull metadata if the new load is a pointer
498/// load instead of an integer load and the range doesn't cover null.
499LLVM_ABI void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI,
500 MDNode *N, LoadInst &NewLI);
501
502/// Remove the debug intrinsic instructions for the given instruction.
503LLVM_ABI void dropDebugUsers(Instruction &I);
504
505/// Hoist all of the instructions in the \p IfBlock to the dominant block
506/// \p DomBlock, by moving its instructions to the insertion point \p InsertPt.
507///
508/// The moved instructions receive the insertion point debug location values
509/// (DILocations) and their debug intrinsic instructions are removed.
510LLVM_ABI void hoistAllInstructionsInto(BasicBlock *DomBlock,
511 Instruction *InsertPt, BasicBlock *BB);
512
513/// Given a constant, create a debug information expression.
514LLVM_ABI DIExpression *getExpressionForConstant(DIBuilder &DIB,
515 const Constant &C, Type &Ty);
516
517/// Remap the operands of the debug records attached to \p Inst, and the
518/// operands of \p Inst itself if it's a debug intrinsic.
519LLVM_ABI void remapDebugVariable(ValueToValueMapTy &Mapping, Instruction *Inst);
520
521//===----------------------------------------------------------------------===//
522// Intrinsic pattern matching
523//
524
525/// Try to match a bswap or bitreverse idiom.
526///
527/// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
528/// instructions are returned in \c InsertedInsts. They will all have been added
529/// to a basic block.
530///
531/// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
532/// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
533/// to BW / 4 nodes to be searched, so is significantly faster.
534///
535/// This function returns true on a successful match or false otherwise.
536LLVM_ABI bool
537recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps,
538 bool MatchBitReversals,
539 SmallVectorImpl<Instruction *> &InsertedInsts);
540
541//===----------------------------------------------------------------------===//
542// Sanitizer utilities
543//
544
545/// Given a CallInst, check if it calls a string function known to CodeGen,
546/// and mark it with NoBuiltin if so. To be used by sanitizers that intend
547/// to intercept string functions and want to avoid converting them to target
548/// specific instructions.
549LLVM_ABI void
551 const TargetLibraryInfo *TLI);
552
553//===----------------------------------------------------------------------===//
554// Transform predicates
555//
556
557/// Given an instruction, is it legal to set operand OpIdx to a non-constant
558/// value?
559LLVM_ABI bool canReplaceOperandWithVariable(const Instruction *I,
560 unsigned OpIdx);
561
562//===----------------------------------------------------------------------===//
563// Value helper functions
564//
565
566/// Invert the given true/false value, possibly reusing an existing copy.
567LLVM_ABI Value *invertCondition(Value *Condition);
568
569//===----------------------------------------------------------------------===//
570// Assorted
571//
572
573/// If we can infer one attribute from another on the declaration of a
574/// function, explicitly materialize the maximal set in the IR.
576
577//===----------------------------------------------------------------------===//
578// Helpers to track and update flags on instructions.
579//
580
582 bool HasNUW = true;
583 bool HasNSW = true;
584 bool IsDisjoint = true;
585
586#ifndef NDEBUG
587 /// Opcode of merged instructions. All instructions passed to mergeFlags must
588 /// have the same opcode.
589 std::optional<unsigned> Opcode;
590#endif
591
592 // Note: At the moment, users are responsible to manage AllKnownNonNegative
593 // and AllKnownNonZero manually. AllKnownNonNegative can be true in a case
594 // where one of the operands is negative, but one the operators is not NSW.
595 // AllKnownNonNegative should not be used independently of HasNSW
597 bool AllKnownNonZero = true;
598
599 OverflowTracking() = default;
600
601 /// Merge in the no-wrap flags from \p I.
603
604 /// Apply the no-wrap flags to \p I if applicable.
606};
607
608} // end namespace llvm
609
610#endif // LLVM_TRANSFORMS_UTILS_LOCAL_H
unsigned uint64_t
ReachingDefInfo InstSet & ToRemove
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:215
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static LVOptions Options
Definition LVOptions.cpp:25
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
#define P(N)
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
an instruction to allocate memory on the stack
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This class represents a function call, abstracting a target machine's calling convention.
Conditional Branch instruction.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
Invoke instruction.
An instruction for reading from memory.
Metadata node.
Definition Metadata.h:1069
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
LLVM Value Representation.
Definition Value.h:75
Value handle that is nullable, but tries to track the Value.
A nullable Value handle that is nullable.
CallInst * Call
Abstract Attribute helper functions.
Definition Attributor.h:165
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
LLVM_ABI bool foldBranchToCommonDest(CondBrInst *BI, llvm::DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr, const TargetTransformInfo *TTI=nullptr, AssumptionCache *AC=nullptr, unsigned BonusInstThreshold=1)
If this basic block is ONLY a setcc and a branch, and if a predecessor branches to us and one of our ...
LLVM_ABI unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than its terminator and any present EH pad instructi...
Definition Local.cpp:2516
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
Definition Local.cpp:523
LLVM_ABI BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge, DomTreeUpdater *DTU=nullptr)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition Local.cpp:2633
LLVM_ABI bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DomTreeUpdater *DTU=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
Definition Local.cpp:134
LLVM_ABI bool FlattenCFG(BasicBlock *BB, AAResults *AA=nullptr)
This function is used to flatten a CFG.
LLVM_ABI unsigned replaceDominatedUsesWithIf(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge, function_ref< bool(const Use &U, const Value *To)> ShouldReplace)
Replace each use of 'From' with 'To' if that use is dominated by the given edge and the callback Shou...
Definition Local.cpp:3289
LLVM_ABI unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition Local.cpp:3253
LLVM_ABI void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
Definition Utils.cpp:1675
LLVM_ABI CallInst * changeToCall(InvokeInst *II, DomTreeUpdater *DTU=nullptr)
This function converts the specified invoke into a normal call.
Definition Local.cpp:2609
LLVM_ABI void copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source)
Copy the metadata from the source instruction to the destination (the replacement for the source inst...
Definition Local.cpp:3126
LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)
===------------------------------------------------------------------—===// Dbg Intrinsic utilities
Definition Local.cpp:1704
LLVM_ABI void remapDebugVariable(ValueToValueMapTy &Mapping, Instruction *Inst)
Remap the operands of the debug records attached to Inst, and the operands of Inst itself if it's a d...
Definition Local.cpp:3484
LLVM_ABI bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
Definition Local.cpp:716
LLVM_ABI void insertDebugValuesForPHIs(BasicBlock *BB, SmallVectorImpl< PHINode * > &InsertedPHIs)
Propagate dbg.value intrinsics through the newly inserted PHIs.
Definition Local.cpp:1901
LLVM_ABI bool handleUnreachableTerminator(Instruction *I, SmallVectorImpl< Value * > &PoisonedValues)
If a terminator in an unreachable basic block has an operand of type Instruction, transform it into p...
Definition Local.cpp:2499
LLVM_ABI AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, std::optional< BasicBlock::iterator > AllocaPoint=std::nullopt)
This function takes a virtual register computed by an Instruction and replaces it with a slot in the ...
LLVM_ABI bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool FoldInstsToUnreachable=true)
Remove all blocks that can not be reached from the function's entry.
Definition Local.cpp:2913
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
Definition Local.h:240
LLVM_ABI bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
Definition Local.cpp:403
LLVM_ABI AllocaInst * DemotePHIToStack(PHINode *P, std::optional< BasicBlock::iterator > AllocaPoint=std::nullopt)
This function takes a virtual register computed by a phi node and replaces it with a slot in the stac...
LLVM_ABI bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes,...
Definition Local.cpp:1148
LLVM_ABI bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction * > &InsertedInsts)
Try to match a bswap or bitreverse idiom.
Definition Local.cpp:3789
LLVM_ABI Align getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
Definition Local.cpp:1559
LLVM_ABI bool LowerDbgDeclare(Function &F)
Lowers dbg.declare records into appropriate set of dbg.value records.
Definition Local.cpp:1814
LLVM_ABI DIExpression * getExpressionForConstant(DIBuilder &DIB, const Constant &C, Type &Ty)
Given a constant, create a debug information expression.
Definition Local.cpp:3442
LLVM_ABI CallInst * createCallMatchingInvoke(InvokeInst *II)
Create a call that matches the invoke II in terms of arguments, attributes, debug information,...
Definition Local.cpp:2584
LLVM_ABI void salvageDebugInfoForDbgValues(Instruction &I, ArrayRef< DbgVariableRecord * > DbgRecords)
Salvage only the records in DbgRecords instead of finding every debug user of I.
Definition Local.cpp:2122
LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)
Inserts a dbg.value record before a store to an alloca'd value that has an associated dbg....
Definition Local.cpp:1655
LLVM_ABI Instruction * removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
Replace 'BB's terminator with one that does not have an unwind successor block.
Definition Local.cpp:2875
LLVM_ABI bool wouldInstructionBeTriviallyDead(const Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction would have no side effects if it was not used.
Definition Local.cpp:410
LLVM_ABI void patchReplacementInstruction(Instruction *I, Value *Repl)
Patch the replacement so that it is not more restrictive than the value being replaced.
Definition Local.cpp:3189
LLVM_ABI bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, SmallPtrSetImpl< PHINode * > *KnownNonDeadPHIs=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
Definition Local.cpp:623
LLVM_ABI unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge)
Replace each use of 'From' with 'To' if that use is dominated by the given edge.
Definition Local.cpp:3268
LLVM_ABI unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition Local.cpp:2544
LLVM_ABI bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
Definition Local.cpp:2445
LLVM_ABI Value * salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Ops, SmallVectorImpl< Value * > &AdditionalValues)
Definition Local.cpp:2305
LLVM_ABI void combineMetadataForCSE(Instruction *K, const Instruction *J, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
Definition Local.cpp:3117
LLVM_ABI void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
Definition Local.cpp:3389
TargetTransformInfo TTI
LLVM_ABI void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!...
Definition Local.cpp:756
LLVM_ABI cl::opt< bool > RequireAndPreserveDomTree
This function is used to do simplification of a CFG.
LLVM_ABI void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt, BasicBlock *BB)
Hoist all of the instructions in the IfBlock to the dominant block DomBlock, by moving its instructio...
Definition Local.cpp:3396
LLVM_ABI void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a range metadata node to a new load instruction.
Definition Local.cpp:3365
LLVM_ABI void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
Definition Local.cpp:3340
LLVM_ABI bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx)
Given an instruction, is it legal to set operand OpIdx to a non-constant value?
Definition Local.cpp:3902
LLVM_ABI void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, int Offset=0)
Replaces multiple dbg.value records when the alloca it describes is replaced with a new value.
Definition Local.cpp:2004
LLVM_ABI Align tryEnforceAlignment(Value *V, Align PrefAlign, const DataLayout &DL)
If the specified pointer points to an object that we control, try to modify the object's alignment to...
Definition Local.cpp:1510
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructionsPermissive(SmallVectorImpl< WeakTrackingVH > &DeadInsts, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow instructions that are not...
Definition Local.cpp:538
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
LLVM_ABI bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, DomTreeUpdater *DTU=nullptr, const SimplifyCFGOptions &Options={}, ArrayRef< WeakVH > LoopHeaders={})
LLVM_ABI void combineAAMetadata(Instruction *K, const Instruction *J)
Combine metadata of two instructions, where instruction J is a memory access that has been merged int...
Definition Local.cpp:3122
LLVM_ABI bool inferAttributesFromOthers(Function &F)
If we can infer one attribute from another on the declaration of a function, explicitly materialize t...
Definition Local.cpp:4025
LLVM_ABI Value * invertCondition(Value *Condition)
Invert the given true/false value, possibly reusing an existing copy.
Definition Local.cpp:3991
LLVM_ABI void maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI, const TargetLibraryInfo *TLI)
Given a CallInst, check if it calls a string function known to CodeGen, and mark it with NoBuiltin if...
Definition Local.cpp:3893
LLVM_ABI bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Definition Local.cpp:1502
LLVM_ABI bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI)
Return true if this call calls a gc leaf function.
Definition Local.cpp:3316
LLVM_ABI bool replaceDbgDeclare(Value *Address, Value *NewAddress, DIBuilder &Builder, uint8_t DIExprFlags, int Offset)
Replaces dbg.declare record when the address it describes is replaced with a new value.
Definition Local.cpp:1964
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
std::optional< unsigned > Opcode
Opcode of merged instructions.
Definition Local.h:589
LLVM_ABI void mergeFlags(Instruction &I)
Merge in the no-wrap flags from I.
Definition Local.cpp:4055
LLVM_ABI void applyFlags(Instruction &I)
Apply the no-wrap flags to I if applicable.
Definition Local.cpp:4071