Lower addresses of globals

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75960 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anton Korobeynikov 2009-07-16 13:57:27 +00:00
parent ed1a6d4cad
commit bad769f11a
4 changed files with 48 additions and 2 deletions

View File

@ -65,6 +65,7 @@ SystemZTargetLowering::SystemZTargetLowering(SystemZTargetMachine &tm) :
setOperationAction(ISD::BRCOND, MVT::Other, Expand); setOperationAction(ISD::BRCOND, MVT::Other, Expand);
setOperationAction(ISD::BR_CC, MVT::i32, Custom); setOperationAction(ISD::BR_CC, MVT::i32, Custom);
setOperationAction(ISD::BR_CC, MVT::i64, Custom); setOperationAction(ISD::BR_CC, MVT::i64, Custom);
setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
// FIXME: Can we lower these 2 efficiently? // FIXME: Can we lower these 2 efficiently?
setOperationAction(ISD::SETCC, MVT::i32, Expand); setOperationAction(ISD::SETCC, MVT::i32, Expand);
@ -87,6 +88,7 @@ SDValue SystemZTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
case ISD::CALL: return LowerCALL(Op, DAG); case ISD::CALL: return LowerCALL(Op, DAG);
case ISD::BR_CC: return LowerBR_CC(Op, DAG); case ISD::BR_CC: return LowerBR_CC(Op, DAG);
case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
default: default:
assert(0 && "unimplemented operand"); assert(0 && "unimplemented operand");
return SDValue(); return SDValue();
@ -511,6 +513,16 @@ SDValue SystemZTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) {
return DAG.getNode(SystemZISD::SELECT, dl, VTs, &Ops[0], Ops.size()); return DAG.getNode(SystemZISD::SELECT, dl, VTs, &Ops[0], Ops.size());
} }
SDValue SystemZTargetLowering::LowerGlobalAddress(SDValue Op,
SelectionDAG &DAG) {
DebugLoc dl = Op.getDebugLoc();
GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
SDValue GA = DAG.getTargetGlobalAddress(GV, getPointerTy());
// FIXME: Verify stuff for constant globals entries
return DAG.getNode(SystemZISD::PCRelativeWrapper, dl, getPointerTy(), GA);
}
const char *SystemZTargetLowering::getTargetNodeName(unsigned Opcode) const { const char *SystemZTargetLowering::getTargetNodeName(unsigned Opcode) const {
switch (Opcode) { switch (Opcode) {
@ -520,6 +532,7 @@ const char *SystemZTargetLowering::getTargetNodeName(unsigned Opcode) const {
case SystemZISD::CMP: return "SystemZISD::CMP"; case SystemZISD::CMP: return "SystemZISD::CMP";
case SystemZISD::UCMP: return "SystemZISD::UCMP"; case SystemZISD::UCMP: return "SystemZISD::UCMP";
case SystemZISD::SELECT: return "SystemZISD::SELECT"; case SystemZISD::SELECT: return "SystemZISD::SELECT";
case SystemZISD::PCRelativeWrapper: return "SystemZISD::PCRelativeWrapper";
default: return NULL; default: return NULL;
} }
} }

View File

@ -32,6 +32,9 @@ namespace llvm {
/// instruction, which includes a bunch of information. /// instruction, which includes a bunch of information.
CALL, CALL,
/// PCRelativeWrapper - PC relative address
PCRelativeWrapper,
/// CMP, UCMP - Compare instruction /// CMP, UCMP - Compare instruction
CMP, CMP,
UCMP, UCMP,
@ -66,6 +69,7 @@ namespace llvm {
SDValue LowerCALL(SDValue Op, SelectionDAG &DAG); SDValue LowerCALL(SDValue Op, SelectionDAG &DAG);
SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG); SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG);
SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG); SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG);
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG);
SDValue LowerCCCArguments(SDValue Op, SelectionDAG &DAG); SDValue LowerCCCArguments(SDValue Op, SelectionDAG &DAG);
SDValue LowerCCCCallTo(SDValue Op, SelectionDAG &DAG, unsigned CC); SDValue LowerCCCCallTo(SDValue Op, SelectionDAG &DAG, unsigned CC);

View File

@ -24,7 +24,7 @@ class SDTCisI64<int OpNum> : SDTCisVT<OpNum, i64>;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Type Profiles. // Type Profiles.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def SDT_SystemZCall : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>; def SDT_SystemZCall : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
def SDT_SystemZCallSeqStart : SDCallSeqStart<[SDTCisI64<0>]>; def SDT_SystemZCallSeqStart : SDCallSeqStart<[SDTCisI64<0>]>;
def SDT_SystemZCallSeqEnd : SDCallSeqEnd<[SDTCisI64<0>, SDTCisI64<1>]>; def SDT_SystemZCallSeqEnd : SDCallSeqEnd<[SDTCisI64<0>, SDTCisI64<1>]>;
def SDT_CmpTest : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>; def SDT_CmpTest : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
@ -34,7 +34,8 @@ def SDT_BrCond : SDTypeProfile<0, 2,
def SDT_SelectCC : SDTypeProfile<1, 3, def SDT_SelectCC : SDTypeProfile<1, 3,
[SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
SDTCisI8<3>]>; SDTCisI8<3>]>;
def SDT_Address : SDTypeProfile<1, 1,
[SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// SystemZ Specific Node Definitions. // SystemZ Specific Node Definitions.
@ -54,6 +55,7 @@ def SystemZucmp : SDNode<"SystemZISD::UCMP", SDT_CmpTest, [SDNPOutFlag]>;
def SystemZbrcond : SDNode<"SystemZISD::BRCOND", SDT_BrCond, def SystemZbrcond : SDNode<"SystemZISD::BRCOND", SDT_BrCond,
[SDNPHasChain, SDNPInFlag]>; [SDNPHasChain, SDNPInFlag]>;
def SystemZselect : SDNode<"SystemZISD::SELECT", SDT_SelectCC, [SDNPInFlag]>; def SystemZselect : SDNode<"SystemZISD::SELECT", SDT_SelectCC, [SDNPInFlag]>;
def SystemZpcrelwrapper : SDNode<"SystemZISD::PCRelativeWrapper", SDT_Address, []>;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Instruction Pattern Stuff. // Instruction Pattern Stuff.
@ -315,6 +317,10 @@ let isReMaterializable = 1 in
def LA64r : Pseudo<(outs GR64:$dst), (ins laaddr:$src), def LA64r : Pseudo<(outs GR64:$dst), (ins laaddr:$src),
"lay\t{$dst, $src}", "lay\t{$dst, $src}",
[(set GR64:$dst, laaddr:$src)]>; [(set GR64:$dst, laaddr:$src)]>;
def LA64rm : Pseudo<(outs GR64:$dst), (ins i64imm:$src),
"larl\t{$dst, $src}",
[(set GR64:$dst,
(SystemZpcrelwrapper tglobaladdr:$src))]>;
let neverHasSideEffects = 1 in let neverHasSideEffects = 1 in
def NOP : Pseudo<(outs), (ins), "# no-op", []>; def NOP : Pseudo<(outs), (ins), "# no-op", []>;

View File

@ -0,0 +1,23 @@
; RUN: llvm-as < %s | llc | grep larl | count 3
target datalayout = "E-p:64:64:64-i1:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128"
target triple = "s390x-linux"
@bar = common global i64 0, align 8 ; <i64*> [#uses=3]
define i64 @foo() nounwind readonly {
entry:
%tmp = load i64* @bar ; <i64> [#uses=1]
ret i64 %tmp
}
define i64* @foo2() nounwind readnone {
entry:
ret i64* @bar
}
define i64* @foo3(i64 %idx) nounwind readnone {
entry:
%add.ptr.sum = add i64 %idx, 1 ; <i64> [#uses=1]
%add.ptr2 = getelementptr i64* @bar, i64 %add.ptr.sum ; <i64*> [#uses=1]
ret i64* %add.ptr2
}