LLVM: lib/Frontend/HLSL/CBuffer.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

14

15using namespace llvm;

17

22

24 assert((HandleTy->getName().ends_with(".CBuffer") ||

25 HandleTy->getName() == "spirv.VulkanBuffer") &&

26 "Not a cbuffer type");

27 assert(HandleTy->getNumTypeParameters() == 1 && "Expected layout type");

28 auto *LayoutTy = cast(HandleTy->getTypeParameter(0));

29

30 const StructLayout *SL = DL.getStructLayout(LayoutTy);

31 for (int I = 0, E = LayoutTy->getNumElements(); I < E; ++I)

32 if (!IsPadding(LayoutTy->getElementType(I)))

34

35 return Offsets;

36}

37

38std::optional

40 NamedMDNode *CBufMD = M.getNamedMetadata("hlsl.cbs");

41 if (!CBufMD)

42 return std::nullopt;

43

44 std::optional Result({CBufMD});

45

47 assert(MD->getNumOperands() && "Invalid cbuffer metadata");

48

49

50 Metadata *OpMD = MD->getOperand(0);

51 if (!OpMD)

52 continue;

53

54 auto *Handle =

56 CBufferMapping &Mapping = Result->Mappings.emplace_back(Handle);

57

60

61 for (int I = 1, E = MD->getNumOperands(); I < E; ++I) {

62 Metadata *OpMD = MD->getOperand(I);

63

64 if (!OpMD)

65 continue;

67 Mapping.Members.emplace_back(V, MemberOffsets[I - 1]);

68 }

69 }

70

71 return Result;

72}

73

75

76 MD->eraseFromParent();

77}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

static SmallVector< size_t > getMemberOffsets(const DataLayout &DL, GlobalVariable *Handle, llvm::function_ref< bool(Type *)> IsPadding)

Definition CBuffer.cpp:19

Module.h This file contains the declarations for the Module class.

A parsed version of the target data layout string in and methods for querying it.

Type * getValueType() const

A Module instance is used to store all the information related to an LLVM module.

iterator_range< op_iterator > operands()

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...

TypeSize getElementOffset(unsigned Idx) const

The instances of the Type class are immutable: once they are created, they are never changed.

An efficient, type-erasing, non-owning reference to a callable.

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

SmallVector< CBufferMember > Members