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 //===----------------------------------------------------------------------===//
178 // Control Flow Graph Restructuring.
179 //
180 
181 /// Like BasicBlock::removePredecessor, this method is called when we're about
182 /// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
183 /// drops the entries in the PHI nodes for Pred.
184 ///
185 /// Unlike the removePredecessor method, this attempts to simplify uses of PHI
186 /// nodes that collapse into identity values. For example, if we have:
187 /// x = phi(1, 0, 0, 0)
188 /// y = and x, z
189 ///
190 /// .. and delete the predecessor corresponding to the '1', this will attempt to
191 /// recursively fold the 'and' to 0.
193  DomTreeUpdater *DTU = nullptr);
194 
195 /// BB is a block with one predecessor and its predecessor is known to have one
196 /// successor (BB!). Eliminate the edge between them, moving the instructions in
197 /// the predecessor into BB. This deletes the predecessor block.
198 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
199 
200 /// BB is known to contain an unconditional branch, and contains no instructions
201 /// other than PHI nodes, potential debug intrinsics and the branch. If
202 /// possible, eliminate BB by rewriting all the predecessors to branch to the
203 /// successor block and return true. If we can't transform, return false.
205  DomTreeUpdater *DTU = nullptr);
206 
207 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
208 /// to be clever about PHI nodes which differ only in the order of the incoming
209 /// values, but instcombine orders them so it usually won't matter.
211 
212 /// This function is used to do simplification of a CFG. For example, it
213 /// adjusts branches to branches to eliminate the extra hop, it eliminates
214 /// unreachable basic blocks, and does other peephole optimization of the CFG.
215 /// It returns true if a modification was made, possibly deleting the basic
216 /// block that was pointed to. LoopHeaders is an optional input parameter
217 /// providing the set of loop headers that SimplifyCFG should not eliminate.
218 bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
219  const SimplifyCFGOptions &Options = {},
220  SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
221 
222 /// This function is used to flatten a CFG. For example, it uses parallel-and
223 /// and parallel-or mode to collapse if-conditions and merge if-regions with
224 /// identical statements.
225 bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
226 
227 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
228 /// branches to us and one of our successors, fold the setcc into the
229 /// predecessor and use logical operations to pick the right destination.
231 
232 /// This function takes a virtual register computed by an Instruction and
233 /// replaces it with a slot in the stack frame, allocated via alloca.
234 /// This allows the CFG to be changed around without fear of invalidating the
235 /// SSA information for the value. It returns the pointer to the alloca inserted
236 /// to create a stack slot for X.
238  bool VolatileLoads = false,
239  Instruction *AllocaPoint = nullptr);
240 
241 /// This function takes a virtual register computed by a phi node and replaces
242 /// it with a slot in the stack frame, allocated via alloca. The phi node is
243 /// deleted and it returns the pointer to the alloca inserted.
244 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
245 
246 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
247 /// the owning object can be modified and has an alignment less than \p
248 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
249 /// cannot be increased, the known alignment of the value is returned.
250 ///
251 /// It is not always possible to modify the alignment of the underlying object,
252 /// so if alignment is important, a more reliable approach is to simply align
253 /// all global variables and allocation instructions to their preferred
254 /// alignment from the beginning.
255 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
256  const DataLayout &DL,
257  const Instruction *CxtI = nullptr,
258  AssumptionCache *AC = nullptr,
259  const DominatorTree *DT = nullptr);
260 
261 /// Try to infer an alignment for the specified pointer.
262 inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
263  const Instruction *CxtI = nullptr,
264  AssumptionCache *AC = nullptr,
265  const DominatorTree *DT = nullptr) {
266  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
267 }
268 
269 ///===---------------------------------------------------------------------===//
270 /// Dbg Intrinsic utilities
271 ///
272 
273 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
274 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
276  StoreInst *SI, DIBuilder &Builder);
277 
278 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
279 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
281  LoadInst *LI, DIBuilder &Builder);
282 
283 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
284 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
286  PHINode *LI, DIBuilder &Builder);
287 
288 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
289 /// llvm.dbg.value intrinsics.
290 bool LowerDbgDeclare(Function &F);
291 
292 /// Propagate dbg.value intrinsics through the newly inserted PHIs.
294  SmallVectorImpl<PHINode *> &InsertedPHIs);
295 
296 /// Finds all intrinsics declaring local variables as living in the memory that
297 /// 'V' points to. This may include a mix of dbg.declare and
298 /// dbg.addr intrinsics.
300 
301 /// Finds the llvm.dbg.value intrinsics describing a value.
303 
304 /// Finds the debug info intrinsics describing a value.
306 
307 /// Replaces llvm.dbg.declare instruction when the address it
308 /// describes is replaced with a new value. If Deref is true, an
309 /// additional DW_OP_deref is prepended to the expression. If Offset
310 /// is non-zero, a constant displacement is added to the expression
311 /// (between the optional Deref operations). Offset can be negative.
312 bool replaceDbgDeclare(Value *Address, Value *NewAddress,
313  Instruction *InsertBefore, DIBuilder &Builder,
314  bool DerefBefore, int Offset, bool DerefAfter);
315 
316 /// Replaces llvm.dbg.declare instruction when the alloca it describes
317 /// is replaced with a new value. If Deref is true, an additional
318 /// DW_OP_deref is prepended to the expression. If Offset is non-zero,
319 /// a constant displacement is added to the expression (between the
320 /// optional Deref operations). Offset can be negative. The new
321 /// llvm.dbg.declare is inserted immediately after AI.
322 bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
323  DIBuilder &Builder, bool DerefBefore,
324  int Offset, bool DerefAfter);
325 
326 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
327 /// is replaced with a new value. If Offset is non-zero, a constant displacement
328 /// is added to the expression (after the mandatory Deref). Offset can be
329 /// negative. New llvm.dbg.value instructions are inserted at the locations of
330 /// the instructions they replace.
331 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
332  DIBuilder &Builder, int Offset = 0);
333 
334 /// Assuming the instruction \p I is going to be deleted, attempt to salvage
335 /// debug users of \p I by writing the effect of \p I in a DIExpression.
336 /// Returns true if any debug users were updated.
338 
339 /// Point debug users of \p From to \p To or salvage them. Use this function
340 /// only when replacing all uses of \p From with \p To, with a guarantee that
341 /// \p From is going to be deleted.
342 ///
343 /// Follow these rules to prevent use-before-def of \p To:
344 /// . If \p To is a linked Instruction, set \p DomPoint to \p To.
345 /// . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
346 /// \p To will be inserted after.
347 /// . If \p To is not an Instruction (e.g a Constant), the choice of
348 /// \p DomPoint is arbitrary. Pick \p From for simplicity.
349 ///
350 /// If a debug user cannot be preserved without reordering variable updates or
351 /// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
352 /// or deleted. Returns true if any debug users were updated.
354  DominatorTree &DT);
355 
356 /// Remove all instructions from a basic block other than it's terminator
357 /// and any present EH pad instructions.
359 
360 /// Insert an unreachable instruction before the specified
361 /// instruction, making it and the rest of the code in the block dead.
362 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
363  bool PreserveLCSSA = false,
364  DomTreeUpdater *DTU = nullptr);
365 
366 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
367 /// block. This also splits the basic block where CI is located, because
368 /// InvokeInst is a terminator instruction. Returns the newly split basic
369 /// block.
371  BasicBlock *UnwindEdge);
372 
373 /// Replace 'BB's terminator with one that does not have an unwind successor
374 /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
375 /// successor.
376 ///
377 /// \param BB Block whose terminator will be replaced. Its terminator must
378 /// have an unwind successor.
379 void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
380 
381 /// Remove all blocks that can not be reached from the function's entry.
382 ///
383 /// Returns true if any basic block was removed.
384 bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr,
385  DomTreeUpdater *DTU = nullptr,
386  MemorySSAUpdater *MSSAU = nullptr);
387 
388 /// Combine the metadata of two instructions so that K can replace J. Some
389 /// metadata kinds can only be kept if K does not move, meaning it dominated
390 /// J in the original IR.
391 ///
392 /// Metadata not listed as known via KnownIDs is removed
393 void combineMetadata(Instruction *K, const Instruction *J,
394  ArrayRef<unsigned> KnownIDs, bool DoesKMove);
395 
396 /// Combine the metadata of two instructions so that K can replace J. This
397 /// specifically handles the case of CSE-like transformations. Some
398 /// metadata can only be kept if K dominates J. For this to be correct,
399 /// K cannot be hoisted.
400 ///
401 /// Unknown metadata is removed.
403  bool DoesKMove);
404 
405 /// Patch the replacement so that it is not more restrictive than the value
406 /// being replaced. It assumes that the replacement does not get moved from
407 /// its original position.
409 
410 // Replace each use of 'From' with 'To', if that use does not belong to basic
411 // block where 'From' is defined. Returns the number of replacements made.
412 unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
413 
414 /// Replace each use of 'From' with 'To' if that use is dominated by
415 /// the given edge. Returns the number of replacements made.
416 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
417  const BasicBlockEdge &Edge);
418 /// Replace each use of 'From' with 'To' if that use is dominated by
419 /// the end of the given BasicBlock. Returns the number of replacements made.
420 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
421  const BasicBlock *BB);
422 
423 /// Return true if the CallSite CS calls a gc leaf function.
424 ///
425 /// A leaf function is a function that does not safepoint the thread during its
426 /// execution. During a call or invoke to such a function, the callers stack
427 /// does not have to be made parseable.
428 ///
429 /// Most passes can and should ignore this information, and it is only used
430 /// during lowering by the GC infrastructure.
432 
433 /// Copy a nonnull metadata node to a new load instruction.
434 ///
435 /// This handles mapping it to range metadata if the new load is an integer
436 /// load instead of a pointer load.
437 void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
438 
439 /// Copy a range metadata node to a new load instruction.
440 ///
441 /// This handles mapping it to nonnull metadata if the new load is a pointer
442 /// load instead of an integer load and the range doesn't cover null.
443 void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
444  LoadInst &NewLI);
445 
446 /// Remove the debug intrinsic instructions for the given instruction.
447 void dropDebugUsers(Instruction &I);
448 
449 //===----------------------------------------------------------------------===//
450 // Intrinsic pattern matching
451 //
452 
453 /// Try to match a bswap or bitreverse idiom.
454 ///
455 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
456 /// instructions are returned in \c InsertedInsts. They will all have been added
457 /// to a basic block.
458 ///
459 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
460 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
461 /// to BW / 4 nodes to be searched, so is significantly faster.
462 ///
463 /// This function returns true on a successful match or false otherwise.
465  Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
466  SmallVectorImpl<Instruction *> &InsertedInsts);
467 
468 //===----------------------------------------------------------------------===//
469 // Sanitizer utilities
470 //
471 
472 /// Given a CallInst, check if it calls a string function known to CodeGen,
473 /// and mark it with NoBuiltin if so. To be used by sanitizers that intend
474 /// to intercept string functions and want to avoid converting them to target
475 /// specific instructions.
477  const TargetLibraryInfo *TLI);
478 
479 //===----------------------------------------------------------------------===//
480 // Transform predicates
481 //
482 
483 /// Given an instruction, is it legal to set operand OpIdx to a non-constant
484 /// value?
485 bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
486 
487 } // end namespace llvm
488 
489 #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:632
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:1175
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:1593
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:1558
Compute iterated dominance frontiers using a linear time algorithm.
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:2218
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: Local.cpp:1525
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:1609
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:581
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:2437
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:90
void patchReplacementInstruction(Instruction *I, Value *Repl)
Patch the replacement so that it is not more restrictive than the value being replaced.
Definition: Local.cpp:2369
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:664
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:1914
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:1447
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: Local.cpp:1513
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
Definition: Local.cpp:2482
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:950
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:2291
void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
Definition: Local.cpp:2525
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:1826
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:1070
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:2795
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:2507
bool callsGCLeafFunction(ImmutableCallSite CS, const TargetLibraryInfo &TLI)
Return true if the CallSite CS calls a gc leaf function.
Definition: Local.cpp:2456
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:1391
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:1491
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:502
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:1893
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:2178
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:1538
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:262
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:2785
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:1268
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition: Local.cpp:1979
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:2357
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:2711
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition: Local.cpp:2420
an instruction to allocate memory on the stack
Definition: Instructions.h:60