LLVM  8.0.0svn
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/DomTreeUpdater.h"
30 #include "llvm/IR/Dominators.h"
32 #include "llvm/IR/Operator.h"
33 #include "llvm/IR/Type.h"
34 #include "llvm/IR/User.h"
35 #include "llvm/IR/Value.h"
36 #include "llvm/Support/Casting.h"
37 #include <cstdint>
38 #include <limits>
39 
40 namespace llvm {
41 
42 class AllocaInst;
43 class AssumptionCache;
44 class BasicBlock;
45 class BranchInst;
46 class CallInst;
47 class DbgVariableIntrinsic;
48 class DbgValueInst;
49 class DIBuilder;
50 class Function;
51 class Instruction;
52 class LazyValueInfo;
53 class LoadInst;
54 class MDNode;
55 class MemorySSAUpdater;
56 class PHINode;
57 class StoreInst;
58 class TargetLibraryInfo;
59 class TargetTransformInfo;
60 
61 /// A set of parameters used to control the transforms in the SimplifyCFG pass.
62 /// Options may change depending on the position in the optimization pipeline.
63 /// For example, canonical form that includes switches and branches may later be
64 /// replaced by lookup tables and selects.
72 
73  SimplifyCFGOptions(unsigned BonusThreshold = 1,
74  bool ForwardSwitchCond = false,
75  bool SwitchToLookup = false, bool CanonicalLoops = true,
76  bool SinkCommon = false,
77  AssumptionCache *AssumpCache = nullptr)
78  : BonusInstThreshold(BonusThreshold),
79  ForwardSwitchCondToPhi(ForwardSwitchCond),
80  ConvertSwitchToLookupTable(SwitchToLookup),
81  NeedCanonicalLoop(CanonicalLoops),
82  SinkCommonInsts(SinkCommon),
83  AC(AssumpCache) {}
84 
85  // Support 'builder' pattern to set members by name at construction time.
87  BonusInstThreshold = I;
88  return *this;
89  }
91  ForwardSwitchCondToPhi = B;
92  return *this;
93  }
95  ConvertSwitchToLookupTable = B;
96  return *this;
97  }
99  NeedCanonicalLoop = B;
100  return *this;
101  }
103  SinkCommonInsts = B;
104  return *this;
105  }
107  AC = Cache;
108  return *this;
109  }
110 };
111 
112 //===----------------------------------------------------------------------===//
113 // Local constant propagation.
114 //
115 
116 /// If a terminator instruction is predicated on a constant value, convert it
117 /// into an unconditional branch to the constant destination.
118 /// This is a nontrivial operation because the successors of this basic block
119 /// must have their PHI nodes updated.
120 /// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
121 /// conditions and indirectbr addresses this might make dead if
122 /// DeleteDeadConditions is true.
123 bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
124  const TargetLibraryInfo *TLI = nullptr,
125  DomTreeUpdater *DTU = nullptr);
126 
127 //===----------------------------------------------------------------------===//
128 // Local dead code elimination.
129 //
130 
131 /// Return true if the result produced by the instruction is not used, and the
132 /// instruction has no side effects.
134  const TargetLibraryInfo *TLI = nullptr);
135 
136 /// Return true if the result produced by the instruction would have no side
137 /// effects if it was not used. This is equivalent to checking whether
138 /// isInstructionTriviallyDead would be true if the use count was 0.
140  const TargetLibraryInfo *TLI = nullptr);
141 
142 /// If the specified value is a trivially dead instruction, delete it.
143 /// If that makes any of its operands trivially dead, delete them too,
144 /// recursively. Return true if any instructions were deleted.
146  Value *V, const TargetLibraryInfo *TLI = nullptr,
147  MemorySSAUpdater *MSSAU = nullptr);
148 
149 /// Delete all of the instructions in `DeadInsts`, and all other instructions
150 /// that deleting these in turn causes to be trivially dead.
151 ///
152 /// The initial instructions in the provided vector must all have empty use
153 /// lists and satisfy `isInstructionTriviallyDead`.
154 ///
155 /// `DeadInsts` will be used as scratch storage for this routine and will be
156 /// empty afterward.
159  const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr);
160 
161 /// If the specified value is an effectively dead PHI node, due to being a
162 /// def-use chain of single-use nodes that either forms a cycle or is terminated
163 /// by a trivially dead instruction, delete it. If that makes any of its
164 /// operands trivially dead, delete them too, recursively. Return true if a
165 /// change was made.
167  const TargetLibraryInfo *TLI = nullptr);
168 
169 /// Scan the specified basic block and try to simplify any instructions in it
170 /// and recursively delete dead instructions.
171 ///
172 /// This returns true if it changed the code, note that it can delete
173 /// instructions in other blocks as well in this block.
175  const TargetLibraryInfo *TLI = nullptr);
176 
177 /// Replace all the uses of an SSA value in @llvm.dbg intrinsics with
178 /// undef. This is useful for signaling that a variable, e.g. has been
179 /// found dead and hence it's unavailable at a given program point.
180 /// Returns true if the dbg values have been changed.
182 
183 //===----------------------------------------------------------------------===//
184 // Control Flow Graph Restructuring.
185 //
186 
187 /// Like BasicBlock::removePredecessor, this method is called when we're about
188 /// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
189 /// drops the entries in the PHI nodes for Pred.
190 ///
191 /// Unlike the removePredecessor method, this attempts to simplify uses of PHI
192 /// nodes that collapse into identity values. For example, if we have:
193 /// x = phi(1, 0, 0, 0)
194 /// y = and x, z
195 ///
196 /// .. and delete the predecessor corresponding to the '1', this will attempt to
197 /// recursively fold the 'and' to 0.
199  DomTreeUpdater *DTU = nullptr);
200 
201 /// BB is a block with one predecessor and its predecessor is known to have one
202 /// successor (BB!). Eliminate the edge between them, moving the instructions in
203 /// the predecessor into BB. This deletes the predecessor block.
204 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
205 
206 /// BB is known to contain an unconditional branch, and contains no instructions
207 /// other than PHI nodes, potential debug intrinsics and the branch. If
208 /// possible, eliminate BB by rewriting all the predecessors to branch to the
209 /// successor block and return true. If we can't transform, return false.
211  DomTreeUpdater *DTU = nullptr);
212 
213 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
214 /// to be clever about PHI nodes which differ only in the order of the incoming
215 /// values, but instcombine orders them so it usually won't matter.
217 
218 /// This function is used to do simplification of a CFG. For example, it
219 /// adjusts branches to branches to eliminate the extra hop, it eliminates
220 /// unreachable basic blocks, and does other peephole optimization of the CFG.
221 /// It returns true if a modification was made, possibly deleting the basic
222 /// block that was pointed to. LoopHeaders is an optional input parameter
223 /// providing the set of loop headers that SimplifyCFG should not eliminate.
224 bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
225  const SimplifyCFGOptions &Options = {},
226  SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
227 
228 /// This function is used to flatten a CFG. For example, it uses parallel-and
229 /// and parallel-or mode to collapse if-conditions and merge if-regions with
230 /// identical statements.
231 bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
232 
233 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
234 /// branches to us and one of our successors, fold the setcc into the
235 /// predecessor and use logical operations to pick the right destination.
237 
238 /// This function takes a virtual register computed by an Instruction and
239 /// replaces it with a slot in the stack frame, allocated via alloca.
240 /// This allows the CFG to be changed around without fear of invalidating the
241 /// SSA information for the value. It returns the pointer to the alloca inserted
242 /// to create a stack slot for X.
244  bool VolatileLoads = false,
245  Instruction *AllocaPoint = nullptr);
246 
247 /// This function takes a virtual register computed by a phi node and replaces
248 /// it with a slot in the stack frame, allocated via alloca. The phi node is
249 /// deleted and it returns the pointer to the alloca inserted.
250 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
251 
252 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
253 /// the owning object can be modified and has an alignment less than \p
254 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
255 /// cannot be increased, the known alignment of the value is returned.
256 ///
257 /// It is not always possible to modify the alignment of the underlying object,
258 /// so if alignment is important, a more reliable approach is to simply align
259 /// all global variables and allocation instructions to their preferred
260 /// alignment from the beginning.
261 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
262  const DataLayout &DL,
263  const Instruction *CxtI = nullptr,
264  AssumptionCache *AC = nullptr,
265  const DominatorTree *DT = nullptr);
266 
267 /// Try to infer an alignment for the specified pointer.
268 inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
269  const Instruction *CxtI = nullptr,
270  AssumptionCache *AC = nullptr,
271  const DominatorTree *DT = nullptr) {
272  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
273 }
274 
275 ///===---------------------------------------------------------------------===//
276 /// Dbg Intrinsic utilities
277 ///
278 
279 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
280 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
282  StoreInst *SI, DIBuilder &Builder);
283 
284 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
285 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
287  LoadInst *LI, DIBuilder &Builder);
288 
289 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
290 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
292  PHINode *LI, DIBuilder &Builder);
293 
294 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
295 /// llvm.dbg.value intrinsics.
296 bool LowerDbgDeclare(Function &F);
297 
298 /// Propagate dbg.value intrinsics through the newly inserted PHIs.
300  SmallVectorImpl<PHINode *> &InsertedPHIs);
301 
302 /// Finds all intrinsics declaring local variables as living in the memory that
303 /// 'V' points to. This may include a mix of dbg.declare and
304 /// dbg.addr intrinsics.
306 
307 /// Finds the llvm.dbg.value intrinsics describing a value.
309 
310 /// Finds the debug info intrinsics describing a value.
312 
313 /// Replaces llvm.dbg.declare instruction when the address it
314 /// describes is replaced with a new value. If Deref is true, an
315 /// additional DW_OP_deref is prepended to the expression. If Offset
316 /// is non-zero, a constant displacement is added to the expression
317 /// (between the optional Deref operations). Offset can be negative.
318 bool replaceDbgDeclare(Value *Address, Value *NewAddress,
319  Instruction *InsertBefore, DIBuilder &Builder,
320  bool DerefBefore, int Offset, bool DerefAfter);
321 
322 /// Replaces llvm.dbg.declare instruction when the alloca it describes
323 /// is replaced with a new value. If Deref is true, an additional
324 /// DW_OP_deref is prepended to the expression. If Offset is non-zero,
325 /// a constant displacement is added to the expression (between the
326 /// optional Deref operations). Offset can be negative. The new
327 /// llvm.dbg.declare is inserted immediately after AI.
328 bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
329  DIBuilder &Builder, bool DerefBefore,
330  int Offset, bool DerefAfter);
331 
332 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
333 /// is replaced with a new value. If Offset is non-zero, a constant displacement
334 /// is added to the expression (after the mandatory Deref). Offset can be
335 /// negative. New llvm.dbg.value instructions are inserted at the locations of
336 /// the instructions they replace.
337 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
338  DIBuilder &Builder, int Offset = 0);
339 
340 /// Assuming the instruction \p I is going to be deleted, attempt to salvage
341 /// debug users of \p I by writing the effect of \p I in a DIExpression.
342 /// Returns true if any debug users were updated.
344 
345 /// Point debug users of \p From to \p To or salvage them. Use this function
346 /// only when replacing all uses of \p From with \p To, with a guarantee that
347 /// \p From is going to be deleted.
348 ///
349 /// Follow these rules to prevent use-before-def of \p To:
350 /// . If \p To is a linked Instruction, set \p DomPoint to \p To.
351 /// . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
352 /// \p To will be inserted after.
353 /// . If \p To is not an Instruction (e.g a Constant), the choice of
354 /// \p DomPoint is arbitrary. Pick \p From for simplicity.
355 ///
356 /// If a debug user cannot be preserved without reordering variable updates or
357 /// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
358 /// or deleted. Returns true if any debug users were updated.
360  DominatorTree &DT);
361 
362 /// Remove all instructions from a basic block other than it's terminator
363 /// and any present EH pad instructions.
365 
366 /// Insert an unreachable instruction before the specified
367 /// instruction, making it and the rest of the code in the block dead.
368 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
369  bool PreserveLCSSA = false,
370  DomTreeUpdater *DTU = nullptr);
371 
372 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
373 /// block. This also splits the basic block where CI is located, because
374 /// InvokeInst is a terminator instruction. Returns the newly split basic
375 /// block.
377  BasicBlock *UnwindEdge);
378 
379 /// Replace 'BB's terminator with one that does not have an unwind successor
380 /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
381 /// successor.
382 ///
383 /// \param BB Block whose terminator will be replaced. Its terminator must
384 /// have an unwind successor.
385 void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
386 
387 /// Remove all blocks that can not be reached from the function's entry.
388 ///
389 /// Returns true if any basic block was removed.
390 bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr,
391  DomTreeUpdater *DTU = nullptr,
392  MemorySSAUpdater *MSSAU = nullptr);
393 
394 /// Combine the metadata of two instructions so that K can replace J. Some
395 /// metadata kinds can only be kept if K does not move, meaning it dominated
396 /// J in the original IR.
397 ///
398 /// Metadata not listed as known via KnownIDs is removed
399 void combineMetadata(Instruction *K, const Instruction *J,
400  ArrayRef<unsigned> KnownIDs, bool DoesKMove);
401 
402 /// Combine the metadata of two instructions so that K can replace J. This
403 /// specifically handles the case of CSE-like transformations. Some
404 /// metadata can only be kept if K dominates J. For this to be correct,
405 /// K cannot be hoisted.
406 ///
407 /// Unknown metadata is removed.
409  bool DoesKMove);
410 
411 /// Patch the replacement so that it is not more restrictive than the value
412 /// being replaced. It assumes that the replacement does not get moved from
413 /// its original position.
415 
416 // Replace each use of 'From' with 'To', if that use does not belong to basic
417 // block where 'From' is defined. Returns the number of replacements made.
418 unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
419 
420 /// Replace each use of 'From' with 'To' if that use is dominated by
421 /// the given edge. Returns the number of replacements made.
422 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
423  const BasicBlockEdge &Edge);
424 /// Replace each use of 'From' with 'To' if that use is dominated by
425 /// the end of the given BasicBlock. Returns the number of replacements made.
426 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
427  const BasicBlock *BB);
428 
429 /// Return true if the CallSite CS calls a gc leaf function.
430 ///
431 /// A leaf function is a function that does not safepoint the thread during its
432 /// execution. During a call or invoke to such a function, the callers stack
433 /// does not have to be made parseable.
434 ///
435 /// Most passes can and should ignore this information, and it is only used
436 /// during lowering by the GC infrastructure.
438 
439 /// Copy a nonnull metadata node to a new load instruction.
440 ///
441 /// This handles mapping it to range metadata if the new load is an integer
442 /// load instead of a pointer load.
443 void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
444 
445 /// Copy a range metadata node to a new load instruction.
446 ///
447 /// This handles mapping it to nonnull metadata if the new load is a pointer
448 /// load instead of an integer load and the range doesn't cover null.
449 void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
450  LoadInst &NewLI);
451 
452 /// Remove the debug intrinsic instructions for the given instruction.
453 void dropDebugUsers(Instruction &I);
454 
455 /// Hoist all of the instructions in the \p IfBlock to the dominant block
456 /// \p DomBlock, by moving its instructions to the insertion point \p InsertPt.
457 ///
458 /// The moved instructions receive the insertion point debug location values
459 /// (DILocations) and their debug intrinsic instructions (dbg.values) are
460 /// removed.
461 void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,
462  BasicBlock *BB);
463 
464 //===----------------------------------------------------------------------===//
465 // Intrinsic pattern matching
466 //
467 
468 /// Try to match a bswap or bitreverse idiom.
469 ///
470 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
471 /// instructions are returned in \c InsertedInsts. They will all have been added
472 /// to a basic block.
473 ///
474 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
475 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
476 /// to BW / 4 nodes to be searched, so is significantly faster.
477 ///
478 /// This function returns true on a successful match or false otherwise.
480  Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
481  SmallVectorImpl<Instruction *> &InsertedInsts);
482 
483 //===----------------------------------------------------------------------===//
484 // Sanitizer utilities
485 //
486 
487 /// Given a CallInst, check if it calls a string function known to CodeGen,
488 /// and mark it with NoBuiltin if so. To be used by sanitizers that intend
489 /// to intercept string functions and want to avoid converting them to target
490 /// specific instructions.
492  const TargetLibraryInfo *TLI);
493 
494 //===----------------------------------------------------------------------===//
495 // Transform predicates
496 //
497 
498 /// Given an instruction, is it legal to set operand OpIdx to a non-constant
499 /// value?
500 bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
501 
502 } // end namespace llvm
503 
504 #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 ...
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred, DomTreeUpdater *DTU=nullptr)
Like BasicBlock::removePredecessor, this method is called when we&#39;re about to delete Pred as a predec...
Definition: Local.cpp:643
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:1184
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:1602
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:1567
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Various leaf nodes.
Definition: ISDOpcodes.h:60
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:105
AssumptionCache * AC
Definition: Local.h:71
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function&#39;s entry.
Definition: Local.cpp:2227
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: Local.cpp:1534
This class represents a function call, abstracting a target machine&#39;s calling convention.
SimplifyCFGOptions & bonusInstThreshold(int I)
Definition: Local.h:86
SimplifyCFGOptions & sinkCommonInsts(bool B)
Definition: Local.h:102
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:1618
bool replaceDbgUsesWithUndef(Instruction *I)
Replace all the uses of an SSA value in .dbg intrinsics with undef.
Definition: Local.cpp:479
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:592
Metadata node.
Definition: Metadata.h:864
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:2454
SimplifyCFGOptions & forwardSwitchCondToPhi(bool B)
Definition: Local.h:90
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:2549
void patchReplacementInstruction(Instruction *I, Value *Repl)
Patch the replacement so that it is not more restrictive than the value being replaced.
Definition: Local.cpp:2386
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:675
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition: Local.cpp:1923
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:1456
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: Local.cpp:1522
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
Definition: Local.cpp:2499
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:960
This is the common base class for debug info intrinsics for variables.
Definition: IntrinsicInst.h:88
static cl::opt< bool > SinkCommon("simplifycfg-sink-common", cl::Hidden, cl::init(true), cl::desc("Sink common instructions down to the end block"))
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:2300
void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
Definition: Local.cpp:2542
An instruction for storing to memory.
Definition: Instructions.h:310
bool ForwardSwitchCondToPhi
Definition: Local.h:67
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
Definition: Local.cpp:1835
SimplifyCFGOptions & convertSwitchToLookupTable(bool B)
Definition: Local.h:94
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Definition: Local.cpp:1079
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:145
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:58
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:2853
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool ConvertSwitchToLookupTable
Definition: Local.h:68
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:2524
bool callsGCLeafFunction(ImmutableCallSite CS, const TargetLibraryInfo &TLI)
Return true if the CallSite CS calls a gc leaf function.
Definition: Local.cpp:2473
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
If the specified value is a trivially dead instruction, delete it.
Definition: Local.cpp:430
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
Definition: Local.cpp:1400
TinyPtrVector< DbgVariableIntrinsic * > FindDbgAddrUses(Value *V)
Finds all intrinsics declaring local variables as living in the memory that &#39;V&#39; points to...
Definition: Local.cpp:1500
BlockVerifier::State From
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.
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:513
SimplifyCFGOptions & needCanonicalLoops(bool B)
Definition: Local.h:98
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:1902
SimplifyCFGOptions & setAssumptionCache(AssumptionCache *Cache)
Definition: Local.h:106
void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
Replace &#39;BB&#39;s terminator with one that does not have an unwind successor block.
Definition: Local.cpp:2187
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:1547
Establish a view to a call site for examination.
Definition: CallSite.h:711
#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:268
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:2843
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:348
LLVM Value Representation.
Definition: Value.h:73
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Definition: Local.cpp:1277
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition: Local.cpp:1988
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:355
void combineMetadataForCSE(Instruction *K, const Instruction *J, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:2374
SimplifyCFGOptions(unsigned BonusThreshold=1, bool ForwardSwitchCond=false, bool SwitchToLookup=false, bool CanonicalLoops=true, bool SinkCommon=false, AssumptionCache *AssumpCache=nullptr)
Definition: Local.h:73
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:65
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction *> &InsertedInsts)
Try to match a bswap or bitreverse idiom.
Definition: Local.cpp:2769
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition: Local.cpp:2437
an instruction to allocate memory on the stack
Definition: Instructions.h:60