The first email bounced, so lets try again.
This patch implements the first part of the proposed solution to bug
1521. It adds the byval attribute and propagates it to DAG level.
The patch also changes the matching code for CCIfType, so that no
backend matches a byval argument. Instead, a backend should be
modified to use a CCIfStruct (see the X86 backend). For now CCIfStruct
is just a placeholder that aborts at run time.
Then plan now is to implement a CCIfStruct that is common to all
backends and just reproduces the same behavior of llvm-gcc. Later on
we can change this to allow for backend specific code to actually fix
the bug.
Sounds like the right direction? OK to commit to trunk?
Cheers,
--
Rafael Avila de Espindola
Google Ireland Ltd.
Gordon House
Barrow Street
Dublin 4
Ireland
Registered in Dublin, Ireland
Registration Number: 368047
Index: include/llvm/ParameterAttributes.h
===================================================================
--- include/llvm/ParameterAttributes.h (revision 37894)
+++ include/llvm/ParameterAttributes.h (working copy)
@@ -36,7 +36,8 @@
InReg = 1 << 3, ///< force argument to be passed in register
StructRet = 1 << 4, ///< hidden pointer to structure to return
NoUnwind = 1 << 5, ///< Function doesn't unwind stack
- NoAlias = 1 << 6 ///< Considered to not alias after call.
+ NoAlias = 1 << 6, ///< Considered to not alias after call.
+ ByVal = 1 << 7 ///< Pass structure by value
};
}
Index: include/llvm/CodeGen/SelectionDAGNodes.h
===================================================================
--- include/llvm/CodeGen/SelectionDAGNodes.h (revision 37894)
+++ include/llvm/CodeGen/SelectionDAGNodes.h (working copy)
@@ -63,6 +63,8 @@
InRegOffs = 2,
StructReturn = 1<<3, ///< Hidden struct-return pointer
StructReturnOffs = 3,
+ SturtByVal = 1<<4, ///< Struct passed by value
+ StructByVal = 4,
OrigAlignment = 0x1F<<27,
OrigAlignmentOffs = 27
};
Index: utils/TableGen/CallingConvEmitter.cpp
===================================================================
--- utils/TableGen/CallingConvEmitter.cpp (revision 37894)
+++ utils/TableGen/CallingConvEmitter.cpp (working copy)
@@ -67,12 +67,14 @@
O << IndentStr << "if (";
if (Action->isSubClassOf("CCIfType")) {
+ O << "!(ArgFlags & ISD::ParamFlags::StructByVal) && (";
ListInit *VTs = Action->getValueAsListInit("VTs");
for (unsigned i = 0, e = VTs->getSize(); i != e; ++i) {
Record *VT = VTs->getElementAsRecord(i);
if (i != 0) O << " ||\n " << IndentStr;
O << "LocVT == " << getEnumName(getValueType(VT));
}
+ O << ")";
} else if (Action->isSubClassOf("CCIf")) {
O << Action->getValueAsString("Predicate");
@@ -129,10 +131,11 @@
<< IndentStr << IndentStr << "LocInfo = CCValAssign::ZExt;\n"
<< IndentStr << "else\n"
<< IndentStr << IndentStr << "LocInfo = CCValAssign::AExt;\n";
+ } else if (Action->isSubClassOf("CCStructAssign")) {
+ O << "assert(0 && \"Not Implemented\");\n";
} else {
Action->dump();
throw "Unknown CCAction!";
}
}
}
-
Index: lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (revision 37894)
+++ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (working copy)
@@ -3804,6 +3804,8 @@
Flags |= ISD::ParamFlags::InReg;
if (Attrs && Attrs->paramHasAttr(j, ParamAttr::StructRet))
Flags |= ISD::ParamFlags::StructReturn;
+ if (Attrs && Attrs->paramHasAttr(j, ParamAttr::ByVal))
+ Flags |= ISD::ParamFlags::StructByVal;
Flags |= (OriginalAlignment << ISD::ParamFlags::OrigAlignmentOffs);
switch (getTypeAction(VT)) {
Index: lib/Target/X86/X86CallingConv.td
===================================================================
--- lib/Target/X86/X86CallingConv.td (revision 37894)
+++ lib/Target/X86/X86CallingConv.td (working copy)
@@ -94,6 +94,8 @@
// Promote i8/i16 arguments to i32.
CCIfType<[i8, i16], CCPromoteToType<i32>>,
+ CCIfStruct<CCStructAssign<[RDI, RSI, RDX, RCX, R8, R9 ]>>,
+
// The first 6 integer arguments are passed in integer registers.
CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D, R9D]>>,
CCIfType<[i64], CCAssignToReg<[RDI, RSI, RDX, RCX, R8 , R9 ]>>,
@@ -168,5 +170,3 @@
// Otherwise, same as everything else.
CCDelegateTo<CC_X86_32_Common>
]>;
-
-
Index: lib/Target/TargetCallingConv.td
===================================================================
--- lib/Target/TargetCallingConv.td (revision 37894)
+++ lib/Target/TargetCallingConv.td (working copy)
@@ -32,6 +32,11 @@
string Predicate = predicate;
}
+/// CCIfStruct - If the current argument is struct, apply
+/// Action A.
+class CCIfStruct<CCAction A> : CCIf<"ArgFlags & ISD::ParamFlags::StructByVal", A> {
+}
+
/// CCIfCC - Match of the current calling convention is 'CC'.
class CCIfCC<string CC, CCAction A>
: CCIf<!strconcat("State.getCallingConv() == ", CC), A> {}
@@ -57,6 +62,12 @@
int Align = align;
}
+/// CCStructAssign - This action always matches: it will use the C ABI and
+/// the register availability to decided whether to assign to a set of
+/// registers or to a stack slot.
+class CCStructAssign<list<Register> regList> : CCAction {
+ list<Register> RegList = regList;
+}
/// CCPromoteToType - If applied, this promotes the specified current value to
/// the specified type.
@@ -75,4 +86,3 @@
class CallingConv<list<CCAction> actions> {
list<CCAction> Actions = actions;
}
-
Index: lib/VMCore/Function.cpp
===================================================================
--- lib/VMCore/Function.cpp (revision 37894)
+++ lib/VMCore/Function.cpp (working copy)
@@ -103,6 +103,8 @@
Result += "noalias ";
if (Attrs & ParamAttr::StructRet)
Result += "sret ";
+ if (Attrs & ParamAttr::ByVal)
+ Result += "byval ";
return Result;
}
Index: lib/AsmParser/llvmAsmParser.y
===================================================================
--- lib/AsmParser/llvmAsmParser.y (revision 37894)
+++ lib/AsmParser/llvmAsmParser.y (working copy)
@@ -1101,7 +1101,7 @@
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
// Function Attributes
-%token NORETURN INREG SRET NOUNWIND NOALIAS
+%token NORETURN INREG SRET NOUNWIND NOALIAS BYVAL
// Visibility Styles
%token DEFAULT HIDDEN PROTECTED
@@ -1229,6 +1229,7 @@
| INREG { $$ = ParamAttr::InReg; }
| SRET { $$ = ParamAttr::StructRet; }
| NOALIAS { $$ = ParamAttr::NoAlias; }
+ | BYVAL { $$ = ParamAttr::ByVal; }
;
OptParamAttrs : /* empty */ { $$ = ParamAttr::None; }
Index: lib/AsmParser/Lexer.l
===================================================================
--- lib/AsmParser/Lexer.l (revision 37894)
+++ lib/AsmParser/Lexer.l (working copy)
@@ -230,6 +230,7 @@
nounwind { return NOUNWIND; }
noreturn { return NORETURN; }
noalias { return NOALIAS; }
+byval { return BYVAL; }
void { RET_TY(Type::VoidTy, VOID); }
float { RET_TY(Type::FloatTy, FLOAT); }
_______________________________________________
llvm-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits