| ... | @@ -771,6 +771,30 @@ const DataLayoutBuilder = struct { | ... | @@ -771,6 +771,30 @@ const DataLayoutBuilder = struct { |
| 771 | } | 771 | } |
| 772 | }; | 772 | }; |
| 773 | | 773 | |
| | 774 | // Avoid depending on `llvm.CodeModel` in the bitcode-only case. |
| | 775 | const CodeModel = enum { |
| | 776 | default, |
| | 777 | tiny, |
| | 778 | small, |
| | 779 | kernel, |
| | 780 | medium, |
| | 781 | large, |
| | 782 | }; |
| | 783 | |
| | 784 | fn codeModel(model: std.builtin.CodeModel, target: std.Target) CodeModel { |
| | 785 | // Roughly match Clang's mapping of GCC code models to LLVM code models. |
| | 786 | return switch (model) { |
| | 787 | .default => .default, |
| | 788 | .extreme, .large => .large, |
| | 789 | .kernel => .kernel, |
| | 790 | .medany => if (target.cpu.arch.isRISCV()) .medium else .large, |
| | 791 | .medium => if (target.os.tag == .aix) .large else .medium, |
| | 792 | .medmid => .medium, |
| | 793 | .normal, .medlow, .small => .small, |
| | 794 | .tiny => .tiny, |
| | 795 | }; |
| | 796 | } |
| | 797 | |
| 774 | pub const Object = struct { | 798 | pub const Object = struct { |
| 775 | gpa: Allocator, | 799 | gpa: Allocator, |
| 776 | builder: Builder, | 800 | builder: Builder, |
| ... | @@ -1135,14 +1159,17 @@ pub const Object = struct { | ... | @@ -1135,14 +1159,17 @@ pub const Object = struct { |
| 1135 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( | 1159 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( |
| 1136 | behavior_error, | 1160 | behavior_error, |
| 1137 | try o.builder.metadataString("Code Model"), | 1161 | try o.builder.metadataString("Code Model"), |
| 1138 | try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(i32, switch (comp.root_mod.code_model) { | 1162 | try o.builder.metadataConstant(try o.builder.intConst(.i32, @as( |
| 1139 | .tiny => 0, | 1163 | i32, |
| 1140 | .small => 1, | 1164 | switch (codeModel(comp.root_mod.code_model, comp.root_mod.resolved_target.result)) { |
| 1141 | .kernel => 2, | 1165 | .default => unreachable, |
| 1142 | .medium => 3, | 1166 | .tiny => 0, |
| 1143 | .large => 4, | 1167 | .small => 1, |
| 1144 | else => unreachable, | 1168 | .kernel => 2, |
| 1145 | }))), | 1169 | .medium => 3, |
| | 1170 | .large => 4, |
| | 1171 | }, |
| | 1172 | ))), |
| 1146 | )); | 1173 | )); |
| 1147 | } | 1174 | } |
| 1148 | | 1175 | |
| ... | @@ -1294,7 +1321,7 @@ pub const Object = struct { | ... | @@ -1294,7 +1321,7 @@ pub const Object = struct { |
| 1294 | else | 1321 | else |
| 1295 | .Static; | 1322 | .Static; |
| 1296 | | 1323 | |
| 1297 | const code_model: llvm.CodeModel = switch (comp.root_mod.code_model) { | 1324 | const code_model: llvm.CodeModel = switch (codeModel(comp.root_mod.code_model, comp.root_mod.resolved_target.result)) { |
| 1298 | .default => .Default, | 1325 | .default => .Default, |
| 1299 | .tiny => .Tiny, | 1326 | .tiny => .Tiny, |
| 1300 | .small => .Small, | 1327 | .small => .Small, |