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