aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/example.c
AgeCommit message (Collapse)AuthorFilesLines
2020-11-21add a new instruction for label-as-valueLuc Van Oostenryck1-3/+5
Convert OP_SETVAL of a label into a new instruction: OP_LABEL. There is 2 reasons to do this: *) there is slightly less checking to be done in later phases (since OP_SETVAL can be for labels but also strings) *) OP_SETVAL is CSEd but this is largely useless because this instruction is hashed on the expression's address and these are (most) often not shared. With a separate instruction for label expressions, their CSE is now OK because the hashing is done on the BB. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-06-28bool: remove OP_{AND,OR}_BOOL instructionsLuc Van Oostenryck1-3/+0
Now that these instructions are not generated anymore, we can remove all related code, defines and doc. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-06-23cast: specialize integer castsLuc Van Oostenryck1-3/+6
Casts to integer used to be done with only 2 instructions: OP_CAST & OP_SCAST. Those are not very convenient as they don't reflect the real operations that need to be done. This patch specialize these instructions in: - OP_TRUNC, for casts to a smaller type - OP_ZEXT, for casts that need a zero extension - OP_SEXT, for casts that need a sign extension - Integer-to-integer casts of the same size are considered as a NOPs and are, in fact, never emitted. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-06-23cast: specialize cast from pointersLuc Van Oostenryck1-0/+2
Currently all casts to pointers are processed alike. This is simple but rather unconvenient in later phases as this correspond to different operations that obeys to different rules and which later need extra checks. Change this by using a specific instructions (OP_UTPTR) for [unsigned] integer to pointers. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-06-23cast: specialize casts from unsigned to pointersLuc Van Oostenryck1-0/+2
Currently all casts to pointers are processed alike. This is simple but rather unconvenient as it correspond to different operations that obeys to different rules and which later need extra checks. Change this by using a specific instructions (OP_UTPTR) for unsigned integer to pointers. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-06-23cast: specialize floats to integer conversionLuc Van Oostenryck1-0/+3
Currently, casts from floats to integers are processed like integers (or any other type) to integers. This is simple but rather unconvenient as it correspond to different operations that obeys to different rules and which later need extra checks. Change this by directly using specific instructions: - FCVTU for floats to unsigned integers - FCVTS for floats to signed integers Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-06-23cast: specialize FPCAST into [USF]CVTFLuc Van Oostenryck1-2/+6
Currently, all casts to a floating point type use OP_FPCAST. This is maybe simple but rather uncovenient as it correspond to several quite different operations that later need extra checks. Change this by directly using different instructions for the different cases: - FCVTF for float-float conversions - UCVTF for unsigned integer to floats - SCVTF for signed integer to floats and reject attempts to cast a pointer to a float. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-06-21ptrlist: remove the now unneeded FOR_EACH_PTR_NOTAG()Luc Van Oostenryck1-2/+2
Now that FOR_EACH_PTR() doesn't strip the tag anymore, there is no more needs for FOR_EACH_PTR_NOTAG() as both do the same. So convert the few uses to FOR_EACH_PTR() and remove its definition. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-06-13ptrlist: make explicit when tagged pointers are used.Luc Van Oostenryck1-8/+8
Only a few places need list recursions on tagged pointers but currently they use the same macros as the common case where no tag is used. Make this very explicit by adding using the macro FOR_EACH_PTR_TAG() for these few cases. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-03-01IR: remove never-generated instructionsLuc Van Oostenryck1-8/+0
Some of the IR instructions have been defined but are never generated. Remove them as they have no purposes. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-03-01IR: remove now unused OP_LNOP & OP_SNOPLuc Van Oostenryck1-2/+0
No instructions have an opcode set to OP_[LS]NOP anymore so we can now remove all remaining traces of these opcode. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-02-20no need for signed & unsigned multiplicationLuc Van Oostenryck1-3/+2
Currently, we have OP_MULS & OP_MULU but unless it's full, widening multiplication both must give exactly the same result (the world run on 2's complement CPUs now, right?). Also, the IR doesn't have widening multiplication but only instruction where both operands and the result have the same size. So, since theer is no reasons to keep 2 instructions, merge OP_MULS & OP_MULU into a single one: OP_MUL. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2017-03-06split OP_BR between unconditional & conditional: OP_CBRLuc Van Oostenryck1-0/+2
OP_BR instructions exist in two flavours, relatively much differentiated: conditional & non-conditional. One has an operand (and thus its usage need to be cared for, must be handled in liveness analysis, ..) the other has not; one has two BB target, the other only one. There is essentially no places in the code where both flavours are handled the same. Sometimes they both must be handled but each with their specificities but in most cases only one of them is concerned and we need to filter out the other one. In both cases it means that we need to check what kind we're dealing with. There is already a problem with this because there is several ways to test which kind an OP_BR is and they are not exactly equivalent: 1) testing if insn->cond is NULL 2) testing if one of insn->bb_true or ->bb_false is NULL. There exist also an helper (is_branch_goto()) which does the second tests but which is never used. It appears that the first test should not be used because in some cases an conditional OP_BR is changed into a non-conditional one by (amongst others things) setting it's ->cond to VOID. We should thus always use the seconds test (which need two compares with NULL). This could be corrected in several ways (like changing all the places wheer the first test is used, use the helper everywhere or never set ->cond to VOID) but the simplest is to simply split them in two separated instructions: OP_BR & OP_CBR, especailly given the fact that in most cases the OP_BR was first selected by a switch (opcode). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2008-12-17Unhardcode byte size being 8 bits.David Given1-1/+1
Signed-off-by: David Given <dg@cowlark.com> [negative value division fixed by alexey.zaytsev@gmal.com] Signed-off-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
2007-05-01Fix most -Wshadow warnings in Sparse.0.3Josh Triplett1-1/+1
Signed-off-by: Josh Triplett <josh@freedesktop.org>
2007-03-09Use GCC format and sentinel attributes on appropriate functionsJosh Triplett1-4/+4
Expose the FORMAT_ATTR portability macro in lib.h, and use it on the various printf-like functions in sparse. Add a new SENTINEL_ATTR portability macro for the GCC sentinel attribute, and use it on match_idents in parse.c. match_oplist in expression.c should use SENTINEL_ATTR, but GCC does not accept an integer 0 as a sentinel, only a pointer 0 like NULL. Signed-off-by: Josh Triplett <josh@freedesktop.org>
2007-03-09Fix typos in commentsJosh Triplett1-3/+3
Signed-off-by: Josh Triplett <josh@freedesktop.org>
2007-02-28Disable liveness "dead" instruction by default.Christopher Li1-0/+1
The liveness instruction takes up about 10% of the bytecode bloat file. It is not very useful, it is duplicate information that can be obtained from the def/user chain. This change disables the liveness instruction by default. The caller can track_pseudo_death() if needed. Signed-Off-By: Christopher Li <sparse@chrisli.org>
2007-01-27Coding style fix: in a pointer type, * goes with the name, not the type.Josh Triplett1-1/+1
Signed-off-by: Josh Triplett <josh@freedesktop.org>
2006-12-04cleanup write to argument array hackChristopher Li1-3/+7
The sparse interface is a kind of snaky that it change the input argument array. The function sparse() does the same hack just to skip the files. This patch add the ptr list for string. So sparse_initialize will return list of file to compile. The string pointer is not aligned at word boundary. This patch introduce non taged version of the ptr list iteration function. Signed-off-by: Christopher Li <sparse@chrisli.org>
2006-11-06Typo fixesPavel Roskin1-2/+2
Signed-off-by: Pavel Roskin <proski@gnu.org> Signed-off-by: Josh Triplett <josh@freedesktop.org>
2005-11-25[PATCH] avoid a crash caused by the phisrc OP_COPY with a NULL ->def.Luc Van Oostenryck1-1/+1
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@looxix.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-22example: OP_COPY must destroy any old pseudo stateLinus Torvalds1-0/+24
Toto, I have a feeling We're not in SSA land any more. (Not that it really helps. The example compiler not only had SSA assumptions, it also depended on liveness information and insn->def state, both of which are destroyed by the un-ssa phase. So this is really a small bandage around a much larger problem, and doesn't really fix anything fundamental). Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-22Make the "example" compiler use the new unssa() phaseLinus Torvalds1-54/+14
Yeah, this probably breaks the example in a totally _different_ way than it was broken before ;) But it's certainly no worse than before. At least not much. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-02Handle symbols from "-include" file tooLinus Torvalds1-1/+1
Noted by Mitesh Shah Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-03Update the calling interface to "sparse()".Linus Torvalds1-2/+5
Start off with sparse_initialize(argc, argv); which will return the number of filenames found. You can then use that, or just check if *argv is NULL in a loop like while (*argv) list = sparse(argv); where you get the declaration list for each file in turn.
2005-04-07Add compile-time "range-check" infrastructure to sparseLinus Torvalds1-1/+3
2005-04-07Duh. When a function returns VOID, we should _not_ add thatLinus Torvalds1-1/+2
to the return register state.
2005-04-07Fix code generation confusion between OP_ADDR and theLinus Torvalds1-12/+45
value that is contained within.
2005-04-07Make the example code generator do something half-way saneLinus Torvalds1-14/+32
about addresses of local variables.
2005-04-07Split the binops where signedness matters into unsigned and signed.Linus Torvalds1-7/+12
This is OP_MUL/OP_DIV/OP_MOD/OP_SHR. We actually do the constant simplifications still wrong, but now the information is all there.
2005-04-07Make output_insn() tell where it was called from, and avoidLinus Torvalds1-0/+7
doing unnecessary register->sameregister moves.
2005-04-07Make "fill_reg" do somewhat the right thing when we take theLinus Torvalds1-1/+28
address of a symbol. Not quite there..
2005-04-07Oops. Missed a place where we still tested for "busy" thinking thatLinus Torvalds1-1/+1
it meant "contains a pseudo".
2005-04-07Make the argument storage setup be a bit more accurate.Linus Torvalds1-10/+33
Take argument type into account (somewhat), and do a first (broken, but it's a good example) cut at having different calling conventions for different kinds of functions.
2005-04-07Make "reg->busy" mean how many "operands" actually reference thisLinus Torvalds1-26/+53
register right now. Change users that just wanted to test for "empty" to check that "reg->contains" is NULL instead.
2005-04-07Start moving to a more symbol "struct operand" notion, rather thanLinus Torvalds1-15/+144
using static strings. If we ever want to generate more abstract output (and we do), we can't just have strings.
2005-04-07Split OP_SETVAL into OP_SETVAL (fp expressions and labels) and OP_SYMADDRLinus Torvalds1-2/+2
(symbol addresses). They are pretty different. Symbol addresses have special meaning during various phases, from symbol simplification to CSE.
2005-04-07Make sure to mark all registers that have already been allocatedLinus Torvalds1-0/+28
by a parent as outputs as unavailable as an input register. The parent won't be able to write two different pseudos to the same register..
2005-04-07The stack offset is global, not per-bb.Linus Torvalds1-6/+5
We could make the internal per-bb allocations be local, though. That would require some more care.
2005-04-07Duh. We marked the wrong register REG_FIXED when we wrote outLinus Torvalds1-1/+1
the outgoing pseudos. This caused us to then possibly double-allocate that register later for another pseudo..
2005-04-07Add some back-of-the-envelope support for asm inputs tiedLinus Torvalds1-5/+31
to the outputs.
2005-04-07Do absolutely horrid job of generating code for asms.Linus Torvalds1-7/+137
I totally botch the constraints handling, but hey, it's just an example.
2005-04-07Use the one-deep CC-cache for OP_SEL too.Linus Torvalds1-21/+30
2005-04-07If we decide to mark a register as being its own storage,Linus Torvalds1-2/+3
return NULL from find_pseudo_storage(). That way the caller won't bother to move the register to itself - it sees that it has no separate storage.
2005-04-07Add a one-deep CC-cache for condition code setting and usage.Linus Torvalds1-123/+218
We could make it deeper if we wanted to combine conditionals, but one-deep is good enough to catch the common "setXX + brcc" thing, and thus makes the conditional branches MUCH more readable. This also moves things around a bit to help organization.
2005-04-07Show asm inputs/outputs as bugus instructions as opposed to comments.Linus Torvalds1-2/+2
They otherwise get drowned out by the _real_ comments.
2005-04-07Start looking at asms in code generation.Linus Torvalds1-1/+40
Just the infrastructure.
2005-04-07Do some kind of signed cast too.Linus Torvalds1-5/+8
2005-04-07Do slightly better on casts.Linus Torvalds1-6/+13
In particular, casts to a smaller type doesn't need to do anything.
2005-04-07Teach code generator about commutative operations.Linus Torvalds1-6/+63
It can select the order based on whether one of the sources is dead, or on the target register choice.
2005-04-07Mark the backing store storage dead when marking a pseudo dead.Linus Torvalds1-19/+25
This allows us to mark a register dead when we load it from dead backing store. NOTE! This all sounds nonsensical, but we mark things "dead" _before_ the last use, not after. So dead means not that it's gone, it means that this use is the last one.
2005-04-07Make "find_pseudo_storage()" return the storage hash entryLinus Torvalds1-6/+10
rather than the storage itself. I'll want to mark the hash entry dead when marking the pseudo dead, and this allows me to use the common helper routine.
2005-04-07Split up the code that finds the underlying storage for aLinus Torvalds1-44/+71
pseudo into a routine of its own. Cleaner and more readable. This also allows us to be a lot better at the "generic" inputs (aka gcc "g" specifier), since it can now just look up the storage instead of having to load it into a register.
2005-04-07Add support for various arch-specific storage allocationLinus Torvalds1-2/+116
issues: - argument passign setup - return value storage - silly switch register hack.
2005-04-07Kill off dead pseudos before doing target allocation for casts and loads.Linus Torvalds1-12/+16
That allows us to re-use the sources if they have died.
2005-04-07Keep dead pseudos in the register "busy" count, add "dead" count.Linus Torvalds1-5/+57
This makes it much easier to look at the real state of a register: - busy == 0 means no users - busy == dead means all users are dead - dead != 0 means that we should clean it
2005-04-07Add comment on where incoming pseudos come from.Linus Torvalds1-0/+1
2005-04-07Generate pseudo-code for OP_SEL.Linus Torvalds1-0/+18
You know the drill by now. It's not so much correct, as it is "kind of looks right".
2005-04-07Make target register allocation prefer empty registers.Linus Torvalds1-0/+4
Yeah, yeah, it's still pretty stupid.
2005-04-07Generate cheesy "cast" instructions.Linus Torvalds1-0/+23
No sign extension, no nuffink. My opcode generation gets worse and worse.
2005-04-07Add fake OP_CALL code generation.Linus Torvalds1-0/+39
Just real enough to make it look good.
2005-04-07Be a bit more forgiving about impossible output register situations.Linus Torvalds1-1/+4
We get those when encountering unimplemented instructions, since then we'll have bad register contents. Let's just silently ignore it for now.
2005-04-07Output unimplemented instructions as such, ratherLinus Torvalds1-1/+1
than as comments. This makes them visible even without having to make the output verbose (and verbose is _really_ verbose these days).
2005-04-07Clean up final register flushing, and allow flushing to a temporaryLinus Torvalds1-14/+80
new register if one is available. Use a few symbolic macros to make some of the logic more readable, and split up the "try to flush" logic into a function of its own.
2005-04-07Add comment about input storage selection.Linus Torvalds1-0/+7
2005-04-07When fulfilling the output register requirements, don'tLinus Torvalds1-4/+22
be so eager to flush to memory. If we can find the proper target register for the existing pseudo, just turn it into a simple reg-reg move instead. Also, don't worry about dead pseudos - they don't need flushing anyway.
2005-04-07Don't kill the same pseudo twice.Linus Torvalds1-0/+2
Keep the busy count valid.
2005-04-07Add tons more comments about register state changes to theLinus Torvalds1-21/+41
example output. Very informational.
2005-04-07Remove old pseudos from register list when we redefine oneLinus Torvalds1-0/+17
through a phi-node.
2005-04-07Make pretty helper functions for showing individual instructionsLinus Torvalds1-37/+87
and labels. And comments, for that matter. This eventually allows us to buffer them up, rather than print them out directly. Which we'll need to do if we want to fix up frame offsets etc (for register save areas). And other post- processing. Also, for comments, make "show_instruction()" return the string rather than print it out.
2005-04-07Don't re-use registers for several different output storages.Linus Torvalds1-6/+27
We used to be lazy and just assume that if a value was in a register when we exited, we could just use that register. Not so, since now a register can contain multiple pseudos, that may all need different output storages.
2005-04-07Use the ptr-list tagging for marking pseudos dirty.Linus Torvalds1-11/+16
Remove hardreg dirty bit, it really is per-pseudo.
2005-04-07Be smarter about when we need to flush a pseudo.Linus Torvalds1-1/+27
We can often just re-generate it (from its source, or from an earlier flush).
2005-04-07Now that we can have multiple pseudos per reg, we shouldLinus Torvalds1-42/+55
make "busy" be a counter of non-dead pseudos.
2005-04-07Generate some kind of code for OP_RETLinus Torvalds1-0/+15
2005-04-07Remove stale assertion.Linus Torvalds1-1/+0
Now that we let several pseudos be associated with one hardreg, it may not be totally empty any more by the writeback phase.
2005-04-07Make the hardreg pseudo pointer be a _list_ of pseudos definedLinus Torvalds1-36/+59
by the hardreg. We often have more than one pseudo with the same value, notably when generating a phi source. Use the new list tagging to tag which ones are dead (and which ones need writeback).
2005-04-07Teach register "allocator" about preferred register targets.Linus Torvalds1-9/+22
Avoid a few silly reg-reg moves.
2005-04-07Make "last_reg" be entry-point global rather than bb-global.Linus Torvalds1-15/+17
We don't want to always start from the same reg at each bb entry.
2005-04-07Remove some stale (and very confusing) register instantiation.Linus Torvalds1-1/+1
2005-04-07Add a few more hard registers, and let things live a bit longer.Linus Torvalds1-6/+30
Our binops are destructive, but maybe we should try to copy the destroyed register if it's still live.
2005-04-07Fix up example storage usage details.Linus Torvalds1-5/+6
This actually makes some trivial cases come out almost right.
2005-04-07Generate code for conditional branches.Linus Torvalds1-21/+61
2005-04-07If we don't have any pre-defined incoming storage, selectLinus Torvalds1-1/+12
something. If we can try to go for a register, all the better.
2005-04-07Make our pitiful code generation a bit less pitiful.Linus Torvalds1-15/+173
You can kind of start seeing what it's trying to do. Kind of.
2005-04-07Generate "code" for binops.Linus Torvalds1-35/+171
It ain't pretty, but that's not the aim right now.
2005-04-07Do some initial totally ridiculous "code generation" inLinus Torvalds1-25/+220
the example. And by "totally ridiculous", I mean "do one instruction, and do it badly".
2005-04-07Slowly, slowly, make the output of "example" slightly more readable.Linus Torvalds1-11/+82
I dunno if this will ever get anywhere.
2005-04-07Make "storage" be part of the sparse library, and split outLinus Torvalds1-0/+69
the "example output" program from it.
2005-04-07Start splitting out generic "storage" handling from example.cLinus Torvalds1-348/+0
Start by renaming.
2005-04-07Small cleanups for example storage handling.Linus Torvalds1-42/+83
Next step: start generating x86-like code for simple instructions.
2005-04-07Add silly storage handling example.Linus Torvalds1-0/+307
This one links up the inter-bb usage pseudos to each other with "storage" structures, which should make it possible to write a simple code generator that doesn't need to worry about any global state - all the decisions are local. There are probably cases where this simply doesn't work, but I want to try to start generating _some_ code at least.