Skip to content

Commit 9ae6c52

Browse files
committed
Do not inline type IDs in LLVM IR
1 parent 9b7fd8d commit 9ae6c52

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/compiler/crystal/codegen/codegen.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,7 @@ module Crystal
24622462
global.linkage = LLVM::Linkage::Private
24632463
global.global_constant = true
24642464
global.initializer = llvm_context.const_struct [
2465-
type_id(@program.string),
2465+
int32(@program.llvm_id.type_id(@program.string)), # in practice, should always be 1
24662466
int32(str.bytesize),
24672467
int32(str.size),
24682468
llvm_context.const_string(str),

src/compiler/crystal/codegen/type_id.cr

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ class Crystal::CodeGenVisitor
6565
end
6666

6767
private def type_id_impl(type)
68-
int(@program.llvm_id.type_id(type))
68+
type_id_name = "#{type.llvm_name}:type_id"
69+
70+
global = @main_mod.globals[type_id_name]?
71+
unless global
72+
global = @main_mod.globals.add(@main_llvm_context.int32, type_id_name)
73+
global.linkage = LLVM::Linkage::Internal if @single_module
74+
global.initializer = @main_llvm_context.int32.const_int(@program.llvm_id.type_id(type))
75+
global.global_constant = true
76+
end
77+
78+
if @llvm_mod != @main_mod
79+
global = @llvm_mod.globals[type_id_name]?
80+
unless global
81+
global = @llvm_mod.globals.add(@llvm_context.int32, type_id_name)
82+
global.linkage = LLVM::Linkage::External
83+
global.global_constant = true
84+
end
85+
end
86+
87+
load(@llvm_context.int32, global)
6988
end
7089
end

0 commit comments

Comments
 (0)