LLVM 22.0.0git
Macros | Functions
DXILCBufferAccess.cpp File Reference
#include "DXILCBufferAccess.h"
#include "DirectX.h"
#include "llvm/Frontend/HLSL/CBuffer.h"
#include "llvm/Frontend/HLSL/HLSLResource.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/IntrinsicsDirectX.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Transforms/Utils/Local.h"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "dxil-cbuffer-access"
 

Functions

static void replaceLoad (LoadInst *LI, CBufferResource &CBR, SmallVectorImpl< WeakTrackingVH > &DeadInsts)
 Replace load via cbuffer global with a load from the cbuffer handle itself.
 
static void copyArrayElemsForMemCpy (IRBuilder<> &Builder, MemCpyInst *MCI, CBufferResource &CBR, ArrayType *ArrTy, size_t ArrOffset, size_t N, const Twine &Name="")
 This function recursively copies N array elements from the cbuffer resource CBR to the MemCpy Destination.
 
static void replaceMemCpy (MemCpyInst *MCI, CBufferResource &CBR)
 Replace memcpy from a cbuffer global with a memcpy from the cbuffer handle itself.
 
static void replaceAccessesWithHandle (CBufferResource &CBR)
 
static bool replaceCBufferAccesses (Module &M)
 
 INITIALIZE_PASS (DXILCBufferAccessLegacy, DEBUG_TYPE, "DXIL CBuffer Access", false, false) ModulePass *llvm
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "dxil-cbuffer-access"

Definition at line 21 of file DXILCBufferAccess.cpp.

Function Documentation

◆ copyArrayElemsForMemCpy()

static void copyArrayElemsForMemCpy ( IRBuilder<> &  Builder,
MemCpyInst MCI,
CBufferResource &  CBR,
ArrayType ArrTy,
size_t  ArrOffset,
size_t  N,
const Twine Name = "" 
)
static

This function recursively copies N array elements from the cbuffer resource CBR to the MemCpy Destination.

Recursion is used to unravel multidimensional arrays into a sequence of scalar/vector extracts and stores.

Definition at line 200 of file DXILCBufferAccess.cpp.

References copyArrayElemsForMemCpy(), llvm::IRBuilderBase::CreateInBoundsGEP(), llvm::IRBuilderBase::CreateStore(), DL, GEP, llvm::Instruction::getDataLayout(), llvm::MemIntrinsicBase< Derived >::getDest(), llvm::IRBuilderBase::getInt8Ty(), llvm::MemTransferBase< BaseCL >::getSource(), llvm::Value::getType(), llvm::APInt::getZExtValue(), I, llvm::MemIntrinsic::isVolatile(), N, Name, llvm::Offset, and llvm::hlsl::translateCBufArrayOffset().

Referenced by copyArrayElemsForMemCpy(), and replaceMemCpy().

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( DXILCBufferAccessLegacy  ,
DEBUG_TYPE  ,
"DXIL CBuffer Access"  ,
false  ,
false   
)

Definition at line 341 of file DXILCBufferAccess.cpp.

◆ replaceAccessesWithHandle()

static void replaceAccessesWithHandle ( CBufferResource &  CBR)
static

◆ replaceCBufferAccesses()

static bool replaceCBufferAccesses ( Module M)
static

◆ replaceLoad()

static void replaceLoad ( LoadInst LI,
CBufferResource &  CBR,
SmallVectorImpl< WeakTrackingVH > &  DeadInsts 
)
static

◆ replaceMemCpy()

static void replaceMemCpy ( MemCpyInst MCI,
CBufferResource &  CBR 
)
static

Replace memcpy from a cbuffer global with a memcpy from the cbuffer handle itself.

Assumes the cbuffer global is an array, and the length of bytes to copy is divisible by array element allocation size. The memcpy source must also be a direct cbuffer global reference, not a GEP.

Definition at line 235 of file DXILCBufferAccess.cpp.

References assert(), copyArrayElemsForMemCpy(), DL, llvm::Instruction::eraseFromParent(), llvm::MemIntrinsicBase< Derived >::getDest(), llvm::MemIntrinsicBase< Derived >::getLength(), llvm::Value::getName(), llvm::MemTransferBase< BaseCL >::getSource(), llvm::Length, and llvm::reportFatalUsageError().

Referenced by replaceAccessesWithHandle().