@@ -2669,12 +2669,34 @@ static SDValue LowerWRITE_REGISTER(SDValue Op, SelectionDAG &DAG) {
2669
2669
// Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only
2670
2670
// be used to form addressing mode. These wrapped nodes will be selected
2671
2671
// into MOVi.
2672
- static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) {
2672
+ SDValue ARMTargetLowering::LowerConstantPool(SDValue Op,
2673
+ SelectionDAG &DAG) const {
2673
2674
EVT PtrVT = Op.getValueType();
2674
2675
// FIXME there is no actual debug info here
2675
2676
SDLoc dl(Op);
2676
2677
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
2677
2678
SDValue Res;
2679
+
2680
+ // When generating execute-only code Constant Pools must be promoted to the
2681
+ // global data section. It's a bit ugly that we can't share them across basic
2682
+ // blocks, but this way we guarantee that execute-only behaves correct with
2683
+ // position-independent addressing modes.
2684
+ if (Subtarget->genExecuteOnly()) {
2685
+ auto AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>();
2686
+ auto T = const_cast<Type*>(CP->getType());
2687
+ auto C = const_cast<Constant*>(CP->getConstVal());
2688
+ auto M = const_cast<Module*>(DAG.getMachineFunction().
2689
+ getFunction()->getParent());
2690
+ auto L = Twine(DAG.getDataLayout().getPrivateGlobalPrefix()) + "CP" +
2691
+ Twine(DAG.getMachineFunction().getFunctionNumber()) + "_" +
2692
+ Twine(AFI->createPICLabelUId());
2693
+ auto GV = new GlobalVariable(*M, T, /*isConstant=*/true,
2694
+ GlobalVariable::InternalLinkage, C, L);
2695
+ SDValue GA = DAG.getTargetGlobalAddress(dyn_cast<GlobalValue>(GV),
2696
+ dl, PtrVT);
2697
+ return LowerGlobalAddress(GA, DAG);
2698
+ }
2699
+
2678
2700
if (CP->isMachineConstantPoolEntry())
2679
2701
Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT,
2680
2702
CP->getAlignment());
@@ -3118,6 +3140,19 @@ static bool isReadOnly(const GlobalValue *GV) {
3118
3140
isa<Function>(GV);
3119
3141
}
3120
3142
3143
+ SDValue ARMTargetLowering::LowerGlobalAddress(SDValue Op,
3144
+ SelectionDAG &DAG) const {
3145
+ switch (Subtarget->getTargetTriple().getObjectFormat()) {
3146
+ default: llvm_unreachable("unknown object format");
3147
+ case Triple::COFF:
3148
+ return LowerGlobalAddressWindows(Op, DAG);
3149
+ case Triple::ELF:
3150
+ return LowerGlobalAddressELF(Op, DAG);
3151
+ case Triple::MachO:
3152
+ return LowerGlobalAddressDarwin(Op, DAG);
3153
+ }
3154
+ }
3155
+
3121
3156
SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
3122
3157
SelectionDAG &DAG) const {
3123
3158
EVT PtrVT = getPointerTy(DAG.getDataLayout());
@@ -7634,21 +7669,9 @@ SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
7634
7669
switch (Op.getOpcode()) {
7635
7670
default: llvm_unreachable("Don't know how to custom lower this!");
7636
7671
case ISD::WRITE_REGISTER: return LowerWRITE_REGISTER(Op, DAG);
7637
- case ISD::ConstantPool:
7638
- if (Subtarget->genExecuteOnly())
7639
- llvm_unreachable("execute-only should not generate constant pools");
7640
- return LowerConstantPool(Op, DAG);
7672
+ case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
7641
7673
case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
7642
- case ISD::GlobalAddress:
7643
- switch (Subtarget->getTargetTriple().getObjectFormat()) {
7644
- default: llvm_unreachable("unknown object format");
7645
- case Triple::COFF:
7646
- return LowerGlobalAddressWindows(Op, DAG);
7647
- case Triple::ELF:
7648
- return LowerGlobalAddressELF(Op, DAG);
7649
- case Triple::MachO:
7650
- return LowerGlobalAddressDarwin(Op, DAG);
7651
- }
7674
+ case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
7652
7675
case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
7653
7676
case ISD::SELECT: return LowerSELECT(Op, DAG);
7654
7677
case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
0 commit comments