brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · 2ca4611 Raw
73 lines · plain
1Changes: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 pointer13  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 a18  wrapper around a vector of pointers to the sub-objects.19 20  Now, instead of having a vector to pointers of objects, the objects are21  maintained in a doubly linked list of values (ie each Instruction now has22  Next & Previous fields).  The containers are now instances of ilist (intrusive23  linked list class), which use the next and previous fields to chain them24  together.  The advantage of this implementation is that iterators can be25  formed directly from pointers to the LLVM value, and invalidation is much26  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 (same30  example: Instruction&) instead of a pointer to the underlying object.  This31  makes it much easier to write nested loops that iterator over things, changing32  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 46* Simplification of #include's: Before, it was necessary for a .cpp file to47  include every .h file that it used.  Now things are batched a little bit more48  to make it easier to use.  Specifically, the include graph now includes these49  edges:50    Module.h -> Function.h, GlobalVariable.h51    Function.h -> BasicBlock.h, Argument.h52    BasicBlock.h -> Instruction.h53 54  Which means that #including Function.h is usually sufficient for getting the55  lower level #includes.56 57* Printing out a Value* has now changed: Printing a Value* will soon print out58  the address of the value instead of the contents of the Value.  To print out59  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 a64  pointer is known to never be null, it is passed in as a reference instead of a65  pointer.  For example, the instruction visitor class uses references instead66  of pointers, and that Pass subclasses now all receive references to Values67  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 like71  iterator over the arguments, now the a*() methods can be used to access them.72 73