Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Transforms/Utils/Local.h
Line
Count
Source (jump to first uncovered line)
1
//===- Local.h - Functions to perform local transformations -----*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This family of functions perform various local transformations to the
10
// program.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
15
#define LLVM_TRANSFORMS_UTILS_LOCAL_H
16
17
#include "llvm/ADT/ArrayRef.h"
18
#include "llvm/ADT/STLExtras.h"
19
#include "llvm/ADT/SmallPtrSet.h"
20
#include "llvm/ADT/SmallVector.h"
21
#include "llvm/ADT/TinyPtrVector.h"
22
#include "llvm/Analysis/AliasAnalysis.h"
23
#include "llvm/Analysis/DomTreeUpdater.h"
24
#include "llvm/Analysis/Utils/Local.h"
25
#include "llvm/IR/Constant.h"
26
#include "llvm/IR/Constants.h"
27
#include "llvm/IR/DataLayout.h"
28
#include "llvm/IR/Dominators.h"
29
#include "llvm/IR/GetElementPtrTypeIterator.h"
30
#include "llvm/IR/Operator.h"
31
#include "llvm/IR/Type.h"
32
#include "llvm/IR/User.h"
33
#include "llvm/IR/Value.h"
34
#include "llvm/Support/Casting.h"
35
#include <cstdint>
36
#include <limits>
37
38
namespace llvm {
39
40
class AllocaInst;
41
class AssumptionCache;
42
class BasicBlock;
43
class BranchInst;
44
class CallInst;
45
class DbgVariableIntrinsic;
46
class DbgValueInst;
47
class DIBuilder;
48
class Function;
49
class Instruction;
50
class LazyValueInfo;
51
class LoadInst;
52
class MDNode;
53
class MemorySSAUpdater;
54
class PHINode;
55
class StoreInst;
56
class TargetLibraryInfo;
57
class TargetTransformInfo;
58
59
/// A set of parameters used to control the transforms in the SimplifyCFG pass.
60
/// Options may change depending on the position in the optimization pipeline.
61
/// For example, canonical form that includes switches and branches may later be
62
/// replaced by lookup tables and selects.
63
struct SimplifyCFGOptions {
64
  int BonusInstThreshold;
65
  bool ForwardSwitchCondToPhi;
66
  bool ConvertSwitchToLookupTable;
67
  bool NeedCanonicalLoop;
68
  bool SinkCommonInsts;
69
  AssumptionCache *AC;
70
71
  SimplifyCFGOptions(unsigned BonusThreshold = 1,
72
                     bool ForwardSwitchCond = false,
73
                     bool SwitchToLookup = false, bool CanonicalLoops = true,
74
                     bool SinkCommon = false,
75
                     AssumptionCache *AssumpCache = nullptr)
76
      : BonusInstThreshold(BonusThreshold),
77
        ForwardSwitchCondToPhi(ForwardSwitchCond),
78
        ConvertSwitchToLookupTable(SwitchToLookup),
79
        NeedCanonicalLoop(CanonicalLoops),
80
        SinkCommonInsts(SinkCommon),
81
121k
        AC(AssumpCache) {}
82
83
  // Support 'builder' pattern to set members by name at construction time.
84
2
  SimplifyCFGOptions &bonusInstThreshold(int I) {
85
2
    BonusInstThreshold = I;
86
2
    return *this;
87
2
  }
88
1.29k
  SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) {
89
1.29k
    ForwardSwitchCondToPhi = B;
90
1.29k
    return *this;
91
1.29k
  }
92
1.30k
  SimplifyCFGOptions &convertSwitchToLookupTable(bool B) {
93
1.30k
    ConvertSwitchToLookupTable = B;
94
1.30k
    return *this;
95
1.30k
  }
96
1.30k
  SimplifyCFGOptions &needCanonicalLoops(bool B) {
97
1.30k
    NeedCanonicalLoop = B;
98
1.30k
    return *this;
99
1.30k
  }
100
1.29k
  SimplifyCFGOptions &sinkCommonInsts(bool B) {
101
1.29k
    SinkCommonInsts = B;
102
1.29k
    return *this;
103
1.29k
  }
104
0
  SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) {
105
0
    AC = Cache;
106
0
    return *this;
107
0
  }
108
};
109
110
//===----------------------------------------------------------------------===//
111
//  Local constant propagation.
112
//
113
114
/// If a terminator instruction is predicated on a constant value, convert it
115
/// into an unconditional branch to the constant destination.
116
/// This is a nontrivial operation because the successors of this basic block
117
/// must have their PHI nodes updated.
118
/// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
119
/// conditions and indirectbr addresses this might make dead if
120
/// DeleteDeadConditions is true.
121
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
122
                            const TargetLibraryInfo *TLI = nullptr,
123
                            DomTreeUpdater *DTU = nullptr);
124
125
//===----------------------------------------------------------------------===//
126
//  Local dead code elimination.
127
//
128
129
/// Return true if the result produced by the instruction is not used, and the
130
/// instruction has no side effects.
131
bool isInstructionTriviallyDead(Instruction *I,
132
                                const TargetLibraryInfo *TLI = nullptr);
133
134
/// Return true if the result produced by the instruction would have no side
135
/// effects if it was not used. This is equivalent to checking whether
136
/// isInstructionTriviallyDead would be true if the use count was 0.
137
bool wouldInstructionBeTriviallyDead(Instruction *I,
138
                                     const TargetLibraryInfo *TLI = nullptr);
139
140
/// If the specified value is a trivially dead instruction, delete it.
141
/// If that makes any of its operands trivially dead, delete them too,
142
/// recursively. Return true if any instructions were deleted.
143
bool RecursivelyDeleteTriviallyDeadInstructions(
144
    Value *V, const TargetLibraryInfo *TLI = nullptr,
145
    MemorySSAUpdater *MSSAU = nullptr);
146
147
/// Delete all of the instructions in `DeadInsts`, and all other instructions
148
/// that deleting these in turn causes to be trivially dead.
149
///
150
/// The initial instructions in the provided vector must all have empty use
151
/// lists and satisfy `isInstructionTriviallyDead`.
152
///
153
/// `DeadInsts` will be used as scratch storage for this routine and will be
154
/// empty afterward.
155
void RecursivelyDeleteTriviallyDeadInstructions(
156
    SmallVectorImpl<Instruction *> &DeadInsts,
157
    const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr);
158
159
/// If the specified value is an effectively dead PHI node, due to being a
160
/// def-use chain of single-use nodes that either forms a cycle or is terminated
161
/// by a trivially dead instruction, delete it. If that makes any of its
162
/// operands trivially dead, delete them too, recursively. Return true if a
163
/// change was made.
164
bool RecursivelyDeleteDeadPHINode(PHINode *PN,
165
                                  const TargetLibraryInfo *TLI = nullptr);
166
167
/// Scan the specified basic block and try to simplify any instructions in it
168
/// and recursively delete dead instructions.
169
///
170
/// This returns true if it changed the code, note that it can delete
171
/// instructions in other blocks as well in this block.
172
bool SimplifyInstructionsInBlock(BasicBlock *BB,
173
                                 const TargetLibraryInfo *TLI = nullptr);
174
175
/// Replace all the uses of an SSA value in @llvm.dbg intrinsics with
176
/// undef. This is useful for signaling that a variable, e.g. has been
177
/// found dead and hence it's unavailable at a given program point.
178
/// Returns true if the dbg values have been changed.
179
bool replaceDbgUsesWithUndef(Instruction *I);
180
181
//===----------------------------------------------------------------------===//
182
//  Control Flow Graph Restructuring.
183
//
184
185
/// Like BasicBlock::removePredecessor, this method is called when we're about
186
/// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
187
/// drops the entries in the PHI nodes for Pred.
188
///
189
/// Unlike the removePredecessor method, this attempts to simplify uses of PHI
190
/// nodes that collapse into identity values.  For example, if we have:
191
///   x = phi(1, 0, 0, 0)
192
///   y = and x, z
193
///
194
/// .. and delete the predecessor corresponding to the '1', this will attempt to
195
/// recursively fold the 'and' to 0.
196
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred,
197
                                  DomTreeUpdater *DTU = nullptr);
198
199
/// BB is a block with one predecessor and its predecessor is known to have one
200
/// successor (BB!). Eliminate the edge between them, moving the instructions in
201
/// the predecessor into BB. This deletes the predecessor block.
202
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
203
204
/// BB is known to contain an unconditional branch, and contains no instructions
205
/// other than PHI nodes, potential debug intrinsics and the branch. If
206
/// possible, eliminate BB by rewriting all the predecessors to branch to the
207
/// successor block and return true. If we can't transform, return false.
208
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
209
                                             DomTreeUpdater *DTU = nullptr);
210
211
/// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
212
/// to be clever about PHI nodes which differ only in the order of the incoming
213
/// values, but instcombine orders them so it usually won't matter.
214
bool EliminateDuplicatePHINodes(BasicBlock *BB);
215
216
/// This function is used to do simplification of a CFG.  For example, it
217
/// adjusts branches to branches to eliminate the extra hop, it eliminates
218
/// unreachable basic blocks, and does other peephole optimization of the CFG.
219
/// It returns true if a modification was made, possibly deleting the basic
220
/// block that was pointed to. LoopHeaders is an optional input parameter
221
/// providing the set of loop headers that SimplifyCFG should not eliminate.
222
bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
223
                 const SimplifyCFGOptions &Options = {},
224
                 SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
225
226
/// This function is used to flatten a CFG. For example, it uses parallel-and
227
/// and parallel-or mode to collapse if-conditions and merge if-regions with
228
/// identical statements.
229
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
230
231
/// If this basic block is ONLY a setcc and a branch, and if a predecessor
232
/// branches to us and one of our successors, fold the setcc into the
233
/// predecessor and use logical operations to pick the right destination.
234
bool FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU = nullptr,
235
                            unsigned BonusInstThreshold = 1);
236
237
/// This function takes a virtual register computed by an Instruction and
238
/// replaces it with a slot in the stack frame, allocated via alloca.
239
/// This allows the CFG to be changed around without fear of invalidating the
240
/// SSA information for the value. It returns the pointer to the alloca inserted
241
/// to create a stack slot for X.
242
AllocaInst *DemoteRegToStack(Instruction &X,
243
                             bool VolatileLoads = false,
244
                             Instruction *AllocaPoint = nullptr);
245
246
/// This function takes a virtual register computed by a phi node and replaces
247
/// it with a slot in the stack frame, allocated via alloca. The phi node is
248
/// deleted and it returns the pointer to the alloca inserted.
249
AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
250
251
/// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
252
/// the owning object can be modified and has an alignment less than \p
253
/// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
254
/// cannot be increased, the known alignment of the value is returned.
255
///
256
/// It is not always possible to modify the alignment of the underlying object,
257
/// so if alignment is important, a more reliable approach is to simply align
258
/// all global variables and allocation instructions to their preferred
259
/// alignment from the beginning.
260
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
261
                                    const DataLayout &DL,
262
                                    const Instruction *CxtI = nullptr,
263
                                    AssumptionCache *AC = nullptr,
264
                                    const DominatorTree *DT = nullptr);
265
266
/// Try to infer an alignment for the specified pointer.
267
inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
268
                                  const Instruction *CxtI = nullptr,
269
                                  AssumptionCache *AC = nullptr,
270
780k
                                  const DominatorTree *DT = nullptr) {
271
780k
  return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
272
780k
}
273
274
/// This function converts the specified invoek into a normall call.
275
void changeToCall(InvokeInst *II, DomTreeUpdater *DTU = nullptr);
276
277
///===---------------------------------------------------------------------===//
278
///  Dbg Intrinsic utilities
279
///
280
281
/// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
282
/// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
283
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
284
                                     StoreInst *SI, DIBuilder &Builder);
285
286
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
287
/// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
288
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
289
                                     LoadInst *LI, DIBuilder &Builder);
290
291
/// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
292
/// llvm.dbg.declare or llvm.dbg.addr intrinsic.
293
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
294
                                     PHINode *LI, DIBuilder &Builder);
295
296
/// Lowers llvm.dbg.declare intrinsics into appropriate set of
297
/// llvm.dbg.value intrinsics.
298
bool LowerDbgDeclare(Function &F);
299
300
/// Propagate dbg.value intrinsics through the newly inserted PHIs.
301
void insertDebugValuesForPHIs(BasicBlock *BB,
302
                              SmallVectorImpl<PHINode *> &InsertedPHIs);
303
304
/// Finds all intrinsics declaring local variables as living in the memory that
305
/// 'V' points to. This may include a mix of dbg.declare and
306
/// dbg.addr intrinsics.
307
TinyPtrVector<DbgVariableIntrinsic *> FindDbgAddrUses(Value *V);
308
309
/// Finds the llvm.dbg.value intrinsics describing a value.
310
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V);
311
312
/// Finds the debug info intrinsics describing a value.
313
void findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts, Value *V);
314
315
/// Replaces llvm.dbg.declare instruction when the address it
316
/// describes is replaced with a new value. If Deref is true, an
317
/// additional DW_OP_deref is prepended to the expression. If Offset
318
/// is non-zero, a constant displacement is added to the expression
319
/// (between the optional Deref operations). Offset can be negative.
320
bool replaceDbgDeclare(Value *Address, Value *NewAddress,
321
                       Instruction *InsertBefore, DIBuilder &Builder,
322
                       uint8_t DIExprFlags, int Offset);
323
324
/// Replaces llvm.dbg.declare instruction when the alloca it describes
325
/// is replaced with a new value. If Deref is true, an additional
326
/// DW_OP_deref is prepended to the expression. If Offset is non-zero,
327
/// a constant displacement is added to the expression (between the
328
/// optional Deref operations). Offset can be negative. The new
329
/// llvm.dbg.declare is inserted immediately after AI.
330
bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
331
                                DIBuilder &Builder, uint8_t DIExprFlags,
332
                                int Offset);
333
334
/// Replaces multiple llvm.dbg.value instructions when the alloca it describes
335
/// is replaced with a new value. If Offset is non-zero, a constant displacement
336
/// is added to the expression (after the mandatory Deref). Offset can be
337
/// negative. New llvm.dbg.value instructions are inserted at the locations of
338
/// the instructions they replace.
339
void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
340
                              DIBuilder &Builder, int Offset = 0);
341
342
/// Finds alloca where the value comes from.
343
AllocaInst *findAllocaForValue(Value *V,
344
                               DenseMap<Value *, AllocaInst *> &AllocaForValue);
345
346
/// Assuming the instruction \p I is going to be deleted, attempt to salvage
347
/// debug users of \p I by writing the effect of \p I in a DIExpression.
348
/// Returns true if any debug users were updated.
349
bool salvageDebugInfo(Instruction &I);
350
351
/// Implementation of salvageDebugInfo, applying only to instructions in
352
/// \p Insns, rather than all debug users of \p I.
353
bool salvageDebugInfoForDbgValues(Instruction &I,
354
                                  ArrayRef<DbgVariableIntrinsic *> Insns);
355
356
/// Given an instruction \p I and DIExpression \p DIExpr operating on it, write
357
/// the effects of \p I into the returned DIExpression, or return nullptr if
358
/// it cannot be salvaged. \p StackVal: whether DW_OP_stack_value should be
359
/// appended to the expression.
360
DIExpression *salvageDebugInfoImpl(Instruction &I, DIExpression *DIExpr,
361
                                   bool StackVal);
362
363
/// Point debug users of \p From to \p To or salvage them. Use this function
364
/// only when replacing all uses of \p From with \p To, with a guarantee that
365
/// \p From is going to be deleted.
366
///
367
/// Follow these rules to prevent use-before-def of \p To:
368
///   . If \p To is a linked Instruction, set \p DomPoint to \p To.
369
///   . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
370
///     \p To will be inserted after.
371
///   . If \p To is not an Instruction (e.g a Constant), the choice of
372
///     \p DomPoint is arbitrary. Pick \p From for simplicity.
373
///
374
/// If a debug user cannot be preserved without reordering variable updates or
375
/// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
376
/// or deleted. Returns true if any debug users were updated.
377
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint,
378
                           DominatorTree &DT);
379
380
/// Remove all instructions from a basic block other than it's terminator
381
/// and any present EH pad instructions.
382
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB);
383
384
/// Insert an unreachable instruction before the specified
385
/// instruction, making it and the rest of the code in the block dead.
386
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
387
                             bool PreserveLCSSA = false,
388
                             DomTreeUpdater *DTU = nullptr,
389
                             MemorySSAUpdater *MSSAU = nullptr);
390
391
/// Convert the CallInst to InvokeInst with the specified unwind edge basic
392
/// block.  This also splits the basic block where CI is located, because
393
/// InvokeInst is a terminator instruction.  Returns the newly split basic
394
/// block.
395
BasicBlock *changeToInvokeAndSplitBasicBlock(CallInst *CI,
396
                                             BasicBlock *UnwindEdge);
397
398
/// Replace 'BB's terminator with one that does not have an unwind successor
399
/// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
400
/// successor.
401
///
402
/// \param BB  Block whose terminator will be replaced.  Its terminator must
403
///            have an unwind successor.
404
void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
405
406
/// Remove all blocks that can not be reached from the function's entry.
407
///
408
/// Returns true if any basic block was removed.
409
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr,
410
                             DomTreeUpdater *DTU = nullptr,
411
                             MemorySSAUpdater *MSSAU = nullptr);
412
413
/// Combine the metadata of two instructions so that K can replace J. Some
414
/// metadata kinds can only be kept if K does not move, meaning it dominated
415
/// J in the original IR.
416
///
417
/// Metadata not listed as known via KnownIDs is removed
418
void combineMetadata(Instruction *K, const Instruction *J,
419
                     ArrayRef<unsigned> KnownIDs, bool DoesKMove);
420
421
/// Combine the metadata of two instructions so that K can replace J. This
422
/// specifically handles the case of CSE-like transformations. Some
423
/// metadata can only be kept if K dominates J. For this to be correct,
424
/// K cannot be hoisted.
425
///
426
/// Unknown metadata is removed.
427
void combineMetadataForCSE(Instruction *K, const Instruction *J,
428
                           bool DoesKMove);
429
430
/// Patch the replacement so that it is not more restrictive than the value
431
/// being replaced. It assumes that the replacement does not get moved from
432
/// its original position.
433
void patchReplacementInstruction(Instruction *I, Value *Repl);
434
435
// Replace each use of 'From' with 'To', if that use does not belong to basic
436
// block where 'From' is defined. Returns the number of replacements made.
437
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
438
439
/// Replace each use of 'From' with 'To' if that use is dominated by
440
/// the given edge.  Returns the number of replacements made.
441
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
442
                                  const BasicBlockEdge &Edge);
443
/// Replace each use of 'From' with 'To' if that use is dominated by
444
/// the end of the given BasicBlock. Returns the number of replacements made.
445
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
446
                                  const BasicBlock *BB);
447
448
/// Return true if this call calls a gc leaf function.
449
///
450
/// A leaf function is a function that does not safepoint the thread during its
451
/// execution.  During a call or invoke to such a function, the callers stack
452
/// does not have to be made parseable.
453
///
454
/// Most passes can and should ignore this information, and it is only used
455
/// during lowering by the GC infrastructure.
456
bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI);
457
458
/// Copy a nonnull metadata node to a new load instruction.
459
///
460
/// This handles mapping it to range metadata if the new load is an integer
461
/// load instead of a pointer load.
462
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
463
464
/// Copy a range metadata node to a new load instruction.
465
///
466
/// This handles mapping it to nonnull metadata if the new load is a pointer
467
/// load instead of an integer load and the range doesn't cover null.
468
void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
469
                       LoadInst &NewLI);
470
471
/// Remove the debug intrinsic instructions for the given instruction.
472
void dropDebugUsers(Instruction &I);
473
474
/// Hoist all of the instructions in the \p IfBlock to the dominant block
475
/// \p DomBlock, by moving its instructions to the insertion point \p InsertPt.
476
///
477
/// The moved instructions receive the insertion point debug location values
478
/// (DILocations) and their debug intrinsic instructions are removed.
479
void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,
480
                              BasicBlock *BB);
481
482
//===----------------------------------------------------------------------===//
483
//  Intrinsic pattern matching
484
//
485
486
/// Try to match a bswap or bitreverse idiom.
487
///
488
/// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
489
/// instructions are returned in \c InsertedInsts. They will all have been added
490
/// to a basic block.
491
///
492
/// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
493
/// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
494
/// to BW / 4 nodes to be searched, so is significantly faster.
495
///
496
/// This function returns true on a successful match or false otherwise.
497
bool recognizeBSwapOrBitReverseIdiom(
498
    Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
499
    SmallVectorImpl<Instruction *> &InsertedInsts);
500
501
//===----------------------------------------------------------------------===//
502
//  Sanitizer utilities
503
//
504
505
/// Given a CallInst, check if it calls a string function known to CodeGen,
506
/// and mark it with NoBuiltin if so.  To be used by sanitizers that intend
507
/// to intercept string functions and want to avoid converting them to target
508
/// specific instructions.
509
void maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI,
510
                                            const TargetLibraryInfo *TLI);
511
512
//===----------------------------------------------------------------------===//
513
//  Transform predicates
514
//
515
516
/// Given an instruction, is it legal to set operand OpIdx to a non-constant
517
/// value?
518
bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
519
520
} // end namespace llvm
521
522
#endif // LLVM_TRANSFORMS_UTILS_LOCAL_H