authorgravatar for gwenzek@users.noreply.github.comGuillaume Wenzek <gwenzek@users.noreply.github.com> 2023-01-03 12:05:09+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-01-03 13:05:09+02:00
loga44085dc2ab81877fc71fb50e846454c2694a14c
treee3ffb828f5933a7a1df32c7e06f2c90871d59c8f
parent93bdd04e8880f0ae2ad73b5922d499ec8500a82c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

add -fopt-bisect-limit


8 files changed, 35 insertions(+), 0 deletions(-)

src/Compilation.zig+2
......@@ -968,6 +968,7 @@ pub const InitOptions = struct {
968968 linker_print_gc_sections: bool = false,
969969 linker_print_icf_sections: bool = false,
970970 linker_print_map: bool = false,
971 linker_opt_bisect_limit: i32 = -1,
971972 each_lib_rpath: ?bool = null,
972973 build_id: ?bool = null,
973974 disable_c_depfile: bool = false,
......@@ -1826,6 +1827,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
18261827 .print_gc_sections = options.linker_print_gc_sections,
18271828 .print_icf_sections = options.linker_print_icf_sections,
18281829 .print_map = options.linker_print_map,
1830 .opt_bisect_limit = options.linker_opt_bisect_limit,
18291831 .z_nodelete = options.linker_z_nodelete,
18301832 .z_notext = options.linker_z_notext,
18311833 .z_defs = options.linker_z_defs,
src/codegen/llvm.zig+4
......@@ -520,6 +520,10 @@ pub const Object = struct {
520520 if (options.pie) llvm_module.setModulePIELevel();
521521 if (code_model != .Default) llvm_module.setModuleCodeModel(code_model);
522522
523 if (options.opt_bisect_limit >= 0) {
524 context.setOptBisectLimit(std.math.lossyCast(c_int, options.opt_bisect_limit));
525 }
526
523527 return Object{
524528 .gpa = gpa,
525529 .module = options.module.?,
src/codegen/llvm/bindings.zig+3
......@@ -85,6 +85,9 @@ pub const Context = opaque {
8585
8686 pub const createBuilder = LLVMCreateBuilderInContext;
8787 extern fn LLVMCreateBuilderInContext(C: *Context) *Builder;
88
89 pub const setOptBisectLimit = ZigLLVMSetOptBisectLimit;
90 extern fn ZigLLVMSetOptBisectLimit(C: *Context, limit: c_int) void;
8891};
8992
9093pub const Value = opaque {
src/link.zig+1
......@@ -169,6 +169,7 @@ pub const Options = struct {
169169 print_gc_sections: bool,
170170 print_icf_sections: bool,
171171 print_map: bool,
172 opt_bisect_limit: i32,
172173
173174 objects: []Compilation.LinkObject,
174175 framework_dirs: []const []const u8,
src/main.zig+5
......@@ -536,6 +536,7 @@ const usage_build_generic =
536536 \\ --test-runner [path] Specify a custom test runner
537537 \\
538538 \\Debug Options (Zig Compiler Development):
539 \\ -fopt-bisect-limit [limit] Only run [limit] first LLVM optimization passes
539540 \\ -ftime-report Print timing diagnostics
540541 \\ -fstack-report Print stack size diagnostics
541542 \\ --verbose-link Display linker invocations
......@@ -729,6 +730,7 @@ fn buildOutputType(
729730 var linker_print_gc_sections: bool = false;
730731 var linker_print_icf_sections: bool = false;
731732 var linker_print_map: bool = false;
733 var linker_opt_bisect_limit: i32 = -1;
732734 var linker_z_nocopyreloc = false;
733735 var linker_z_nodelete = false;
734736 var linker_z_notext = false;
......@@ -1285,6 +1287,8 @@ fn buildOutputType(
12851287 no_builtin = false;
12861288 } else if (mem.eql(u8, arg, "-fno-builtin")) {
12871289 no_builtin = true;
1290 } else if (mem.startsWith(u8, arg, "-fopt-bisect-limit=")) {
1291 linker_opt_bisect_limit = std.math.lossyCast(i32, parseIntSuffix(arg, "-fopt-bisect-limit=".len));
12881292 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
12891293 link_eh_frame_hdr = true;
12901294 } else if (mem.eql(u8, arg, "--emit-relocs")) {
......@@ -2996,6 +3000,7 @@ fn buildOutputType(
29963000 .linker_print_gc_sections = linker_print_gc_sections,
29973001 .linker_print_icf_sections = linker_print_icf_sections,
29983002 .linker_print_map = linker_print_map,
3003 .linker_opt_bisect_limit = linker_opt_bisect_limit,
29993004 .linker_global_base = linker_global_base,
30003005 .linker_export_symbol_names = linker_export_symbol_names.items,
30013006 .linker_z_nocopyreloc = linker_z_nocopyreloc,
src/zig_llvm.cpp+13
......@@ -31,6 +31,7 @@
3131#include <llvm/IR/Instructions.h>
3232#include <llvm/IR/LegacyPassManager.h>
3333#include <llvm/IR/Module.h>
34#include <llvm/IR/OptBisect.h>
3435#include <llvm/IR/PassManager.h>
3536#include <llvm/IR/Verifier.h>
3637#include <llvm/InitializePasses.h>
......@@ -412,6 +413,18 @@ ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref) {
412413 return wrap(Type::getTokenTy(*unwrap(context_ref)));
413414}
414415
416
417ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit) {
418 // In LLVM15 we just have an OptBisect singleton we can edit.
419 OptBisect& bisect = getOptBisector();
420 bisect.setLimit(limit);
421
422 // In LLVM16 OptBisect will be wrapped in OptPassGate, and will need to be set per context.
423 // static OptBisect _opt_bisector;
424 // _opt_bisector.setLimit(limit);
425 // unwrap(context_ref)->setOptPassGate(_opt_bisector);
426}
427
415428LLVMValueRef ZigLLVMAddFunctionInAddressSpace(LLVMModuleRef M, const char *Name, LLVMTypeRef FunctionTy, unsigned AddressSpace) {
416429 Function* func = Function::Create(unwrap<FunctionType>(FunctionTy), GlobalValue::ExternalLinkage, AddressSpace, Name, unwrap(M));
417430 return wrap(func);
src/zig_llvm.h+2
......@@ -67,6 +67,8 @@ ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, co
6767
6868ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref);
6969
70ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit);
71
7072ZIG_EXTERN_C LLVMValueRef ZigLLVMAddFunctionInAddressSpace(LLVMModuleRef M, const char *Name,
7173 LLVMTypeRef FunctionTy, unsigned AddressSpace);
7274
tools/stage2_gdb_pretty_printers.py+5
......@@ -2,8 +2,13 @@
22# put "source /path/to/stage2_gdb_pretty_printers.py" in ~/.gdbinit to load it automatically.
33import re
44import gdb.printing
5
6import sys
7from pathlib import Path
8sys.path.insert(0, str(Path(__file__).parent))
59import stage2_pretty_printers_common as common
610
11
712class TypePrinter:
813 def __init__(self, val):
914 self.val = val