LLVM  9.0.0svn
Local.h
Go to the documentation of this file.
1 //===- Local.h - Functions to perform local transformations -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This family of functions perform various local transformations to the
10 // program.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
15 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
16
25 #include "llvm/IR/Constant.h"
26 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/Dominators.h"
30 #include "llvm/IR/Operator.h"
31 #include "llvm/IR/Type.h"
32 #include "llvm/IR/User.h"
33 #include "llvm/IR/Value.h"
34 #include "llvm/Support/Casting.h"
35 #include <cstdint>
36 #include <limits>
37
38 namespace llvm {
39
40 class AllocaInst;
41 class AssumptionCache;
42 class BasicBlock;
43 class BranchInst;
44 class CallInst;
45 class DbgVariableIntrinsic;
46 class DbgValueInst;
47 class DIBuilder;
48 class Function;
49 class Instruction;
50 class LazyValueInfo;
52 class MDNode;
53 class MemorySSAUpdater;
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
121 bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
122  const TargetLibraryInfo *TLI = nullptr,
123  DomTreeUpdater *DTU = 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  Value *V, const TargetLibraryInfo *TLI = nullptr,
145  MemorySSAUpdater *MSSAU = nullptr);
146
147 /// Delete all of the instructions in DeadInsts, and all other instructions
148 /// that deleting these in turn causes to be trivially dead.
149 ///
150 /// The initial instructions in the provided vector must all have empty use
151 /// lists and satisfy isInstructionTriviallyDead.
152 ///
153 /// DeadInsts will be used as scratch storage for this routine and will be
154 /// empty afterward.
157  const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr);
158
159 /// If the specified value is an effectively dead PHI node, due to being a
160 /// def-use chain of single-use nodes that either forms a cycle or is terminated
161 /// by a trivially dead instruction, delete it. If that makes any of its
162 /// operands trivially dead, delete them too, recursively. Return true if a
165  const TargetLibraryInfo *TLI = nullptr);
166
167 /// Scan the specified basic block and try to simplify any instructions in it
168 /// and recursively delete dead instructions.
169 ///
170 /// This returns true if it changed the code, note that it can delete
171 /// instructions in other blocks as well in this block.
173  const TargetLibraryInfo *TLI = nullptr);
174
175 /// Replace all the uses of an SSA value in @llvm.dbg intrinsics with
176 /// undef. This is useful for signaling that a variable, e.g. has been
177 /// found dead and hence it's unavailable at a given program point.
178 /// Returns true if the dbg values have been changed.
180
181 //===----------------------------------------------------------------------===//
182 // Control Flow Graph Restructuring.
183 //
184
185 /// Like BasicBlock::removePredecessor, this method is called when we're about
186 /// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
187 /// drops the entries in the PHI nodes for Pred.
188 ///
189 /// Unlike the removePredecessor method, this attempts to simplify uses of PHI
190 /// nodes that collapse into identity values. For example, if we have:
191 /// x = phi(1, 0, 0, 0)
192 /// y = and x, z
193 ///
194 /// .. and delete the predecessor corresponding to the '1', this will attempt to
195 /// recursively fold the 'and' to 0.
197  DomTreeUpdater *DTU = nullptr);
198
199 /// BB is a block with one predecessor and its predecessor is known to have one
200 /// successor (BB!). Eliminate the edge between them, moving the instructions in
201 /// the predecessor into BB. This deletes the predecessor block.
202 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
203
204 /// BB is known to contain an unconditional branch, and contains no instructions
205 /// other than PHI nodes, potential debug intrinsics and the branch. If
206 /// possible, eliminate BB by rewriting all the predecessors to branch to the
207 /// successor block and return true. If we can't transform, return false.
209  DomTreeUpdater *DTU = nullptr);
210
211 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
212 /// to be clever about PHI nodes which differ only in the order of the incoming
213 /// values, but instcombine orders them so it usually won't matter.
215
216 /// This function is used to do simplification of a CFG. For example, it
217 /// adjusts branches to branches to eliminate the extra hop, it eliminates
218 /// unreachable basic blocks, and does other peephole optimization of the CFG.
219 /// It returns true if a modification was made, possibly deleting the basic
220 /// block that was pointed to. LoopHeaders is an optional input parameter
221 /// providing the set of loop headers that SimplifyCFG should not eliminate.
222 bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
223  const SimplifyCFGOptions &Options = {},
224  SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
225
226 /// This function is used to flatten a CFG. For example, it uses parallel-and
227 /// and parallel-or mode to collapse if-conditions and merge if-regions with
228 /// identical statements.
229 bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
230
231 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
232 /// branches to us and one of our successors, fold the setcc into the
233 /// predecessor and use logical operations to pick the right destination.
235
236 /// This function takes a virtual register computed by an Instruction and
237 /// replaces it with a slot in the stack frame, allocated via alloca.
238 /// This allows the CFG to be changed around without fear of invalidating the
239 /// SSA information for the value. It returns the pointer to the alloca inserted
240 /// to create a stack slot for X.
243  Instruction *AllocaPoint = nullptr);
244
245 /// This function takes a virtual register computed by a phi node and replaces
246 /// it with a slot in the stack frame, allocated via alloca. The phi node is
247 /// deleted and it returns the pointer to the alloca inserted.
248 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
249
250 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
251 /// the owning object can be modified and has an alignment less than \p
252 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
253 /// cannot be increased, the known alignment of the value is returned.
254 ///
255 /// It is not always possible to modify the alignment of the underlying object,
256 /// so if alignment is important, a more reliable approach is to simply align
257 /// all global variables and allocation instructions to their preferred
258 /// alignment from the beginning.
259 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
260  const DataLayout &DL,
261  const Instruction *CxtI = nullptr,
262  AssumptionCache *AC = nullptr,
263  const DominatorTree *DT = nullptr);
264
265 /// Try to infer an alignment for the specified pointer.
266 inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
267  const Instruction *CxtI = nullptr,
268  AssumptionCache *AC = nullptr,
269  const DominatorTree *DT = nullptr) {
270  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
271 }
272
273 ///===---------------------------------------------------------------------===//
274 /// Dbg Intrinsic utilities
275 ///
276
277 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
278 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
280  StoreInst *SI, DIBuilder &Builder);
281
282 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
283 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
286
287 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
288 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
290  PHINode *LI, DIBuilder &Builder);
291
292 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
293 /// llvm.dbg.value intrinsics.
294 bool LowerDbgDeclare(Function &F);
295
296 /// Propagate dbg.value intrinsics through the newly inserted PHIs.
298  SmallVectorImpl<PHINode *> &InsertedPHIs);
299
300 /// Finds all intrinsics declaring local variables as living in the memory that
301 /// 'V' points to. This may include a mix of dbg.declare and
304
305 /// Finds the llvm.dbg.value intrinsics describing a value.
307
308 /// Finds the debug info intrinsics describing a value.
310
311 /// Replaces llvm.dbg.declare instruction when the address it
312 /// describes is replaced with a new value. If Deref is true, an
313 /// additional DW_OP_deref is prepended to the expression. If Offset
314 /// is non-zero, a constant displacement is added to the expression
315 /// (between the optional Deref operations). Offset can be negative.
317  Instruction *InsertBefore, DIBuilder &Builder,
318  bool DerefBefore, int Offset, bool DerefAfter);
319
320 /// Replaces llvm.dbg.declare instruction when the alloca it describes
321 /// is replaced with a new value. If Deref is true, an additional
322 /// DW_OP_deref is prepended to the expression. If Offset is non-zero,
323 /// a constant displacement is added to the expression (between the
324 /// optional Deref operations). Offset can be negative. The new
325 /// llvm.dbg.declare is inserted immediately after AI.
326 bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
327  DIBuilder &Builder, bool DerefBefore,
328  int Offset, bool DerefAfter);
329
330 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
331 /// is replaced with a new value. If Offset is non-zero, a constant displacement
332 /// is added to the expression (after the mandatory Deref). Offset can be
333 /// negative. New llvm.dbg.value instructions are inserted at the locations of
334 /// the instructions they replace.
335 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
336  DIBuilder &Builder, int Offset = 0);
337
338 /// Assuming the instruction \p I is going to be deleted, attempt to salvage
339 /// debug users of \p I by writing the effect of \p I in a DIExpression.
340 /// Returns true if any debug users were updated.
342
343 /// Implementation of salvageDebugInfo, applying only to instructions in
344 /// \p Insns, rather than all debug users of \p I.
347
348 /// Given an instruction \p I and DIExpression \p DIExpr operating on it, write
349 /// the effects of \p I into the returned DIExpression, or return nullptr if
350 /// it cannot be salvaged. \p StackVal: whether DW_OP_stack_value should be
351 /// appended to the expression.
353  bool StackVal);
354
355 /// Point debug users of \p From to \p To or salvage them. Use this function
356 /// only when replacing all uses of \p From with \p To, with a guarantee that
357 /// \p From is going to be deleted.
358 ///
359 /// Follow these rules to prevent use-before-def of \p To:
360 /// . If \p To is a linked Instruction, set \p DomPoint to \p To.
361 /// . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
362 /// \p To will be inserted after.
363 /// . If \p To is not an Instruction (e.g a Constant), the choice of
364 /// \p DomPoint is arbitrary. Pick \p From for simplicity.
365 ///
366 /// If a debug user cannot be preserved without reordering variable updates or
367 /// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
368 /// or deleted. Returns true if any debug users were updated.
370  DominatorTree &DT);
371
372 /// Remove all instructions from a basic block other than it's terminator
373 /// and any present EH pad instructions.
375
376 /// Insert an unreachable instruction before the specified
377 /// instruction, making it and the rest of the code in the block dead.
378 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
379  bool PreserveLCSSA = false,
380  DomTreeUpdater *DTU = nullptr);
381
382 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
383 /// block. This also splits the basic block where CI is located, because
384 /// InvokeInst is a terminator instruction. Returns the newly split basic
385 /// block.
387  BasicBlock *UnwindEdge);
388
389 /// Replace 'BB's terminator with one that does not have an unwind successor
390 /// block. Rewrites invoke to call, etc. Updates any PHIs in unwind
391 /// successor.
392 ///
393 /// \param BB Block whose terminator will be replaced. Its terminator must
394 /// have an unwind successor.
395 void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
396
397 /// Remove all blocks that can not be reached from the function's entry.
398 ///
399 /// Returns true if any basic block was removed.
400 bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr,
401  DomTreeUpdater *DTU = nullptr,
402  MemorySSAUpdater *MSSAU = nullptr);
403
404 /// Combine the metadata of two instructions so that K can replace J. Some
405 /// metadata kinds can only be kept if K does not move, meaning it dominated
406 /// J in the original IR.
407 ///
408 /// Metadata not listed as known via KnownIDs is removed
409 void combineMetadata(Instruction *K, const Instruction *J,
410  ArrayRef<unsigned> KnownIDs, bool DoesKMove);
411
412 /// Combine the metadata of two instructions so that K can replace J. This
413 /// specifically handles the case of CSE-like transformations. Some
414 /// metadata can only be kept if K dominates J. For this to be correct,
415 /// K cannot be hoisted.
416 ///
417 /// Unknown metadata is removed.
419  bool DoesKMove);
420
421 /// Patch the replacement so that it is not more restrictive than the value
422 /// being replaced. It assumes that the replacement does not get moved from
423 /// its original position.
425
426 // Replace each use of 'From' with 'To', if that use does not belong to basic
427 // block where 'From' is defined. Returns the number of replacements made.
428 unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
429
430 /// Replace each use of 'From' with 'To' if that use is dominated by
431 /// the given edge. Returns the number of replacements made.
432 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
433  const BasicBlockEdge &Edge);
434 /// Replace each use of 'From' with 'To' if that use is dominated by
435 /// the end of the given BasicBlock. Returns the number of replacements made.
436 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
437  const BasicBlock *BB);
438
439 /// Return true if this call calls a gc leaf function.
440 ///
441 /// A leaf function is a function that does not safepoint the thread during its
442 /// execution. During a call or invoke to such a function, the callers stack
443 /// does not have to be made parseable.
444 ///
445 /// Most passes can and should ignore this information, and it is only used
446 /// during lowering by the GC infrastructure.
447 bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI);
448
449 /// Copy a nonnull metadata node to a new load instruction.
450 ///
451 /// This handles mapping it to range metadata if the new load is an integer
454
455 /// Copy a range metadata node to a new load instruction.
456 ///
457 /// This handles mapping it to nonnull metadata if the new load is a pointer
461
462 /// Remove the debug intrinsic instructions for the given instruction.
463 void dropDebugUsers(Instruction &I);
464
465 /// Hoist all of the instructions in the \p IfBlock to the dominant block
466 /// \p DomBlock, by moving its instructions to the insertion point \p InsertPt.
467 ///
468 /// The moved instructions receive the insertion point debug location values
469 /// (DILocations) and their debug intrinsic instructions are removed.
470 void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,
471  BasicBlock *BB);
472
473 //===----------------------------------------------------------------------===//
474 // Intrinsic pattern matching
475 //
476
477 /// Try to match a bswap or bitreverse idiom.
478 ///
479 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
480 /// instructions are returned in \c InsertedInsts. They will all have been added
481 /// to a basic block.
482 ///
483 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
484 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
485 /// to BW / 4 nodes to be searched, so is significantly faster.
486 ///
487 /// This function returns true on a successful match or false otherwise.
489  Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
490  SmallVectorImpl<Instruction *> &InsertedInsts);
491
492 //===----------------------------------------------------------------------===//
493 // Sanitizer utilities
494 //
495
496 /// Given a CallInst, check if it calls a string function known to CodeGen,
497 /// and mark it with NoBuiltin if so. To be used by sanitizers that intend
498 /// to intercept string functions and want to avoid converting them to target
499 /// specific instructions.
501  const TargetLibraryInfo *TLI);
502
503 //===----------------------------------------------------------------------===//
504 // Transform predicates
505 //
506
507 /// Given an instruction, is it legal to set operand OpIdx to a non-constant
508 /// value?
509 bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
510
511 } // end namespace llvm
512
513 #endif // LLVM_TRANSFORMS_UTILS_LOCAL_H
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:110
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:644
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:1198
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:1589
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:1554
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Various leaf nodes.
Definition: ISDOpcodes.h:59
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:69
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:2219
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: Local.cpp:1521
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:1605
bool replaceDbgUsesWithUndef(Instruction *I)
Replace all the uses of an SSA value in .dbg intrinsics with undef.
Definition: Local.cpp:480
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:593
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1014
F(f)
An instruction for reading from memory.
Definition: Instructions.h:167
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Definition: TinyPtrVector.h:30
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:2452
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:343
SimplifyCFGOptions & forwardSwitchCondToPhi(bool B)
Definition: Local.h:88
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:2547
void patchReplacementInstruction(Instruction *I, Value *Repl)
Patch the replacement so that it is not more restrictive than the value being replaced.
Definition: Local.cpp:2383
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:677
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:1910
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
void insertDebugValuesForPHIs(BasicBlock *BB, SmallVectorImpl< PHINode *> &InsertedPHIs)
Propagate dbg.value intrinsics through the newly inserted PHIs.
Definition: Local.cpp:1443
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: Local.cpp:1509
Definition: Local.cpp:2497
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:962
This is the common base class for debug info intrinsics for variables.
Definition: IntrinsicInst.h:87
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:2292
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
Definition: Local.cpp:2540
An instruction for storing to memory.
Definition: Instructions.h:320
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:1822
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:1093
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
This function is used to flatten a CFG.
Definition: FlattenCFG.cpp:489
#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:57
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:2851
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool ConvertSwitchToLookupTable
Definition: Local.h:66
Definition: Local.cpp:2522
DIExpression * salvageDebugInfoImpl(Instruction &I, DIExpression *DIExpr, bool StackVal)
Given an instruction I and DIExpression DIExpr operating on it, write the effects of I into the retur...
Definition: Local.cpp:1641
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:431
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
Definition: Local.cpp:1387
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:1487
BlockVerifier::State From
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI)
Return true if this call calls a gc leaf function.
Definition: Local.cpp:2471
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:514
SimplifyCFGOptions & needCanonicalLoops(bool B)
Definition: Local.h:96
Remove all instructions from a basic block other than it&#39;s terminator and any present EH pad instruct...
Definition: Local.cpp:1889
DWARF expression.
SimplifyCFGOptions & setAssumptionCache(AssumptionCache *Cache)
Definition: Local.h:104
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:1534
#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:266
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:2841
This pass computes, caches, and vends lazy value constraint information.
Definition: LazyValueInfo.h:31
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:350
LLVM Value Representation.
Definition: Value.h:72
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Definition: Local.cpp:1291
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition: Local.cpp:1977
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:357
void combineMetadataForCSE(Instruction *K, const Instruction *J, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:2370
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:2767
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition: Local.cpp:2435
an instruction to allocate memory on the stack
Definition: Instructions.h:59
bool salvageDebugInfoForDbgValues(Instruction &I, ArrayRef< DbgVariableIntrinsic *> Insns)
Implementation of salvageDebugInfo, applying only to instructions in Insns, rather than all debug use...
Definition: Local.cpp:1614