xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Transforms/Utils/LowerMemIntrinsics.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- llvm/Transforms/Utils/LowerMemIntrinsics.h ---------------*- 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 // Lower memset, memcpy, memmov intrinsics to loops (e.g. for targets without
10 // library support).
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_UTILS_LOWERMEMINTRINSICS_H
15 #define LLVM_TRANSFORMS_UTILS_LOWERMEMINTRINSICS_H
16 
17 #include "llvm/Support/Compiler.h"
18 #include <cstdint>
19 #include <optional>
20 
21 namespace llvm {
22 
23 class AnyMemCpyInst;
24 class ConstantInt;
25 class Instruction;
26 class MemCpyInst;
27 class MemMoveInst;
28 class MemSetInst;
29 class MemSetPatternInst;
30 class ScalarEvolution;
31 class TargetTransformInfo;
32 class Value;
33 struct Align;
34 
35 /// Emit a loop implementing the semantics of llvm.memcpy where the size is not
36 /// a compile-time constant. Loop will be inserted at \p InsertBefore.
37 LLVM_ABI void createMemCpyLoopUnknownSize(
38     Instruction *InsertBefore, Value *SrcAddr, Value *DstAddr, Value *CopyLen,
39     Align SrcAlign, Align DestAlign, bool SrcIsVolatile, bool DstIsVolatile,
40     bool CanOverlap, const TargetTransformInfo &TTI,
41     std::optional<unsigned> AtomicSize = std::nullopt);
42 
43 /// Emit a loop implementing the semantics of an llvm.memcpy whose size is a
44 /// compile time constant. Loop is inserted at \p InsertBefore.
45 LLVM_ABI void createMemCpyLoopKnownSize(
46     Instruction *InsertBefore, Value *SrcAddr, Value *DstAddr,
47     ConstantInt *CopyLen, Align SrcAlign, Align DestAlign, bool SrcIsVolatile,
48     bool DstIsVolatile, bool CanOverlap, const TargetTransformInfo &TTI,
49     std::optional<uint32_t> AtomicCpySize = std::nullopt);
50 
51 /// Expand \p MemCpy as a loop. \p MemCpy is not deleted.
52 LLVM_ABI void expandMemCpyAsLoop(MemCpyInst *MemCpy,
53                                  const TargetTransformInfo &TTI,
54                                  ScalarEvolution *SE = nullptr);
55 
56 /// Expand \p MemMove as a loop. \p MemMove is not deleted. Returns true if the
57 /// memmove was lowered.
58 LLVM_ABI bool expandMemMoveAsLoop(MemMoveInst *MemMove,
59                                   const TargetTransformInfo &TTI);
60 
61 /// Expand \p MemSet as a loop. \p MemSet is not deleted.
62 LLVM_ABI void expandMemSetAsLoop(MemSetInst *MemSet);
63 
64 /// Expand \p MemSetPattern as a loop. \p MemSet is not deleted.
65 LLVM_ABI void expandMemSetPatternAsLoop(MemSetPatternInst *MemSet);
66 
67 /// Expand \p AtomicMemCpy as a loop. \p AtomicMemCpy is not deleted.
68 LLVM_ABI void expandAtomicMemCpyAsLoop(AnyMemCpyInst *AtomicMemCpy,
69                                        const TargetTransformInfo &TTI,
70                                        ScalarEvolution *SE);
71 
72 } // namespace llvm
73 
74 #endif
75