LLVM  4.0.0
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 
19 #include "llvm/IR/DataLayout.h"
20 #include "llvm/IR/Dominators.h"
22 #include "llvm/IR/IRBuilder.h"
23 #include "llvm/IR/Operator.h"
24 #include "llvm/ADT/SmallPtrSet.h"
25 
26 namespace llvm {
27 
28 class User;
29 class BasicBlock;
30 class Function;
31 class BranchInst;
32 class Instruction;
33 class CallInst;
34 class DbgDeclareInst;
35 class DbgValueInst;
36 class StoreInst;
37 class LoadInst;
38 class Value;
39 class PHINode;
40 class AllocaInst;
41 class AssumptionCache;
42 class ConstantExpr;
43 class DataLayout;
44 class TargetLibraryInfo;
45 class TargetTransformInfo;
46 class DIBuilder;
47 class DominatorTree;
48 class LazyValueInfo;
49 
50 template<typename T> class SmallVectorImpl;
51 
53 
54 //===----------------------------------------------------------------------===//
55 // Local constant propagation.
56 //
57 
58 /// If a terminator instruction is predicated on a constant value, convert it
59 /// into an unconditional branch to the constant destination.
60 /// This is a nontrivial operation because the successors of this basic block
61 /// must have their PHI nodes updated.
62 /// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
63 /// conditions and indirectbr addresses this might make dead if
64 /// DeleteDeadConditions is true.
65 bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
66  const TargetLibraryInfo *TLI = nullptr);
67 
68 //===----------------------------------------------------------------------===//
69 // Local dead code elimination.
70 //
71 
72 /// Return true if the result produced by the instruction is not used, and the
73 /// instruction has no side effects.
75  const TargetLibraryInfo *TLI = nullptr);
76 
77 /// If the specified value is a trivially dead instruction, delete it.
78 /// If that makes any of its operands trivially dead, delete them too,
79 /// recursively. Return true if any instructions were deleted.
81  const TargetLibraryInfo *TLI = nullptr);
82 
83 /// If the specified value is an effectively dead PHI node, due to being a
84 /// def-use chain of single-use nodes that either forms a cycle or is terminated
85 /// by a trivially dead instruction, delete it. If that makes any of its
86 /// operands trivially dead, delete them too, recursively. Return true if a
87 /// change was made.
89  const TargetLibraryInfo *TLI = nullptr);
90 
91 /// Scan the specified basic block and try to simplify any instructions in it
92 /// and recursively delete dead instructions.
93 ///
94 /// This returns true if it changed the code, note that it can delete
95 /// instructions in other blocks as well in this block.
97  const TargetLibraryInfo *TLI = nullptr);
98 
99 //===----------------------------------------------------------------------===//
100 // Control Flow Graph Restructuring.
101 //
102 
103 /// Like BasicBlock::removePredecessor, this method is called when we're about
104 /// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
105 /// drops the entries in the PHI nodes for Pred.
106 ///
107 /// Unlike the removePredecessor method, this attempts to simplify uses of PHI
108 /// nodes that collapse into identity values. For example, if we have:
109 /// x = phi(1, 0, 0, 0)
110 /// y = and x, z
111 ///
112 /// .. and delete the predecessor corresponding to the '1', this will attempt to
113 /// recursively fold the 'and' to 0.
115 
116 /// BB is a block with one predecessor and its predecessor is known to have one
117 /// successor (BB!). Eliminate the edge between them, moving the instructions in
118 /// the predecessor into BB. This deletes the predecessor block.
119 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT = nullptr);
120 
121 /// BB is known to contain an unconditional branch, and contains no instructions
122 /// other than PHI nodes, potential debug intrinsics and the branch. If
123 /// possible, eliminate BB by rewriting all the predecessors to branch to the
124 /// successor block and return true. If we can't transform, return false.
126 
127 /// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
128 /// to be clever about PHI nodes which differ only in the order of the incoming
129 /// values, but instcombine orders them so it usually won't matter.
131 
132 /// This function is used to do simplification of a CFG. For
133 /// example, it adjusts branches to branches to eliminate the extra hop, it
134 /// eliminates unreachable basic blocks, and does other "peephole" optimization
135 /// of the CFG. It returns true if a modification was made, possibly deleting
136 /// the basic block that was pointed to. LoopHeaders is an optional input
137 /// parameter, providing the set of loop header that SimplifyCFG should not
138 /// eliminate.
139 bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
140  unsigned BonusInstThreshold, AssumptionCache *AC = nullptr,
141  SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
142 
143 /// This function is used to flatten a CFG. For example, it uses parallel-and
144 /// and parallel-or mode to collapse if-conditions and merge if-regions with
145 /// identical statements.
146 bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
147 
148 /// If this basic block is ONLY a setcc and a branch, and if a predecessor
149 /// branches to us and one of our successors, fold the setcc into the
150 /// predecessor and use logical operations to pick the right destination.
151 bool FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold = 1);
152 
153 /// This function takes a virtual register computed by an Instruction and
154 /// replaces it with a slot in the stack frame, allocated via alloca.
155 /// This allows the CFG to be changed around without fear of invalidating the
156 /// SSA information for the value. It returns the pointer to the alloca inserted
157 /// to create a stack slot for X.
159  bool VolatileLoads = false,
160  Instruction *AllocaPoint = nullptr);
161 
162 /// This function takes a virtual register computed by a phi node and replaces
163 /// it with a slot in the stack frame, allocated via alloca. The phi node is
164 /// deleted and it returns the pointer to the alloca inserted.
165 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
166 
167 /// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
168 /// the owning object can be modified and has an alignment less than \p
169 /// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
170 /// cannot be increased, the known alignment of the value is returned.
171 ///
172 /// It is not always possible to modify the alignment of the underlying object,
173 /// so if alignment is important, a more reliable approach is to simply align
174 /// all global variables and allocation instructions to their preferred
175 /// alignment from the beginning.
176 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
177  const DataLayout &DL,
178  const Instruction *CxtI = nullptr,
179  AssumptionCache *AC = nullptr,
180  const DominatorTree *DT = nullptr);
181 
182 /// Try to infer an alignment for the specified pointer.
183 static inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
184  const Instruction *CxtI = nullptr,
185  AssumptionCache *AC = nullptr,
186  const DominatorTree *DT = nullptr) {
187  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
188 }
189 
190 /// Given a getelementptr instruction/constantexpr, emit the code necessary to
191 /// compute the offset from the base pointer (without adding in the base
192 /// pointer). Return the result as a signed integer of intptr size.
193 /// When NoAssumptions is true, no assumptions about index computation not
194 /// overflowing is made.
195 template <typename IRBuilderTy>
196 Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
197  bool NoAssumptions = false) {
198  GEPOperator *GEPOp = cast<GEPOperator>(GEP);
199  Type *IntPtrTy = DL.getIntPtrType(GEP->getType());
200  Value *Result = Constant::getNullValue(IntPtrTy);
201 
202  // If the GEP is inbounds, we know that none of the addressing operations will
203  // overflow in an unsigned sense.
204  bool isInBounds = GEPOp->isInBounds() && !NoAssumptions;
205 
206  // Build a mask for high order bits.
207  unsigned IntPtrWidth = IntPtrTy->getScalarType()->getIntegerBitWidth();
208  uint64_t PtrSizeMask = ~0ULL >> (64 - IntPtrWidth);
209 
211  for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e;
212  ++i, ++GTI) {
213  Value *Op = *i;
214  uint64_t Size = DL.getTypeAllocSize(GTI.getIndexedType()) & PtrSizeMask;
215  if (Constant *OpC = dyn_cast<Constant>(Op)) {
216  if (OpC->isZeroValue())
217  continue;
218 
219  // Handle a struct index, which adds its field offset to the pointer.
220  if (StructType *STy = GTI.getStructTypeOrNull()) {
221  if (OpC->getType()->isVectorTy())
222  OpC = OpC->getSplatValue();
223 
224  uint64_t OpValue = cast<ConstantInt>(OpC)->getZExtValue();
225  Size = DL.getStructLayout(STy)->getElementOffset(OpValue);
226 
227  if (Size)
228  Result = Builder->CreateAdd(Result, ConstantInt::get(IntPtrTy, Size),
229  GEP->getName()+".offs");
230  continue;
231  }
232 
233  Constant *Scale = ConstantInt::get(IntPtrTy, Size);
234  Constant *OC = ConstantExpr::getIntegerCast(OpC, IntPtrTy, true /*SExt*/);
235  Scale = ConstantExpr::getMul(OC, Scale, isInBounds/*NUW*/);
236  // Emit an add instruction.
237  Result = Builder->CreateAdd(Result, Scale, GEP->getName()+".offs");
238  continue;
239  }
240  // Convert to correct type.
241  if (Op->getType() != IntPtrTy)
242  Op = Builder->CreateIntCast(Op, IntPtrTy, true, Op->getName()+".c");
243  if (Size != 1) {
244  // We'll let instcombine(mul) convert this to a shl if possible.
245  Op = Builder->CreateMul(Op, ConstantInt::get(IntPtrTy, Size),
246  GEP->getName()+".idx", isInBounds /*NUW*/);
247  }
248 
249  // Emit an add instruction.
250  Result = Builder->CreateAdd(Op, Result, GEP->getName()+".offs");
251  }
252  return Result;
253 }
254 
255 ///===---------------------------------------------------------------------===//
256 /// Dbg Intrinsic utilities
257 ///
258 
259 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
260 /// that has an associated llvm.dbg.decl intrinsic.
261 void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
262  StoreInst *SI, DIBuilder &Builder);
263 
264 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
265 /// that has an associated llvm.dbg.decl intrinsic.
266 void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
267  LoadInst *LI, DIBuilder &Builder);
268 
269 /// Inserts a llvm.dbg.value intrinsic after a phi of an alloca'd value
270 /// that has an associated llvm.dbg.decl intrinsic.
271 void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
272  PHINode *LI, DIBuilder &Builder);
273 
274 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
275 /// llvm.dbg.value intrinsics.
276 bool LowerDbgDeclare(Function &F);
277 
278 /// Finds the llvm.dbg.declare intrinsic corresponding to an alloca, if any.
279 DbgDeclareInst *FindAllocaDbgDeclare(Value *V);
280 
281 /// Finds the llvm.dbg.value intrinsics corresponding to an alloca, if any.
282 void FindAllocaDbgValues(DbgValueList &DbgValues, Value *V);
283 
284 /// Replaces llvm.dbg.declare instruction when the address it describes
285 /// is replaced with a new value. If Deref is true, an additional DW_OP_deref is
286 /// prepended to the expression. If Offset is non-zero, a constant displacement
287 /// is added to the expression (after the optional Deref). Offset can be
288 /// negative.
289 bool replaceDbgDeclare(Value *Address, Value *NewAddress,
290  Instruction *InsertBefore, DIBuilder &Builder,
291  bool Deref, int Offset);
292 
293 /// Replaces llvm.dbg.declare instruction when the alloca it describes
294 /// is replaced with a new value. If Deref is true, an additional DW_OP_deref is
295 /// prepended to the expression. If Offset is non-zero, a constant displacement
296 /// is added to the expression (after the optional Deref). Offset can be
297 /// negative. New llvm.dbg.declare is inserted immediately before AI.
298 bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
299  DIBuilder &Builder, bool Deref, int Offset = 0);
300 
301 /// Replaces multiple llvm.dbg.value instructions when the alloca it describes
302 /// is replaced with a new value. If Offset is non-zero, a constant displacement
303 /// is added to the expression (after the mandatory Deref). Offset can be
304 /// negative. New llvm.dbg.value instructions are inserted at the locations of
305 /// the instructions they replace.
306 void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
307  DIBuilder &Builder, int Offset = 0);
308 
309 /// Remove all instructions from a basic block other than it's terminator
310 /// and any present EH pad instructions.
312 
313 /// Insert an unreachable instruction before the specified
314 /// instruction, making it and the rest of the code in the block dead.
315 unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
316  bool PreserveLCSSA = false);
317 
318 /// Convert the CallInst to InvokeInst with the specified unwind edge basic
319 /// block. This also splits the basic block where CI is located, because
320 /// InvokeInst is a terminator instruction. Returns the newly split basic
321 /// block.
323  BasicBlock *UnwindEdge);
324 
325 /// Replace 'BB's terminator with one that does not have an unwind successor
326 /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
327 /// successor.
328 ///
329 /// \param BB Block whose terminator will be replaced. Its terminator must
330 /// have an unwind successor.
331 void removeUnwindEdge(BasicBlock *BB);
332 
333 /// Remove all blocks that can not be reached from the function's entry.
334 ///
335 /// Returns true if any basic block was removed.
336 bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr);
337 
338 /// Combine the metadata of two instructions so that K can replace J
339 ///
340 /// Metadata not listed as known via KnownIDs is removed
341 void combineMetadata(Instruction *K, const Instruction *J, ArrayRef<unsigned> KnownIDs);
342 
343 /// Combine the metadata of two instructions so that K can replace J. This
344 /// specifically handles the case of CSE-like transformations.
345 ///
346 /// Unknown metadata is removed.
347 void combineMetadataForCSE(Instruction *K, const Instruction *J);
348 
349 /// Replace each use of 'From' with 'To' if that use is dominated by
350 /// the given edge. Returns the number of replacements made.
351 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
352  const BasicBlockEdge &Edge);
353 /// Replace each use of 'From' with 'To' if that use is dominated by
354 /// the end of the given BasicBlock. Returns the number of replacements made.
355 unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
356  const BasicBlock *BB);
357 
358 
359 /// Return true if the CallSite CS calls a gc leaf function.
360 ///
361 /// A leaf function is a function that does not safepoint the thread during its
362 /// execution. During a call or invoke to such a function, the callers stack
363 /// does not have to be made parseable.
364 ///
365 /// Most passes can and should ignore this information, and it is only used
366 /// during lowering by the GC infrastructure.
367 bool callsGCLeafFunction(ImmutableCallSite CS);
368 
369 //===----------------------------------------------------------------------===//
370 // Intrinsic pattern matching
371 //
372 
373 /// Try and match a bswap or bitreverse idiom.
374 ///
375 /// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
376 /// instructions are returned in \c InsertedInsts. They will all have been added
377 /// to a basic block.
378 ///
379 /// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
380 /// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
381 /// to BW / 4 nodes to be searched, so is significantly faster.
382 ///
383 /// This function returns true on a successful match or false otherwise.
385  Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
386  SmallVectorImpl<Instruction *> &InsertedInsts);
387 
388 //===----------------------------------------------------------------------===//
389 // Sanitizer utilities
390 //
391 
392 /// Given a CallInst, check if it calls a string function known to CodeGen,
393 /// and mark it with NoBuiltin if so. To be used by sanitizers that intend
394 /// to intercept string functions and want to avoid converting them to target
395 /// specific instructions.
397  const TargetLibraryInfo *TLI);
398 
399 } // End llvm namespace
400 
401 #endif
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:196
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
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:1306
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 ...
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:1019
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:1341
bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI, unsigned BonusInstThreshold, AssumptionCache *AC=nullptr, SmallPtrSetImpl< BasicBlock * > *LoopHeaders=nullptr)
This function is used to do simplification of a CFG.
size_t i
Various leaf nodes.
Definition: ISDOpcodes.h:60
DbgDeclareInst * FindAllocaDbgDeclare(Value *V)
Finds the llvm.dbg.declare intrinsic corresponding to an alloca, if any.
Definition: Local.cpp:1234
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:572
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:489
Hexagon Common GEP
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred)
Like BasicBlock::removePredecessor, this method is called when we're about to delete Pred as a predec...
Definition: Local.cpp:541
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:1373
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge)
Replace each use of 'From' with 'To' if that use is dominated by the given edge.
Definition: Local.cpp:1758
op_iterator op_begin()
Definition: User.h:205
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:195
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:345
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:1535
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:566
Class to represent struct types.
Definition: DerivedTypes.h:199
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:68
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:32
#define F(x, y, z)
Definition: MD5.cpp:51
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
Definition: Local.cpp:916
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:96
static 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:183
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA=nullptr)
This function is used to flatten a CFG.
Definition: FlattenCFG.cpp:480
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:517
#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 ...
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes...
Definition: Local.cpp:822
Conditional or Unconditional Branch instruction.
void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Definition: Local.cpp:1091
This is an important base class in LLVM.
Definition: Constant.h:42
op_iterator op_end()
Definition: User.h:207
uint32_t Offset
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
bool callsGCLeafFunction(ImmutableCallSite CS)
Return true if the CallSite CS calls a gc leaf function.
Definition: Local.cpp:1798
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:1286
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
If the specified value is a trivially dead instruction, delete it.
Definition: Local.cpp:355
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
Definition: Local.cpp:1185
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:709
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:408
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr)
Remove all blocks that can not be reached from the function's entry.
Definition: Local.cpp:1648
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
Provides information about what library functions are available for the current target.
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
Definition: Local.cpp:412
void FindAllocaDbgValues(DbgValueList &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics corresponding to an alloca, if any.
Definition: Local.cpp:1246
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:558
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than it's terminator and any present EH pad instruct...
Definition: Local.cpp:1352
void removeUnwindEdge(BasicBlock *BB)
Replace 'BB's terminator with one that does not have an unwind successor block.
Definition: Local.cpp:1611
could "use" a pointer
SmallVector< DbgValueInst *, 1 > DbgValueList
Definition: Local.h:50
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Definition: Operator.h:385
#define I(x, y, z)
Definition: MD5.cpp:54
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction * > &InsertedInsts)
Try and match a bswap or bitreverse idiom.
Definition: Local.cpp:1994
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:2068
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
Definition: Local.cpp:1747
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:288
LLVM Value Representation.
Definition: Value.h:71
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition: Local.cpp:1424
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2154
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:1682
an instruction to allocate memory on the stack
Definition: Instructions.h:60
gep_type_iterator gep_type_begin(const User *GEP)