16 #include "llvm/IR/IntrinsicsAMDGPU.h" 17 #include "llvm/IR/IntrinsicsR600.h" 22 #define DEBUG_TYPE "amdgpu-lower-intrinsics" 28 static int MaxStaticSize;
31 "amdgpu-mem-intrinsic-expand-size",
32 cl::desc(
"Set minimum mem intrinsic size to expand in IR"),
38 class AMDGPULowerIntrinsics :
public ModulePass {
40 bool makeLIDRangeMetadata(
Function &
F)
const;
47 bool runOnModule(
Module &M)
override;
50 return "AMDGPU Lower Intrinsics";
69 static
bool shouldExpandOperationWithSize(
Value *
Size) {
74 bool AMDGPULowerIntrinsics::expandMemIntrinsicUses(
Function &
F) {
78 for (
auto I =
F.user_begin(),
E =
F.user_end();
I !=
E;) {
83 case Intrinsic::memcpy: {
84 auto *Memcpy = cast<MemCpyInst>(Inst);
85 if (shouldExpandOperationWithSize(Memcpy->getLength())) {
88 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(*ParentFunc);
91 Memcpy->eraseFromParent();
96 case Intrinsic::memmove: {
97 auto *Memmove = cast<MemMoveInst>(Inst);
98 if (shouldExpandOperationWithSize(Memmove->getLength())) {
101 Memmove->eraseFromParent();
106 case Intrinsic::memset: {
107 auto *Memset = cast<MemSetInst>(Inst);
108 if (shouldExpandOperationWithSize(Memset->getLength())) {
111 Memset->eraseFromParent();
124 bool AMDGPULowerIntrinsics::makeLIDRangeMetadata(
Function &
F)
const {
125 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
130 bool Changed =
false;
132 for (
auto *U :
F.users()) {
133 auto *CI = dyn_cast<CallInst>(U);
139 Changed |=
ST.makeLIDRangeMetadata(CI);
144 bool AMDGPULowerIntrinsics::runOnModule(
Module &M) {
145 bool Changed =
false;
148 if (!
F.isDeclaration())
151 switch (
F.getIntrinsicID()) {
152 case Intrinsic::memcpy:
153 case Intrinsic::memmove:
154 case Intrinsic::memset:
155 if (expandMemIntrinsicUses(
F))
159 case Intrinsic::amdgcn_workitem_id_x:
160 case Intrinsic::r600_read_tidig_x:
161 case Intrinsic::amdgcn_workitem_id_y:
162 case Intrinsic::r600_read_tidig_y:
163 case Intrinsic::amdgcn_workitem_id_z:
164 case Intrinsic::r600_read_tidig_z:
165 case Intrinsic::r600_read_local_size_x:
166 case Intrinsic::r600_read_local_size_y:
167 case Intrinsic::r600_read_local_size_z:
168 Changed |= makeLIDRangeMetadata(
F);
180 return new AMDGPULowerIntrinsics();
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
void expandMemMoveAsLoop(MemMoveInst *MemMove)
Expand MemMove as a loop. MemMove is not deleted.
A Module instance is used to store all the information related to an LLVM module.
INITIALIZE_PASS(AMDGPULowerIntrinsics, DEBUG_TYPE, "Lower intrinsics", false, false) static bool shouldExpandOperationWithSize(Value *Size)
void expandMemSetAsLoop(MemSetInst *MemSet)
Expand MemSet as a loop. MemSet is not deleted.
static const AMDGPUSubtarget & get(const MachineFunction &MF)
AnalysisUsage & addRequired()
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
ModulePass * createAMDGPULowerIntrinsicsPass()
This is the shared class of boolean and integer constants.
Module.h This file contains the declarations for the Module class.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
char & AMDGPULowerIntrinsicsID
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
LocationClass< Ty > location(Ty &L)
void expandMemCpyAsLoop(MemCpyInst *MemCpy, const TargetTransformInfo &TTI)
Expand MemCpy as a loop. MemCpy is not deleted.