From 1102f4282ceb430dbc9fcedb9dd2ad25898a09e8 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sat, 4 Apr 2009 00:49:24 +0000 Subject: [PATCH] Basic support for regparm codegen git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68414 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Attr.h | 2 +- lib/CodeGen/CGCall.cpp | 25 ++++++++++++++++++++++--- lib/CodeGen/CodeGenModule.cpp | 3 --- lib/Sema/SemaDeclAttr.cpp | 1 - 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 2a2d0f377b..28f7ec2db6 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -552,7 +552,7 @@ class RegparmAttr : public Attr { public: RegparmAttr(unsigned np) : Attr(Regparm), NumParams(np) {} - unsigned getNumParams() { return NumParams; } + unsigned getNumParams() const { return NumParams; } // Implement isa/cast/dyncast/etc. diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 19f66b1671..e3f824fc74 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1646,6 +1646,7 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, unsigned FuncAttrs = 0; unsigned RetAttrs = 0; + // FIXME: handle sseregparm someday... if (TargetDecl) { if (TargetDecl->getAttr()) FuncAttrs |= llvm::Attribute::NoUnwind; @@ -1691,19 +1692,29 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, 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()) + 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 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, 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; diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b92776face..b4cf533186 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -296,9 +296,6 @@ void CodeGenModule::SetFunctionAttributes(const Decl *D, if (D->getAttr()) F->setCallingConv(llvm::CallingConv::X86_StdCall); - - if (D->getAttr()) - ErrorUnsupported(D, "regparm attribute"); } /// SetFunctionAttributesForDefinition - Set function attributes diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index a68ddf6c00..cecae0e27b 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1471,7 +1471,6 @@ static void HandleRegparmAttr(Decl *d, const AttributeList &Attr, Sema &S) { 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(); -- 2.40.0