16#include "llvm/IR/IntrinsicsR600.h"
22#define DEBUG_TYPE "amdgpu-lower-intrinsics"
28static int MaxStaticSize;
31 "amdgpu-mem-intrinsic-expand-size",
32 cl::desc(
"Set minimum mem intrinsic size to expand in IR"),
38class AMDGPULowerIntrinsics :
public ModulePass {
40 bool makeLIDRangeMetadata(
Function &
F)
const;
50 return "AMDGPU Lower Intrinsics";
60char AMDGPULowerIntrinsics::ID = 0;
69static
bool shouldExpandOperationWithSize(
Value *
Size) {
74bool AMDGPULowerIntrinsics::expandMemIntrinsicUses(
Function &
F) {
82 case Intrinsic::memcpy: {
83 auto *Memcpy = cast<MemCpyInst>(Inst);
84 if (shouldExpandOperationWithSize(Memcpy->getLength())) {
87 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(*ParentFunc);
90 Memcpy->eraseFromParent();
95 case Intrinsic::memmove: {
96 auto *Memmove = cast<MemMoveInst>(Inst);
97 if (shouldExpandOperationWithSize(Memmove->getLength())) {
100 Memmove->eraseFromParent();
105 case Intrinsic::memset: {
106 auto *Memset = cast<MemSetInst>(Inst);
107 if (shouldExpandOperationWithSize(Memset->getLength())) {
110 Memset->eraseFromParent();
123bool AMDGPULowerIntrinsics::makeLIDRangeMetadata(
Function &
F)
const {
124 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
129 bool Changed =
false;
131 for (
auto *U :
F.users()) {
132 auto *CI = dyn_cast<CallInst>(U);
138 Changed |=
ST.makeLIDRangeMetadata(CI);
143bool AMDGPULowerIntrinsics::runOnModule(
Module &M) {
144 bool Changed =
false;
147 if (!
F.isDeclaration())
150 switch (
F.getIntrinsicID()) {
151 case Intrinsic::memcpy:
152 case Intrinsic::memmove:
153 case Intrinsic::memset:
154 if (expandMemIntrinsicUses(
F))
158 case Intrinsic::r600_read_tidig_x:
159 case Intrinsic::r600_read_tidig_y:
160 case Intrinsic::r600_read_tidig_z:
161 case Intrinsic::r600_read_local_size_x:
162 case Intrinsic::r600_read_local_size_y:
163 case Intrinsic::r600_read_local_size_z:
164 Changed |= makeLIDRangeMetadata(
F);
176 return new AMDGPULowerIntrinsics();
Base class for AMDGPU specific classes of TargetSubtarget.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
const char LLVMTargetMachineRef TM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Target-Independent Code Generator Pass Configuration Options pass.
static const AMDGPUSubtarget & get(const MachineFunction &MF)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
This is the shared class of boolean and integer constants.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Module * getParent()
Get the module that this global value is contained inside of...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
StringRef - Represent a constant reference to a string, i.e.
Primary interface to the complete machine description for the target machine.
LLVM Value Representation.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
ModulePass * createAMDGPULowerIntrinsicsPass()
void expandMemMoveAsLoop(MemMoveInst *MemMove)
Expand MemMove as a loop. MemMove is not deleted.
char & AMDGPULowerIntrinsicsID
void expandMemCpyAsLoop(MemCpyInst *MemCpy, const TargetTransformInfo &TTI, ScalarEvolution *SE=nullptr)
Expand MemCpy as a loop. MemCpy is not deleted.
void expandMemSetAsLoop(MemSetInst *MemSet)
Expand MemSet as a loop. MemSet is not deleted.