xref: /aosp_15_r20/external/llvm/docs/HistoricalNotes/2001-02-09-AdveComments.txt (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard WorkerOk, here are my comments and suggestions about the LLVM instruction set.
2*9880d681SAndroid Build Coastguard WorkerWe should discuss some now, but can discuss many of them later, when we
3*9880d681SAndroid Build Coastguard Workerrevisit synchronization, type inference, and other issues.
4*9880d681SAndroid Build Coastguard Worker(We have discussed some of the comments already.)
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Workero  We should consider eliminating the type annotation in cases where it is
8*9880d681SAndroid Build Coastguard Worker   essentially obvious from the instruction type, e.g., in br, it is obvious
9*9880d681SAndroid Build Coastguard Worker   that the first arg. should be a bool and the other args should be labels:
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker	br bool <cond>, label <iftrue>, label <iffalse>
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker   I think your point was that making all types explicit improves clarity
14*9880d681SAndroid Build Coastguard Worker   and readability.  I agree to some extent, but it also comes at the cost
15*9880d681SAndroid Build Coastguard Worker   of verbosity.  And when the types are obvious from people's experience
16*9880d681SAndroid Build Coastguard Worker   (e.g., in the br instruction), it doesn't seem to help as much.
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Workero  On reflection, I really like your idea of having the two different switch
20*9880d681SAndroid Build Coastguard Worker   types (even though they encode implementation techniques rather than
21*9880d681SAndroid Build Coastguard Worker   semantics).  It should simplify building the CFG and my guess is it could
22*9880d681SAndroid Build Coastguard Worker   enable some significant optimizations, though we should think about which.
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Workero  In the lookup-indirect form of the switch, is there a reason not to make
26*9880d681SAndroid Build Coastguard Worker   the val-type uint?  Most HLL switch statements (including Java and C++)
27*9880d681SAndroid Build Coastguard Worker   require that anyway.  And it would also make the val-type uniform
28*9880d681SAndroid Build Coastguard Worker   in the two forms of the switch.
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker   I did see the switch-on-bool examples and, while cute, we can just use
31*9880d681SAndroid Build Coastguard Worker   the branch instructions in that particular case.
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Workero  I agree with your comment that we don't need 'neg'.
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Workero  There's a trade-off with the cast instruction:
38*9880d681SAndroid Build Coastguard Worker   +  it avoids having to define all the upcasts and downcasts that are
39*9880d681SAndroid Build Coastguard Worker      valid for the operands of each instruction  (you probably have thought
40*9880d681SAndroid Build Coastguard Worker      of other benefits also)
41*9880d681SAndroid Build Coastguard Worker   -  it could make the bytecode significantly larger because there could
42*9880d681SAndroid Build Coastguard Worker      be a lot of cast operations
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker
45*9880d681SAndroid Build Coastguard Workero  Making the second arg. to 'shl' a ubyte seems good enough to me.
46*9880d681SAndroid Build Coastguard Worker   255 positions seems adequate for several generations of machines
47*9880d681SAndroid Build Coastguard Worker   and is more compact than uint.
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard Workero  I still have some major concerns about including malloc and free in the
51*9880d681SAndroid Build Coastguard Worker   language (either as builtin functions or instructions).  LLVM must be
52*9880d681SAndroid Build Coastguard Worker   able to represent code from many different languages.  Languages such as
53*9880d681SAndroid Build Coastguard Worker   C, C++ Java and Fortran 90 would not be able to use our malloc anyway
54*9880d681SAndroid Build Coastguard Worker   because each of them will want to provide a library implementation of it.
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Worker   This gets even worse when code from different languages is linked
57*9880d681SAndroid Build Coastguard Worker   into a single executable (which is fairly common in large apps).
58*9880d681SAndroid Build Coastguard Worker   Having a single malloc would just not suffice, and instead would simply
59*9880d681SAndroid Build Coastguard Worker   complicate the picture further because it adds an extra variant in
60*9880d681SAndroid Build Coastguard Worker   addition to the one each language provides.
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker   Instead, providing a default library version of malloc and free
63*9880d681SAndroid Build Coastguard Worker   (and perhaps a malloc_gc with garbage collection instead of free)
64*9880d681SAndroid Build Coastguard Worker   would make a good implementation available to anyone who wants it.
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker   I don't recall all your arguments in favor so let's discuss this again,
67*9880d681SAndroid Build Coastguard Worker   and soon.
68*9880d681SAndroid Build Coastguard Worker
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Workero  'alloca' on the other hand sounds like a good idea, and the
71*9880d681SAndroid Build Coastguard Worker   implementation seems fairly language-independent so it doesn't have the
72*9880d681SAndroid Build Coastguard Worker   problems with malloc listed above.
73*9880d681SAndroid Build Coastguard Worker
74*9880d681SAndroid Build Coastguard Worker
75*9880d681SAndroid Build Coastguard Workero  About indirect call:
76*9880d681SAndroid Build Coastguard Worker   Your option #2 sounded good to me.  I'm not sure I understand your
77*9880d681SAndroid Build Coastguard Worker   concern about an explicit 'icall' instruction?
78*9880d681SAndroid Build Coastguard Worker
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Workero  A pair of important synchronization instr'ns to think about:
81*9880d681SAndroid Build Coastguard Worker     load-linked
82*9880d681SAndroid Build Coastguard Worker     store-conditional
83*9880d681SAndroid Build Coastguard Worker
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Workero  Other classes of instructions that are valuable for pipeline performance:
86*9880d681SAndroid Build Coastguard Worker     conditional-move
87*9880d681SAndroid Build Coastguard Worker     predicated instructions
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Worker
90*9880d681SAndroid Build Coastguard Workero  I believe tail calls are relatively easy to identify; do you know why
91*9880d681SAndroid Build Coastguard Worker   .NET has a tailcall instruction?
92*9880d681SAndroid Build Coastguard Worker
93*9880d681SAndroid Build Coastguard Worker
94*9880d681SAndroid Build Coastguard Workero  I agree that we need a static data space.  Otherwise, emulating global
95*9880d681SAndroid Build Coastguard Worker   data gets unnecessarily complex.
96*9880d681SAndroid Build Coastguard Worker
97*9880d681SAndroid Build Coastguard Worker
98*9880d681SAndroid Build Coastguard Workero  About explicit parallelism:
99*9880d681SAndroid Build Coastguard Worker
100*9880d681SAndroid Build Coastguard Worker   We once talked about adding a symbolic thread-id field to each
101*9880d681SAndroid Build Coastguard Worker   instruction.  (It could be optional so single-threaded codes are
102*9880d681SAndroid Build Coastguard Worker   not penalized.)  This could map well to multi-threaded architectures
103*9880d681SAndroid Build Coastguard Worker   while providing easy ILP for single-threaded onces.  But it is probably
104*9880d681SAndroid Build Coastguard Worker   too radical an idea to include in a base version of LLVM.  Instead, it
105*9880d681SAndroid Build Coastguard Worker   could a great topic for a separate study.
106*9880d681SAndroid Build Coastguard Worker
107*9880d681SAndroid Build Coastguard Worker   What is the semantics of the IA64 stop bit?
108*9880d681SAndroid Build Coastguard Worker
109*9880d681SAndroid Build Coastguard Worker
110*9880d681SAndroid Build Coastguard Worker
111*9880d681SAndroid Build Coastguard Worker
112*9880d681SAndroid Build Coastguard Workero  And finally, another thought about the syntax for arrays :-)
113*9880d681SAndroid Build Coastguard Worker
114*9880d681SAndroid Build Coastguard Worker   Although this syntax:
115*9880d681SAndroid Build Coastguard Worker	  array <dimension-list> of <type>
116*9880d681SAndroid Build Coastguard Worker   is verbose, it will be used only in the human-readable assembly code so
117*9880d681SAndroid Build Coastguard Worker   size should not matter.  I think we should consider it because I find it
118*9880d681SAndroid Build Coastguard Worker   to be the clearest syntax.  It could even make arrays of function
119*9880d681SAndroid Build Coastguard Worker   pointers somewhat readable.
120*9880d681SAndroid Build Coastguard Worker
121