xref: /llvm-project/llvm/include/llvm/Transforms/Utils/LowerMemIntrinsics.h (revision 298127dcbe2ecd1f3c49c2109ac96654778f20be)
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 <cstdint>
18 #include <optional>
19 
20 namespace llvm {
21 
22 class AtomicMemCpyInst;
23 class ConstantInt;
24 class Instruction;
25 class MemCpyInst;
26 class MemMoveInst;
27 class MemSetInst;
28 class MemSetPatternInst;
29 class ScalarEvolution;
30 class TargetTransformInfo;
31 class Value;
32 struct Align;
33 
34 /// Emit a loop implementing the semantics of llvm.memcpy where the size is not
35 /// a compile-time constant. Loop will be insterted at \p InsertBefore.
36 void createMemCpyLoopUnknownSize(
37     Instruction *InsertBefore, Value *SrcAddr, Value *DstAddr, Value *CopyLen,
38     Align SrcAlign, Align DestAlign, bool SrcIsVolatile, bool DstIsVolatile,
39     bool CanOverlap, const TargetTransformInfo &TTI,
40     std::optional<unsigned> AtomicSize = std::nullopt);
41 
42 /// Emit a loop implementing the semantics of an llvm.memcpy whose size is a
43 /// compile time constant. Loop is inserted at \p InsertBefore.
44 void createMemCpyLoopKnownSize(
45     Instruction *InsertBefore, Value *SrcAddr, Value *DstAddr,
46     ConstantInt *CopyLen, Align SrcAlign, Align DestAlign, bool SrcIsVolatile,
47     bool DstIsVolatile, bool CanOverlap, const TargetTransformInfo &TTI,
48     std::optional<uint32_t> AtomicCpySize = std::nullopt);
49 
50 /// Expand \p MemCpy as a loop. \p MemCpy is not deleted.
51 void expandMemCpyAsLoop(MemCpyInst *MemCpy, const TargetTransformInfo &TTI,
52                         ScalarEvolution *SE = nullptr);
53 
54 /// Expand \p MemMove as a loop. \p MemMove is not deleted. Returns true if the
55 /// memmove was lowered.
56 bool expandMemMoveAsLoop(MemMoveInst *MemMove, const TargetTransformInfo &TTI);
57 
58 /// Expand \p MemSet as a loop. \p MemSet is not deleted.
59 void expandMemSetAsLoop(MemSetInst *MemSet);
60 
61 /// Expand \p MemSetPattern as a loop. \p MemSet is not deleted.
62 void expandMemSetPatternAsLoop(MemSetPatternInst *MemSet);
63 
64 /// Expand \p AtomicMemCpy as a loop. \p AtomicMemCpy is not deleted.
65 void expandAtomicMemCpyAsLoop(AtomicMemCpyInst *AtomicMemCpy,
66                               const TargetTransformInfo &TTI,
67                               ScalarEvolution *SE);
68 
69 } // End llvm namespace
70 
71 #endif
72