LLVM  7.0.0
Local.h
Go to the documentation of this file.
1 //===- Local.h - Functions to perform local transformations -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This family of functions perform various local transformations to the
11 // program.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
16 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/TinyPtrVector.h"
25 #include "llvm/IR/CallSite.h"
26 #include "llvm/IR/Constant.h"
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/DataLayout.h"
29 #include "llvm/IR/Dominators.h"
31 #include "llvm/IR/Operator.h"
32 #include "llvm/IR/Type.h"
33 #include "llvm/IR/User.h"
34 #include "llvm/IR/Value.h"
35 #include "llvm/Support/Casting.h"
36 #include <cstdint>
37 #include <limits>
38 
39 namespace llvm {
40 
41 class AllocaInst;
42 class AssumptionCache;
43 class BasicBlock;
44 class BranchInst;
45 class CallInst;
46 class DbgInfoIntrinsic;
47 class DbgValueInst;
48 class DIBuilder;
49 class Function;
50 class Instruction;
51 class LazyValueInfo;
52 class LoadInst;
53 class MDNode;
54 class PHINode;
55 class StoreInst;
56 class TargetLibraryInfo;
57 class TargetTransformInfo;
58 
59 /// A set of parameters used to control the transforms in the SimplifyCFG pass.
60 /// Options may change depending on the position in the optimization pipeline.
61 /// For example, canonical form that includes switches and branches may later be
62 /// replaced by lookup tables and selects.
70 
71  SimplifyCFGOptions(unsigned BonusThreshold = 1,
72  bool ForwardSwitchCond = false,
73  bool SwitchToLookup = false, bool CanonicalLoops = true,
74  bool SinkCommon = false,
75  AssumptionCache *AssumpCache = nullptr)
76  : BonusInstThreshold(BonusThreshold),
77  ForwardSwitchCondToPhi(ForwardSwitchCond),
78  ConvertSwitchToLookupTable(SwitchToLookup),
79  NeedCanonicalLoop(CanonicalLoops),
80  SinkCommonInsts(SinkCommon),
81  AC(AssumpCache) {}
82 
83  // Support 'builder' pattern to set members by name at construction time.
85  BonusInstThreshold = I;
86  return *this;
87  }
89  ForwardSwitchCondToPhi = B;
90  return *this;
91  }
93  ConvertSwitchToLookupTable = B;
94  return *this;
95  }
97  NeedCanonicalLoop = B;
98  return *this;
99  }
101  SinkCommonInsts = B;
102  return *this;
103  }
105  AC = Cache;
106  return *this;
107  }
108 };
109 
110 //===----------------------------------------------------------------------===//
111 // Local constant propagation.
112 //
113 
114 /// If a terminator instruction is predicated on a constant value, convert it
115 /// into an unconditional branch to the constant destination.
116 /// This is a nontrivial operation because the successors of this basic block
117 /// must have their PHI nodes updated.
118 /// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
119 /// conditions and indirectbr addresses this might make dead if
120 /// DeleteDeadConditions is true.
121 bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
122  const TargetLibraryInfo *TLI = nullptr,
123  DeferredDominance *DDT = nullptr);
124 
125 //===----------------------------------------------------------------------===//
126 // Local dead code elimination.
127 //
128 
129 /// Return true if the result produced by the instruction is not used, and the
130 /// instruction has no side effects.
132  const TargetLibraryInfo *TLI = nullptr);
133 
134 /// Return true if the result produced by the instruction would have no side
135 /// effects if it was not used. This is equivalent to checking whether
136 /// isInstructionTriviallyDead would be true if the use count was 0.
138  const TargetLibraryInfo *TLI = nullptr);
139 
140 /// If the specified value is a trivially dead instruction, delete it.
141 /// If that makes any of its operands trivially dead, delete them too,
142 /// recursively. Return true if any instructions were deleted.
144  const TargetLibraryInfo *TLI = nullptr);
145 
146 /// Delete all of the instructions in `DeadInsts`, and all other instructions
147 /// that deleting these in turn causes to be trivially dead.
148 ///
149 /// The initial instructions in the provided vector must all have empty use
150 /// lists and satisfy `isInstructionTriviallyDead`.
151 ///
152 /// `DeadInsts` will be used as scratch storage for this routine and will be
153 /// empty afterward.
156  const TargetLibraryInfo *TLI = nullptr);
157 
158 /// If the specified value is an effectively dead PHI node, due to being a
159 /// def-use chain of single-use nodes that either forms a cycle or is terminated
160 /// by a trivially dead instruction, delete it. If that makes any of its
161 /// operands trivially dead, delete them too, recursively. Return true if a
162 /// change was made.
164  const TargetLibraryInfo *TLI = nullptr);
165 
166 /// Scan the specified basic block and try to simplify any instructions in it
167 /// and recursively delete dead instructions.
168 ///
169 /// This returns true if it changed the code, note that it can delete
170 /// instructions in other blocks as well in this block.
172  const TargetLibraryInfo *TLI = nullptr);
173 
174 //===----------------------------------------------------------------------===//
175 // Control Flow Graph Restructuring.
176 //
177 
178 /// Like BasicBlock::removePredecessor, this method is called when we're about
179 /// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
180 /// drops the entries in the PHI nodes for Pred.
181 ///
182 /// Unlike the removePredecessor method, this attempts to simplify uses of PHI
183 /// nodes that collapse into identity values. For example, if we have:
184 /// x = phi(1, 0, 0, 0)
185 /// y = and x, z
186 ///
187 /// .. and delete the predecessor corresponding to the '1', this will attempt to
188 /// recursively fold the 'and' to 0.
190  DeferredDominance *DDT = nullptr);
191 
192 /// BB is a block with one predecessor and its predecessor is known to have one
193 /// successor (BB!). Eliminate the edge between them, moving the instructions in
194 /// the predecessor into BB. This deletes the predecessor block.
196  DeferredDominance *DDT = nullptr);
197 
198 /// BB is known to contain an unconditional branch, and contains no instructions
199 /// other than PHI nodes, potential debug intrinsics and the branch. If
200 /// possible, eliminate BB by rewriting all the predecessors to branch to the
201 /// successor block and return true. If we can't transform, return false.
203  DeferredDominance *DDT = nullptr);
204 
205 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
206 /// to be clever about PHI nodes which differ only in the order of the incoming
207 /// values, but instcombine orders them so it usually won't matter.
209 
210 /// This function is used to do simplification of a CFG. For example, it
211 /// adjusts branches to branches to eliminate the extra hop, it eliminates
212 /// unreachable basic blocks, and does other peephole optimization of the CFG.
213 /// It returns true if a modification was made, possibly deleting the basic
214 /// block that was pointed to. LoopHeaders is an optional input parameter
215 /// providing the set of loop headers that SimplifyCFG should not eliminate.
216 bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
217  const SimplifyCFGOptions &Options = {},
218  SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
219 
220 /// This function is used to flatten a CFG. For example, it uses parallel-and
221 /// and parallel-or mode to collapse if-conditions and merge if-regions with
222 /// identical statements.
223 bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
224 
225 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
226 /// branches to us and one of our successors, fold the setcc into the
227 /// predecessor and use logical operations to pick the right destination.
229 
230 /// This function takes a virtual register computed by an Instruction and
231 /// replaces it with a slot in the stack frame, allocated via alloca.
232 /// This allows the CFG to be changed around without fear of invalidating the
233 /// SSA information for the value. It returns the pointer to the alloca inserted
234 /// to create a stack slot for X.
236  bool VolatileLoads = false,
237  Instruction *AllocaPoint = nullptr);
238 
239 /// This function takes a virtual register computed by a phi node and replaces
240 /// it with a slot in the stack frame, allocated via alloca. The phi node is
241 /// deleted and it returns the pointer to the alloca inserted.
242 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
243 
244 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
245 /// the owning object can be modified and has an alignment less than \p
246 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
247 /// cannot be increased, the known alignment of the value is returned.
248 ///
249 /// It is not always possible to modify the alignment of the underlying object,
250 /// so if alignment is important, a more reliable approach is to simply align
251 /// all global variables and allocation instructions to their preferred
252 /// alignment from the beginning.
253 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
254  const DataLayout &DL,
255  const Instruction *CxtI = nullptr,
256  AssumptionCache *AC = nullptr,
257  const DominatorTree *DT = nullptr);
258 
259 /// Try to infer an alignment for the specified pointer.
260 inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
261  const Instruction *CxtI = nullptr,
262  AssumptionCache *AC = nullptr,
263  const DominatorTree *DT = nullptr) {
264  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
265 }
266 
267 ///===---------------------------------------------------------------------===//
268 /// Dbg Intrinsic utilities
269 ///
270 
271 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
272 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
274  StoreInst *SI, DIBuilder &Builder);
275 
276 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
277 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
279  LoadInst *LI, DIBuilder &Builder);
280 
281 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
282 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
284  PHINode *LI, DIBuilder &Builder);
285 
286 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
287 /// llvm.dbg.value intrinsics.
288 bool LowerDbgDeclare(Function &F);
289 
290 /// Propagate dbg.value intrinsics through the newly inserted PHIs.
292  SmallVectorImpl<PHINode *> &InsertedPHIs);
293 
294 /// Finds all intrinsics declaring local variables as living in the memory that
295 /// 'V' points to. This may include a mix of dbg.declare and
296 /// dbg.addr intrinsics.
298 
299 /// Finds the llvm.dbg.value intrinsics describing a value.
301 
302 /// Finds the debug info intrinsics describing a value.
304 
305 /// Replaces llvm.dbg.declare instruction when the address it
306 /// describes is replaced with a new value. If Deref is true, an
307 /// additional DW_OP_deref is prepended to the expression. If Offset
308 /// is non-zero, a constant displacement is added to the expression
309 /// (between the optional Deref operations). Offset can be negative.
310 bool replaceDbgDeclare(Value *Address, Value *NewAddress,
311  Instruction *InsertBefore, DIBuilder &Builder,
312  bool DerefBefore, int Offset, bool DerefAfter);
313 
314 /// Replaces llvm.dbg.declare instruction when the alloca it describes
315 /// is replaced with a new value. If Deref is true, an additional
316 /// DW_OP_deref is prepended to the expression. If Offset is non-zero,
317 /// a constant displacement is added to the expression (between the
318 /// optional Deref operations). Offset can be negative. The new
319 /// llvm.dbg.declare is inserted immediately after AI.
320 bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
321  DIBuilder &Builder, bool DerefBefore,
322  int Offset, bool DerefAfter);
323 
324 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
325 /// is replaced with a new value. If Offset is non-zero, a constant displacement
326 /// is added to the expression (after the mandatory Deref). Offset can be
327 /// negative. New llvm.dbg.value instructions are inserted at the locations of
328 /// the instructions they replace.
329 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
330  DIBuilder &Builder, int Offset = 0);
331 
332 /// Assuming the instruction \p I is going to be deleted, attempt to salvage
333 /// debug users of \p I by writing the effect of \p I in a DIExpression.
334 /// Returns true if any debug users were updated.
336 
337 /// Point debug users of \p From to \p To or salvage them. Use this function
338 /// only when replacing all uses of \p From with \p To, with a guarantee that
339 /// \p From is going to be deleted.
340 ///
341 /// Follow these rules to prevent use-before-def of \p To:
342 /// . If \p To is a linked Instruction, set \p DomPoint to \p To.
343 /// . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
344 /// \p To will be inserted after.
345 /// . If \p To is not an Instruction (e.g a Constant), the choice of
346 /// \p DomPoint is arbitrary. Pick \p From for simplicity.
347 ///
348 /// If a debug user cannot be preserved without reordering variable updates or
349 /// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
350 /// or deleted. Returns true if any debug users were updated.
351 bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint,
352  DominatorTree &DT);
353 
354 /// Remove all instructions from a basic block other than it's terminator
355 /// and any present EH pad instructions.
357 
358 /// Insert an unreachable instruction before the specified
359 /// instruction, making it and the rest of the code in the block dead.
360 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
361  bool PreserveLCSSA = false,
362  DeferredDominance *DDT = nullptr);
363 
364 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
365 /// block. This also splits the basic block where CI is located, because
366 /// InvokeInst is a terminator instruction. Returns the newly split basic
367 /// block.
369  BasicBlock *UnwindEdge);
370 
371 /// Replace 'BB's terminator with one that does not have an unwind successor
372 /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
373 /// successor.
374 ///
375 /// \param BB Block whose terminator will be replaced. Its terminator must
376 /// have an unwind successor.
377 void removeUnwindEdge(BasicBlock *BB, DeferredDominance *DDT = nullptr);
378 
379 /// Remove all blocks that can not be reached from the function's entry.
380 ///
381 /// Returns true if any basic block was removed.
382 bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr,
383  DeferredDominance *DDT = nullptr);
384 
385 /// Combine the metadata of two instructions so that K can replace J
386 ///
387 /// Metadata not listed as known via KnownIDs is removed
388 void combineMetadata(Instruction *K, const Instruction *J, ArrayRef<unsigned> KnownIDs);
389 
390 /// Combine the metadata of two instructions so that K can replace J. This
391 /// specifically handles the case of CSE-like transformations.
392 ///
393 /// Unknown metadata is removed.
395 
396 // Replace each use of 'From' with 'To', if that use does not belong to basic
397 // block where 'From' is defined. Returns the number of replacements made.
398 unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
399 
400 /// Replace each use of 'From' with 'To' if that use is dominated by
401 /// the given edge. Returns the number of replacements made.
402 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
403  const BasicBlockEdge &Edge);
404 /// Replace each use of 'From' with 'To' if that use is dominated by
405 /// the end of the given BasicBlock. Returns the number of replacements made.
406 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
407  const BasicBlock *BB);
408 
409 /// Return true if the CallSite CS calls a gc leaf function.
410 ///
411 /// A leaf function is a function that does not safepoint the thread during its
412 /// execution. During a call or invoke to such a function, the callers stack
413 /// does not have to be made parseable.
414 ///
415 /// Most passes can and should ignore this information, and it is only used
416 /// during lowering by the GC infrastructure.
418 
419 /// Copy a nonnull metadata node to a new load instruction.
420 ///
421 /// This handles mapping it to range metadata if the new load is an integer
422 /// load instead of a pointer load.
423 void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
424 
425 /// Copy a range metadata node to a new load instruction.
426 ///
427 /// This handles mapping it to nonnull metadata if the new load is a pointer
428 /// load instead of an integer load and the range doesn't cover null.
429 void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
430  LoadInst &NewLI);
431 
432 //===----------------------------------------------------------------------===//
433 // Intrinsic pattern matching
434 //
435 
436 /// Try to match a bswap or bitreverse idiom.
437 ///
438 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
439 /// instructions are returned in \c InsertedInsts. They will all have been added
440 /// to a basic block.
441 ///
442 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
443 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
444 /// to BW / 4 nodes to be searched, so is significantly faster.
445 ///
446 /// This function returns true on a successful match or false otherwise.
448  Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
449  SmallVectorImpl<Instruction *> &InsertedInsts);
450 
451 //===----------------------------------------------------------------------===//
452 // Sanitizer utilities
453 //
454 
455 /// Given a CallInst, check if it calls a string function known to CodeGen,
456 /// and mark it with NoBuiltin if so. To be used by sanitizers that intend
457 /// to intercept string functions and want to avoid converting them to target
458 /// specific instructions.
460  const TargetLibraryInfo *TLI);
461 
462 //===----------------------------------------------------------------------===//
463 // Transform predicates
464 //
465 
466 /// Given an instruction, is it legal to set operand OpIdx to a non-constant
467 /// value?
468 bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
469 
470 } // end namespace llvm
471 
472 #endif // LLVM_TRANSFORMS_UTILS_LOCAL_H
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, Instruction *AllocaPoint=nullptr)
This function takes a virtual register computed by an Instruction and replaces it with a slot in the ...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
unsigned getOrEnforceKnownAlignment(Value *V, unsigned 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:1165
void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, int Offset=0)
Replaces multiple llvm.dbg.value instructions when the alloca it describes is replaced with a new val...
Definition: Local.cpp:1583
bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, bool DerefBefore, int Offset, bool DerefAfter)
Replaces llvm.dbg.declare instruction when the alloca it describes is replaced with a new value...
Definition: Local.cpp:1548
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Various leaf nodes.
Definition: ISDOpcodes.h:60
AssumptionCache * AC
Definition: Local.h:69
This class represents a function call, abstracting a target machine&#39;s calling convention.
SimplifyCFGOptions & bonusInstThreshold(int I)
Definition: Local.h:84
SimplifyCFGOptions & sinkCommonInsts(bool B)
Definition: Local.h:100
A cache of @llvm.assume calls within a function.
bool salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage debug users of I by writing the...
Definition: Local.cpp:1599
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:577
Metadata node.
Definition: Metadata.h:862
F(f)
An instruction for reading from memory.
Definition: Instructions.h:168
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Definition: TinyPtrVector.h:31
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge)
Replace each use of &#39;From&#39; with &#39;To&#39; if that use is dominated by the given edge.
Definition: Local.cpp:2369
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:344
SimplifyCFGOptions & forwardSwitchCondToPhi(bool B)
Definition: Local.h:88
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT=nullptr, DeferredDominance *DDT=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!)...
Definition: Local.cpp:660
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void insertDebugValuesForPHIs(BasicBlock *BB, SmallVectorImpl< PHINode *> &InsertedPHIs)
Propagate dbg.value intrinsics through the newly inserted PHIs.
Definition: Local.cpp:1437
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: Local.cpp:1503
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
Definition: Local.cpp:2414
static cl::opt< bool > SinkCommon("simplifycfg-sink-common", cl::Hidden, cl::init(true), cl::desc("Sink common instructions down to the end block"))
An instruction for storing to memory.
Definition: Instructions.h:310
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr, DeferredDominance *DDT=nullptr)
Remove all blocks that can not be reached from the function&#39;s entry.
Definition: Local.cpp:2207
bool ForwardSwitchCondToPhi
Definition: Local.h:65
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
Definition: Local.cpp:1816
SimplifyCFGOptions & convertSwitchToLookupTable(bool B)
Definition: Local.h:92
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Definition: Local.cpp:1060
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:142
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
This function is used to flatten a CFG.
Definition: FlattenCFG.cpp:490
#define P(N)
bool FoldBranchToCommonDest(BranchInst *BI, 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 ...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
Conditional or Unconditional Branch instruction.
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:2720
void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Definition: Local.cpp:1258
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool ConvertSwitchToLookupTable
Definition: Local.h:66
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:2439
bool callsGCLeafFunction(ImmutableCallSite CS, const TargetLibraryInfo &TLI)
Return true if the CallSite CS calls a gc leaf function.
Definition: Local.cpp:2388
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DeferredDominance *DDT=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
Definition: Local.cpp:103
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
If the specified value is a trivially dead instruction, delete it.
Definition: Local.cpp:429
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
Definition: Local.cpp:1381
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, DeferredDominance *DDT=nullptr)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes...
Definition: Local.cpp:947
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Provides information about what library functions are available for the current target.
This is the common base class for debug info intrinsics.
Definition: IntrinsicInst.h:67
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=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:498
SimplifyCFGOptions & needCanonicalLoops(bool B)
Definition: Local.h:96
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than it&#39;s terminator and any present EH pad instruct...
Definition: Local.cpp:1883
void removeUnwindEdge(BasicBlock *BB, DeferredDominance *DDT=nullptr)
Replace &#39;BB&#39;s terminator with one that does not have an unwind successor block.
Definition: Local.cpp:2167
SimplifyCFGOptions & setAssumptionCache(AssumptionCache *Cache)
Definition: Local.h:104
Class to defer updates to a DominatorTree.
Definition: Dominators.h:307
TinyPtrVector< DbgInfoIntrinsic * > FindDbgAddrUses(Value *V)
Finds all intrinsics declaring local variables as living in the memory that &#39;V&#39; points to...
Definition: Local.cpp:1481
bool replaceDbgDeclare(Value *Address, Value *NewAddress, Instruction *InsertBefore, DIBuilder &Builder, bool DerefBefore, int Offset, bool DerefAfter)
Replaces llvm.dbg.declare instruction when the address it describes is replaced with a new value...
Definition: Local.cpp:1528
Establish a view to a call site for examination.
Definition: CallSite.h:714
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
unsigned 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:260
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:2710
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:2321
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred, DeferredDominance *DDT=nullptr)
Like BasicBlock::removePredecessor, this method is called when we&#39;re about to delete Pred as a predec...
Definition: Local.cpp:628
void findDbgUsers(SmallVectorImpl< DbgInfoIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: Local.cpp:1515
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false, DeferredDominance *DDT=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition: Local.cpp:1904
This pass computes, caches, and vends lazy value constraint information.
Definition: LazyValueInfo.h:32
AllocaInst * DemotePHIToStack(PHINode *P, Instruction *AllocaPoint=nullptr)
This function takes a virtual register computed by a phi node and replaces it with a slot in the stac...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
Definition: Local.cpp:346
LLVM Value Representation.
Definition: Value.h:73
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition: Local.cpp:1968
bool wouldInstructionBeTriviallyDead(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:353
SimplifyCFGOptions(unsigned BonusThreshold=1, bool ForwardSwitchCond=false, bool SwitchToLookup=false, bool CanonicalLoops=true, bool SinkCommon=false, AssumptionCache *AssumpCache=nullptr)
Definition: Local.h:71
bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, const SimplifyCFGOptions &Options={}, SmallPtrSetImpl< BasicBlock *> *LoopHeaders=nullptr)
This function is used to do simplification of a CFG.
A set of parameters used to control the transforms in the SimplifyCFG pass.
Definition: Local.h:63
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction *> &InsertedInsts)
Try to match a bswap or bitreverse idiom.
Definition: Local.cpp:2636
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:2256
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition: Local.cpp:2352
an instruction to allocate memory on the stack
Definition: Instructions.h:60