LLVM  7.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_ANALYSIS_UTILS_LOCAL_H
16 #define LLVM_ANALYSIS_UTILS_LOCAL_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/TinyPtrVector.h"
23 #include "llvm/IR/CallSite.h"
24 #include "llvm/IR/Constant.h"
25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/Dominators.h"
29 #include "llvm/IR/Operator.h"
30 #include "llvm/IR/Type.h"
31 #include "llvm/IR/User.h"
32 #include "llvm/IR/Value.h"
33 #include "llvm/Support/Casting.h"
34 #include <cstdint>
35 #include <limits>
36 
37 namespace llvm {
38 
39 class AllocaInst;
40 class AssumptionCache;
41 class BasicBlock;
42 class BranchInst;
43 class CallInst;
44 class DbgInfoIntrinsic;
45 class DbgValueInst;
46 class DIBuilder;
47 class Function;
48 class Instruction;
49 class LazyValueInfo;
50 class LoadInst;
51 class MDNode;
52 class PHINode;
53 class StoreInst;
54 class TargetLibraryInfo;
55 class TargetTransformInfo;
56 
57 /// A set of parameters used to control the transforms in the SimplifyCFG pass.
58 /// Options may change depending on the position in the optimization pipeline.
59 /// For example, canonical form that includes switches and branches may later be
60 /// replaced by lookup tables and selects.
68 
69  SimplifyCFGOptions(unsigned BonusThreshold = 1,
70  bool ForwardSwitchCond = false,
71  bool SwitchToLookup = false, bool CanonicalLoops = true,
72  bool SinkCommon = false,
73  AssumptionCache *AssumpCache = nullptr)
74  : BonusInstThreshold(BonusThreshold),
75  ForwardSwitchCondToPhi(ForwardSwitchCond),
76  ConvertSwitchToLookupTable(SwitchToLookup),
77  NeedCanonicalLoop(CanonicalLoops),
78  SinkCommonInsts(SinkCommon),
79  AC(AssumpCache) {}
80 
81  // Support 'builder' pattern to set members by name at construction time.
83  BonusInstThreshold = I;
84  return *this;
85  }
87  ForwardSwitchCondToPhi = B;
88  return *this;
89  }
91  ConvertSwitchToLookupTable = B;
92  return *this;
93  }
95  NeedCanonicalLoop = B;
96  return *this;
97  }
99  SinkCommonInsts = B;
100  return *this;
101  }
103  AC = Cache;
104  return *this;
105  }
106 };
107 
108 //===----------------------------------------------------------------------===//
109 // Local constant propagation.
110 //
111 
112 /// If a terminator instruction is predicated on a constant value, convert it
113 /// into an unconditional branch to the constant destination.
114 /// This is a nontrivial operation because the successors of this basic block
115 /// must have their PHI nodes updated.
116 /// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
117 /// conditions and indirectbr addresses this might make dead if
118 /// DeleteDeadConditions is true.
119 bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
120  const TargetLibraryInfo *TLI = nullptr,
121  DeferredDominance *DDT = nullptr);
122 
123 //===----------------------------------------------------------------------===//
124 // Local dead code elimination.
125 //
126 
127 /// Return true if the result produced by the instruction is not used, and the
128 /// instruction has no side effects.
130  const TargetLibraryInfo *TLI = nullptr);
131 
132 /// Return true if the result produced by the instruction would have no side
133 /// effects if it was not used. This is equivalent to checking whether
134 /// isInstructionTriviallyDead would be true if the use count was 0.
136  const TargetLibraryInfo *TLI = nullptr);
137 
138 /// If the specified value is a trivially dead instruction, delete it.
139 /// If that makes any of its operands trivially dead, delete them too,
140 /// recursively. Return true if any instructions were deleted.
142  const TargetLibraryInfo *TLI = nullptr);
143 
144 /// Delete all of the instructions in `DeadInsts`, and all other instructions
145 /// that deleting these in turn causes to be trivially dead.
146 ///
147 /// The initial instructions in the provided vector must all have empty use
148 /// lists and satisfy `isInstructionTriviallyDead`.
149 ///
150 /// `DeadInsts` will be used as scratch storage for this routine and will be
151 /// empty afterward.
154  const TargetLibraryInfo *TLI = nullptr);
155 
156 /// If the specified value is an effectively dead PHI node, due to being a
157 /// def-use chain of single-use nodes that either forms a cycle or is terminated
158 /// by a trivially dead instruction, delete it. If that makes any of its
159 /// operands trivially dead, delete them too, recursively. Return true if a
160 /// change was made.
162  const TargetLibraryInfo *TLI = nullptr);
163 
164 /// Scan the specified basic block and try to simplify any instructions in it
165 /// and recursively delete dead instructions.
166 ///
167 /// This returns true if it changed the code, note that it can delete
168 /// instructions in other blocks as well in this block.
170  const TargetLibraryInfo *TLI = nullptr);
171 
172 //===----------------------------------------------------------------------===//
173 // Control Flow Graph Restructuring.
174 //
175 
176 /// Like BasicBlock::removePredecessor, this method is called when we're about
177 /// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
178 /// drops the entries in the PHI nodes for Pred.
179 ///
180 /// Unlike the removePredecessor method, this attempts to simplify uses of PHI
181 /// nodes that collapse into identity values. For example, if we have:
182 /// x = phi(1, 0, 0, 0)
183 /// y = and x, z
184 ///
185 /// .. and delete the predecessor corresponding to the '1', this will attempt to
186 /// recursively fold the 'and' to 0.
188  DeferredDominance *DDT = nullptr);
189 
190 /// BB is a block with one predecessor and its predecessor is known to have one
191 /// successor (BB!). Eliminate the edge between them, moving the instructions in
192 /// the predecessor into BB. This deletes the predecessor block.
194  DeferredDominance *DDT = nullptr);
195 
196 /// BB is known to contain an unconditional branch, and contains no instructions
197 /// other than PHI nodes, potential debug intrinsics and the branch. If
198 /// possible, eliminate BB by rewriting all the predecessors to branch to the
199 /// successor block and return true. If we can't transform, return false.
201  DeferredDominance *DDT = nullptr);
202 
203 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
204 /// to be clever about PHI nodes which differ only in the order of the incoming
205 /// values, but instcombine orders them so it usually won't matter.
207 
208 /// This function is used to do simplification of a CFG. For example, it
209 /// adjusts branches to branches to eliminate the extra hop, it eliminates
210 /// unreachable basic blocks, and does other peephole optimization of the CFG.
211 /// It returns true if a modification was made, possibly deleting the basic
212 /// block that was pointed to. LoopHeaders is an optional input parameter
213 /// providing the set of loop headers that SimplifyCFG should not eliminate.
214 bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
215  const SimplifyCFGOptions &Options = {},
216  SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
217 
218 /// This function is used to flatten a CFG. For example, it uses parallel-and
219 /// and parallel-or mode to collapse if-conditions and merge if-regions with
220 /// identical statements.
221 bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
222 
223 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
224 /// branches to us and one of our successors, fold the setcc into the
225 /// predecessor and use logical operations to pick the right destination.
227 
228 /// This function takes a virtual register computed by an Instruction and
229 /// replaces it with a slot in the stack frame, allocated via alloca.
230 /// This allows the CFG to be changed around without fear of invalidating the
231 /// SSA information for the value. It returns the pointer to the alloca inserted
232 /// to create a stack slot for X.
234  bool VolatileLoads = false,
235  Instruction *AllocaPoint = nullptr);
236 
237 /// This function takes a virtual register computed by a phi node and replaces
238 /// it with a slot in the stack frame, allocated via alloca. The phi node is
239 /// deleted and it returns the pointer to the alloca inserted.
240 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
241 
242 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
243 /// the owning object can be modified and has an alignment less than \p
244 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
245 /// cannot be increased, the known alignment of the value is returned.
246 ///
247 /// It is not always possible to modify the alignment of the underlying object,
248 /// so if alignment is important, a more reliable approach is to simply align
249 /// all global variables and allocation instructions to their preferred
250 /// alignment from the beginning.
251 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
252  const DataLayout &DL,
253  const Instruction *CxtI = nullptr,
254  AssumptionCache *AC = nullptr,
255  const DominatorTree *DT = nullptr);
256 
257 /// Try to infer an alignment for the specified pointer.
258 inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
259  const Instruction *CxtI = nullptr,
260  AssumptionCache *AC = nullptr,
261  const DominatorTree *DT = nullptr) {
262  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
263 }
264 
265 /// Given a getelementptr instruction/constantexpr, emit the code necessary to
266 /// compute the offset from the base pointer (without adding in the base
267 /// pointer). Return the result as a signed integer of intptr size.
268 /// When NoAssumptions is true, no assumptions about index computation not
269 /// overflowing is made.
270 template <typename IRBuilderTy>
271 Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
272  bool NoAssumptions = false) {
273  GEPOperator *GEPOp = cast<GEPOperator>(GEP);
274  Type *IntPtrTy = DL.getIntPtrType(GEP->getType());
275  Value *Result = Constant::getNullValue(IntPtrTy);
276 
277  // If the GEP is inbounds, we know that none of the addressing operations will
278  // overflow in an unsigned sense.
279  bool isInBounds = GEPOp->isInBounds() && !NoAssumptions;
280 
281  // Build a mask for high order bits.
282  unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
283  uint64_t PtrSizeMask =
284  std::numeric_limits<uint64_t>::max() >> (64 - IntPtrWidth);
285 
287  for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e;
288  ++i, ++GTI) {
289  Value *Op = *i;
290  uint64_t Size = DL.getTypeAllocSize(GTI.getIndexedType()) & PtrSizeMask;
291  if (Constant *OpC = dyn_cast<Constant>(Op)) {
292  if (OpC->isZeroValue())
293  continue;
294 
295  // Handle a struct index, which adds its field offset to the pointer.
296  if (StructType *STy = GTI.getStructTypeOrNull()) {
297  if (OpC->getType()->isVectorTy())
298  OpC = OpC->getSplatValue();
299 
300  uint64_t OpValue = cast<ConstantInt>(OpC)->getZExtValue();
301  Size = DL.getStructLayout(STy)->getElementOffset(OpValue);
302 
303  if (Size)
304  Result = Builder->CreateAdd(Result, ConstantInt::get(IntPtrTy, Size),
305  GEP->getName()+".offs");
306  continue;
307  }
308 
309  Constant *Scale = ConstantInt::get(IntPtrTy, Size);
310  Constant *OC = ConstantExpr::getIntegerCast(OpC, IntPtrTy, true /*SExt*/);
311  Scale = ConstantExpr::getMul(OC, Scale, isInBounds/*NUW*/);
312  // Emit an add instruction.
313  Result = Builder->CreateAdd(Result, Scale, GEP->getName()+".offs");
314  continue;
315  }
316  // Convert to correct type.
317  if (Op->getType() != IntPtrTy)
318  Op = Builder->CreateIntCast(Op, IntPtrTy, true, Op->getName()+".c");
319  if (Size != 1) {
320  // We'll let instcombine(mul) convert this to a shl if possible.
321  Op = Builder->CreateMul(Op, ConstantInt::get(IntPtrTy, Size),
322  GEP->getName()+".idx", isInBounds /*NUW*/);
323  }
324 
325  // Emit an add instruction.
326  Result = Builder->CreateAdd(Op, Result, GEP->getName()+".offs");
327  }
328  return Result;
329 }
330 
331 ///===---------------------------------------------------------------------===//
332 /// Dbg Intrinsic utilities
333 ///
334 
335 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
336 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
338  StoreInst *SI, DIBuilder &Builder);
339 
340 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
341 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
343  LoadInst *LI, DIBuilder &Builder);
344 
345 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
346 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
348  PHINode *LI, DIBuilder &Builder);
349 
350 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
351 /// llvm.dbg.value intrinsics.
352 bool LowerDbgDeclare(Function &F);
353 
354 /// Propagate dbg.value intrinsics through the newly inserted PHIs.
356  SmallVectorImpl<PHINode *> &InsertedPHIs);
357 
358 /// Finds all intrinsics declaring local variables as living in the memory that
359 /// 'V' points to. This may include a mix of dbg.declare and
360 /// dbg.addr intrinsics.
362 
363 /// Finds the llvm.dbg.value intrinsics describing a value.
365 
366 /// Finds the debug info intrinsics describing a value.
368 
369 /// Replaces llvm.dbg.declare instruction when the address it
370 /// describes is replaced with a new value. If Deref is true, an
371 /// additional DW_OP_deref is prepended to the expression. If Offset
372 /// is non-zero, a constant displacement is added to the expression
373 /// (between the optional Deref operations). Offset can be negative.
374 bool replaceDbgDeclare(Value *Address, Value *NewAddress,
375  Instruction *InsertBefore, DIBuilder &Builder,
376  bool DerefBefore, int Offset, bool DerefAfter);
377 
378 /// Replaces llvm.dbg.declare instruction when the alloca it describes
379 /// is replaced with a new value. If Deref is true, an additional
380 /// DW_OP_deref is prepended to the expression. If Offset is non-zero,
381 /// a constant displacement is added to the expression (between the
382 /// optional Deref operations). Offset can be negative. The new
383 /// llvm.dbg.declare is inserted immediately before AI.
384 bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
385  DIBuilder &Builder, bool DerefBefore,
386  int Offset, bool DerefAfter);
387 
388 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
389 /// is replaced with a new value. If Offset is non-zero, a constant displacement
390 /// is added to the expression (after the mandatory Deref). Offset can be
391 /// negative. New llvm.dbg.value instructions are inserted at the locations of
392 /// the instructions they replace.
393 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
394  DIBuilder &Builder, int Offset = 0);
395 
396 /// Assuming the instruction \p I is going to be deleted, attempt to salvage any
397 /// dbg.value intrinsics referring to \p I by rewriting its effect into a
398 /// DIExpression.
400 
401 /// Remove all instructions from a basic block other than it's terminator
402 /// and any present EH pad instructions.
404 
405 /// Insert an unreachable instruction before the specified
406 /// instruction, making it and the rest of the code in the block dead.
407 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
408  bool PreserveLCSSA = false,
409  DeferredDominance *DDT = nullptr);
410 
411 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
412 /// block. This also splits the basic block where CI is located, because
413 /// InvokeInst is a terminator instruction. Returns the newly split basic
414 /// block.
416  BasicBlock *UnwindEdge);
417 
418 /// Replace 'BB's terminator with one that does not have an unwind successor
419 /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
420 /// successor.
421 ///
422 /// \param BB Block whose terminator will be replaced. Its terminator must
423 /// have an unwind successor.
424 void removeUnwindEdge(BasicBlock *BB, DeferredDominance *DDT = nullptr);
425 
426 /// Remove all blocks that can not be reached from the function's entry.
427 ///
428 /// Returns true if any basic block was removed.
429 bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr,
430  DeferredDominance *DDT = nullptr);
431 
432 /// Combine the metadata of two instructions so that K can replace J
433 ///
434 /// Metadata not listed as known via KnownIDs is removed
435 void combineMetadata(Instruction *K, const Instruction *J, ArrayRef<unsigned> KnownIDs);
436 
437 /// Combine the metadata of two instructions so that K can replace J. This
438 /// specifically handles the case of CSE-like transformations.
439 ///
440 /// Unknown metadata is removed.
442 
443 // Replace each use of 'From' with 'To', if that use does not belong to basic
444 // block where 'From' is defined. Returns the number of replacements made.
445 unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
446 
447 /// Replace each use of 'From' with 'To' if that use is dominated by
448 /// the given edge. Returns the number of replacements made.
449 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
450  const BasicBlockEdge &Edge);
451 /// Replace each use of 'From' with 'To' if that use is dominated by
452 /// the end of the given BasicBlock. Returns the number of replacements made.
453 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
454  const BasicBlock *BB);
455 
456 /// Return true if the CallSite CS calls a gc leaf function.
457 ///
458 /// A leaf function is a function that does not safepoint the thread during its
459 /// execution. During a call or invoke to such a function, the callers stack
460 /// does not have to be made parseable.
461 ///
462 /// Most passes can and should ignore this information, and it is only used
463 /// during lowering by the GC infrastructure.
465 
466 /// Copy a nonnull metadata node to a new load instruction.
467 ///
468 /// This handles mapping it to range metadata if the new load is an integer
469 /// load instead of a pointer load.
470 void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
471 
472 /// Copy a range metadata node to a new load instruction.
473 ///
474 /// This handles mapping it to nonnull metadata if the new load is a pointer
475 /// load instead of an integer load and the range doesn't cover null.
476 void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
477  LoadInst &NewLI);
478 
479 //===----------------------------------------------------------------------===//
480 // Intrinsic pattern matching
481 //
482 
483 /// Try to match a bswap or bitreverse idiom.
484 ///
485 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
486 /// instructions are returned in \c InsertedInsts. They will all have been added
487 /// to a basic block.
488 ///
489 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
490 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
491 /// to BW / 4 nodes to be searched, so is significantly faster.
492 ///
493 /// This function returns true on a successful match or false otherwise.
495  Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
496  SmallVectorImpl<Instruction *> &InsertedInsts);
497 
498 //===----------------------------------------------------------------------===//
499 // Sanitizer utilities
500 //
501 
502 /// Given a CallInst, check if it calls a string function known to CodeGen,
503 /// and mark it with NoBuiltin if so. To be used by sanitizers that intend
504 /// to intercept string functions and want to avoid converting them to target
505 /// specific instructions.
507  const TargetLibraryInfo *TLI);
508 
509 //===----------------------------------------------------------------------===//
510 // Transform predicates
511 //
512 
513 /// Given an instruction, is it legal to set operand OpIdx to a non-constant
514 /// value?
515 bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
516 
517 } // end namespace llvm
518 
519 #endif // LLVM_TRANSFORMS_UTILS_LOCAL_H
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
Given a getelementptr instruction/constantexpr, emit the code necessary to compute the offset from th...
Definition: Local.h:271
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
AllocaInst * DemoteRegToStack(Instruction &X, bool VolatileLoads=false, Instruction *AllocaPoint=nullptr)
This function takes a virtual register computed by an Instruction and replaces it with a slot in the ...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
Definition: Local.cpp:1165
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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:1512
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:1477
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Various leaf nodes.
Definition: ISDOpcodes.h:60
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Definition: DataLayout.cpp:588
AssumptionCache * AC
Definition: Local.h:67
This class represents a function call, abstracting a target machine&#39;s calling convention.
SimplifyCFGOptions & bonusInstThreshold(int I)
Definition: Local.h:82
SimplifyCFGOptions & sinkCommonInsts(bool B)
Definition: Local.h:98
A cache of @llvm.assume calls within a function.
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
Definition: Local.cpp:577
Metadata node.
Definition: Metadata.h:862
F(f)
An instruction for reading from memory.
Definition: Instructions.h:164
Hexagon Common GEP
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:2124
op_iterator op_begin()
Definition: User.h:230
static Constant * getNullValue(Type *Ty)
Constructor to create a &#39;0&#39; constant of arbitrary type.
Definition: Constants.cpp:258
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:86
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:1580
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT=nullptr, DeferredDominance *DDT=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!)...
Definition: Local.cpp:660
Class to represent struct types.
Definition: DerivedTypes.h:201
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
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:1378
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: Local.cpp:1440
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
Definition: Local.cpp:2169
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Definition: Operator.h:444
void salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage any dbg.value intrinsics referr...
Definition: Local.cpp:1523
static cl::opt< bool > SinkCommon("simplifycfg-sink-common", cl::Hidden, cl::init(true), cl::desc("Sink common instructions down to the end block"))
An instruction for storing to memory.
Definition: Instructions.h:306
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr, DeferredDominance *DDT=nullptr)
Remove all blocks that can not be reached from the function&#39;s entry.
Definition: Local.cpp:1962
bool ForwardSwitchCondToPhi
Definition: Local.h:63
SimplifyCFGOptions & convertSwitchToLookupTable(bool B)
Definition: Local.h:90
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Definition: Local.cpp:1060
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:142
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
This function is used to flatten a CFG.
Definition: FlattenCFG.cpp:490
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Definition: DataLayout.cpp:744
#define P(N)
bool FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold=1)
If this basic block is ONLY a setcc and a branch, and if a predecessor branches to us and one of our ...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Conditional or Unconditional Branch instruction.
This is an important base class in LLVM.
Definition: Constant.h:42
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:2475
void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Definition: Local.cpp:1233
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool ConvertSwitchToLookupTable
Definition: Local.h:64
op_iterator op_end()
Definition: User.h:232
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:2194
bool callsGCLeafFunction(ImmutableCallSite CS, const TargetLibraryInfo &TLI)
Return true if the CallSite CS calls a gc leaf function.
Definition: Local.cpp:2143
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DeferredDominance *DDT=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
Definition: Local.cpp:103
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
If the specified value is a trivially dead instruction, delete it.
Definition: Local.cpp:429
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
Definition: Local.cpp:1323
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, DeferredDominance *DDT=nullptr)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes...
Definition: Local.cpp:947
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Provides information about what library functions are available for the current target.
This is the common base class for debug info intrinsics.
Definition: IntrinsicInst.h:67
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
Definition: Local.cpp:498
SimplifyCFGOptions & needCanonicalLoops(bool B)
Definition: Local.h:94
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:611
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:1642
void removeUnwindEdge(BasicBlock *BB, DeferredDominance *DDT=nullptr)
Replace &#39;BB&#39;s terminator with one that does not have an unwind successor block.
Definition: Local.cpp:1922
SimplifyCFGOptions & setAssumptionCache(AssumptionCache *Cache)
Definition: Local.h:102
Class to defer updates to a DominatorTree.
Definition: Dominators.h:307
TinyPtrVector< DbgInfoIntrinsic * > FindDbgAddrUses(Value *V)
Finds all intrinsics declaring local variables as living in the memory that &#39;V&#39; points to...
Definition: Local.cpp:1422
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:1457
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:428
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:543
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
Establish a view to a call site for examination.
Definition: CallSite.h:713
#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:258
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:2465
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:2076
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred, DeferredDominance *DDT=nullptr)
Like BasicBlock::removePredecessor, this method is called when we&#39;re about to delete Pred as a predec...
Definition: Local.cpp:628
void findDbgUsers(SmallVectorImpl< DbgInfoIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: Local.cpp:1448
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false, DeferredDominance *DDT=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition: Local.cpp:1663
This pass computes, caches, and vends lazy value constraint information.
Definition: LazyValueInfo.h:32
AllocaInst * DemotePHIToStack(PHINode *P, Instruction *AllocaPoint=nullptr)
This function takes a virtual register computed by a phi node and replaces it with a slot in the stac...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
Definition: Local.cpp:346
LLVM Value Representation.
Definition: Value.h:73
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition: Local.cpp:1727
bool wouldInstructionBeTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction would have no side effects if it was not used...
Definition: Local.cpp:353
SimplifyCFGOptions(unsigned BonusThreshold=1, bool ForwardSwitchCond=false, bool SwitchToLookup=false, bool CanonicalLoops=true, bool SinkCommon=false, AssumptionCache *AssumpCache=nullptr)
Definition: Local.h:69
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:61
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction *> &InsertedInsts)
Try to match a bswap or bitreverse idiom.
Definition: Local.cpp:2391
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2199
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:2011
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition: Local.cpp:2107
an instruction to allocate memory on the stack
Definition: Instructions.h:60
gep_type_iterator gep_type_begin(const User *GEP)