No of Datastructures

Hi

I am trying to count the no of datastructures and the type, say for example the number of arrays in a given code. Which pass would give me this info? And what do I need to use in it?

Thanks for the help

Cheers
Nipun :slight_smile:

Hi Nipun,

Hi

I am trying to count the no of datastructures and the type, say for example the number of arrays in a given code. Which pass would give me this info? And what do I need to use in it?

What are you trying to achieve here with this information ?

You can iterate over types to collect the info you need. For example,

TypeSymbolTable &TST = MyModule.getTypeSymbolTable();
for(TypeSymbolTable::iterator TI = TST.begin(), TE =TST.end(); TI != TE; ++TI) {
const Type *Ty = TI->second;


}

http://llvm.org/docs/ProgrammersManual.html is very useful document for beginners.

Hey Devang,

Thanks for the assist, I’m trying to extract a signature which uniquely identifies a block of code… this is required for a project I am doing.
The no of data structures is one of the identifying features of this signature.

Thanks
Nipun

How do you define a data structure for this purpose? Do you mean individual data types like structs or arrays? Or higher-level "logical" structures like lists, trees, or hash tables? The former is obviously easier but even the latter is possible, in some cases.

--Vikram
Associate Professor, Computer Science
University of Illinois at Urbana-Champaign
http://llvm.org/~vadve

Right now I am writing passes just to look for arrays & structs
I am trying to identify the array by parsing the memory description(use regex’s)
ex./ { [20 x i8], i32 } *- for a struct. is a structure with a character array of size 20 and an integer.
I’m not sure if llvm provides an easier way to do this?
The type id for most arrays comes out to be a pointer rather than an array, its pretty much the same case for structs.

I haven’t yet been able to extend this to “logical” structures, and objects still looking into it. Any ideas?

Thanks
Nipun

For a conservative way to identify logical structures, see Chris Lattner's thesis and the references therein:

  "Macroscopic Data Structure Analysis and Optimization"
  http://llvm.org/pubs/2005-05-04-LattnerPHDThesis.html

The code is available in SVN, in the llvm-poolalloc project.

--Vikram
Associate Professor, Computer Science
University of Illinois at Urbana-Champaign
http://llvm.org/~vadve

Hi

I was having just one more problem. I would like to find these datastructures/ primitive types etc inside a block, however the valuesymbol table is available only at a functional level. What can I do so as to get the number + type of datastructs(eg. arrays etc) inside a single block?

Thanks
Nipun

Nipun Arora wrote:

Hi

I was having just one more problem. I would like to find these datastructures/ primitive types etc inside a block, however the valuesymbol table is available only at a functional level. What can I do so as to get the number + type of datastructs(eg. arrays etc) inside a single block?

If by block you mean a source level block (such as the brackets {} in C), then you can examine the bitcode file for use of the LLVM Debugging Intrinsics. I believe llvm.dgb.region.start marks the beginning of a source level block.

Basically, the debugging intrinsics mark the beginning and end of blocks and can map information back to the original source file. To get llvm-gcc to emit them, just use llvm-gcc -emit-llvm -g.

Information on the LLVM debugging intrinsics can be found here: http://llvm.org/docs/SourceLevelDebugging.html

-- John T.