• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tudasc / TypeART / 25217128016

01 May 2026 02:00PM UTC coverage: 89.27% (-1.0%) from 90.246%
25217128016

Pull #188

github

web-flow
Merge c465c8fb5 into 278119205
Pull Request #188: GPU memory allocation support

214 of 298 new or added lines in 20 files covered. (71.81%)

1 existing line in 1 file now uncovered.

5075 of 5685 relevant lines covered (89.27%)

43483.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.78
/lib/passes/support/TypeUtil.cpp
1
// TypeART library
2
//
3
// Copyright (c) 2017-2026 TypeART Authors
4
// Distributed under the BSD 3-Clause license.
5
// (See accompanying file LICENSE.txt or copy at
6
// https://opensource.org/licenses/BSD-3-Clause)
7
//
8
// Project home: https://github.com/tudasc/TypeART
9
//
10
// SPDX-License-Identifier: BSD-3-Clause
11
//
12

13
#include "TypeUtil.h"
14

15
#include "support/Logger.h"
16

17
#include "llvm/IR/Constants.h"
18
#include "llvm/IR/DataLayout.h"
19
#include "llvm/IR/DerivedTypes.h"
20
#include "llvm/IR/Instructions.h"
21
#include "llvm/IR/Type.h"
22
#include "llvm/IR/Value.h"
23
#include "llvm/Support/Casting.h"
24
#include "llvm/Support/TypeSize.h"
25
#include "llvm/Support/raw_ostream.h"
26

27
#include <optional>
28

29
using namespace llvm;
30

31
namespace typeart::util::type {
32

33
#if LLVM_VERSION_MAJOR < 15
34
bool isi64Ptr(llvm::Type* type) {
155✔
35
  return type->isPointerTy() && type->getPointerElementType()->isIntegerTy(64);
155✔
36
}
37

38
bool isVoidPtr(llvm::Type* type) {
81✔
39
  return type->isPointerTy() && type->getPointerElementType()->isIntegerTy(8);
81✔
40
}
41
#endif
42

43
/**
44
 * Code was imported from jplehr/llvm-memprofiler project
45
 */
46
unsigned getTypeSizeInBytes(llvm::Type* t, const llvm::DataLayout& dl) {
845✔
47
  unsigned bytes = getScalarSizeInBytes(t);
845✔
48

49
  if (t->isArrayTy()) {
845✔
50
    bytes = getArraySizeInBytes(t, dl);
3✔
51
  } else if (t->isStructTy()) {
845✔
52
    bytes = getStructSizeInBytes(t, dl);
150✔
53
  } else if (t->isPointerTy()) {
842✔
54
    bytes = getPointerSizeInBytes(t, dl);
9✔
55
  } else if (t->isVectorTy()) {
692✔
56
    bytes = getVectorSizeInBytes(t, dl);
9✔
57
  }
9✔
58

59
  return bytes;
845✔
60
}
61

62
unsigned getScalarSizeInBytes(llvm::Type* t) {
845✔
63
  return t->getScalarSizeInBits() / 8;
845✔
64
}
65

66
unsigned getArraySizeInBytes(llvm::Type* arrT, const llvm::DataLayout& dl) {
3✔
67
  auto st = dyn_cast<ArrayType>(arrT);
3✔
68
  return getTypeSizeInBytes(getArrayElementType(st), dl) * getArrayLengthFlattened(st);
3✔
69
}
70

71
unsigned getVectorSizeInBytes(llvm::Type* vectorT, const llvm::DataLayout& dl) {
9✔
72
  // TODO: Most of these utility functions can be eliminated with the use of getTypeAllocSize() and getTypeStoreSize()
73
  //  auto vt = dyn_cast<VectorType>(vectorT);
74
  return dl.getTypeAllocSize(vectorT);
9✔
75
  // return getTypeSizeInBytes(vt->getVectorElementType(), dl) * vt->getVectorNumElements();
76
}
77

78
/**
79
 * \brief Resolves the element type of the given array recursively. Works for multidimensional arrays.
80
 */
81
llvm::Type* getArrayElementType(llvm::Type* arrT) {
1,730✔
82
  while (arrT->isArrayTy()) {
3,475✔
83
    arrT = arrT->getArrayElementType();
1,745✔
84
  }
85
  return arrT;
1,730✔
86
}
87

88
/**
89
 * \brief Determines the length of the flattened array.
90
 *  TODO: Handle VLAs
91
 */
92
unsigned getArrayLengthFlattened(llvm::Type* arrT) {
1,727✔
93
  unsigned len = 1;
1,727✔
94
  while (arrT->isArrayTy()) {
3,469✔
95
    len *= arrT->getArrayNumElements();
1,742✔
96
    arrT = arrT->getArrayElementType();
1,742✔
97
  }
98
  return len;
1,727✔
99
}
100

101
unsigned getStructSizeInBytes(llvm::Type* structT, const llvm::DataLayout& dl) {
150✔
102
  auto st                    = dyn_cast<llvm::StructType>(structT);
150✔
103
  const StructLayout* layout = dl.getStructLayout(st);
150✔
104
  return layout->getSizeInBytes();
150✔
105
}
106

107
unsigned getPointerSizeInBytes(llvm::Type* /*ptrT*/, const llvm::DataLayout& dl) {
9✔
108
  return dl.getPointerSizeInBits() / 8;
9✔
109
}
110

111
std::optional<llvm::Type*> getPointerElementType(llvm::Type* ptr_type) {
827✔
112
  auto* pointer_type = dyn_cast_or_null<llvm::PointerType>(ptr_type);
827✔
113
  if (pointer_type == nullptr) {
827✔
NEW
114
    return {};
×
115
  }
116

117
#if LLVM_VERSION_MAJOR < 15
118
  return pointer_type->getPointerElementType();
827✔
119
#else
120
  return {};
121
#endif
122
}
827✔
123

124
}  // namespace typeart::util::type
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc