2 * Change the casting code to be const correct. Now, doing this is invalid:
4 Instruction *I = dyn_cast<Instruction>(V);
5 instead, the second line should be:
6 const Instruction *I = dyn_cast<Instruction>(V);
8 * Change the casting code to allow casting a reference value thus:
10 Instruction &I = cast<Instruction>(V);
12 dyn_cast does not work with references, because it must return a null pointer
15 * Fundamentally change how instructions and other values are represented.
16 Before, every llvm container was an instance of the ValueHolder template,
17 instantiated for each container type. This ValueHolder was effectively a
18 wrapper around a vector of pointers to the sub-objects.
20 Now, instead of having a vector to pointers of objects, the objects are
21 maintained in a doubly linked list of values (ie each Instruction now has
22 Next & Previous fields). The containers are now instances of ilist (intrusive
23 linked list class), which use the next and previous fields to chain them
24 together. The advantage of this implementation is that iterators can be
25 formed directly from pointers to the LLVM value, and invalidation is much
28 * As part of the above change, dereferencing an iterator (for example:
29 BasicBlock::iterator) now produces a reference to the underlying type (same
30 example: Instruction&) instead of a pointer to the underlying object. This
31 makes it much easier to write nested loops that iterator over things, changing
34 for (Function::iterator BI = Func->begin(); BI != Func->end(); ++BI)
35 for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II)
40 for (Function::iterator BI = Func->begin(); BI != Func->end(); ++BI)
41 for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II)
44 which is much more natural and what users expect.
46 * Simplification of #include's: Before, it was necessary for a .cpp file to
47 include every .h file that it used. Now things are batched a little bit more
48 to make it easier to use. Specifically, the include graph now includes these
50 Module.h -> Function.h, GlobalVariable.h
51 Function.h -> BasicBlock.h, Argument.h
52 BasicBlock.h -> Instruction.h
54 Which means that #including Function.h is usually sufficient for getting the
55 lower level #includes.
57 * Printing out a Value* has now changed: Printing a Value* will soon print out
58 the address of the value instead of the contents of the Value. To print out
59 the contents, you must convert it to a reference with (for example)
60 'cout << *I' instead of 'cout << I;'. This conversion is not yet complete,
61 but will be eventually. In the mean time, both forms print out the contents.
63 * References are used much more throughout the code base. In general, if a
64 pointer is known to never be null, it is passed in as a reference instead of a
65 pointer. For example, the instruction visitor class uses references instead
66 of pointers, and that Pass subclasses now all receive references to Values
67 instead of pointers, because they may never be null.
69 * The Function class now has helper functions for accessing the Arguments list.
70 Instead of having to go through getArgumentList for simple things like
71 iterator over the arguments, now the a*() methods can be used to access them.