optimizeProgram runs a series of optimizations and transformations that are needed to convert a program to its final form. Some transformations are not optional and must be run as the compiler expects them to run.
(mod llvm.Module, config *compileopts.Config)
| 1196 | // needed to convert a program to its final form. Some transformations are not |
| 1197 | // optional and must be run as the compiler expects them to run. |
| 1198 | func optimizeProgram(mod llvm.Module, config *compileopts.Config) error { |
| 1199 | err := interp.Run(mod, config.Options.InterpTimeout, config.DumpSSA()) |
| 1200 | if err != nil { |
| 1201 | return err |
| 1202 | } |
| 1203 | if config.VerifyIR() { |
| 1204 | // Only verify if we really need it. |
| 1205 | // The IR has already been verified before writing the bitcode to disk |
| 1206 | // and the interp function above doesn't need to do a lot as most of the |
| 1207 | // package initializers have already run. Additionally, verifying this |
| 1208 | // linked IR is _expensive_ because dead code hasn't been removed yet, |
| 1209 | // easily costing a few hundred milliseconds. Therefore, only do it when |
| 1210 | // specifically requested. |
| 1211 | if err := llvm.VerifyModule(mod, llvm.PrintMessageAction); err != nil { |
| 1212 | return errors.New("verification error after interpreting runtime.initAll") |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | // Run most of the whole-program optimizations (including the whole |
| 1217 | // O0/O1/O2/Os/Oz optimization pipeline). |
| 1218 | errs := transform.Optimize(mod, config) |
| 1219 | if len(errs) > 0 { |
| 1220 | return newMultiError(errs, "") |
| 1221 | } |
| 1222 | if err := llvm.VerifyModule(mod, llvm.PrintMessageAction); err != nil { |
| 1223 | return errors.New("verification failure after LLVM optimization passes") |
| 1224 | } |
| 1225 | |
| 1226 | return nil |
| 1227 | } |
| 1228 | |
| 1229 | func makeGlobalsModule(ctx llvm.Context, globals map[string]map[string]string, machine llvm.TargetMachine) llvm.Module { |
| 1230 | mod := ctx.NewModule("cmdline-globals") |