Skip to content

Commit f942cde

Browse files
committed
MSP430: Avoid using getPointerSize/getPointerTy
Use the contextually appropriate value instead of relying on the default address space default parameters. Usually you should be reusing a pre-existing type.
1 parent 6d481ad commit f942cde

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

llvm/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ bool MSP430DAGToDAGISel::SelectAddr(SDValue N,
255255
Base = (AM.BaseType == MSP430ISelAddressMode::FrameIndexBase)
256256
? CurDAG->getTargetFrameIndex(
257257
AM.Base.FrameIndex,
258-
getTargetLowering()->getPointerTy(CurDAG->getDataLayout()))
258+
N.getValueType())
259259
: AM.Base.Reg;
260260

261261
if (AM.GV)

llvm/lib/Target/MSP430/MSP430ISelLowering.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -670,16 +670,17 @@ SDValue MSP430TargetLowering::LowerCCCArguments(
670670
InVals.push_back(ArgValue);
671671
}
672672
} else {
673-
// Only arguments passed on the stack should make it here.
673+
// Only arguments passed on the stack should make it here.
674674
assert(VA.isMemLoc());
675675

676676
SDValue InVal;
677677
ISD::ArgFlagsTy Flags = Ins[i].Flags;
678678

679679
if (Flags.isByVal()) {
680+
MVT PtrVT = VA.getLocVT();
680681
int FI = MFI.CreateFixedObject(Flags.getByValSize(),
681682
VA.getLocMemOffset(), true);
682-
InVal = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
683+
InVal = DAG.getFrameIndex(FI, PtrVT);
683684
} else {
684685
// Load the argument to a virtual register
685686
unsigned ObjSize = VA.getLocVT().getSizeInBits()/8;
@@ -777,13 +778,14 @@ MSP430TargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
777778
if (!Reg)
778779
llvm_unreachable("sret virtual register not created in entry block");
779780

781+
MVT PtrVT = getFrameIndexTy(DAG.getDataLayout());
780782
SDValue Val =
781-
DAG.getCopyFromReg(Chain, dl, Reg, getPointerTy(DAG.getDataLayout()));
783+
DAG.getCopyFromReg(Chain, dl, Reg, PtrVT);
782784
unsigned R12 = MSP430::R12;
783785

784786
Chain = DAG.getCopyToReg(Chain, dl, R12, Val, Flag);
785787
Flag = Chain.getValue(1);
786-
RetOps.push_back(DAG.getRegister(R12, getPointerTy(DAG.getDataLayout())));
788+
RetOps.push_back(DAG.getRegister(R12, PtrVT));
787789
}
788790

789791
unsigned Opc = (CallConv == CallingConv::MSP430_INTR ?
@@ -814,7 +816,7 @@ SDValue MSP430TargetLowering::LowerCCCCallTo(
814816

815817
// Get a count of how many bytes are to be pushed on the stack.
816818
unsigned NumBytes = CCInfo.getNextStackOffset();
817-
auto PtrVT = getPointerTy(DAG.getDataLayout());
819+
MVT PtrVT = getFrameIndexTy(DAG.getDataLayout());
818820

819821
Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, dl);
820822

@@ -1010,7 +1012,7 @@ SDValue MSP430TargetLowering::LowerGlobalAddress(SDValue Op,
10101012
SelectionDAG &DAG) const {
10111013
const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
10121014
int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset();
1013-
auto PtrVT = getPointerTy(DAG.getDataLayout());
1015+
EVT PtrVT = Op.getValueType();
10141016

10151017
// Create the TargetGlobalAddress node, folding in the constant offset.
10161018
SDValue Result = DAG.getTargetGlobalAddress(GV, SDLoc(Op), PtrVT, Offset);
@@ -1021,7 +1023,7 @@ SDValue MSP430TargetLowering::LowerExternalSymbol(SDValue Op,
10211023
SelectionDAG &DAG) const {
10221024
SDLoc dl(Op);
10231025
const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol();
1024-
auto PtrVT = getPointerTy(DAG.getDataLayout());
1026+
EVT PtrVT = Op.getValueType();
10251027
SDValue Result = DAG.getTargetExternalSymbol(Sym, PtrVT);
10261028

10271029
return DAG.getNode(MSP430ISD::Wrapper, dl, PtrVT, Result);
@@ -1030,8 +1032,8 @@ SDValue MSP430TargetLowering::LowerExternalSymbol(SDValue Op,
10301032
SDValue MSP430TargetLowering::LowerBlockAddress(SDValue Op,
10311033
SelectionDAG &DAG) const {
10321034
SDLoc dl(Op);
1033-
auto PtrVT = getPointerTy(DAG.getDataLayout());
10341035
const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
1036+
EVT PtrVT = Op.getValueType();
10351037
SDValue Result = DAG.getTargetBlockAddress(BA, PtrVT);
10361038

10371039
return DAG.getNode(MSP430ISD::Wrapper, dl, PtrVT, Result);
@@ -1248,11 +1250,11 @@ MSP430TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) const {
12481250
MachineFunction &MF = DAG.getMachineFunction();
12491251
MSP430MachineFunctionInfo *FuncInfo = MF.getInfo<MSP430MachineFunctionInfo>();
12501252
int ReturnAddrIndex = FuncInfo->getRAIndex();
1251-
auto PtrVT = getPointerTy(MF.getDataLayout());
1253+
MVT PtrVT = getFrameIndexTy(MF.getDataLayout());
12521254

12531255
if (ReturnAddrIndex == 0) {
12541256
// Set up a frame object for the return address.
1255-
uint64_t SlotSize = MF.getDataLayout().getPointerSize();
1257+
uint64_t SlotSize = PtrVT.getStoreSize();
12561258
ReturnAddrIndex = MF.getFrameInfo().CreateFixedObject(SlotSize, -SlotSize,
12571259
true);
12581260
FuncInfo->setRAIndex(ReturnAddrIndex);
@@ -1271,12 +1273,12 @@ SDValue MSP430TargetLowering::LowerRETURNADDR(SDValue Op,
12711273

12721274
unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
12731275
SDLoc dl(Op);
1274-
auto PtrVT = getPointerTy(DAG.getDataLayout());
1276+
EVT PtrVT = Op.getValueType();
12751277

12761278
if (Depth > 0) {
12771279
SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
12781280
SDValue Offset =
1279-
DAG.getConstant(DAG.getDataLayout().getPointerSize(), dl, MVT::i16);
1281+
DAG.getConstant(PtrVT.getStoreSize(), dl, MVT::i16);
12801282
return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(),
12811283
DAG.getNode(ISD::ADD, dl, PtrVT, FrameAddr, Offset),
12821284
MachinePointerInfo());
@@ -1308,22 +1310,24 @@ SDValue MSP430TargetLowering::LowerVASTART(SDValue Op,
13081310
SelectionDAG &DAG) const {
13091311
MachineFunction &MF = DAG.getMachineFunction();
13101312
MSP430MachineFunctionInfo *FuncInfo = MF.getInfo<MSP430MachineFunctionInfo>();
1311-
auto PtrVT = getPointerTy(DAG.getDataLayout());
1313+
1314+
SDValue Ptr = Op.getOperand(1);
1315+
EVT PtrVT = Ptr.getValueType();
13121316

13131317
// Frame index of first vararg argument
13141318
SDValue FrameIndex =
13151319
DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT);
13161320
const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
13171321

13181322
// Create a store of the frame index to the location operand
1319-
return DAG.getStore(Op.getOperand(0), SDLoc(Op), FrameIndex, Op.getOperand(1),
1323+
return DAG.getStore(Op.getOperand(0), SDLoc(Op), FrameIndex, Ptr,
13201324
MachinePointerInfo(SV));
13211325
}
13221326

13231327
SDValue MSP430TargetLowering::LowerJumpTable(SDValue Op,
13241328
SelectionDAG &DAG) const {
13251329
JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
1326-
auto PtrVT = getPointerTy(DAG.getDataLayout());
1330+
EVT PtrVT = Op.getValueType();
13271331
SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
13281332
return DAG.getNode(MSP430ISD::Wrapper, SDLoc(JT), PtrVT, Result);
13291333
}

0 commit comments

Comments
 (0)