From 5d07e0448e38d4be0cc7b1079d72b5e3644e941c Mon Sep 17 00:00:00 2001 From: Wolfgang Pieb Date: Mon, 6 Feb 2023 13:50:37 -0800 Subject: [TLS]: Clamp the alignment of TLS global variables if required by the target Adding a module flag 'MaxTLSAlign' describing the maximum alignment a global TLS variable can have. Optimizers are prevented from increasing the alignment of such variables beyond this threshold. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D140123 --- llvm/lib/IR/Module.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'llvm/lib/IR/Module.cpp') diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 49fadc9..3df1e7b 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -746,6 +746,13 @@ unsigned Module::getOverrideStackAlignment() const { return 0; } +unsigned Module::getMaxTLSAlignment() const { + Metadata *MD = getModuleFlag("MaxTLSAlign"); + if (auto *CI = mdconst::dyn_extract_or_null(MD)) + return CI->getZExtValue(); + return 0; +} + void Module::setOverrideStackAlignment(unsigned Align) { addModuleFlag(ModFlagBehavior::Error, "override-stack-alignment", Align); } -- cgit v1.1