llvm.org GIT mirror llvm / 82ac87c
New file git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2618 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
1 changed file(s) with 55 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 Date: Sun, 12 May 2002 17:12:53 -0500 (CDT)
1 From: Chris Lattner
2 To: "Vikram S. Adve"
3 Subject: LLVM change
4
5 There is a fairly fundemental change that I would like to make to the LLVM
6 infrastructure, but I'd like to know if you see any drawbacks that I
7 don't...
8
9 Basically right now at the basic block level, each basic block contains an
10 instruction list (returned by getInstList()) that is a ValueHolder of
11 instructions. To iterate over instructions, we must actually iterate over
12 the instlist, and access the instructions through the instlist.
13
14 To add or remove an instruction from a basic block, we need to get an
15 iterator to an instruction, which, given just an Instruction*, requires a
16 linear search of the basic block the instruction is contained in... just
17 to insert an instruction before another instruction, or to delete an
18 instruction! This complicates algorithms that should be very simple (like
19 simple constant propogation), because they aren't actually sparse anymore,
20 they have to traverse basic blocks to remove constant propogated
21 instructions.
22
23 Additionally, adding or removing instructions to a basic block
24 _invalidates all iterators_ pointing into that block, which is really
25 irritating.
26
27 To fix these problems (and others), I would like to make the ordering of
28 the instructions be represented with a doubly linked list in the
29 instructions themselves, instead of an external data structure. This is
30 how many other representations do it, and frankly I can't remember why I
31 originally implemented it the way I did.
32
33 Long term, all of the code that depends on the nasty features in the
34 instruction list (which can be found by grep'ing for getInstList()) will
35 be changed to do nice local transformations. In the short term, I'll
36 change the representation, but preserve the interface (including
37 getInstList()) so that all of the code doesn't have to change.
38
39 Iteration over the instructions in a basic block remains the simple:
40 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) ...
41
42 But we will also support:
43 for (Instruction *I = BB->front(); I; I = I->getNext()) ...
44
45 After converting instructions over, I'll convert basic blocks and
46 functions to have a similar interface.
47
48 The only negative aspect of this change that I see is that it increases
49 the amount of memory consumed by one pointer per instruction. Given the
50 benefits, I think this is a very reasonable tradeoff.
51
52 What do you think?
53
54 -Chris