[clang] [llvm] [PowerPC] Tune AIX shared library TLS model at function level by heuristic (PR #84132)
Hubert Tong via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 16:21:35 PDT 2024
================
@@ -3362,6 +3362,64 @@ SDValue PPCTargetLowering::LowerGlobalTLSAddress(SDValue Op,
return LowerGlobalTLSAddressLinux(Op, DAG);
}
+/// updateForAIXShLibTLSModelOpt - Helper to initialize TLS model opt settings,
+/// and then apply the update.
+static void updateForAIXShLibTLSModelOpt(TLSModel::Model &Model,
+ SelectionDAG &DAG,
+ const TargetMachine &TM) {
+ // Initialize TLS model opt setting lazily:
+ // (1) Use initial-exec for single TLS var references within current function.
+ // (2) Use local-dynamic for multiple TLS var references within current
+ // function.
+ PPCFunctionInfo *FuncInfo =
+ DAG.getMachineFunction().getInfo<PPCFunctionInfo>();
+ if (!FuncInfo->isAIXFuncUseInitDone()) {
+ SmallPtrSet<const GlobalValue *, 8> TLSGV;
+ // Iterate over all instructions within current function, collect all TLS
+ // global variables (global variables taken as the first parameter to
+ // Intrinsic::threadlocal_address).
+ const Function &Func = DAG.getMachineFunction().getFunction();
+ for (Function::const_iterator BI = Func.begin(), BE = Func.end(); BI != BE;
+ ++BI)
+ for (BasicBlock::const_iterator II = BI->begin(), IE = BI->end();
+ II != IE; ++II)
+ if (II->getOpcode() == Instruction::Call)
+ if (const CallInst *CI = dyn_cast<const CallInst>(&*II))
+ if (Function *CF = CI->getCalledFunction())
+ if (CF->isDeclaration() &&
+ CF->getIntrinsicID() == Intrinsic::threadlocal_address)
+ if (const GlobalValue *GV =
+ dyn_cast<GlobalValue>(II->getOperand(0))) {
+ TLSModel::Model GVModel = TM.getTLSModel(GV);
+ if (GVModel == TLSModel::InitialExec ||
----------------
hubert-reinterpretcast wrote:
We should only count the number of `local-dynamic` accesses.
Rationale:
The option can be taken as providing the information that the shared object is loaded with the executable (not `dlopen`ed later). In that case, all variables accessed using the `local-dynamic` model can be accessed using `initial-exec`; however, there would still be variables accessed using `initial-exec` that cannot be accessed using `local-dynamic`.
https://github.com/llvm/llvm-project/pull/84132
More information about the llvm-commits
mailing list