[clang] [CIR] Add support for thread-local storage (TLS) (PR #168662)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 3 13:49:38 PST 2025
================
@@ -1933,6 +1902,35 @@ void CIRGenModule::setGVPropertiesAux(mlir::Operation *op,
assert(!cir::MissingFeatures::opGlobalPartition());
}
+cir::TLS_Model CIRGenModule::GetDefaultCIRTLSModel() const {
+ switch (getCodeGenOpts().getDefaultTLSModel()) {
+ case CodeGenOptions::GeneralDynamicTLSModel:
+ return cir::TLS_Model::GeneralDynamic;
+ case CodeGenOptions::LocalDynamicTLSModel:
+ return cir::TLS_Model::LocalDynamic;
+ case CodeGenOptions::InitialExecTLSModel:
+ return cir::TLS_Model::InitialExec;
+ case CodeGenOptions::LocalExecTLSModel:
+ return cir::TLS_Model::LocalExec;
+ }
+ llvm_unreachable("Invalid TLS model!");
+}
+
+void CIRGenModule::setTLSMode(mlir::Operation *op, const VarDecl &d) const {
+ assert(d.getTLSKind() && "setting TLS mode on non-TLS var!");
+
+ auto tlm = GetDefaultCIRTLSModel();
+
+ // Override the TLS model if it is explicitly specified.
+ if (d.getAttr<TLSModelAttr>()) {
+ llvm_unreachable("NYI");
+ }
+
+ auto global = dyn_cast<cir::GlobalOp>(op);
+ assert(global && "NYI for other operations");
----------------
andykaylor wrote:
```suggestion
auto global = cast<cir::GlobalOp>(op);
```
Using `cast` versus `dyn_cast` performs the assert as part of the cast.
https://github.com/llvm/llvm-project/pull/168662
More information about the cfe-commits
mailing list