Skip to content

Commit

Permalink
use CreateThreadLocalAddress() to get address to use for thread_local…
Browse files Browse the repository at this point in the history
… variable gc_enabled
  • Loading branch information
stevenmeker committed Oct 24, 2024
1 parent 234de94 commit e34dffb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/codegen/CreateTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,12 @@ llvm::Value *create_term::disable_gc() {
= module_->getOrInsertGlobal("gc_enabled", llvm::Type::getInt1Ty(ctx_));
auto *global_var = llvm::cast<llvm::GlobalVariable>(global);
global_var->setThreadLocal(true);
llvm::IRBuilder b(current_block_);
auto global_var_address = b.CreateThreadLocalAddress(global_var);
auto *old_val = new llvm::LoadInst(
llvm::Type::getInt1Ty(ctx_), global_var, "was_enabled", current_block_);
llvm::Type::getInt1Ty(ctx_), global_var_address, "was_enabled", current_block_);
new llvm::StoreInst(
llvm::ConstantInt::getFalse(ctx_), global_var, current_block_);
llvm::ConstantInt::getFalse(ctx_), global_var_address, current_block_);
return old_val;
}

Expand All @@ -795,7 +797,9 @@ void create_term::enable_gc(llvm::Value *was_enabled) {
= module_->getOrInsertGlobal("gc_enabled", llvm::Type::getInt1Ty(ctx_));
auto *global_var = llvm::cast<llvm::GlobalVariable>(global);
global_var->setThreadLocal(true);
new llvm::StoreInst(was_enabled, global_var, current_block_);
llvm::IRBuilder b(current_block_);
auto global_var_address = b.CreateThreadLocalAddress(global_var);
new llvm::StoreInst(was_enabled, global_var_address, current_block_);
}

// We use tailcc calling convention for apply_rule_* and eval_* functions to
Expand Down

0 comments on commit e34dffb

Please sign in to comment.