Skip to content

Commit 7880ec5

Browse files
committed
[AVR] Use separate ProgMemWrapper for GlobalAddresses of constants
1 parent 6b94570 commit 7880ec5

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/Target/AVR/AVRISelLowering.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ const char *AVRTargetLowering::getTargetNodeName(unsigned Opcode) const {
236236
NODE(RETI_FLAG);
237237
NODE(CALL);
238238
NODE(WRAPPER);
239+
NODE(PROGMEM_WRAPPER);
239240
NODE(LSL);
240241
NODE(LSR);
241242
NODE(ROL);
@@ -381,13 +382,20 @@ SDValue AVRTargetLowering::LowerGlobalAddress(SDValue Op,
381382
SelectionDAG &DAG) const {
382383
auto DL = DAG.getDataLayout();
383384

384-
const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
385+
const auto *GA = cast<GlobalAddressSDNode>(Op);
386+
const GlobalValue *GV = GA->getGlobal();
387+
388+
unsigned Wrapper = AVRISD::WRAPPER;
389+
if (const auto *GVar = dyn_cast<GlobalVariable>(GV))
390+
if (GVar->isConstant())
391+
Wrapper = AVRISD::PROGMEM_WRAPPER;
392+
385393
int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset();
386394

387395
// Create the TargetGlobalAddress node, folding in the constant offset.
388396
SDValue Result =
389397
DAG.getTargetGlobalAddress(GV, SDLoc(Op), getPointerTy(DL), Offset);
390-
return DAG.getNode(AVRISD::WRAPPER, SDLoc(Op), getPointerTy(DL), Result);
398+
return DAG.getNode(Wrapper, SDLoc(Op), getPointerTy(DL), Result);
391399
}
392400

393401
SDValue AVRTargetLowering::LowerBlockAddress(SDValue Op,

lib/Target/AVR/AVRISelLowering.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum NodeType {
3636
/// A wrapper node for TargetConstantPool,
3737
/// TargetExternalSymbol, and TargetGlobalAddress.
3838
WRAPPER,
39+
PROGMEM_WRAPPER,
3940
LSL, ///< Logical shift left.
4041
LSR, ///< Logical shift right.
4142
ASR, ///< Arithmetic shift right.

lib/Target/AVR/AVRInstrInfo.td

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def SDT_AVRCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i16>]>;
2121
def SDT_AVRCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
2222
def SDT_AVRCall : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
2323
def SDT_AVRWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
24+
def SDT_AVRProgMemWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
2425
def SDT_AVRBrcond : SDTypeProfile<0, 2,
2526
[SDTCisVT<0, OtherVT>, SDTCisVT<1, i8>]>;
2627
def SDT_AVRCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
@@ -46,6 +47,7 @@ def AVRcall : SDNode<"AVRISD::CALL", SDT_AVRCall,
4647
[SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
4748

4849
def AVRWrapper : SDNode<"AVRISD::WRAPPER", SDT_AVRWrapper>;
50+
def AVRProgMemWrapper : SDNode<"AVRISD::PROGMEM_WRAPPER", SDT_AVRProgMemWrapper>;
4951

5052
def AVRbrcond : SDNode<"AVRISD::BRCOND", SDT_AVRBrcond,
5153
[SDNPHasChain, SDNPInGlue]>;
@@ -2033,9 +2035,9 @@ def Asr16 : ShiftPseudo<
20332035
// Non-Instruction Patterns
20342036
//===----------------------------------------------------------------------===//
20352037

2036-
def : Pat<(i8 (load (add i16:$offset, (AVRWrapper tglobaladdr:$base)))),
2038+
def : Pat<(i8 (load (add i16:$offset, (AVRProgMemWrapper tglobaladdr:$base)))),
20372039
(LPMRdZ (SUBIWRdK i16:$offset, tglobaladdr:$base))>;
2038-
def : Pat<(i16 (load (add i16:$offset, (AVRWrapper tglobaladdr:$base)))),
2040+
def : Pat<(i16 (load (add i16:$offset, (AVRProgMemWrapper tglobaladdr:$base)))),
20392041
(LPMWRdZ (SUBIWRdK i16:$offset, tglobaladdr:$base))>;
20402042

20412043
//:TODO: look in x86InstrCompiler.td for odd encoding trick related to

0 commit comments

Comments
 (0)