Skip to content

Commit 66011c1

Browse files
committed
propagate struct size and alignment of byval arguments to the DAG
llvm-svn: 40986
1 parent 7014615 commit 66011c1

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

llvm/include/llvm/CodeGen/CallingConvLower.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ class CCState {
190190
StackOffset += Size;
191191
return Result;
192192
}
193+
194+
void HandleStruct(unsigned ValNo, MVT::ValueType ValVT,
195+
MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
196+
unsigned ArgFlags);
193197
private:
194198
/// MarkAllocated - Mark a register and all of its aliases as allocated.
195199
void MarkAllocated(unsigned Reg);

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ namespace ISD {
6868
ByValOffs = 4,
6969
Nest = 1<<5, ///< Parameter is nested function static chain
7070
NestOffs = 5,
71+
ByValAlign = 0xF << 6, //< The alignment of the struct
72+
ByValAlignOffs = 6,
73+
ByValSize = 0x1ffff << 10, //< The size of the struct
74+
ByValSizeOffs = 10,
7175
OrigAlignment = 0x1F<<27,
7276
OrigAlignmentOffs = 27
7377
};
@@ -200,6 +204,10 @@ namespace ISD {
200204
/// Bit 0 - signness
201205
/// Bit 1 - 'inreg' attribute
202206
/// Bit 2 - 'sret' attribute
207+
/// Bit 4 - 'byval' attribute
208+
/// Bit 5 - 'nest' attribute
209+
/// Bit 6-9 - alignment of byval structures
210+
/// Bit 10-26 - size of byval structures
203211
/// Bits 31:27 - argument ABI alignment in the first argument piece and
204212
/// alignment '1' in other argument pieces.
205213
CALL,

llvm/lib/CodeGen/SelectionDAG/CallingConvLower.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ CCState::CCState(unsigned CC, bool isVarArg, const TargetMachine &tm,
2828
UsedRegs.resize(MRI.getNumRegs());
2929
}
3030

31+
void CCState::HandleStruct(unsigned ValNo, MVT::ValueType ValVT,
32+
MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
33+
unsigned ArgFlags) {
34+
unsigned Align = 1 << ((ArgFlags & ISD::ParamFlags::ByValAlign) >>
35+
ISD::ParamFlags::ByValAlignOffs);
36+
unsigned Size = (ArgFlags & ISD::ParamFlags::ByValSize) >>
37+
ISD::ParamFlags::ByValSizeOffs;
38+
unsigned Offset = AllocateStack(Size, Align);
39+
40+
addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
41+
}
3142

3243
/// MarkAllocated - Mark a register and all of its aliases as allocated.
3344
void CCState::MarkAllocated(unsigned Reg) {
@@ -99,4 +110,3 @@ void CCState::AnalyzeCallResult(SDNode *TheCall, CCAssignFn Fn) {
99110
}
100111
}
101112
}
102-

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3836,8 +3836,15 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
38363836
Flags |= ISD::ParamFlags::InReg;
38373837
if (Attrs && Attrs->paramHasAttr(j, ParamAttr::StructRet))
38383838
Flags |= ISD::ParamFlags::StructReturn;
3839-
if (Attrs && Attrs->paramHasAttr(j, ParamAttr::ByVal))
3839+
if (Attrs && Attrs->paramHasAttr(j, ParamAttr::ByVal)) {
38403840
Flags |= ISD::ParamFlags::ByVal;
3841+
const PointerType *Ty = cast<PointerType>(I->getType());
3842+
const StructType *STy = cast<StructType>(Ty->getElementType());
3843+
unsigned StructAlign = Log2_32(getTargetData()->getABITypeAlignment(STy));
3844+
unsigned StructSize = getTargetData()->getTypeSize(STy);
3845+
Flags |= (StructAlign << ISD::ParamFlags::ByValAlignOffs);
3846+
Flags |= (StructSize << ISD::ParamFlags::ByValSizeOffs);
3847+
}
38413848
if (Attrs && Attrs->paramHasAttr(j, ParamAttr::Nest))
38423849
Flags |= ISD::ParamFlags::Nest;
38433850
Flags |= (OriginalAlignment << ISD::ParamFlags::OrigAlignmentOffs);

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,12 @@ X86TargetLowering::LowerX86_64CCCArguments(SDOperand Op, SelectionDAG &DAG) {
12601260
int FI = MFI->CreateFixedObject(MVT::getSizeInBits(VA.getValVT())/8,
12611261
VA.getLocMemOffset());
12621262
SDOperand FIN = DAG.getFrameIndex(FI, getPointerTy());
1263-
ArgValues.push_back(DAG.getLoad(VA.getValVT(), Root, FIN, NULL, 0));
1263+
1264+
unsigned Flags = cast<ConstantSDNode>(Op.getOperand(3 + i))->getValue();
1265+
if (Flags & ISD::ParamFlags::ByVal)
1266+
ArgValues.push_back(FIN);
1267+
else
1268+
ArgValues.push_back(DAG.getLoad(VA.getValVT(), Root, FIN, NULL, 0));
12641269
}
12651270
}
12661271

llvm/utils/TableGen/CallingConvEmitter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ void CallingConvEmitter::EmitAction(Record *Action,
130130
<< IndentStr << "else\n"
131131
<< IndentStr << IndentStr << "LocInfo = CCValAssign::AExt;\n";
132132
} else if (Action->isSubClassOf("CCStructAssign")) {
133-
O << "assert(0 && \"Not Implemented\");\n";
133+
O << IndentStr <<
134+
"State.HandleStruct(ValNo, ValVT, LocVT, LocInfo, ArgFlags);\n";
135+
O << IndentStr << "return false;\n";
134136
} else {
135137
Action->dump();
136138
throw "Unknown CCAction!";

0 commit comments

Comments
 (0)