| ... | @@ -457,6 +457,30 @@ pub fn dataLayout(target: std.Target) []const u8 { | ... | @@ -457,6 +457,30 @@ pub fn dataLayout(target: std.Target) []const u8 { |
| 457 | }; | 457 | }; |
| 458 | } | 458 | } |
| 459 | | 459 | |
| | 460 | // Avoid depending on `llvm.CodeModel` in the bitcode-only case. |
| | 461 | const CodeModel = enum { |
| | 462 | default, |
| | 463 | tiny, |
| | 464 | small, |
| | 465 | kernel, |
| | 466 | medium, |
| | 467 | large, |
| | 468 | }; |
| | 469 | |
| | 470 | fn codeModel(model: std.builtin.CodeModel, target: std.Target) CodeModel { |
| | 471 | // Roughly match Clang's mapping of GCC code models to LLVM code models. |
| | 472 | return switch (model) { |
| | 473 | .default => .default, |
| | 474 | .extreme, .large => .large, |
| | 475 | .kernel => .kernel, |
| | 476 | .medany => if (target.cpu.arch.isRISCV()) .medium else .large, |
| | 477 | .medium => if (target.os.tag == .aix) .large else .medium, |
| | 478 | .medmid => .medium, |
| | 479 | .normal, .medlow, .small => .small, |
| | 480 | .tiny => .tiny, |
| | 481 | }; |
| | 482 | } |
| | 483 | |
| 460 | pub const Object = struct { | 484 | pub const Object = struct { |
| 461 | gpa: Allocator, | 485 | gpa: Allocator, |
| 462 | builder: Builder, | 486 | builder: Builder, |
| ... | @@ -821,14 +845,17 @@ pub const Object = struct { | ... | @@ -821,14 +845,17 @@ pub const Object = struct { |
| 821 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | 845 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( |
| 822 | behavior_error, | 846 | behavior_error, |
| 823 | try o.builder.metadataString("Code Model"), | 847 | try o.builder.metadataString("Code Model"), |
| 824 | try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(i32, switch (comp.root_mod.code_model) { | 848 | try o.builder.metadataConstant(try o.builder.intConst(.i32, @as( |
| 825 | .tiny => 0, | 849 | i32, |
| 826 | .small => 1, | 850 | switch (codeModel(comp.root_mod.code_model, comp.root_mod.resolved_target.result)) { |
| 827 | .kernel => 2, | 851 | .default => unreachable, |
| 828 | .medium => 3, | 852 | .tiny => 0, |
| 829 | .large => 4, | 853 | .small => 1, |
| 830 | else => unreachable, | 854 | .kernel => 2, |
| 831 | }))), | 855 | .medium => 3, |
| | 856 | .large => 4, |
| | 857 | }, |
| | 858 | ))), |
| 832 | )); | 859 | )); |
| 833 | } | 860 | } |
| 834 | | 861 | |
| ... | @@ -980,7 +1007,7 @@ pub const Object = struct { | ... | @@ -980,7 +1007,7 @@ pub const Object = struct { |
| 980 | else | 1007 | else |
| 981 | .Static; | 1008 | .Static; |
| 982 | | 1009 | |
| 983 | const code_model: llvm.CodeModel = switch (comp.root_mod.code_model) { | 1010 | const code_model: llvm.CodeModel = switch (codeModel(comp.root_mod.code_model, comp.root_mod.resolved_target.result)) { |
| 984 | .default => .Default, | 1011 | .default => .Default, |
| 985 | .tiny => .Tiny, | 1012 | .tiny => .Tiny, |
| 986 | .small => .Small, | 1013 | .small => .Small, |