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 /// If the specified value is an effectively dead PHI node, due to being a
145 /// def-use chain of single-use nodes that either forms a cycle or is terminated
146 /// by a trivially dead instruction, delete it. If that makes any of its
147 /// operands trivially dead, delete them too, recursively. Return true if a
148 /// change was made.
150  const TargetLibraryInfo *TLI = nullptr);
151 
152 /// Scan the specified basic block and try to simplify any instructions in it
153 /// and recursively delete dead instructions.
154 ///
155 /// This returns true if it changed the code, note that it can delete
156 /// instructions in other blocks as well in this block.
158  const TargetLibraryInfo *TLI = nullptr);
159 
160 //===----------------------------------------------------------------------===//
161 // Control Flow Graph Restructuring.
162 //
163 
164 /// Like BasicBlock::removePredecessor, this method is called when we're about
165 /// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
166 /// drops the entries in the PHI nodes for Pred.
167 ///
168 /// Unlike the removePredecessor method, this attempts to simplify uses of PHI
169 /// nodes that collapse into identity values. For example, if we have:
170 /// x = phi(1, 0, 0, 0)
171 /// y = and x, z
172 ///
173 /// .. and delete the predecessor corresponding to the '1', this will attempt to
174 /// recursively fold the 'and' to 0.
176  DeferredDominance *DDT = nullptr);
177 
178 /// BB is a block with one predecessor and its predecessor is known to have one
179 /// successor (BB!). Eliminate the edge between them, moving the instructions in
180 /// the predecessor into BB. This deletes the predecessor block.
182  DeferredDominance *DDT = nullptr);
183 
184 /// BB is known to contain an unconditional branch, and contains no instructions
185 /// other than PHI nodes, potential debug intrinsics and the branch. If
186 /// possible, eliminate BB by rewriting all the predecessors to branch to the
187 /// successor block and return true. If we can't transform, return false.
189  DeferredDominance *DDT = nullptr);
190 
191 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
192 /// to be clever about PHI nodes which differ only in the order of the incoming
193 /// values, but instcombine orders them so it usually won't matter.
195 
196 /// This function is used to do simplification of a CFG. For example, it
197 /// adjusts branches to branches to eliminate the extra hop, it eliminates
198 /// unreachable basic blocks, and does other peephole optimization of the CFG.
199 /// It returns true if a modification was made, possibly deleting the basic
200 /// block that was pointed to. LoopHeaders is an optional input parameter
201 /// providing the set of loop headers that SimplifyCFG should not eliminate.
202 bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
203  const SimplifyCFGOptions &Options = {},
204  SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
205 
206 /// This function is used to flatten a CFG. For example, it uses parallel-and
207 /// and parallel-or mode to collapse if-conditions and merge if-regions with
208 /// identical statements.
209 bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
210 
211 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
212 /// branches to us and one of our successors, fold the setcc into the
213 /// predecessor and use logical operations to pick the right destination.
215 
216 /// This function takes a virtual register computed by an Instruction and
217 /// replaces it with a slot in the stack frame, allocated via alloca.
218 /// This allows the CFG to be changed around without fear of invalidating the
219 /// SSA information for the value. It returns the pointer to the alloca inserted
220 /// to create a stack slot for X.
222  bool VolatileLoads = false,
223  Instruction *AllocaPoint = nullptr);
224 
225 /// This function takes a virtual register computed by a phi node and replaces
226 /// it with a slot in the stack frame, allocated via alloca. The phi node is
227 /// deleted and it returns the pointer to the alloca inserted.
228 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
229 
230 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
231 /// the owning object can be modified and has an alignment less than \p
232 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
233 /// cannot be increased, the known alignment of the value is returned.
234 ///
235 /// It is not always possible to modify the alignment of the underlying object,
236 /// so if alignment is important, a more reliable approach is to simply align
237 /// all global variables and allocation instructions to their preferred
238 /// alignment from the beginning.
239 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
240  const DataLayout &DL,
241  const Instruction *CxtI = nullptr,
242  AssumptionCache *AC = nullptr,
243  const DominatorTree *DT = nullptr);
244 
245 /// Try to infer an alignment for the specified pointer.
246 inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
247  const Instruction *CxtI = nullptr,
248  AssumptionCache *AC = nullptr,
249  const DominatorTree *DT = nullptr) {
250  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
251 }
252 
253 /// Given a getelementptr instruction/constantexpr, emit the code necessary to
254 /// compute the offset from the base pointer (without adding in the base
255 /// pointer). Return the result as a signed integer of intptr size.
256 /// When NoAssumptions is true, no assumptions about index computation not
257 /// overflowing is made.
258 template <typename IRBuilderTy>
259 Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
260  bool NoAssumptions = false) {
261  GEPOperator *GEPOp = cast<GEPOperator>(GEP);
262  Type *IntPtrTy = DL.getIntPtrType(GEP->getType());
263  Value *Result = Constant::getNullValue(IntPtrTy);
264 
265  // If the GEP is inbounds, we know that none of the addressing operations will
266  // overflow in an unsigned sense.
267  bool isInBounds = GEPOp->isInBounds() && !NoAssumptions;
268 
269  // Build a mask for high order bits.
270  unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
271  uint64_t PtrSizeMask =
272  std::numeric_limits<uint64_t>::max() >> (64 - IntPtrWidth);
273 
275  for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e;
276  ++i, ++GTI) {
277  Value *Op = *i;
278  uint64_t Size = DL.getTypeAllocSize(GTI.getIndexedType()) & PtrSizeMask;
279  if (Constant *OpC = dyn_cast<Constant>(Op)) {
280  if (OpC->isZeroValue())
281  continue;
282 
283  // Handle a struct index, which adds its field offset to the pointer.
284  if (StructType *STy = GTI.getStructTypeOrNull()) {
285  if (OpC->getType()->isVectorTy())
286  OpC = OpC->getSplatValue();
287 
288  uint64_t OpValue = cast<ConstantInt>(OpC)->getZExtValue();
289  Size = DL.getStructLayout(STy)->getElementOffset(OpValue);
290 
291  if (Size)
292  Result = Builder->CreateAdd(Result, ConstantInt::get(IntPtrTy, Size),
293  GEP->getName()+".offs");
294  continue;
295  }
296 
297  Constant *Scale = ConstantInt::get(IntPtrTy, Size);
298  Constant *OC = ConstantExpr::getIntegerCast(OpC, IntPtrTy, true /*SExt*/);
299  Scale = ConstantExpr::getMul(OC, Scale, isInBounds/*NUW*/);
300  // Emit an add instruction.
301  Result = Builder->CreateAdd(Result, Scale, GEP->getName()+".offs");
302  continue;
303  }
304  // Convert to correct type.
305  if (Op->getType() != IntPtrTy)
306  Op = Builder->CreateIntCast(Op, IntPtrTy, true, Op->getName()+".c");
307  if (Size != 1) {
308  // We'll let instcombine(mul) convert this to a shl if possible.
309  Op = Builder->CreateMul(Op, ConstantInt::get(IntPtrTy, Size),
310  GEP->getName()+".idx", isInBounds /*NUW*/);
311  }
312 
313  // Emit an add instruction.
314  Result = Builder->CreateAdd(Op, Result, GEP->getName()+".offs");
315  }
316  return Result;
317 }
318 
319 ///===---------------------------------------------------------------------===//
320 /// Dbg Intrinsic utilities
321 ///
322 
323 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
324 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
326  StoreInst *SI, DIBuilder &Builder);
327 
328 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
329 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
331  LoadInst *LI, DIBuilder &Builder);
332 
333 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
334 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
336  PHINode *LI, DIBuilder &Builder);
337 
338 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
339 /// llvm.dbg.value intrinsics.
340 bool LowerDbgDeclare(Function &F);
341 
342 /// Propagate dbg.value intrinsics through the newly inserted PHIs.
344  SmallVectorImpl<PHINode *> &InsertedPHIs);
345 
346 /// Finds all intrinsics declaring local variables as living in the memory that
347 /// 'V' points to. This may include a mix of dbg.declare and
348 /// dbg.addr intrinsics.
350 
351 /// Finds the llvm.dbg.value intrinsics describing a value.
353 
354 /// Finds the debug info intrinsics describing a value.
356 
357 /// Replaces llvm.dbg.declare instruction when the address it
358 /// describes is replaced with a new value. If Deref is true, an
359 /// additional DW_OP_deref is prepended to the expression. If Offset
360 /// is non-zero, a constant displacement is added to the expression
361 /// (between the optional Deref operations). Offset can be negative.
362 bool replaceDbgDeclare(Value *Address, Value *NewAddress,
363  Instruction *InsertBefore, DIBuilder &Builder,
364  bool DerefBefore, int Offset, bool DerefAfter);
365 
366 /// Replaces llvm.dbg.declare instruction when the alloca it describes
367 /// is replaced with a new value. If Deref is true, an additional
368 /// DW_OP_deref is prepended to the expression. If Offset is non-zero,
369 /// a constant displacement is added to the expression (between the
370 /// optional Deref operations). Offset can be negative. The new
371 /// llvm.dbg.declare is inserted immediately before AI.
372 bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
373  DIBuilder &Builder, bool DerefBefore,
374  int Offset, bool DerefAfter);
375 
376 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
377 /// is replaced with a new value. If Offset is non-zero, a constant displacement
378 /// is added to the expression (after the mandatory Deref). Offset can be
379 /// negative. New llvm.dbg.value instructions are inserted at the locations of
380 /// the instructions they replace.
381 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
382  DIBuilder &Builder, int Offset = 0);
383 
384 /// Assuming the instruction \p I is going to be deleted, attempt to salvage any
385 /// dbg.value intrinsics referring to \p I by rewriting its effect into a
386 /// DIExpression.
388 
389 /// Remove all instructions from a basic block other than it's terminator
390 /// and any present EH pad instructions.
392 
393 /// Insert an unreachable instruction before the specified
394 /// instruction, making it and the rest of the code in the block dead.
395 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
396  bool PreserveLCSSA = false,
397  DeferredDominance *DDT = nullptr);
398 
399 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
400 /// block. This also splits the basic block where CI is located, because
401 /// InvokeInst is a terminator instruction. Returns the newly split basic
402 /// block.
404  BasicBlock *UnwindEdge);
405 
406 /// Replace 'BB's terminator with one that does not have an unwind successor
407 /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
408 /// successor.
409 ///
410 /// \param BB Block whose terminator will be replaced. Its terminator must
411 /// have an unwind successor.
412 void removeUnwindEdge(BasicBlock *BB, DeferredDominance *DDT = nullptr);
413 
414 /// Remove all blocks that can not be reached from the function's entry.
415 ///
416 /// Returns true if any basic block was removed.
417 bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr,
418  DeferredDominance *DDT = nullptr);
419 
420 /// Combine the metadata of two instructions so that K can replace J
421 ///
422 /// Metadata not listed as known via KnownIDs is removed
423 void combineMetadata(Instruction *K, const Instruction *J, ArrayRef<unsigned> KnownIDs);
424 
425 /// Combine the metadata of two instructions so that K can replace J. This
426 /// specifically handles the case of CSE-like transformations.
427 ///
428 /// Unknown metadata is removed.
430 
431 // Replace each use of 'From' with 'To', if that use does not belong to basic
432 // block where 'From' is defined. Returns the number of replacements made.
433 unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
434 
435 /// Replace each use of 'From' with 'To' if that use is dominated by
436 /// the given edge. Returns the number of replacements made.
437 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
438  const BasicBlockEdge &Edge);
439 /// Replace each use of 'From' with 'To' if that use is dominated by
440 /// the end of the given BasicBlock. Returns the number of replacements made.
441 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
442  const BasicBlock *BB);
443 
444 /// Return true if the CallSite CS calls a gc leaf function.
445 ///
446 /// A leaf function is a function that does not safepoint the thread during its
447 /// execution. During a call or invoke to such a function, the callers stack
448 /// does not have to be made parseable.
449 ///
450 /// Most passes can and should ignore this information, and it is only used
451 /// during lowering by the GC infrastructure.
453 
454 /// Copy a nonnull metadata node to a new load instruction.
455 ///
456 /// This handles mapping it to range metadata if the new load is an integer
457 /// load instead of a pointer load.
458 void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
459 
460 /// Copy a range metadata node to a new load instruction.
461 ///
462 /// This handles mapping it to nonnull metadata if the new load is a pointer
463 /// load instead of an integer load and the range doesn't cover null.
464 void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
465  LoadInst &NewLI);
466 
467 //===----------------------------------------------------------------------===//
468 // Intrinsic pattern matching
469 //
470 
471 /// Try to match a bswap or bitreverse idiom.
472 ///
473 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
474 /// instructions are returned in \c InsertedInsts. They will all have been added
475 /// to a basic block.
476 ///
477 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
478 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
479 /// to BW / 4 nodes to be searched, so is significantly faster.
480 ///
481 /// This function returns true on a successful match or false otherwise.
483  Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
484  SmallVectorImpl<Instruction *> &InsertedInsts);
485 
486 //===----------------------------------------------------------------------===//
487 // Sanitizer utilities
488 //
489 
490 /// Given a CallInst, check if it calls a string function known to CodeGen,
491 /// and mark it with NoBuiltin if so. To be used by sanitizers that intend
492 /// to intercept string functions and want to avoid converting them to target
493 /// specific instructions.
495  const TargetLibraryInfo *TLI);
496 
497 //===----------------------------------------------------------------------===//
498 // Transform predicates
499 //
500 
501 /// Given an instruction, is it legal to set operand OpIdx to a non-constant
502 /// value?
503 bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
504 
505 } // end namespace llvm
506 
507 #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:259
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:1154
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:1501
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:1466
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:566
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:2113
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:649
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
void insertDebugValuesForPHIs(BasicBlock *BB, SmallVectorImpl< PHINode *> &InsertedPHIs)
Propagate dbg.value intrinsics through the newly inserted PHIs.
Definition: Local.cpp:1367
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: Local.cpp:1429
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:2158
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Definition: Operator.h:433
void salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage any dbg.value intrinsics referr...
Definition: Local.cpp:1512
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:1951
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:1049
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:2464
void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Definition: Local.cpp:1222
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:2183
bool callsGCLeafFunction(ImmutableCallSite CS, const TargetLibraryInfo &TLI)
Return true if the CallSite CS calls a gc leaf function.
Definition: Local.cpp:2132
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:1312
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:936
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:487
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:1631
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:1911
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:1411
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:1446
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:246
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:2454
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:2065
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:617
void findDbgUsers(SmallVectorImpl< DbgInfoIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Definition: Local.cpp:1437
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:1652
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:1716
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:2380
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:2000
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition: Local.cpp:2096
an instruction to allocate memory on the stack
Definition: Instructions.h:60
gep_type_iterator gep_type_begin(const User *GEP)