LLVM: lib/Target/DirectX/CBufferDataLayout.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

14

17

18namespace llvm {

19namespace dxil {

20

21

22

24 struct LegacyStructLayout {

28 std::pair<uint32_t, uint32_t> getElementLegacyOffset(unsigned Idx) const {

29 assert(Idx < Offsets.size() && "Invalid element idx!");

32 return std::make_pair((Offset - Ch) / RowAlign, Ch);

33 }

34 };

35

36public:

39

40private:

43 LegacyStructLayout &getStructLayout(StructType *ST);

46

47 static const uint32_t RowAlign = 16;

50 }

51};

52

54 return getTypeAllocSize(Ty);

55}

56

59

60 if (AlignedOffset == Offset)

62

64 return AlignedOffset;

67 return AlignedOffset;

68 else

70}

71

72TypeSize LegacyCBufferLayout::getTypeAllocSize(Type *Ty) {

74 LegacyStructLayout &Layout = getStructLayout(ST);

75 return Layout.Size;

77 unsigned NumElts = AT->getNumElements();

78 if (NumElts == 0)

80

81 TypeSize EltSize = getTypeAllocSize(AT->getElementType());

82 TypeSize AlignedEltSize = alignTo4Dwords(EltSize);

83

85 } else {

86

87

88 return DL.getTypeStoreSize(Ty);

89 }

90}

91

92LegacyCBufferLayout::LegacyStructLayout &

93LegacyCBufferLayout::getStructLayout(StructType *ST) {

94 auto it = StructLayouts.find(ST);

95 if (it != StructLayouts.end())

96 return it->second;

97

99 LegacyStructLayout Layout;

100 Layout.ST = ST;

101 for (Type *EltTy : ST->elements()) {

102 TypeSize EltSize = getTypeAllocSize(EltTy);

106 Layout.Offsets.emplace_back(Offset);

108 }

109 Layout.Size = Offset;

110 StructLayouts[ST] = Layout;

111 return StructLayouts[ST];

112}

113

115 : DL(DL), IsLegacyLayout(IsLegacy),

117}

118

120

122 if (IsLegacyLayout)

123 return LegacyDL->getTypeAllocSizeInBytes(Ty);

124 else

125 return DL.getTypeAllocSize(Ty);

126}

127

128}

129}

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

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

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

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

Class to represent struct types.

static constexpr TypeSize getFixed(ScalarTy ExactSize)

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

Type * getScalarType() const

If this is a vector type, return the element type, otherwise return 'this'.

LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY

Return the basic size of this type if it is a primitive type.

CBufferDataLayout(const DataLayout &DL, const bool IsLegacy)

Definition CBufferDataLayout.cpp:114

llvm::TypeSize getTypeAllocSizeInBytes(Type *Ty)

Definition CBufferDataLayout.cpp:121

LegacyCBufferLayout(const DataLayout &DL)

Definition CBufferDataLayout.cpp:37

TypeSize getTypeAllocSizeInBytes(Type *Ty)

Definition CBufferDataLayout.cpp:53

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

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

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

Implement std::hash so that hash_code can be used in STL containers.