Skip to content

Commit a268129

Browse files
committed
[NFC]Fix IR/MC depency issue for function descriptor SDAG implementation
Summary: llvm/IR/GlobalValue.h can't be included in MC, that creates a circular dependency between MC and IR libraries. This circular dependency is causing an issue for build system that enforce layering. Author: Xiangling_L Reviewers: sfertile, jasonliu, hubert.reinterpretcast, gribozavr Reviewed By: gribozavr Subscribers: wuzish, nemanjai, hiraditya, kbarton, MaskRay, jsji, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64445 llvm-svn: 365701
1 parent 9a6c17b commit a268129

File tree

2 files changed

+35
-54
lines changed

2 files changed

+35
-54
lines changed

llvm/include/llvm/MC/MCSymbolXCOFF.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,11 @@
1313

1414
namespace llvm {
1515

16-
class GlobalValue;
17-
1816
class MCSymbolXCOFF : public MCSymbol {
19-
// The IR symbol this MCSymbolXCOFF is based on. It is set on function
20-
// entry point symbols when they are the callee operand of a direct call
21-
// SDNode.
22-
const GlobalValue *GV = nullptr;
23-
2417
public:
2518
MCSymbolXCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
2619
: MCSymbol(SymbolKindXCOFF, Name, isTemporary) {}
2720

28-
void setGlobalValue(const GlobalValue *G) { GV = G; }
29-
const GlobalValue *getGlobalValue() const { return GV; }
30-
3121
static bool classof(const MCSymbol *S) { return S->isXCOFF(); }
3222
};
3323

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,25 +4432,15 @@ static bool isFunctionGlobalAddress(SDValue Callee);
44324432
static bool
44334433
callsShareTOCBase(const Function *Caller, SDValue Callee,
44344434
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();
44544444
// The medium and large code models are expected to provide a sufficiently
44554445
// large TOC to provide all data addressing needs of a module with a
44564446
// 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,
49344924
// we're building with the leopard linker or later, which automatically
49354925
// synthesizes these stubs.
49364926
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();
49394928
const GlobalValue *GV = nullptr;
49404929
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
49414930
GV = G->getGlobal();
49424931
bool Local = TM.shouldAssumeDSOLocal(*Mod, GV);
49434932
bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64;
49444933

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.
49454937
if (isFunctionGlobalAddress(Callee)) {
49464938
GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Callee);
49474939

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);
49704948
needIndirectCall = false;
49714949
}
49724950

@@ -5245,6 +5223,7 @@ SDValue PPCTargetLowering::FinishCall(
52455223
// same TOC), the NOP will remain unchanged, or become some other NOP.
52465224

52475225
MachineFunction &MF = DAG.getMachineFunction();
5226+
EVT PtrVT = getPointerTy(DAG.getDataLayout());
52485227
if (!isTailCall && !isPatchPoint &&
52495228
((Subtarget.isSVR4ABI() && Subtarget.isPPC64()) ||
52505229
Subtarget.isAIXABI())) {
@@ -5263,7 +5242,6 @@ SDValue PPCTargetLowering::FinishCall(
52635242
// allocated and an unnecessary move instruction being generated.
52645243
CallOpc = PPCISD::BCTRL_LOAD_TOC;
52655244

5266-
EVT PtrVT = getPointerTy(DAG.getDataLayout());
52675245
SDValue StackPtr = DAG.getRegister(PPC::X1, PtrVT);
52685246
unsigned TOCSaveOffset = Subtarget.getFrameLowering()->getTOCSaveOffset();
52695247
SDValue TOCOff = DAG.getIntPtrConstant(TOCSaveOffset, dl);
@@ -5279,6 +5257,19 @@ SDValue PPCTargetLowering::FinishCall(
52795257
}
52805258
}
52815259

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+
52825273
Chain = DAG.getNode(CallOpc, dl, NodeTys, Ops);
52835274
InFlag = Chain.getValue(1);
52845275

0 commit comments

Comments
 (0)