aboutsummaryrefslogtreecommitdiffhomepage
path: root/transform/optimizer.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-11-03 01:24:25 +0100
committerRon Evans <[email protected]>2021-11-06 09:40:15 +0100
commitedcece33caeb0453c105efad799a94239c128dff (patch)
tree5bc4d51da363f5b8a5ebb84bed2879eb2534bddf /transform/optimizer.go
parent30bbdd5aeb6a78388db533da72ebace10545935e (diff)
downloadtinygo-edcece33caeb0453c105efad799a94239c128dff.tar.gz
tinygo-edcece33caeb0453c105efad799a94239c128dff.zip
transform: refactor interrupt lowering
Instead of doing everything in the interrupt lowering pass, generate some more code in gen-device to declare interrupt handler functions and do some work in the compiler so that interrupt lowering becomes a lot simpler. This has several benefits: - Overall code is smaller, in particular the interrupt lowering pass. - The code should be a bit less "magical" and instead a bit easier to read. In particular, instead of having a magic runtime.callInterruptHandler (that is fully written by the interrupt lowering pass), the runtime calls a generated function like device/sifive.InterruptHandler where this switch already exists in code. - Debug information is improved. This can be helpful during actual debugging but is also useful for other uses of DWARF debug information. For an example on debug information improvement, this is what a backtrace might look like before this commit: Breakpoint 1, 0x00000b46 in UART0_IRQHandler () (gdb) bt #0 0x00000b46 in UART0_IRQHandler () #1 <signal handler called> [..etc] Notice that the debugger doesn't see the source code location where it has stopped. After this commit, breaking at the same line might look like this: Breakpoint 1, (*machine.UART).handleInterrupt (arg1=..., uart=<optimized out>) at /home/ayke/src/github.com/tinygo-org/tinygo/src/machine/machine_nrf.go:200 200 uart.Receive(byte(nrf.UART0.RXD.Get())) (gdb) bt #0 (*machine.UART).handleInterrupt (arg1=..., uart=<optimized out>) at /home/ayke/src/github.com/tinygo-org/tinygo/src/machine/machine_nrf.go:200 #1 UART0_IRQHandler () at /home/ayke/src/github.com/tinygo-org/tinygo/src/device/nrf/nrf51.go:176 #2 <signal handler called> [..etc] By now, the debugger sees an actual source location for UART0_IRQHandler (in the generated file) and an inlined function.
Diffstat (limited to 'transform/optimizer.go')
-rw-r--r--transform/optimizer.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/transform/optimizer.go b/transform/optimizer.go
index ec48a1192..bd6d21687 100644
--- a/transform/optimizer.go
+++ b/transform/optimizer.go
@@ -73,7 +73,7 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i
return []error{err}
}
- errs := LowerInterrupts(mod, config)
+ errs := LowerInterrupts(mod)
if len(errs) > 0 {
return errs
}
@@ -105,7 +105,7 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i
if config.FuncImplementation() == "switch" {
LowerFuncValues(mod)
}
- errs := LowerInterrupts(mod, config)
+ errs := LowerInterrupts(mod)
if len(errs) > 0 {
return errs
}