LLVMModule SaveToFile for big module

Hi, everyone, I find that LLVMModule SaveToFile can’t generate large object file, when I step in, I find the original data in here

std::unique_ptr<llvm::Module> CodeGenBlob(const std::string& data, bool system_lib,
                                          LLVMTarget* llvm_target) {
  llvm::TargetMachine* tm = llvm_target->GetOrCreateTargetMachine();
  const llvm::Triple& triple = tm->getTargetTriple();
  llvm::LLVMContext* ctx = llvm_target->GetContext();

is over 10G,but after data is connected with a llvm module, and later the connected llvm module becomes a dev.o by calling LLVMModule SaveToFile, the dev.o is only 1.7G, at last the dev.o is used to generate a lib.so, so this lib.so is only about 1.7G, when I try to load this lib.so by tvm.runtime.load_module, it will always get Segmentation fault, because when it trys to load params from this lib.so, it will reach out of bounds.

Do we have any advice to deal with large data, thanks!

@apivovarov @masahi any ideas, thanks!

Can you share your model and repro script? This could be related to other issues I encountered when I was working on a large model (stable diffusion UNet).

Sorry for the late response, thanks for your advice, finally I find it is a llvm bug, the reason is below:

  /// Return the number of elements in the array or vector.
  unsigned getNumElements() const;

  /// Return the size (in bytes) of each element in the array/vector.
  /// The size of the elements is known to be a multiple of one byte.
  uint64_t getElementByteSize() const;

the original code in llvm, it casts original size which is over 10G to unsigned number, so the result is become 1.7G, I guess the two return type above should exchange, since the elements’ byte is small.

//===----------------------------------------------------------------------===//
/// ConstantDataSequential - A vector or array constant whose element type is a
/// simple 1/2/4/8-byte integer or half/bfloat/float/double, and whose elements
/// are just simple data values (i.e. ConstantInt/ConstantFP).  This Constant
/// node has no operands because it stores all of the elements of the constant
/// as densely packed data, instead of as Value*'s.
///
/// This is the common base class of ConstantDataArray and ConstantDataVector.
///
class ConstantDataSequential : public ConstantData {