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 FreezeInst;
43class Function;
44class Instruction;
45class InvokeInst;
46class LoadInst;
47class MDNode;
49class PHINode;
50class StoreInst;
53
54//===----------------------------------------------------------------------===//
55// Local constant propagation.
56//
57
58/// If a terminator instruction is predicated on a constant value, convert it
59/// into an unconditional branch to the constant destination.
60/// This is a nontrivial operation because the successors of this basic block
61/// must have their PHI nodes updated.
62/// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
63/// conditions and indirectbr addresses this might make dead if
64/// DeleteDeadConditions is true.
66 bool DeleteDeadConditions = false,
67 const TargetLibraryInfo *TLI = nullptr,
68 DomTreeUpdater *DTU = nullptr);
69
70//===----------------------------------------------------------------------===//
71// Local dead code elimination.
72//
73
74/// Return true if the result produced by the instruction is not used, and the
75/// instruction will return. Certain side-effecting instructions are also
76/// considered dead if there are no uses of the instruction.
77LLVM_ABI bool
79 const TargetLibraryInfo *TLI = nullptr);
80
81/// Return true if the result produced by the instruction would have no side
82/// effects if it was not used. This is equivalent to checking whether
83/// isInstructionTriviallyDead would be true if the use count was 0.
84LLVM_ABI bool
86 const TargetLibraryInfo *TLI = nullptr);
87
88/// If the specified value is a trivially dead instruction, delete it.
89/// If that makes any of its operands trivially dead, delete them too,
90/// recursively. Return true if any instructions were deleted.
92 Value *V, const TargetLibraryInfo *TLI = nullptr,
93 MemorySSAUpdater *MSSAU = nullptr,
94 std::function<void(Value *)> AboutToDeleteCallback =
95 std::function<void(Value *)>());
96
97/// Delete all of the instructions in `DeadInsts`, and all other instructions
98/// that deleting these in turn causes to be trivially dead.
99///
100/// The initial instructions in the provided vector must all have empty use
101/// lists and satisfy `isInstructionTriviallyDead`.
102///
103/// `DeadInsts` will be used as scratch storage for this routine and will be
104/// empty afterward.
107 const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr,
108 std::function<void(Value *)> AboutToDeleteCallback =
109 std::function<void(Value *)>());
110
111/// Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow
112/// instructions that are not trivially dead. These will be ignored.
113/// Returns true if any changes were made, i.e. any instructions trivially dead
114/// were found and deleted.
117 const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr,
118 std::function<void(Value *)> AboutToDeleteCallback =
119 std::function<void(Value *)>());
120
121/// If the specified value is an effectively dead PHI node, due to being a
122/// def-use chain of single-use nodes that either forms a cycle or is terminated
123/// by a trivially dead instruction, delete it. If that makes any of its
124/// operands trivially dead, delete them too, recursively. Return true if a
125/// change was made.
127 PHINode *PN, const TargetLibraryInfo *TLI = nullptr,
128 MemorySSAUpdater *MSSAU = nullptr,
129 SmallPtrSetImpl<PHINode *> *KnownNonDeadPHIs = nullptr);
130
131/// Scan the specified basic block and try to simplify any instructions in it
132/// and recursively delete dead instructions.
133///
134/// This returns true if it changed the code, note that it can delete
135/// instructions in other blocks as well in this block.
136LLVM_ABI bool
138 const TargetLibraryInfo *TLI = nullptr);
139
140//===----------------------------------------------------------------------===//
141// Control Flow Graph Restructuring.
142//
143
144/// BB is a block with one predecessor and its predecessor is known to have one
145/// successor (BB!). Eliminate the edge between them, moving the instructions in
146/// the predecessor into BB. This deletes the predecessor block.
148 DomTreeUpdater *DTU = nullptr);
149
150/// BB is known to contain an unconditional branch, and contains no instructions
151/// other than PHI nodes, potential debug intrinsics and the branch. If
152/// possible, eliminate BB by rewriting all the predecessors to branch to the
153/// successor block and return true. If we can't transform, return false.
154LLVM_ABI bool
156 DomTreeUpdater *DTU = nullptr);
157
158/// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
159/// to be clever about PHI nodes which differ only in the order of the incoming
160/// values, but instcombine orders them so it usually won't matter.
161///
162/// This overload removes the duplicate PHI nodes directly.
164
165/// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
166/// to be clever about PHI nodes which differ only in the order of the incoming
167/// values, but instcombine orders them so it usually won't matter.
168///
169/// This overload collects the PHI nodes to be removed into the ToRemove set.
172
173/// This function is used to do simplification of a CFG. For example, it
174/// adjusts branches to branches to eliminate the extra hop, it eliminates
175/// unreachable basic blocks, and does other peephole optimization of the CFG.
176/// It returns true if a modification was made, possibly deleting the basic
177/// block that was pointed to. LoopHeaders is an optional input parameter
178/// providing the set of loop headers that SimplifyCFG should not eliminate.
180 const SimplifyCFGOptions &Options = {},
181 ArrayRef<WeakVH> LoopHeaders = {});
182
183/// This function is used to flatten a CFG. For example, it uses parallel-and
184/// and parallel-or mode to collapse if-conditions and merge if-regions with
185/// identical statements.
186LLVM_ABI bool FlattenCFG(BasicBlock *BB, AAResults *AA = nullptr);
187
188/// If this basic block is ONLY a setcc and a branch, and if a predecessor
189/// branches to us and one of our successors, fold the setcc into the
190/// predecessor and use logical operations to pick the right destination.
192 MemorySSAUpdater *MSSAU = nullptr,
193 const TargetTransformInfo *TTI = nullptr,
194 AssumptionCache *AC = nullptr,
195 unsigned BonusInstThreshold = 1);
196
197/// This function takes a virtual register computed by an Instruction and
198/// replaces it with a slot in the stack frame, allocated via alloca.
199/// This allows the CFG to be changed around without fear of invalidating the
200/// SSA information for the value. It returns the pointer to the alloca inserted
201/// to create a stack slot for X.
203 Instruction &X, bool VolatileLoads = false,
204 std::optional<BasicBlock::iterator> AllocaPoint = std::nullopt);
205
206/// This function takes a virtual register computed by a phi node and replaces
207/// it with a slot in the stack frame, allocated via alloca. The phi node is
208/// deleted and it returns the pointer to the alloca inserted.
210 PHINode *P, std::optional<BasicBlock::iterator> AllocaPoint = std::nullopt);
211
212/// If the specified pointer points to an object that we control, try to modify
213/// the object's alignment to PrefAlign. Returns a minimum known alignment of
214/// the value after the operation, which may be lower than PrefAlign.
215///
216/// Increating value alignment isn't often possible though. If alignment is
217/// important, a more reliable approach is to simply align all global variables
218/// and allocation instructions to their preferred alignment from the beginning.
220 const DataLayout &DL);
221
222/// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
223/// the owning object can be modified and has an alignment less than \p
224/// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
225/// cannot be increased, the known alignment of the value is returned.
226///
227/// It is not always possible to modify the alignment of the underlying object,
228/// so if alignment is important, a more reliable approach is to simply align
229/// all global variables and allocation instructions to their preferred
230/// alignment from the beginning.
232 const DataLayout &DL,
233 const Instruction *CtxI = nullptr,
234 AssumptionCache *AC = nullptr,
235 const DominatorTree *DT = nullptr);
236
237/// Try to infer an alignment for the specified pointer.
239 const Instruction *CtxI = nullptr,
240 AssumptionCache *AC = nullptr,
241 const DominatorTree *DT = nullptr) {
242 return getOrEnforceKnownAlignment(V, MaybeAlign(), DL, CtxI, AC, DT);
243}
244
245/// Create a call that matches the invoke \p II in terms of arguments,
246/// attributes, debug information, etc. The call is not placed in a block and it
247/// will not have a name. The invoke instruction is not removed, nor are the
248/// uses replaced by the new call.
249LLVM_ABI CallInst *createCallMatchingInvoke(InvokeInst *II);
250
251/// This function converts the specified invoke into a normal call.
252LLVM_ABI CallInst *changeToCall(InvokeInst *II, DomTreeUpdater *DTU = nullptr);
253
254///===---------------------------------------------------------------------===//
255/// Dbg Intrinsic utilities
256///
257
258/// Creates and inserts a dbg_value record intrinsic before a store
259/// that has an associated llvm.dbg.value intrinsic.
260LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI,
261 DIBuilder &Builder);
262
263/// Inserts a dbg.value record before a store to an alloca'd value
264/// that has an associated dbg.declare record.
265LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
266 StoreInst *SI,
267 DIBuilder &Builder);
268
269/// Inserts a dbg.value record before a load of an alloca'd value
270/// that has an associated dbg.declare record.
271LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
272 LoadInst *LI, DIBuilder &Builder);
273
274/// Inserts a dbg.value record after a phi that has an associated
275/// llvm.dbg.declare record.
276LLVM_ABI void ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
277 PHINode *LI, DIBuilder &Builder);
278
279/// Lowers dbg.declare records into appropriate set of dbg.value records.
281
282/// Propagate dbg.value intrinsics through the newly inserted PHIs.
283LLVM_ABI void
284insertDebugValuesForPHIs(BasicBlock *BB,
285 SmallVectorImpl<PHINode *> &InsertedPHIs);
286
287/// Replaces dbg.declare record when the address it
288/// describes is replaced with a new value. If Deref is true, an
289/// additional DW_OP_deref is prepended to the expression. If Offset
290/// is non-zero, a constant displacement is added to the expression
291/// (between the optional Deref operations). Offset can be negative.
292LLVM_ABI bool replaceDbgDeclare(Value *Address, Value *NewAddress,
293 DIBuilder &Builder, uint8_t DIExprFlags,
294 int Offset);
295
296/// Replaces multiple dbg.value records when the alloca it describes
297/// is replaced with a new value. If Offset is non-zero, a constant displacement
298/// is added to the expression (after the mandatory Deref). Offset can be
299/// negative. New dbg.value records are inserted at the locations of
300/// the instructions they replace.
301LLVM_ABI void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
302 DIBuilder &Builder, int Offset = 0);
303
304/// Salvage debug records that use \p I before the instruction is deleted.
305/// Rewrite those uses in terms of its operands where we can, and encode the
306/// instruction's effect in the record's DIExpression. Deleting the instruction
307/// replaces any remaining debug-record uses with poison.
308LLVM_ABI void salvageDebugInfo(Instruction &I);
309
310/// Salvage only the records in \p DbgRecords instead of finding every debug
311/// user of \p I. Every record must be a debug user of the instruction.
312///
313/// Process records in order. For a dbg.assign, salvage a matching address
314/// before its variable location since replacing a variable-location operand
315/// can also replace the address. Stop when a checked variable location cannot
316/// be salvaged. A matching address counts as processed even if salvage leaves
317/// it unchanged. If nothing was processed, call setKillLocation() on every
318/// supplied record.
319LLVM_ABI void
322
323/// Given an instruction \p I and DIExpression \p DIExpr operating on
324/// it, append the effects of \p I to the DIExpression operand list
325/// \p Ops, or return \p nullptr if it cannot be salvaged.
326/// \p CurrentLocOps is the number of SSA values referenced by the
327/// incoming \p Ops. \return the first non-constant operand
328/// implicitly referred to by Ops. If \p I references more than one
329/// non-constant operand, any additional operands are added to
330/// \p AdditionalValues.
331///
332/// \example
333////
334/// I = add %a, i32 1
335///
336/// Return = %a
337/// Ops = llvm::dwarf::DW_OP_lit1 llvm::dwarf::DW_OP_add
338///
339/// I = add %a, %b
340///
341/// Return = %a
342/// Ops = llvm::dwarf::DW_OP_LLVM_arg0 llvm::dwarf::DW_OP_add
343/// AdditionalValues = %b
344LLVM_ABI Value *
345salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
346 SmallVectorImpl<uint64_t> &Ops,
347 SmallVectorImpl<Value *> &AdditionalValues);
348
349/// Point debug users of \p From to \p To or salvage them. Use this function
350/// only when replacing all uses of \p From with \p To, with a guarantee that
351/// \p From is going to be deleted.
352///
353/// Follow these rules to prevent use-before-def of \p To:
354/// . If \p To is a linked Instruction, set \p DomPoint to \p To.
355/// . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
356/// \p To will be inserted after.
357/// . If \p To is not an Instruction (e.g a Constant), the choice of
358/// \p DomPoint is arbitrary. Pick \p From for simplicity.
359///
360/// If a debug user cannot be preserved without reordering variable updates or
361/// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
362/// or deleted. Returns true if any debug users were updated.
363LLVM_ABI bool replaceAllDbgUsesWith(Instruction &From, Value &To,
364 Instruction &DomPoint, DominatorTree &DT);
365
366/// If a terminator in an unreachable basic block has an operand of type
367/// Instruction, transform it into poison. Return true if any operands
368/// are changed to poison. Original Values prior to being changed to poison
369/// are returned in \p PoisonedValues.
370LLVM_ABI bool
371handleUnreachableTerminator(Instruction *I,
372 SmallVectorImpl<Value *> &PoisonedValues);
373
374/// Remove all instructions from a basic block other than its terminator
375/// and any present EH pad instructions. Returns the number of instructions
376/// that have been removed.
378
379/// Insert an unreachable instruction before the specified
380/// instruction, making it and the rest of the code in the block dead.
381LLVM_ABI unsigned changeToUnreachable(Instruction *I,
382 bool PreserveLCSSA = false,
383 DomTreeUpdater *DTU = nullptr,
384 MemorySSAUpdater *MSSAU = nullptr);
385
386/// Convert the CallInst to InvokeInst with the specified unwind edge basic
387/// block. This also splits the basic block where CI is located, because
388/// InvokeInst is a terminator instruction. Returns the newly split basic
389/// block.
390LLVM_ABI BasicBlock *
391changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge,
392 DomTreeUpdater *DTU = nullptr);
393
394/// Replace 'BB's terminator with one that does not have an unwind successor
395/// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
396/// successor. Returns the instruction that replaced the original terminator,
397/// which might be a call in case the original terminator was an invoke.
398///
399/// \param BB Block whose terminator will be replaced. Its terminator must
400/// have an unwind successor.
401LLVM_ABI Instruction *removeUnwindEdge(BasicBlock *BB,
402 DomTreeUpdater *DTU = nullptr);
403
404/// Remove all blocks that can not be reached from the function's entry.
405/// When \p FoldInstsToUnreachable is true, it will also convert obviously
406/// unreachable instructions into unreachable (e.g, store to null).
407///
408/// Returns true if any basic block was removed or any instruction was folded.
410 DomTreeUpdater *DTU = nullptr,
411 MemorySSAUpdater *MSSAU = nullptr,
412 bool FoldInstsToUnreachable = true);
413
414/// Patch the replacement so that it is not more restrictive than the value
415/// being replaced. Unless DoesKMove is set, it assumes that the replacement
416/// does not get moved from its original position.
417LLVM_ABI void patchReplacementInstruction(Instruction *I, Value *Repl,
418 bool DoesKMove = false);
419
420// Replace each use of 'From' with 'To', if that use does not belong to basic
421// block where 'From' is defined. Returns the number of replacements made.
422LLVM_ABI unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
423
424/// Replace each use of 'From' with 'To' if that use is dominated by
425/// the given edge. Returns the number of replacements made.
426LLVM_ABI unsigned replaceDominatedUsesWith(Value *From, Value *To,
427 DominatorTree &DT,
428 const BasicBlockEdge &Edge);
429/// Replace each use of 'From' with 'To' if that use is dominated by
430/// the end of the given BasicBlock. Returns the number of replacements made.
431LLVM_ABI unsigned replaceDominatedUsesWith(Value *From, Value *To,
432 DominatorTree &DT,
433 const BasicBlock *BB);
434/// Replace each use of 'From' with 'To' if that use is dominated by the
435/// given instruction. Returns the number of replacements made.
436LLVM_ABI unsigned replaceDominatedUsesWith(Value *From, Value *To,
437 DominatorTree &DT,
438 const Instruction *I);
439/// Replace each use of 'From' with 'To' if that use is dominated by
440/// the given edge and the callback ShouldReplace returns true. Returns the
441/// number of replacements made.
443 Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge,
444 function_ref<bool(const Use &U, const Value *To)> ShouldReplace);
445/// Replace each use of 'From' with 'To' if that use is dominated by
446/// the end of the given BasicBlock and the callback ShouldReplace returns true.
447/// Returns the number of replacements made.
449 Value *From, Value *To, DominatorTree &DT, const BasicBlock *BB,
450 function_ref<bool(const Use &U, const Value *To)> ShouldReplace);
451/// Replace each use of 'From' with 'To' if that use is dominated by
452/// the given instruction and the callback ShouldReplace returns true. Returns
453/// the number of replacements made.
455 Value *From, Value *To, DominatorTree &DT, const Instruction *I,
456 function_ref<bool(const Use &U, const Value *To)> ShouldReplace);
457
458/// Return true if this call calls a gc leaf function.
459///
460/// A leaf function is a function that does not safepoint the thread during its
461/// execution. During a call or invoke to such a function, the callers stack
462/// does not have to be made parseable.
463///
464/// Most passes can and should ignore this information, and it is only used
465/// during lowering by the GC infrastructure.
466LLVM_ABI bool callsGCLeafFunction(const CallBase *Call,
467 const TargetLibraryInfo &TLI);
468
469/// Remove the debug intrinsic instructions for the given instruction.
470LLVM_ABI void dropDebugUsers(Instruction &I);
471
472/// Hoist all of the instructions in the \p IfBlock to the dominant block
473/// \p DomBlock, by moving its instructions to the insertion point \p InsertPt.
474///
475/// The moved instructions receive the insertion point debug location values
476/// (DILocations) and their debug intrinsic instructions are removed.
477LLVM_ABI void hoistAllInstructionsInto(BasicBlock *DomBlock,
478 Instruction *InsertPt, BasicBlock *BB);
479
480/// Given a constant, create a debug information expression.
481LLVM_ABI DIExpression *getExpressionForConstant(DIBuilder &DIB,
482 const Constant &C, Type &Ty);
483
484/// Remap the operands of the debug records attached to \p Inst, and the
485/// operands of \p Inst itself if it's a debug intrinsic.
486LLVM_ABI void remapDebugVariable(ValueToValueMapTy &Mapping, Instruction *Inst);
487
488//===----------------------------------------------------------------------===//
489// Intrinsic pattern matching
490//
491
492/// Try to match a bswap or bitreverse idiom.
493///
494/// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
495/// instructions are returned in \c InsertedInsts. They will all have been added
496/// to a basic block.
497///
498/// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
499/// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
500/// to BW / 4 nodes to be searched, so is significantly faster.
501///
502/// This function returns true on a successful match or false otherwise.
503LLVM_ABI bool
504recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps,
505 bool MatchBitReversals,
506 SmallVectorImpl<Instruction *> &InsertedInsts);
507
508//===----------------------------------------------------------------------===//
509// Sanitizer utilities
510//
511
512/// Given a CallInst, check if it calls a string function known to CodeGen,
513/// and mark it with NoBuiltin if so. To be used by sanitizers that intend
514/// to intercept string functions and want to avoid converting them to target
515/// specific instructions.
516LLVM_ABI void
518 const TargetLibraryInfo *TLI);
519
520//===----------------------------------------------------------------------===//
521// Transform predicates
522//
523
524/// Given an instruction, is it legal to set operand OpIdx to a non-constant
525/// value?
526LLVM_ABI bool canReplaceOperandWithVariable(const Instruction *I,
527 unsigned OpIdx);
528
529//===----------------------------------------------------------------------===//
530// Value helper functions
531//
532
533/// Invert the given true/false value, possibly reusing an existing copy.
534LLVM_ABI Value *invertCondition(Value *Condition);
535
536/// Move \p FI right after the definition of its operand, and replace the uses
537/// of the operand that it dominates with \p FI. Users whose operand was
538/// replaced are added to \p Users. Returns whether anything changed, which is
539/// not the case if there is no position to move \p FI to.
540LLVM_ABI bool freezeUsesAfterDef(FreezeInst &FI, DominatorTree &DT,
541 SmallVectorImpl<User *> *Users = nullptr);
542
543//===----------------------------------------------------------------------===//
544// Assorted
545//
546
547/// If we can infer one attribute from another on the declaration of a
548/// function, explicitly materialize the maximal set in the IR.
550
551//===----------------------------------------------------------------------===//
552// Helpers to track and update flags on instructions.
553//
554
556 bool HasNUW = true;
557 bool HasNSW = true;
558 bool IsDisjoint = true;
559
560#ifndef NDEBUG
561 /// Opcode of merged instructions. All instructions passed to mergeFlags must
562 /// have the same opcode.
563 std::optional<unsigned> Opcode;
564#endif
565
566 // Note: At the moment, users are responsible to manage AllKnownNonNegative
567 // and AllKnownNonZero manually. AllKnownNonNegative can be true in a case
568 // where one of the operands is negative, but one the operators is not NSW.
569 // AllKnownNonNegative should not be used independently of HasNSW
571 bool AllKnownNonZero = true;
572
573 OverflowTracking() = default;
574
575 /// Merge in the no-wrap flags from \p I.
577
578 /// Apply the no-wrap flags to \p I if applicable.
580};
581
582} // end namespace llvm
583
584#endif // LLVM_TRANSFORMS_UTILS_LOCAL_H
const TargetLowering & TLI
const AArch64InstrInfo MachineBasicBlock::iterator InsertPt
uint64_t uint64_t
ReachingDefInfo InstSet & ToRemove
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
iv Induction Variable Users
Definition IVUsers.cpp:48
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:61
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:63
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
This class represents a freeze function that returns random concrete value if an operand is either a ...
Invoke instruction.
An instruction for reading from memory.
Metadata node.
Definition Metadata.h:1087
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:166
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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:2565
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:2682
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:3094
LLVM_ABI bool freezeUsesAfterDef(FreezeInst &FI, DominatorTree &DT, SmallVectorImpl< User * > *Users=nullptr)
Move FI right after the definition of its operand, and replace the uses of the operand that it domina...
Definition Local.cpp:3781
LLVM_ABI Align getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
Definition Local.cpp:1608
LLVM_ABI unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition Local.cpp:3058
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:1833
LLVM_ABI CallInst * changeToCall(InvokeInst *II, DomTreeUpdater *DTU=nullptr)
This function converts the specified invoke into a normal call.
Definition Local.cpp:2658
LLVM_ABI void InsertDebugValueAtStoreLoc(DbgVariableRecord *DVR, StoreInst *SI, DIBuilder &Builder)
===------------------------------------------------------------------—===// Dbg Intrinsic utilities
Definition Local.cpp:1753
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:3240
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:1950
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:2548
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:2961
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:409
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:1186
LLVM_ABI bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction * > &InsertedInsts)
Try to match a bswap or bitreverse idiom.
Definition Local.cpp:3545
LLVM_ABI bool LowerDbgDeclare(Function &F)
Lowers dbg.declare records into appropriate set of dbg.value records.
Definition Local.cpp:1866
LLVM_ABI DIExpression * getExpressionForConstant(DIBuilder &DIB, const Constant &C, Type &Ty)
Given a constant, create a debug information expression.
Definition Local.cpp:3198
LLVM_ABI CallInst * createCallMatchingInvoke(InvokeInst *II)
Create a call that matches the invoke II in terms of arguments, attributes, debug information,...
Definition Local.cpp:2633
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:2171
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:1704
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:2923
LLVM_ABI void patchReplacementInstruction(Instruction *I, Value *Repl, bool DoesKMove=false)
Patch the replacement so that it is not more restrictive than the value being replaced.
Definition Local.cpp:2993
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:416
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:3073
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:2593
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:2494
LLVM_ABI Value * salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Ops, SmallVectorImpl< Value * > &AdditionalValues)
Definition Local.cpp:2354
LLVM_ABI void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
Definition Local.cpp:3145
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 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:3152
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:3658
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:2053
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:1559
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 foldBranchToCommonDest(CondBrInst *BI, 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 ...
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
Definition Local.h:238
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:3821
LLVM_ABI Value * invertCondition(Value *Condition)
Invert the given true/false value, possibly reusing an existing copy.
Definition Local.cpp:3747
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:3649
LLVM_ABI bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, const SimplifyCFGOptions &Options={}, ArrayRef< WeakVH > LoopHeaders={})
This function is used to do simplification of a CFG.
LLVM_ABI bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Definition Local.cpp:1551
LLVM_ABI bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI)
Return true if this call calls a gc leaf function.
Definition Local.cpp:3121
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:2013
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:111
std::optional< unsigned > Opcode
Opcode of merged instructions.
Definition Local.h:563
LLVM_ABI void mergeFlags(Instruction &I)
Merge in the no-wrap flags from I.
Definition Local.cpp:3851
LLVM_ABI void applyFlags(Instruction &I)
Apply the no-wrap flags to I if applicable.
Definition Local.cpp:3867