| ... | ... | @@ -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 | 798 | pub const Object = struct { |
| 775 | 799 | gpa: Allocator, |
| 776 | 800 | builder: Builder, |
| ... | ... | @@ -1135,14 +1159,17 @@ pub const Object = struct { |
| 1135 | 1159 | module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag( |
| 1136 | 1160 | behavior_error, |
| 1137 | 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) { |
| 1139 | | .tiny => 0, |
| 1140 | | .small => 1, |
| 1141 | | .kernel => 2, |
| 1142 | | .medium => 3, |
| 1143 | | .large => 4, |
| 1144 | | else => unreachable, |
| 1145 | | }))), |
| 1162 | try o.builder.metadataConstant(try o.builder.intConst(.i32, @as( |
| 1163 | i32, |
| 1164 | switch (codeModel(comp.root_mod.code_model, comp.root_mod.resolved_target.result)) { |
| 1165 | .default => unreachable, |
| 1166 | .tiny => 0, |
| 1167 | .small => 1, |
| 1168 | .kernel => 2, |
| 1169 | .medium => 3, |
| 1170 | .large => 4, |
| 1171 | }, |
| 1172 | ))), |
| 1146 | 1173 | )); |
| 1147 | 1174 | } |
| 1148 | 1175 | |
| ... | ... | @@ -1294,7 +1321,7 @@ pub const Object = struct { |
| 1294 | 1321 | else |
| 1295 | 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 | 1325 | .default => .Default, |
| 1299 | 1326 | .tiny => .Tiny, |
| 1300 | 1327 | .small => .Small, |