-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[PowerPC] Tune AIX shared library TLS model at function level #84132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a61fcec
[PowerPC] Rename symbols references by tls-local-dynamic model
4525b9c
[NFC] Update comment.
27ba4ca
WIP: need check assert
7fb862a
Reset to try another approach
ad0db6c
Initial commit for aix-shared-library-tls-model-heuristic
f89db67
Fix issue/update according to comments
3d2630e
Pull out logic as static function guarded by
cc5cd2e
[NFC] address comment
4050abc
Update according to comments:
305d36f
(1) Add test case to check aix-shared-lib-tls-model-opt and
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -141,6 +141,11 @@ static cl::opt<unsigned> PPCGatherAllAliasesMaxDepth( | |||||
"ppc-gather-alias-max-depth", cl::init(18), cl::Hidden, | ||||||
cl::desc("max depth when checking alias info in GatherAllAliases()")); | ||||||
|
||||||
static cl::opt<unsigned> PPCAIXTLSModelOptUseIEForLDLimit( | ||||||
"ppc-aix-shared-lib-tls-model-opt-limit", cl::init(1), cl::Hidden, | ||||||
cl::desc("Set inclusive limit count of TLS local-dynamic access(es) in a " | ||||||
"function to use initial-exec")); | ||||||
|
||||||
STATISTIC(NumTailCalls, "Number of tail calls"); | ||||||
STATISTIC(NumSiblingCalls, "Number of sibling calls"); | ||||||
STATISTIC(ShufflesHandledWithVPERM, | ||||||
|
@@ -3362,6 +3367,54 @@ 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->isAIXFuncTLSModelOptInitDone()) { | ||||||
SmallPtrSet<const GlobalValue *, 8> TLSGV; | ||||||
// Iterate over all instructions within current function, collect all TLS | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit on comment:
Suggested change
|
||||||
// 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::LocalDynamic) | ||||||
TLSGV.insert(GV); | ||||||
} | ||||||
|
||||||
unsigned TLSGVCnt = TLSGV.size(); | ||||||
LLVM_DEBUG(dbgs() << format("LocalDynamic TLSGV count:%d\n", TLSGVCnt)); | ||||||
if (TLSGVCnt <= PPCAIXTLSModelOptUseIEForLDLimit) | ||||||
FuncInfo->setAIXFuncUseTLSIEForLD(); | ||||||
FuncInfo->setAIXFuncTLSModelOptInitDone(); | ||||||
} | ||||||
|
||||||
if (FuncInfo->isAIXFuncUseTLSIEForLD()) { | ||||||
LLVM_DEBUG( | ||||||
dbgs() << DAG.getMachineFunction().getName() | ||||||
<< " function is using the TLS-IE model for TLS-LD access.\n"); | ||||||
Model = TLSModel::InitialExec; | ||||||
} | ||||||
} | ||||||
|
||||||
SDValue PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op, | ||||||
SelectionDAG &DAG) const { | ||||||
GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); | ||||||
|
@@ -3374,6 +3427,11 @@ SDValue PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op, | |||||
EVT PtrVT = getPointerTy(DAG.getDataLayout()); | ||||||
bool Is64Bit = Subtarget.isPPC64(); | ||||||
TLSModel::Model Model = getTargetMachine().getTLSModel(GV); | ||||||
|
||||||
// Apply update to the TLS model. | ||||||
if (Subtarget.hasAIXShLibTLSModelOpt()) | ||||||
updateForAIXShLibTLSModelOpt(Model, DAG, getTargetMachine()); | ||||||
|
||||||
bool IsTLSLocalExecModel = Model == TLSModel::LocalExec; | ||||||
|
||||||
if (IsTLSLocalExecModel || Model == TLSModel::InitialExec) { | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
llvm/test/CodeGen/PowerPC/aix-shared-lib-tls-model-opt-small-local-dynamic-tls.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4 | ||
; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mattr=-altivec -mtriple powerpc64-ibm-aix-xcoff \ | ||
; RUN: -mattr=+aix-shared-lib-tls-model-opt --code-model=large < %s | FileCheck %s --check-prefixes=OPT | ||
; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mattr=-altivec -mtriple powerpc64-ibm-aix-xcoff \ | ||
; RUN: -mattr=+aix-small-local-dynamic-tls --code-model=large < %s | FileCheck %s --check-prefixes=SMALL | ||
; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mattr=-altivec -mtriple powerpc64-ibm-aix-xcoff \ | ||
; RUN: -mattr=+aix-shared-lib-tls-model-opt -mattr=+aix-small-local-dynamic-tls \ | ||
; RUN: --code-model=large < %s | FileCheck %s --check-prefixes=BOTH | ||
|
||
@VarTLSLD1 = internal thread_local(localdynamic) global i32 42, align 4 | ||
|
||
define i32 @Single_LD(i32 %P, i32 %Q) { | ||
; OPT-LABEL: Single_LD: | ||
; OPT: # %bb.0: # %entry | ||
; OPT-NEXT: and 4, 3, 4 | ||
; OPT-NEXT: addis 3, L..C0@u(2) | ||
; OPT-NEXT: ld 3, L..C0@l(3) | ||
; OPT-NEXT: cmpwi 4, -1 | ||
; OPT-NEXT: lwzx 3, 13, 3 | ||
; OPT-NEXT: blr | ||
; | ||
; SMALL-LABEL: Single_LD: | ||
; SMALL: # %bb.0: # %entry | ||
; SMALL-NEXT: mflr 0 | ||
; SMALL-NEXT: stdu 1, -48(1) | ||
; SMALL-NEXT: and 6, 3, 4 | ||
; SMALL-NEXT: addis 3, L..C0@u(2) | ||
; SMALL-NEXT: std 0, 64(1) | ||
; SMALL-NEXT: ld 3, L..C0@l(3) | ||
; SMALL-NEXT: bla .__tls_get_mod[PR] | ||
; SMALL-NEXT: cmpwi 6, -1 | ||
; SMALL-NEXT: lwz 3, VarTLSLD1[TL]@ld(3) | ||
; SMALL-NEXT: addi 1, 1, 48 | ||
; SMALL-NEXT: ld 0, 16(1) | ||
; SMALL-NEXT: mtlr 0 | ||
; SMALL-NEXT: blr | ||
; | ||
; BOTH-LABEL: Single_LD: | ||
; BOTH: # %bb.0: # %entry | ||
; BOTH-NEXT: and 4, 3, 4 | ||
; BOTH-NEXT: addis 3, L..C0@u(2) | ||
; BOTH-NEXT: ld 3, L..C0@l(3) | ||
; BOTH-NEXT: cmpwi 4, -1 | ||
; BOTH-NEXT: lwzx 3, 13, 3 | ||
; BOTH-NEXT: blr | ||
entry: | ||
%a = icmp slt i32 %P, 0 | ||
%b = icmp slt i32 %Q, 0 | ||
%c = and i1 %a, %b | ||
%tls1 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @VarTLSLD1) | ||
%load1 = load i32, ptr %tls1, align 4 | ||
br i1 %c, label %bb1, label %return | ||
|
||
bb1: | ||
%tls2 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @VarTLSLD1) | ||
%load2 = load i32, ptr %tls2, align 4 | ||
ret i32 %load2 | ||
|
||
return: | ||
ret i32 %load1 | ||
} | ||
|
||
; OPT-LABEL: .toc | ||
; OPT-LABEL: L..C0: | ||
; OPT-NEXT: .tc VarTLSLD1[TE],VarTLSLD1[TL]@ie | ||
|
||
; SMALL-LABEL: .toc | ||
; SMALL-LABEL: L..C0: | ||
; SMALL-NEXT: .tc _Renamed..5f24__TLSML[TC],_Renamed..5f24__TLSML[TC]@ml | ||
; SMALL-NEXT: .rename _Renamed..5f24__TLSML[TC],"_$TLSML" | ||
|
||
; BOTH-LABEL: .toc | ||
; BOTH-LABEL: L..C0: | ||
; BOTH-NEXT: .tc VarTLSLD1[TE],VarTLSLD1[TL]@ie |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.