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