[cfe-commits] r68414 - in /cfe/trunk: include/clang/AST/Attr.h lib/CodeGen/CGCall.cpp lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDeclAttr.cpp
Anton Korobeynikov
asl at math.spbu.ru
Fri Apr 3 17:49:25 PDT 2009
Author: asl
Date: Fri Apr 3 19:49:24 2009
New Revision: 68414
URL: http://llvm.org/viewvc/llvm-project?rev=68414&view=rev
Log:
Basic support for regparm codegen
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=68414&r1=68413&r2=68414&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Fri Apr 3 19:49:24 2009
@@ -552,7 +552,7 @@
public:
RegparmAttr(unsigned np) : Attr(Regparm), NumParams(np) {}
- unsigned getNumParams() { return NumParams; }
+ unsigned getNumParams() const { return NumParams; }
// Implement isa/cast/dyncast/etc.
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=68414&r1=68413&r2=68414&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Apr 3 19:49:24 2009
@@ -1646,6 +1646,7 @@
unsigned FuncAttrs = 0;
unsigned RetAttrs = 0;
+ // FIXME: handle sseregparm someday...
if (TargetDecl) {
if (TargetDecl->getAttr<NoThrowAttr>())
FuncAttrs |= llvm::Attribute::NoUnwind;
@@ -1691,19 +1692,29 @@
if (RetAttrs)
PAL.push_back(llvm::AttributeWithIndex::get(0, RetAttrs));
+
+ // FIXME: we need to honour command line settings also...
+ // FIXME: RegParm should be reduced in case of nested functions and/or global
+ // register variable.
+ signed RegParm = 0;
+ if (TargetDecl)
+ if (const RegparmAttr *RegParmAttr = TargetDecl->getAttr<RegparmAttr>())
+ RegParm = RegParmAttr->getNumParams();
+
+ unsigned PointerWidth = getContext().Target.getPointerWidth(0);
for (CGFunctionInfo::const_arg_iterator it = FI.arg_begin(),
ie = FI.arg_end(); it != ie; ++it) {
QualType ParamType = it->type;
const ABIArgInfo &AI = it->info;
unsigned Attributes = 0;
-
+
switch (AI.getKind()) {
case ABIArgInfo::Coerce:
break;
case ABIArgInfo::Indirect:
Attributes |= llvm::Attribute::ByVal;
- Attributes |=
+ Attributes |=
llvm::Attribute::constructAlignmentFromInt(AI.getIndirectAlign());
// byval disables readnone and readonly.
FuncAttrs &= ~(llvm::Attribute::ReadOnly |
@@ -1718,8 +1729,16 @@
Attributes |= llvm::Attribute::ZExt;
}
}
+ if (RegParm > 0 &&
+ (ParamType->isIntegerType() || ParamType->isPointerType())) {
+ RegParm -=
+ (Context.getTypeSize(ParamType) + PointerWidth - 1) / PointerWidth;
+ if (RegParm >= 0)
+ Attributes |= llvm::Attribute::InReg;
+ }
+ // FIXME: handle sseregparm someday...
break;
-
+
case ABIArgInfo::Ignore:
// Skip increment, no matching LLVM parameter.
continue;
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=68414&r1=68413&r2=68414&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Apr 3 19:49:24 2009
@@ -296,9 +296,6 @@
if (D->getAttr<StdCallAttr>())
F->setCallingConv(llvm::CallingConv::X86_StdCall);
-
- if (D->getAttr<RegparmAttr>())
- ErrorUnsupported(D, "regparm attribute");
}
/// SetFunctionAttributesForDefinition - Set function attributes
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=68414&r1=68413&r2=68414&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr 3 19:49:24 2009
@@ -1471,7 +1471,6 @@
return;
}
- // FIXME: we need to honour command line settings also...
if (NumParams.getLimitedValue(4) > S.Context.Target.getRegParmMax()) {
S.Diag(Attr.getLoc(), diag::err_attribute_regparm_invalid_number)
<< S.Context.Target.getRegParmMax() << NumParamsExpr->getSourceRange();
More information about the cfe-commits
mailing list