@@ -1098,78 +1098,63 @@ bool PPCTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base,
1098
1098
// LowerOperation implementation
1099
1099
// ===----------------------------------------------------------------------===//
1100
1100
1101
+ // / GetLabelAccessInfo - Return true if we should reference labels using a
1102
+ // / PICBase, set the HiOpFlags and LoOpFlags to the target MO flags.
1103
+ static bool GetLabelAccessInfo (const TargetMachine &TM, unsigned &HiOpFlags,
1104
+ unsigned &LoOpFlags) {
1105
+ // Don't use the pic base if not in PIC relocation model. Or if we are on a
1106
+ // non-darwin platform. We don't support PIC on other platforms yet.
1107
+ bool isPIC = TM.getRelocationModel () == Reloc::PIC_ &&
1108
+ TM.getSubtarget <PPCSubtarget>().isDarwin ();
1109
+
1110
+ HiOpFlags = isPIC ? PPCII::MO_HA16_PIC : PPCII::MO_HA16;
1111
+ LoOpFlags = isPIC ? PPCII::MO_LO16_PIC : PPCII::MO_LO16;
1112
+ return isPIC;
1113
+ }
1114
+
1115
+ static SDValue LowerLabelRef (SDValue HiPart, SDValue LoPart, bool isPIC,
1116
+ SelectionDAG &DAG) {
1117
+ EVT PtrVT = HiPart.getValueType ();
1118
+ SDValue Zero = DAG.getConstant (0 , PtrVT);
1119
+ DebugLoc DL = HiPart.getDebugLoc ();
1120
+
1121
+ SDValue Hi = DAG.getNode (PPCISD::Hi, DL, PtrVT, HiPart, Zero);
1122
+ SDValue Lo = DAG.getNode (PPCISD::Lo, DL, PtrVT, LoPart, Zero);
1123
+
1124
+ // With PIC, the first instruction is actually "GR+hi(&G)".
1125
+ if (isPIC)
1126
+ Hi = DAG.getNode (ISD::ADD, DL, PtrVT,
1127
+ DAG.getNode (PPCISD::GlobalBaseReg, DL, PtrVT), Hi);
1128
+
1129
+ // Generate non-pic code that has direct accesses to the constant pool.
1130
+ // The address of the global is just (hi(&g)+lo(&g)).
1131
+ return DAG.getNode (ISD::ADD, DL, PtrVT, Hi, Lo);
1132
+ }
1133
+
1101
1134
SDValue PPCTargetLowering::LowerConstantPool (SDValue Op,
1102
1135
SelectionDAG &DAG) const {
1103
1136
EVT PtrVT = Op.getValueType ();
1104
1137
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
1105
1138
const Constant *C = CP->getConstVal ();
1106
- SDValue CPI = DAG.getTargetConstantPool (C, PtrVT, CP->getAlignment ());
1107
- SDValue Zero = DAG.getConstant (0 , PtrVT);
1108
- // FIXME there isn't really any debug info here
1109
- DebugLoc dl = Op.getDebugLoc ();
1110
-
1111
- const TargetMachine &TM = DAG.getTarget ();
1112
-
1113
- SDValue Hi = DAG.getNode (PPCISD::Hi, dl, PtrVT, CPI, Zero);
1114
- SDValue Lo = DAG.getNode (PPCISD::Lo, dl, PtrVT, CPI, Zero);
1115
-
1116
- // If this is a non-darwin platform, we don't support non-static relo models
1117
- // yet.
1118
- if (TM.getRelocationModel () == Reloc::Static ||
1119
- !TM.getSubtarget <PPCSubtarget>().isDarwin ()) {
1120
- // Generate non-pic code that has direct accesses to the constant pool.
1121
- // The address of the global is just (hi(&g)+lo(&g)).
1122
- return DAG.getNode (ISD::ADD, dl, PtrVT, Hi, Lo);
1123
- }
1124
-
1125
- if (TM.getRelocationModel () == Reloc::PIC_) {
1126
- // With PIC, the first instruction is actually "GR+hi(&G)".
1127
- Hi = DAG.getNode (ISD::ADD, dl, PtrVT,
1128
- DAG.getNode (PPCISD::GlobalBaseReg,
1129
- DebugLoc (), PtrVT), Hi);
1130
- }
1131
1139
1132
- Lo = DAG.getNode (ISD::ADD, dl, PtrVT, Hi, Lo);
1133
- return Lo;
1140
+ unsigned MOHiFlag, MOLoFlag;
1141
+ bool isPIC = GetLabelAccessInfo (DAG.getTarget (), MOHiFlag, MOLoFlag);
1142
+ SDValue CPIHi =
1143
+ DAG.getTargetConstantPool (C, PtrVT, CP->getAlignment (), 0 , MOHiFlag);
1144
+ SDValue CPILo =
1145
+ DAG.getTargetConstantPool (C, PtrVT, CP->getAlignment (), 0 , MOLoFlag);
1146
+ return LowerLabelRef (CPIHi, CPILo, isPIC, DAG);
1134
1147
}
1135
1148
1136
1149
SDValue PPCTargetLowering::LowerJumpTable (SDValue Op, SelectionDAG &DAG) const {
1137
1150
EVT PtrVT = Op.getValueType ();
1138
1151
JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
1139
- SDValue JTI = DAG.getTargetJumpTable (JT->getIndex (), PtrVT);
1140
- SDValue Zero = DAG.getConstant (0 , PtrVT);
1141
- // FIXME there isn't really any debug loc here
1142
- DebugLoc dl = Op.getDebugLoc ();
1143
-
1144
- const TargetMachine &TM = DAG.getTarget ();
1145
-
1146
- SDValue Hi = DAG.getNode (PPCISD::Hi, dl, PtrVT, JTI, Zero);
1147
- SDValue Lo = DAG.getNode (PPCISD::Lo, dl, PtrVT, JTI, Zero);
1148
-
1149
- // If this is a non-darwin platform, we don't support non-static relo models
1150
- // yet.
1151
- if (TM.getRelocationModel () == Reloc::Static ||
1152
- !TM.getSubtarget <PPCSubtarget>().isDarwin ()) {
1153
- // Generate non-pic code that has direct accesses to the constant pool.
1154
- // The address of the global is just (hi(&g)+lo(&g)).
1155
- return DAG.getNode (ISD::ADD, dl, PtrVT, Hi, Lo);
1156
- }
1157
-
1158
- if (TM.getRelocationModel () == Reloc::PIC_) {
1159
- // With PIC, the first instruction is actually "GR+hi(&G)".
1160
- Hi = DAG.getNode (ISD::ADD, dl, PtrVT,
1161
- DAG.getNode (PPCISD::GlobalBaseReg,
1162
- DebugLoc (), PtrVT), Hi);
1163
- }
1164
-
1165
- Lo = DAG.getNode (ISD::ADD, dl, PtrVT, Hi, Lo);
1166
- return Lo;
1167
- }
1168
-
1169
- SDValue PPCTargetLowering::LowerGlobalTLSAddress (SDValue Op,
1170
- SelectionDAG &DAG) const {
1171
- llvm_unreachable (" TLS not implemented for PPC." );
1172
- return SDValue (); // Not reached
1152
+
1153
+ unsigned MOHiFlag, MOLoFlag;
1154
+ bool isPIC = GetLabelAccessInfo (DAG.getTarget (), MOHiFlag, MOLoFlag);
1155
+ SDValue JTIHi = DAG.getTargetJumpTable (JT->getIndex (), PtrVT, MOHiFlag);
1156
+ SDValue JTILo = DAG.getTargetJumpTable (JT->getIndex (), PtrVT, MOLoFlag);
1157
+ return LowerLabelRef (JTIHi, JTILo, isPIC, DAG);
1173
1158
}
1174
1159
1175
1160
SDValue PPCTargetLowering::LowerBlockAddress (SDValue Op,
@@ -1178,77 +1163,62 @@ SDValue PPCTargetLowering::LowerBlockAddress(SDValue Op,
1178
1163
DebugLoc DL = Op.getDebugLoc ();
1179
1164
1180
1165
const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress ();
1181
- SDValue TgtBA = DAG.getBlockAddress (BA, PtrVT, /* isTarget=*/ true );
1182
- SDValue Zero = DAG.getConstant (0 , PtrVT);
1183
- SDValue Hi = DAG.getNode (PPCISD::Hi, DL, PtrVT, TgtBA, Zero);
1184
- SDValue Lo = DAG.getNode (PPCISD::Lo, DL, PtrVT, TgtBA, Zero);
1185
-
1186
- // If this is a non-darwin platform, we don't support non-static relo models
1187
- // yet.
1188
- const TargetMachine &TM = DAG.getTarget ();
1189
- if (TM.getRelocationModel () == Reloc::Static ||
1190
- !TM.getSubtarget <PPCSubtarget>().isDarwin ()) {
1191
- // Generate non-pic code that has direct accesses to globals.
1192
- // The address of the global is just (hi(&g)+lo(&g)).
1193
- return DAG.getNode (ISD::ADD, DL, PtrVT, Hi, Lo);
1194
- }
1195
-
1196
- if (TM.getRelocationModel () == Reloc::PIC_) {
1197
- // With PIC, the first instruction is actually "GR+hi(&G)".
1198
- Hi = DAG.getNode (ISD::ADD, DL, PtrVT,
1199
- DAG.getNode (PPCISD::GlobalBaseReg,
1200
- DebugLoc (), PtrVT), Hi);
1201
- }
1202
-
1203
- return DAG.getNode (ISD::ADD, DL, PtrVT, Hi, Lo);
1166
+
1167
+ unsigned MOHiFlag, MOLoFlag;
1168
+ bool isPIC = GetLabelAccessInfo (DAG.getTarget (), MOHiFlag, MOLoFlag);
1169
+ SDValue TgtBAHi = DAG.getBlockAddress (BA, PtrVT, /* isTarget=*/ true , MOHiFlag);
1170
+ SDValue TgtBALo = DAG.getBlockAddress (BA, PtrVT, /* isTarget=*/ true , MOLoFlag);
1171
+ return LowerLabelRef (TgtBAHi, TgtBALo, isPIC, DAG);
1204
1172
}
1205
1173
1206
1174
SDValue PPCTargetLowering::LowerGlobalAddress (SDValue Op,
1207
1175
SelectionDAG &DAG) const {
1208
1176
EVT PtrVT = Op.getValueType ();
1209
1177
GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
1210
- // FIXME there isn't really any debug info here
1211
- DebugLoc dl = GSDN->getDebugLoc ();
1178
+ DebugLoc DL = GSDN->getDebugLoc ();
1212
1179
const GlobalValue *GV = GSDN->getGlobal ();
1213
- SDValue GA = DAG.getTargetGlobalAddress (GV, dl, PtrVT, GSDN->getOffset ());
1214
- SDValue Zero = DAG.getConstant (0 , PtrVT);
1215
1180
1216
1181
const TargetMachine &TM = DAG.getTarget ();
1217
1182
1218
1183
// 64-bit SVR4 ABI code is always position-independent.
1219
1184
// The actual address of the GlobalValue is stored in the TOC.
1220
1185
if (PPCSubTarget.isSVR4ABI () && PPCSubTarget.isPPC64 ()) {
1221
- return DAG.getNode (PPCISD::TOC_ENTRY, dl, MVT::i64, GA,
1186
+ SDValue GA = DAG.getTargetGlobalAddress (GV, DL, PtrVT, GSDN->getOffset ());
1187
+ return DAG.getNode (PPCISD::TOC_ENTRY, DL, MVT::i64, GA,
1222
1188
DAG.getRegister (PPC::X2, MVT::i64));
1223
1189
}
1224
1190
1225
- SDValue Hi = DAG.getNode (PPCISD::Hi, dl, PtrVT, GA, Zero);
1226
- SDValue Lo = DAG.getNode (PPCISD::Lo, dl, PtrVT, GA, Zero);
1191
+ SDValue GA = DAG.getTargetGlobalAddress (GV, DL, PtrVT, GSDN->getOffset ());
1192
+
1193
+
1194
+ SDValue Zero = DAG.getConstant (0 , PtrVT);
1195
+ SDValue Hi = DAG.getNode (PPCISD::Hi, DL, PtrVT, GA, Zero);
1196
+ SDValue Lo = DAG.getNode (PPCISD::Lo, DL, PtrVT, GA, Zero);
1227
1197
1228
1198
// If this is a non-darwin platform, we don't support non-static relo models
1229
1199
// yet.
1230
1200
if (TM.getRelocationModel () == Reloc::Static ||
1231
1201
!TM.getSubtarget <PPCSubtarget>().isDarwin ()) {
1232
1202
// Generate non-pic code that has direct accesses to globals.
1233
1203
// The address of the global is just (hi(&g)+lo(&g)).
1234
- return DAG.getNode (ISD::ADD, dl , PtrVT, Hi, Lo);
1204
+ return DAG.getNode (ISD::ADD, DL , PtrVT, Hi, Lo);
1235
1205
}
1236
1206
1237
1207
if (TM.getRelocationModel () == Reloc::PIC_) {
1238
1208
// With PIC, the first instruction is actually "GR+hi(&G)".
1239
- Hi = DAG.getNode (ISD::ADD, dl , PtrVT,
1209
+ Hi = DAG.getNode (ISD::ADD, DL , PtrVT,
1240
1210
DAG.getNode (PPCISD::GlobalBaseReg,
1241
1211
DebugLoc (), PtrVT), Hi);
1242
1212
}
1243
1213
1244
- Lo = DAG.getNode (ISD::ADD, dl , PtrVT, Hi, Lo);
1214
+ Lo = DAG.getNode (ISD::ADD, DL , PtrVT, Hi, Lo);
1245
1215
1246
1216
if (!TM.getSubtarget <PPCSubtarget>().hasLazyResolverStub (GV, TM))
1247
1217
return Lo;
1248
1218
1249
1219
// If the global is weak or external, we have to go through the lazy
1250
1220
// resolution stub.
1251
- return DAG.getLoad (PtrVT, dl , DAG.getEntryNode (), Lo, MachinePointerInfo (),
1221
+ return DAG.getLoad (PtrVT, DL , DAG.getEntryNode (), Lo, MachinePointerInfo (),
1252
1222
false , false , 0 );
1253
1223
}
1254
1224
@@ -4413,7 +4383,7 @@ SDValue PPCTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
4413
4383
case ISD::ConstantPool: return LowerConstantPool (Op, DAG);
4414
4384
case ISD::BlockAddress: return LowerBlockAddress (Op, DAG);
4415
4385
case ISD::GlobalAddress: return LowerGlobalAddress (Op, DAG);
4416
- case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress (Op, DAG );
4386
+ case ISD::GlobalTLSAddress: llvm_unreachable ( " TLS not implemented for PPC " );
4417
4387
case ISD::JumpTable: return LowerJumpTable (Op, DAG);
4418
4388
case ISD::SETCC: return LowerSETCC (Op, DAG);
4419
4389
case ISD::TRAMPOLINE: return LowerTRAMPOLINE (Op, DAG);
0 commit comments