LLVM  6.0.0svn
Local.h
Go to the documentation of this file.
1 //===- Local.h - Functions to perform local transformations -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This family of functions perform various local transformations to the
11 // program.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
16 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/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.
67 
68  SimplifyCFGOptions(unsigned BonusThreshold = 1,
69  bool ForwardSwitchCond = false,
70  bool SwitchToLookup = false, bool CanonicalLoops = true,
71  AssumptionCache *AssumpCache = nullptr)
72  : BonusInstThreshold(BonusThreshold),
73  ForwardSwitchCondToPhi(ForwardSwitchCond),
74  ConvertSwitchToLookupTable(SwitchToLookup),
75  NeedCanonicalLoop(CanonicalLoops), AC(AssumpCache) {}
76 
77  // Support 'builder' pattern to set members by name at construction time.
79  BonusInstThreshold = I;
80  return *this;
81  }
83  ForwardSwitchCondToPhi = B;
84  return *this;
85  }
87  ConvertSwitchToLookupTable = B;
88  return *this;
89  }
91  NeedCanonicalLoop = B;
92  return *this;
93  }
95  AC = Cache;
96  return *this;
97  }
98 };
99 
100 //===----------------------------------------------------------------------===//
101 // Local constant propagation.
102 //
103 
104 /// If a terminator instruction is predicated on a constant value, convert it
105 /// into an unconditional branch to the constant destination.
106 /// This is a nontrivial operation because the successors of this basic block
107 /// must have their PHI nodes updated.
108 /// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
109 /// conditions and indirectbr addresses this might make dead if
110 /// DeleteDeadConditions is true.
111 bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
112  const TargetLibraryInfo *TLI = nullptr);
113 
114 //===----------------------------------------------------------------------===//
115 // Local dead code elimination.
116 //
117 
118 /// Return true if the result produced by the instruction is not used, and the
119 /// instruction has no side effects.
121  const TargetLibraryInfo *TLI = nullptr);
122 
123 /// Return true if the result produced by the instruction would have no side
124 /// effects if it was not used. This is equivalent to checking whether
125 /// isInstructionTriviallyDead would be true if the use count was 0.
127  const TargetLibraryInfo *TLI = nullptr);
128 
129 /// If the specified value is a trivially dead instruction, delete it.
130 /// If that makes any of its operands trivially dead, delete them too,
131 /// recursively. Return true if any instructions were deleted.
133  const TargetLibraryInfo *TLI = nullptr);
134 
135 /// If the specified value is an effectively dead PHI node, due to being a
136 /// def-use chain of single-use nodes that either forms a cycle or is terminated
137 /// by a trivially dead instruction, delete it. If that makes any of its
138 /// operands trivially dead, delete them too, recursively. Return true if a
139 /// change was made.
141  const TargetLibraryInfo *TLI = nullptr);
142 
143 /// Scan the specified basic block and try to simplify any instructions in it
144 /// and recursively delete dead instructions.
145 ///
146 /// This returns true if it changed the code, note that it can delete
147 /// instructions in other blocks as well in this block.
149  const TargetLibraryInfo *TLI = nullptr);
150 
151 //===----------------------------------------------------------------------===//
152 // Control Flow Graph Restructuring.
153 //
154 
155 /// Like BasicBlock::removePredecessor, this method is called when we're about
156 /// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
157 /// drops the entries in the PHI nodes for Pred.
158 ///
159 /// Unlike the removePredecessor method, this attempts to simplify uses of PHI
160 /// nodes that collapse into identity values. For example, if we have:
161 /// x = phi(1, 0, 0, 0)
162 /// y = and x, z
163 ///
164 /// .. and delete the predecessor corresponding to the '1', this will attempt to
165 /// recursively fold the 'and' to 0.
167 
168 /// BB is a block with one predecessor and its predecessor is known to have one
169 /// successor (BB!). Eliminate the edge between them, moving the instructions in
170 /// the predecessor into BB. This deletes the predecessor block.
171 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT = nullptr);
172 
173 /// BB is known to contain an unconditional branch, and contains no instructions
174 /// other than PHI nodes, potential debug intrinsics and the branch. If
175 /// possible, eliminate BB by rewriting all the predecessors to branch to the
176 /// successor block and return true. If we can't transform, return false.
178 
179 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
180 /// to be clever about PHI nodes which differ only in the order of the incoming
181 /// values, but instcombine orders them so it usually won't matter.
183 
184 /// This function is used to do simplification of a CFG. For example, it
185 /// adjusts branches to branches to eliminate the extra hop, it eliminates
186 /// unreachable basic blocks, and does other peephole optimization of the CFG.
187 /// It returns true if a modification was made, possibly deleting the basic
188 /// block that was pointed to. LoopHeaders is an optional input parameter
189 /// providing the set of loop headers that SimplifyCFG should not eliminate.
190 bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
191  const SimplifyCFGOptions &Options = {},
192  SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
193 
194 /// This function is used to flatten a CFG. For example, it uses parallel-and
195 /// and parallel-or mode to collapse if-conditions and merge if-regions with
196 /// identical statements.
197 bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
198 
199 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
200 /// branches to us and one of our successors, fold the setcc into the
201 /// predecessor and use logical operations to pick the right destination.
203 
204 /// This function takes a virtual register computed by an Instruction and
205 /// replaces it with a slot in the stack frame, allocated via alloca.
206 /// This allows the CFG to be changed around without fear of invalidating the
207 /// SSA information for the value. It returns the pointer to the alloca inserted
208 /// to create a stack slot for X.
210  bool VolatileLoads = false,
211  Instruction *AllocaPoint = nullptr);
212 
213 /// This function takes a virtual register computed by a phi node and replaces
214 /// it with a slot in the stack frame, allocated via alloca. The phi node is
215 /// deleted and it returns the pointer to the alloca inserted.
216 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
217 
218 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
219 /// the owning object can be modified and has an alignment less than \p
220 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
221 /// cannot be increased, the known alignment of the value is returned.
222 ///
223 /// It is not always possible to modify the alignment of the underlying object,
224 /// so if alignment is important, a more reliable approach is to simply align
225 /// all global variables and allocation instructions to their preferred
226 /// alignment from the beginning.
227 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
228  const DataLayout &DL,
229  const Instruction *CxtI = nullptr,
230  AssumptionCache *AC = nullptr,
231  const DominatorTree *DT = nullptr);
232 
233 /// Try to infer an alignment for the specified pointer.
234 inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
235  const Instruction *CxtI = nullptr,
236  AssumptionCache *AC = nullptr,
237  const DominatorTree *DT = nullptr) {
238  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
239 }
240 
241 /// Given a getelementptr instruction/constantexpr, emit the code necessary to
242 /// compute the offset from the base pointer (without adding in the base
243 /// pointer). Return the result as a signed integer of intptr size.
244 /// When NoAssumptions is true, no assumptions about index computation not
245 /// overflowing is made.
246 template <typename IRBuilderTy>
247 Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
248  bool NoAssumptions = false) {
249  GEPOperator *GEPOp = cast<GEPOperator>(GEP);
250  Type *IntPtrTy = DL.getIntPtrType(GEP->getType());
251  Value *Result = Constant::getNullValue(IntPtrTy);
252 
253  // If the GEP is inbounds, we know that none of the addressing operations will
254  // overflow in an unsigned sense.
255  bool isInBounds = GEPOp->isInBounds() && !NoAssumptions;
256 
257  // Build a mask for high order bits.
258  unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
259  uint64_t PtrSizeMask =
260  std::numeric_limits<uint64_t>::max() >> (64 - IntPtrWidth);
261 
263  for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e;
264  ++i, ++GTI) {
265  Value *Op = *i;
266  uint64_t Size = DL.getTypeAllocSize(GTI.getIndexedType()) & PtrSizeMask;
267  if (Constant *OpC = dyn_cast<Constant>(Op)) {
268  if (OpC->isZeroValue())
269  continue;
270 
271  // Handle a struct index, which adds its field offset to the pointer.
272  if (StructType *STy = GTI.getStructTypeOrNull()) {
273  if (OpC->getType()->isVectorTy())
274  OpC = OpC->getSplatValue();
275 
276  uint64_t OpValue = cast<ConstantInt>(OpC)->getZExtValue();
277  Size = DL.getStructLayout(STy)->getElementOffset(OpValue);
278 
279  if (Size)
280  Result = Builder->CreateAdd(Result, ConstantInt::get(IntPtrTy, Size),
281  GEP->getName()+".offs");
282  continue;
283  }
284 
285  Constant *Scale = ConstantInt::get(IntPtrTy, Size);
286  Constant *OC = ConstantExpr::getIntegerCast(OpC, IntPtrTy, true /*SExt*/);
287  Scale = ConstantExpr::getMul(OC, Scale, isInBounds/*NUW*/);
288  // Emit an add instruction.
289  Result = Builder->CreateAdd(Result, Scale, GEP->getName()+".offs");
290  continue;
291  }
292  // Convert to correct type.
293  if (Op->getType() != IntPtrTy)
294  Op = Builder->CreateIntCast(Op, IntPtrTy, true, Op->getName()+".c");
295  if (Size != 1) {
296  // We'll let instcombine(mul) convert this to a shl if possible.
297  Op = Builder->CreateMul(Op, ConstantInt::get(IntPtrTy, Size),
298  GEP->getName()+".idx", isInBounds /*NUW*/);
299  }
300 
301  // Emit an add instruction.
302  Result = Builder->CreateAdd(Op, Result, GEP->getName()+".offs");
303  }
304  return Result;
305 }
306 
307 ///===---------------------------------------------------------------------===//
308 /// Dbg Intrinsic utilities
309 ///
310 
311 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
312 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
314  StoreInst *SI, DIBuilder &Builder);
315 
316 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
317 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
319  LoadInst *LI, DIBuilder &Builder);
320 
321 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
322 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
324  PHINode *LI, DIBuilder &Builder);
325 
326 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
327 /// llvm.dbg.value intrinsics.
328 bool LowerDbgDeclare(Function &F);
329 
330 /// Finds all intrinsics declaring local variables as living in the memory that
331 /// 'V' points to. This may include a mix of dbg.declare and
332 /// dbg.addr intrinsics.
334 
335 /// Finds the llvm.dbg.value intrinsics describing a value.
337 
338 /// Replaces llvm.dbg.declare instruction when the address it describes
339 /// is replaced with a new value. If Deref is true, an additional DW_OP_deref is
340 /// prepended to the expression. If Offset is non-zero, a constant displacement
341 /// is added to the expression (after the optional Deref). Offset can be
342 /// negative.
343 bool replaceDbgDeclare(Value *Address, Value *NewAddress,
344  Instruction *InsertBefore, DIBuilder &Builder,
345  bool Deref, int Offset);
346 
347 /// Replaces llvm.dbg.declare instruction when the alloca it describes
348 /// is replaced with a new value. If Deref is true, an additional DW_OP_deref is
349 /// prepended to the expression. If Offset is non-zero, a constant displacement
350 /// is added to the expression (after the optional Deref). Offset can be
351 /// negative. New llvm.dbg.declare is inserted immediately before AI.
352 bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
353  DIBuilder &Builder, bool Deref, int Offset = 0);
354 
355 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
356 /// is replaced with a new value. If Offset is non-zero, a constant displacement
357 /// is added to the expression (after the mandatory Deref). Offset can be
358 /// negative. New llvm.dbg.value instructions are inserted at the locations of
359 /// the instructions they replace.
360 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
361  DIBuilder &Builder, int Offset = 0);
362 
363 /// Assuming the instruction \p I is going to be deleted, attempt to salvage any
364 /// dbg.value intrinsics referring to \p I by rewriting its effect into a
365 /// DIExpression.
367 
368 /// Remove all instructions from a basic block other than it's terminator
369 /// and any present EH pad instructions.
371 
372 /// Insert an unreachable instruction before the specified
373 /// instruction, making it and the rest of the code in the block dead.
374 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
375  bool PreserveLCSSA = false);
376 
377 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
378 /// block. This also splits the basic block where CI is located, because
379 /// InvokeInst is a terminator instruction. Returns the newly split basic
380 /// block.
382  BasicBlock *UnwindEdge);
383 
384 /// Replace 'BB's terminator with one that does not have an unwind successor
385 /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
386 /// successor.
387 ///
388 /// \param BB Block whose terminator will be replaced. Its terminator must
389 /// have an unwind successor.
390 void removeUnwindEdge(BasicBlock *BB);
391 
392 /// Remove all blocks that can not be reached from the function's entry.
393 ///
394 /// Returns true if any basic block was removed.
395 bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr);
396 
397 /// Combine the metadata of two instructions so that K can replace J
398 ///
399 /// Metadata not listed as known via KnownIDs is removed
400 void combineMetadata(Instruction *K, const Instruction *J, ArrayRef<unsigned> KnownIDs);
401 
402 /// Combine the metadata of two instructions so that K can replace J. This
403 /// specifically handles the case of CSE-like transformations.
404 ///
405 /// Unknown metadata is removed.
407 
408 // Replace each use of 'From' with 'To', if that use does not belong to basic
409 // block where 'From' is defined. Returns the number of replacements made.
410 unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
411 
412 /// Replace each use of 'From' with 'To' if that use is dominated by
413 /// the given edge. Returns the number of replacements made.
414 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
415  const BasicBlockEdge &Edge);
416 /// Replace each use of 'From' with 'To' if that use is dominated by
417 /// the end of the given BasicBlock. Returns the number of replacements made.
418 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
419  const BasicBlock *BB);
420 
421 /// Return true if the CallSite CS calls a gc leaf function.
422 ///
423 /// A leaf function is a function that does not safepoint the thread during its
424 /// execution. During a call or invoke to such a function, the callers stack
425 /// does not have to be made parseable.
426 ///
427 /// Most passes can and should ignore this information, and it is only used
428 /// during lowering by the GC infrastructure.
430 
431 /// Copy a nonnull metadata node to a new load instruction.
432 ///
433 /// This handles mapping it to range metadata if the new load is an integer
434 /// load instead of a pointer load.
435 void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
436 
437 /// Copy a range metadata node to a new load instruction.
438 ///
439 /// This handles mapping it to nonnull metadata if the new load is a pointer
440 /// load instead of an integer load and the range doesn't cover null.
441 void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
442  LoadInst &NewLI);
443 
444 //===----------------------------------------------------------------------===//
445 // Intrinsic pattern matching
446 //
447 
448 /// Try and match a bswap or bitreverse idiom.
449 ///
450 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
451 /// instructions are returned in \c InsertedInsts. They will all have been added
452 /// to a basic block.
453 ///
454 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
455 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
456 /// to BW / 4 nodes to be searched, so is significantly faster.
457 ///
458 /// This function returns true on a successful match or false otherwise.
460  Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
461  SmallVectorImpl<Instruction *> &InsertedInsts);
462 
463 //===----------------------------------------------------------------------===//
464 // Sanitizer utilities
465 //
466 
467 /// Given a CallInst, check if it calls a string function known to CodeGen,
468 /// and mark it with NoBuiltin if so. To be used by sanitizers that intend
469 /// to intercept string functions and want to avoid converting them to target
470 /// specific instructions.
472  const TargetLibraryInfo *TLI);
473 
474 //===----------------------------------------------------------------------===//
475 // Transform predicates
476 //
477 
478 /// Given an instruction, is it legal to set operand OpIdx to a non-constant
479 /// value?
480 bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
481 
482 } // end namespace llvm
483 
484 #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:247
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, bool Deref, int Offset=0)
Replaces llvm.dbg.declare instruction when the alloca it describes is replaced with a new value...
Definition: Local.cpp:1325
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:1066
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:1359
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:562
AssumptionCache * AC
Definition: Local.h:66
This class represents a function call, abstracting a target machine&#39;s calling convention.
SimplifyCFGOptions & bonusInstThreshold(int I)
Definition: Local.h:78
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!)...
Definition: Local.cpp:615
A cache of .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:535
Metadata node.
Definition: Metadata.h:862
F(f)
An instruction for reading from memory.
Definition: Instructions.h:164
Hexagon Common GEP
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred)
Like BasicBlock::removePredecessor, this method is called when we&#39;re about to delete Pred as a predec...
Definition: Local.cpp:586
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition: Local.cpp:1452
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:1877
op_iterator op_begin()
Definition: User.h:214
static Constant * getNullValue(Type *Ty)
Constructor to create a &#39;0&#39; constant of arbitrary type.
Definition: Constants.cpp:207
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:82
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:1518
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
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
Definition: Local.cpp:102
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Definition: Local.cpp:1288
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:1922
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:1370
An instruction for storing to memory.
Definition: Instructions.h:306
bool ForwardSwitchCondToPhi
Definition: Local.h:63
SimplifyCFGOptions & convertSwitchToLookupTable(bool B)
Definition: Local.h:86
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Definition: Local.cpp:961
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:140
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:702
#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
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes...
Definition: Local.cpp:868
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:2230
void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Definition: Local.cpp:1134
This file contains the declarations for the subclasses of Constant, which represent the different fla...
SimplifyCFGOptions(unsigned BonusThreshold=1, bool ForwardSwitchCond=false, bool SwitchToLookup=false, bool CanonicalLoops=true, AssumptionCache *AssumpCache=nullptr)
Definition: Local.h:68
bool ConvertSwitchToLookupTable
Definition: Local.h:64
op_iterator op_end()
Definition: User.h:216
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:1947
bool callsGCLeafFunction(ImmutableCallSite CS, const TargetLibraryInfo &TLI)
Return true if the CallSite CS calls a gc leaf function.
Definition: Local.cpp:1896
bool replaceDbgDeclare(Value *Address, Value *NewAddress, Instruction *InsertBefore, DIBuilder &Builder, bool Deref, int Offset)
Replaces llvm.dbg.declare instruction when the address it describes is replaced with a new value...
Definition: Local.cpp:1305
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
If the specified value is a trivially dead instruction, delete it.
Definition: Local.cpp:401
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
Definition: Local.cpp:1224
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr)
Remove all blocks that can not be reached from the function&#39;s entry.
Definition: Local.cpp:1730
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:458
SimplifyCFGOptions & needCanonicalLoops(bool B)
Definition: Local.h:90
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:560
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:1431
SimplifyCFGOptions & setAssumptionCache(AssumptionCache *Cache)
Definition: Local.h:94
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:1270
void removeUnwindEdge(BasicBlock *BB)
Replace &#39;BB&#39;s terminator with one that does not have an unwind successor block.
Definition: Local.cpp:1692
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:403
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:513
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:220
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:234
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:2220
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:1829
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:324
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:1503
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:331
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 and match a bswap or bitreverse idiom.
Definition: Local.cpp:2146
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2137
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:1764
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Definition: Local.cpp:1860
an instruction to allocate memory on the stack
Definition: Instructions.h:60
gep_type_iterator gep_type_begin(const User *GEP)