Local.h 23 KB

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