@@ -4432,25 +4432,15 @@ static bool isFunctionGlobalAddress(SDValue Callee);
4432
4432
static bool
4433
4433
callsShareTOCBase(const Function *Caller, SDValue Callee,
4434
4434
const TargetMachine &TM) {
4435
- // Need a GlobalValue to determine if a Caller and Callee share the same
4436
- // TOCBase.
4437
- const GlobalValue *GV = nullptr;
4438
-
4439
- if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
4440
- GV = G->getGlobal();
4441
- } else if (MCSymbolSDNode *M = dyn_cast<MCSymbolSDNode>(Callee)) {
4442
- // On AIX only, we replace GlobalAddressSDNode with MCSymbolSDNode for
4443
- // the callee of a direct function call. The MCSymbolSDNode contains the
4444
- // MCSymbol for the funtion entry point.
4445
- const auto *S = cast<MCSymbolXCOFF>(M->getMCSymbol());
4446
- GV = S->getGlobalValue();
4447
- }
4448
-
4449
- // If we failed to get a GlobalValue, then pessimistically assume they do not
4450
- // share a TOCBase.
4451
- if (!GV)
4452
- return false;
4453
-
4435
+ // Callee is either a GlobalAddress or an ExternalSymbol. ExternalSymbols
4436
+ // don't have enough information to determine if the caller and calle share
4437
+ // the same TOC base, so we have to pessimistically assume they don't for
4438
+ // correctness.
4439
+ GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
4440
+ if (!G)
4441
+ return false;
4442
+
4443
+ const GlobalValue *GV = G->getGlobal();
4454
4444
// The medium and large code models are expected to provide a sufficiently
4455
4445
// large TOC to provide all data addressing needs of a module with a
4456
4446
// single TOC. Since each module will be addressed with a single TOC then we
@@ -4934,39 +4924,27 @@ PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValue &InFlag, SDValue &Chain,
4934
4924
// we're building with the leopard linker or later, which automatically
4935
4925
// synthesizes these stubs.
4936
4926
const TargetMachine &TM = DAG.getTarget();
4937
- MachineFunction &MF = DAG.getMachineFunction();
4938
- const Module *Mod = MF.getFunction().getParent();
4927
+ const Module *Mod = DAG.getMachineFunction().getFunction().getParent();
4939
4928
const GlobalValue *GV = nullptr;
4940
4929
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
4941
4930
GV = G->getGlobal();
4942
4931
bool Local = TM.shouldAssumeDSOLocal(*Mod, GV);
4943
4932
bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64;
4944
4933
4934
+ // If the callee is a GlobalAddress/ExternalSymbol node (quite common,
4935
+ // every direct call is) turn it into a TargetGlobalAddress /
4936
+ // TargetExternalSymbol node so that legalize doesn't hack it.
4945
4937
if (isFunctionGlobalAddress(Callee)) {
4946
4938
GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Callee);
4947
4939
4948
- if (TM.getTargetTriple().isOSAIX()) {
4949
- // Direct function calls reference the symbol for the function's entry
4950
- // point, which is named by inserting a "." before the function's
4951
- // C-linkage name.
4952
- auto &Context = MF.getMMI().getContext();
4953
- MCSymbol *S = Context.getOrCreateSymbol(Twine(".") +
4954
- Twine(G->getGlobal()->getName()));
4955
- cast<MCSymbolXCOFF>(S)->setGlobalValue(GV);
4956
- Callee = DAG.getMCSymbol(S, PtrVT);
4957
- } else {
4958
- // A call to a TLS address is actually an indirect call to a
4959
- // thread-specific pointer.
4960
- unsigned OpFlags = 0;
4961
- if (UsePlt)
4962
- OpFlags = PPCII::MO_PLT;
4963
-
4964
- // If the callee is a GlobalAddress/ExternalSymbol node (quite common,
4965
- // every direct call is) turn it into a TargetGlobalAddress /
4966
- // TargetExternalSymbol node so that legalize doesn't hack it.
4967
- Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl,
4968
- Callee.getValueType(), 0, OpFlags);
4969
- }
4940
+ // A call to a TLS address is actually an indirect call to a
4941
+ // thread-specific pointer.
4942
+ unsigned OpFlags = 0;
4943
+ if (UsePlt)
4944
+ OpFlags = PPCII::MO_PLT;
4945
+
4946
+ Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl,
4947
+ Callee.getValueType(), 0, OpFlags);
4970
4948
needIndirectCall = false;
4971
4949
}
4972
4950
@@ -5245,6 +5223,7 @@ SDValue PPCTargetLowering::FinishCall(
5245
5223
// same TOC), the NOP will remain unchanged, or become some other NOP.
5246
5224
5247
5225
MachineFunction &MF = DAG.getMachineFunction();
5226
+ EVT PtrVT = getPointerTy(DAG.getDataLayout());
5248
5227
if (!isTailCall && !isPatchPoint &&
5249
5228
((Subtarget.isSVR4ABI() && Subtarget.isPPC64()) ||
5250
5229
Subtarget.isAIXABI())) {
@@ -5263,7 +5242,6 @@ SDValue PPCTargetLowering::FinishCall(
5263
5242
// allocated and an unnecessary move instruction being generated.
5264
5243
CallOpc = PPCISD::BCTRL_LOAD_TOC;
5265
5244
5266
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
5267
5245
SDValue StackPtr = DAG.getRegister(PPC::X1, PtrVT);
5268
5246
unsigned TOCSaveOffset = Subtarget.getFrameLowering()->getTOCSaveOffset();
5269
5247
SDValue TOCOff = DAG.getIntPtrConstant(TOCSaveOffset, dl);
@@ -5279,6 +5257,19 @@ SDValue PPCTargetLowering::FinishCall(
5279
5257
}
5280
5258
}
5281
5259
5260
+ if (Subtarget.isAIXABI() && isFunctionGlobalAddress(Callee)) {
5261
+ // On AIX, direct function calls reference the symbol for the function's
5262
+ // entry point, which is named by inserting a "." before the function's
5263
+ // C-linkage name.
5264
+ GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Callee);
5265
+ auto &Context = DAG.getMachineFunction().getMMI().getContext();
5266
+ MCSymbol *S = Context.getOrCreateSymbol(Twine(".") +
5267
+ Twine(G->getGlobal()->getName()));
5268
+ Callee = DAG.getMCSymbol(S, PtrVT);
5269
+ // Replace the GlobalAddressSDNode Callee with the MCSymbolSDNode.
5270
+ Ops[1] = Callee;
5271
+ }
5272
+
5282
5273
Chain = DAG.getNode(CallOpc, dl, NodeTys, Ops);
5283
5274
InFlag = Chain.getValue(1);
5284
5275
0 commit comments