Chris Lattner | d00e1a1 | 2002-06-25 16:09:22 +0000 | [diff] [blame] | 1 | Changes: |
| 2 | * Change the casting code to be const correct. Now, doing this is invalid: |
| 3 | const Value *V = ...; |
| 4 | Instruction *I = dyn_cast<Instruction>(V); |
| 5 | instead, the second line should be: |
| 6 | const Instruction *I = dyn_cast<Instruction>(V); |
| 7 | |
| 8 | * Change the casting code to allow casting a reference value thus: |
| 9 | const Value &V = ...; |
| 10 | Instruction &I = cast<Instruction>(V); |
| 11 | |
| 12 | dyn_cast does not work with references, because it must return a null pointer |
| 13 | on failure. |
| 14 | |
| 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. |
| 19 | |
| 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 |
| 26 | easier to handle. |
| 27 | |
| 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 |
| 32 | this: |
| 33 | |
| 34 | for (Function::iterator BI = Func->begin(); BI != Func->end(); ++BI) |
| 35 | for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) |
| 36 | (*II)->dump(); |
| 37 | |
| 38 | into: |
| 39 | |
| 40 | for (Function::iterator BI = Func->begin(); BI != Func->end(); ++BI) |
| 41 | for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) |
| 42 | II->dump(); |
| 43 | |
| 44 | which is much more natural and what users expect. |
| 45 | |
Misha Brukman | ead0e2f | 2003-08-18 14:43:39 +0000 | [diff] [blame] | 46 | * Simplification of #include's: Before, it was necessary for a .cpp file to |
Chris Lattner | d00e1a1 | 2002-06-25 16:09:22 +0000 | [diff] [blame] | 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 |
| 49 | edges: |
| 50 | Module.h -> Function.h, GlobalVariable.h |
| 51 | Function.h -> BasicBlock.h, Argument.h |
| 52 | BasicBlock.h -> Instruction.h |
| 53 | |
| 54 | Which means that #including Function.h is usually sufficient for getting the |
| 55 | lower level #includes. |
| 56 | |
| 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. |
| 62 | |
| 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. |
| 68 | |
| 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. |
| 72 | |