Skip to content

Commit cdf29d8

Browse files
committed
Merge 80404 from mainline.
Let Darwin linker auto-synthesize stubs and lazy-pointers. This deletes a bunch of nasty code in ARM asm printer. llvm-svn: 81647
1 parent bf060da commit cdf29d8

File tree

9 files changed

+59
-262
lines changed

9 files changed

+59
-262
lines changed

llvm/lib/Target/ARM/ARMCodeEmitter.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,9 @@ void Emitter<CodeEmitter>::emitConstPoolInstruction(const MachineInstr &MI) {
423423

424424
GlobalValue *GV = ACPV->getGV();
425425
if (GV) {
426-
assert(!ACPV->isStub() && "Don't know how to deal this yet!");
427-
if (ACPV->isNonLazyPointer())
428-
MCE.addRelocation(MachineRelocation::getIndirectSymbol(
429-
MCE.getCurrentPCOffset(), ARM::reloc_arm_machine_cp_entry, GV,
430-
(intptr_t)ACPV, false));
431-
else
432-
emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
433-
ACPV->isStub() || isa<Function>(GV), (intptr_t)ACPV);
426+
emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
427+
isa<Function>(GV), (intptr_t)ACPV);
434428
} else {
435-
assert(!ACPV->isNonLazyPointer() && "Don't know how to deal this yet!");
436429
emitExternalSymbolAddress(ACPV->getSymbol(), ARM::reloc_arm_absolute);
437430
}
438431
emitWordLE(0);

llvm/lib/Target/ARM/ARMConstantPoolValue.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,25 @@
2121
using namespace llvm;
2222

2323
ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
24-
ARMCP::ARMCPKind k,
2524
unsigned char PCAdj,
2625
const char *Modif,
2726
bool AddCA)
2827
: MachineConstantPoolValue((const Type*)gv->getType()),
29-
GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
28+
GV(gv), S(NULL), LabelId(id), PCAdjust(PCAdj),
3029
Modifier(Modif), AddCurrentAddress(AddCA) {}
3130

3231
ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
3332
const char *s, unsigned id,
34-
ARMCP::ARMCPKind k,
3533
unsigned char PCAdj,
3634
const char *Modif,
3735
bool AddCA)
3836
: MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
39-
GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
37+
GV(NULL), S(strdup(s)), LabelId(id), PCAdjust(PCAdj),
4038
Modifier(Modif), AddCurrentAddress(AddCA) {}
4139

42-
ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
43-
ARMCP::ARMCPKind k,
44-
const char *Modif)
40+
ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
4541
: MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
46-
GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
42+
GV(gv), S(NULL), LabelId(0), PCAdjust(0),
4743
Modifier(Modif) {}
4844

4945
int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
@@ -58,7 +54,6 @@ int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
5854
if (CPV->GV == GV &&
5955
CPV->S == S &&
6056
CPV->LabelId == LabelId &&
61-
CPV->Kind == Kind &&
6257
CPV->PCAdjust == PCAdjust)
6358
return i;
6459
}
@@ -76,7 +71,6 @@ ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
7671
ID.AddPointer(GV);
7772
ID.AddPointer(S);
7873
ID.AddInteger(LabelId);
79-
ID.AddInteger((unsigned)Kind);
8074
ID.AddInteger(PCAdjust);
8175
}
8276

@@ -94,8 +88,6 @@ void ARMConstantPoolValue::print(raw_ostream &O) const {
9488
O << GV->getName();
9589
else
9690
O << S;
97-
if (isNonLazyPointer()) O << "$non_lazy_ptr";
98-
else if (isStub()) O << "$stub";
9991
if (Modifier) O << "(" << Modifier << ")";
10092
if (PCAdjust != 0) {
10193
O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;

llvm/lib/Target/ARM/ARMConstantPoolValue.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,26 @@ namespace llvm {
2222
class GlobalValue;
2323
class LLVMContext;
2424

25-
namespace ARMCP {
26-
enum ARMCPKind {
27-
CPValue,
28-
CPNonLazyPtr,
29-
CPStub
30-
};
31-
}
32-
3325
/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
3426
/// represent PC relative displacement between the address of the load
3527
/// instruction and the global value being loaded, i.e. (&GV-(LPIC+8)).
3628
class ARMConstantPoolValue : public MachineConstantPoolValue {
3729
GlobalValue *GV; // GlobalValue being loaded.
3830
const char *S; // ExtSymbol being loaded.
3931
unsigned LabelId; // Label id of the load.
40-
ARMCP::ARMCPKind Kind; // non_lazy_ptr or stub?
4132
unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative.
4233
// 8 for ARM, 4 for Thumb.
4334
const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
4435
bool AddCurrentAddress;
4536

4637
public:
4738
ARMConstantPoolValue(GlobalValue *gv, unsigned id,
48-
ARMCP::ARMCPKind Kind = ARMCP::CPValue,
4939
unsigned char PCAdj = 0, const char *Modifier = NULL,
5040
bool AddCurrentAddress = false);
5141
ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
52-
ARMCP::ARMCPKind Kind = ARMCP::CPValue,
5342
unsigned char PCAdj = 0, const char *Modifier = NULL,
5443
bool AddCurrentAddress = false);
55-
ARMConstantPoolValue(GlobalValue *GV, ARMCP::ARMCPKind Kind,
56-
const char *Modifier);
44+
ARMConstantPoolValue(GlobalValue *GV, const char *Modifier);
5745
ARMConstantPoolValue();
5846
~ARMConstantPoolValue();
5947

@@ -64,8 +52,6 @@ class ARMConstantPoolValue : public MachineConstantPoolValue {
6452
bool hasModifier() const { return Modifier != NULL; }
6553
bool mustAddCurrentAddress() const { return AddCurrentAddress; }
6654
unsigned getLabelId() const { return LabelId; }
67-
bool isNonLazyPointer() const { return Kind == ARMCP::CPNonLazyPtr; }
68-
bool isStub() const { return Kind == ARMCP::CPStub; }
6955
unsigned char getPCAdjustment() const { return PCAdjust; }
7056

7157
virtual unsigned getRelocationInfo() const {

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,8 @@ ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
975975
isLocalARMFunc = !Subtarget->isThumb() && !isExt;
976976
// tBX takes a register source operand.
977977
if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) {
978-
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex,
979-
ARMCP::CPStub, 4);
978+
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV,
979+
ARMPCLabelIndex, 4);
980980
SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4);
981981
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
982982
Callee = DAG.getLoad(getPointerTy(), dl,
@@ -995,8 +995,7 @@ ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
995995
const char *Sym = S->getSymbol();
996996
if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) {
997997
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(),
998-
Sym, ARMPCLabelIndex,
999-
ARMCP::CPStub, 4);
998+
Sym, ARMPCLabelIndex, 4);
1000999
SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4);
10011000
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
10021001
Callee = DAG.getLoad(getPointerTy(), dl,
@@ -1173,7 +1172,7 @@ ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
11731172
EVT PtrVT = getPointerTy();
11741173
unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8;
11751174
ARMConstantPoolValue *CPV =
1176-
new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue,
1175+
new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex,
11771176
PCAdj, "tlsgd", true);
11781177
SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4);
11791178
Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument);
@@ -1215,7 +1214,7 @@ ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA,
12151214
// initial exec model
12161215
unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8;
12171216
ARMConstantPoolValue *CPV =
1218-
new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue,
1217+
new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex,
12191218
PCAdj, "gottpoff", true);
12201219
Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4);
12211220
Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset);
@@ -1228,8 +1227,7 @@ ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA,
12281227
Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0);
12291228
} else {
12301229
// local exec model
1231-
ARMConstantPoolValue *CPV =
1232-
new ARMConstantPoolValue(GV, ARMCP::CPValue, "tpoff");
1230+
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, "tpoff");
12331231
Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4);
12341232
Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset);
12351233
Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0);
@@ -1263,7 +1261,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
12631261
if (RelocM == Reloc::PIC_) {
12641262
bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility();
12651263
ARMConstantPoolValue *CPV =
1266-
new ARMConstantPoolValue(GV, ARMCP::CPValue, UseGOTOFF ? "GOTOFF":"GOT");
1264+
new ARMConstantPoolValue(GV, UseGOTOFF ? "GOTOFF" : "GOT");
12671265
SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
12681266
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
12691267
SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(),
@@ -1281,34 +1279,19 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
12811279
}
12821280
}
12831281

1284-
/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol
1285-
/// even in non-static mode.
1286-
static bool GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) {
1287-
// If symbol visibility is hidden, the extra load is not needed if
1288-
// the symbol is definitely defined in the current translation unit.
1289-
bool isDecl = GV->isDeclaration() || GV->hasAvailableExternallyLinkage();
1290-
if (GV->hasHiddenVisibility() && (!isDecl && !GV->hasCommonLinkage()))
1291-
return false;
1292-
return RelocM != Reloc::Static && (isDecl || GV->isWeakForLinker());
1293-
}
1294-
12951282
SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op,
12961283
SelectionDAG &DAG) {
12971284
EVT PtrVT = getPointerTy();
12981285
DebugLoc dl = Op.getDebugLoc();
12991286
GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
13001287
Reloc::Model RelocM = getTargetMachine().getRelocationModel();
1301-
bool IsIndirect = GVIsIndirectSymbol(GV, RelocM);
13021288
SDValue CPAddr;
13031289
if (RelocM == Reloc::Static)
13041290
CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4);
13051291
else {
1306-
unsigned PCAdj = (RelocM != Reloc::PIC_)
1307-
? 0 : (Subtarget->isThumb() ? 4 : 8);
1308-
ARMCP::ARMCPKind Kind = IsIndirect ? ARMCP::CPNonLazyPtr
1309-
: ARMCP::CPValue;
1310-
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex,
1311-
Kind, PCAdj);
1292+
unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8);
1293+
ARMConstantPoolValue *CPV =
1294+
new ARMConstantPoolValue(GV, ARMPCLabelIndex, PCAdj);
13121295
CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
13131296
}
13141297
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
@@ -1320,7 +1303,8 @@ SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op,
13201303
SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
13211304
Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel);
13221305
}
1323-
if (IsIndirect)
1306+
1307+
if (Subtarget->GVIsIndirectSymbol(GV, RelocM == Reloc::Static))
13241308
Result = DAG.getLoad(PtrVT, dl, Chain, Result, NULL, 0);
13251309

13261310
return Result;
@@ -1335,8 +1319,7 @@ SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op,
13351319
unsigned PCAdj = Subtarget->isThumb() ? 4 : 8;
13361320
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(),
13371321
"_GLOBAL_OFFSET_TABLE_",
1338-
ARMPCLabelIndex,
1339-
ARMCP::CPValue, PCAdj);
1322+
ARMPCLabelIndex, PCAdj);
13401323
SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
13411324
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
13421325
SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, NULL, 0);
@@ -1417,14 +1400,13 @@ ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) {
14171400
SDValue CPAddr;
14181401
unsigned PCAdj = (RelocM != Reloc::PIC_)
14191402
? 0 : (Subtarget->isThumb() ? 4 : 8);
1420-
ARMCP::ARMCPKind Kind = ARMCP::CPValue;
14211403
// Save off the LSDA name for the AsmPrinter to use when it's time
14221404
// to emit the table
14231405
std::string LSDAName = "L_lsda_";
14241406
LSDAName += MF.getFunction()->getName();
14251407
ARMConstantPoolValue *CPV =
14261408
new ARMConstantPoolValue(*DAG.getContext(), LSDAName.c_str(),
1427-
ARMPCLabelIndex, Kind, PCAdj);
1409+
ARMPCLabelIndex, PCAdj);
14281410
CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
14291411
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
14301412
SDValue Result =

llvm/lib/Target/ARM/ARMSubtarget.cpp

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

1414
#include "ARMSubtarget.h"
1515
#include "ARMGenSubtarget.inc"
16+
#include "llvm/GlobalValue.h"
1617
#include "llvm/Target/TargetOptions.h"
1718
#include "llvm/Support/CommandLine.h"
1819
using namespace llvm;
@@ -92,3 +93,13 @@ ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
9293
if (isTargetDarwin())
9394
IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
9495
}
96+
97+
/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
98+
bool ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, bool isStatic) const {
99+
// If symbol visibility is hidden, the extra load is not needed if
100+
// the symbol is definitely defined in the current translation unit.
101+
bool isDecl = GV->isDeclaration() || GV->hasAvailableExternallyLinkage();
102+
if (GV->hasHiddenVisibility() && (!isDecl && !GV->hasCommonLinkage()))
103+
return false;
104+
return !isStatic && (isDecl || GV->isWeakForLinker());
105+
}

llvm/lib/Target/ARM/ARMSubtarget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020

2121
namespace llvm {
22+
class GlobalValue;
2223

2324
class ARMSubtarget : public TargetSubtarget {
2425
protected:
@@ -129,6 +130,10 @@ class ARMSubtarget : public TargetSubtarget {
129130
/// stack frame on entry to the function and which must be maintained by every
130131
/// function for this subtarget.
131132
unsigned getStackAlignment() const { return stackAlignment; }
133+
134+
/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
135+
/// symbol.
136+
bool GVIsIndirectSymbol(GlobalValue *GV, bool isStatic) const;
132137
};
133138
} // End llvm namespace
134139

0 commit comments

Comments
 (0)