Local.h 23 KB

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