-
Notifications
You must be signed in to change notification settings - Fork 80
Description
I think it would be very useful to have a way of finding the operands of an instruction.
Here's an example of a code generator which makes such a function.
https://gist.github.com/pwaller/255654cd78b77484a02cdfaa6a22237c
In the end, I don't know exactly how I feel about it (especially the code generation part...).
But I guess this gets me quite close to being able to implement a simple dead code pass which can kill unused private functions.
Example use:
func loopOperands(irModule *ir.Module) {
for _, f := range irModule.Funcs {
for _, bb := range f.Blocks {
for _, i := range bb.Insts {
log.Println("inst:", i.Def())
var tmp [16]irvalue.Value
for _, o := range ir.Operands(tmp[:0], i) {
log.Println(" op:", o)
}
}
}
}
}I note that Operands() could almost return pointers to values, so that the references were mutable. However, this is broken. The only reason it is broken that I can find is the Scope field on InstCatchPad and InstCleanupPad. I think if we want to be able to obtain mutable references to Operands, those fields should become of types value.Value. I guess there are pros and cons to that. But if you want mutable references to operands I think the alternatives are going to be much uglier.