Getting TargetData and TargetLibraryInfo for determining Malloc size

Hello;

I was trying to use the computeArraySize() function from the
MemoryBuiltins.cpp file. It requires two arguments DataLayout *TD and
const TargetLibraryInfo *TLI. Can anyone tell me how to get the
TargetLibraryInfo? I am getting the DataLayout using:

DataLayout *TD;
TD = new DataLayout(&M);

I hope that's the right way of getting it.

Thanks a lot;

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
On Behalf Of Arnamoy Bhattacharyya
Subject: [LLVMdev] Getting TargetData and TargetLibraryInfo for determining Malloc size

I was trying to use the computeArraySize() function from the
MemoryBuiltins.cpp file. It requires two arguments DataLayout *TD and
const TargetLibraryInfo *TLI. Can anyone tell me how to get the
TargetLibraryInfo?

For examples, take a look at the related code in the LLVM tools:

tools/clang/lib/CodeGen/BackendUtil.cpp
tools/opt/opt.cpp
tools/llc/llc.cpp

  // Add an appropriate TargetLibraryInfo pass for the module's triple.
  TargetLibraryInfo *TLI = new TargetLibraryInfo(TheTriple);
  if (DisableSimplifyLibCalls)
    TLI->disableAllFunctions();
  PM.add(TLI);

- Chuck