[cfe-commits] r56038 - in /cfe/trunk/lib/CodeGen: CGCall.cpp CGCall.h CodeGenFunction.h CodeGenModule.cpp
Daniel Dunbar
daniel at zuster.org
Tue Sep 9 17:32:18 PDT 2008
Author: ddunbar
Date: Tue Sep 9 19:32:18 2008
New Revision: 56038
URL: http://llvm.org/viewvc/llvm-project?rev=56038&view=rev
Log:
Tweak CGCall functions:
- Move actual param attr list creation to
CodeGenFunction::ConstructParamAttrList.
- Make ReturnTypeUsesSret static.
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGCall.h
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=56038&r1=56037&r2=56038&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Sep 9 19:32:18 2008
@@ -23,53 +23,6 @@
/***/
-static void
-constructParamAttrListInternal(const Decl *TargetDecl,
- const llvm::SmallVector<QualType, 16> &ArgTypes,
- ParamAttrListType &PAL) {
- unsigned FuncAttrs = 0;
-
- if (TargetDecl) {
- if (TargetDecl->getAttr<NoThrowAttr>())
- FuncAttrs |= llvm::ParamAttr::NoUnwind;
- if (TargetDecl->getAttr<NoReturnAttr>())
- FuncAttrs |= llvm::ParamAttr::NoReturn;
- }
-
- unsigned Index = 1;
- if (CodeGenFunction::hasAggregateLLVMType(ArgTypes[0])) {
- PAL.push_back(llvm::ParamAttrsWithIndex::get(Index,
- llvm::ParamAttr::StructRet));
- ++Index;
- } else if (ArgTypes[0]->isPromotableIntegerType()) {
- if (ArgTypes[0]->isSignedIntegerType()) {
- FuncAttrs |= llvm::ParamAttr::SExt;
- } else if (ArgTypes[0]->isUnsignedIntegerType()) {
- FuncAttrs |= llvm::ParamAttr::ZExt;
- }
- }
- if (FuncAttrs)
- PAL.push_back(llvm::ParamAttrsWithIndex::get(0, FuncAttrs));
- for (llvm::SmallVector<QualType, 8>::const_iterator i = ArgTypes.begin() + 1,
- e = ArgTypes.end(); i != e; ++i, ++Index) {
- QualType ParamType = *i;
- unsigned ParamAttrs = 0;
- if (ParamType->isRecordType())
- ParamAttrs |= llvm::ParamAttr::ByVal;
- if (ParamType->isPromotableIntegerType()) {
- if (ParamType->isSignedIntegerType()) {
- ParamAttrs |= llvm::ParamAttr::SExt;
- } else if (ParamType->isUnsignedIntegerType()) {
- ParamAttrs |= llvm::ParamAttr::ZExt;
- }
- }
- if (ParamAttrs)
- PAL.push_back(llvm::ParamAttrsWithIndex::get(Index, ParamAttrs));
- }
-}
-
-/***/
-
// FIXME: Use iterator and sidestep silly type array creation.
CGFunctionInfo::CGFunctionInfo(const FunctionDecl *FD)
@@ -96,23 +49,28 @@
ArgTypes.push_back((*i)->getType());
}
-void CGFunctionInfo::constructParamAttrList(ParamAttrListType &PAL) const {
- constructParamAttrListInternal(TheDecl, ArgTypes, PAL);
+ArgTypeIterator CGFunctionInfo::argtypes_begin() const {
+ return ArgTypes.begin();
+}
+
+ArgTypeIterator CGFunctionInfo::argtypes_end() const {
+ return ArgTypes.end();
}
/***/
-CGCallInfo::CGCallInfo(QualType _ResultType, const CallArgList &_Args)
- : ResultType(_ResultType),
- Args(_Args) {
- ArgTypes.push_back(ResultType);
- for (CallArgList::const_iterator i = Args.begin(), e = Args.end(); i!=e; ++i)
+CGCallInfo::CGCallInfo(QualType _ResultType, const CallArgList &_Args) {
+ ArgTypes.push_back(_ResultType);
+ for (CallArgList::const_iterator i = _Args.begin(), e = _Args.end(); i!=e; ++i)
ArgTypes.push_back(i->second);
}
-void CGCallInfo::constructParamAttrList(ParamAttrListType &PAL) const {
- // FIXME: Provide TargetDecl so nounwind, noreturn, etc, etc get set.
- constructParamAttrListInternal(0, ArgTypes, PAL);
+ArgTypeIterator CGCallInfo::argtypes_begin() const {
+ return ArgTypes.begin();
+}
+
+ArgTypeIterator CGCallInfo::argtypes_end() const {
+ return ArgTypes.end();
}
/***/
@@ -121,6 +79,51 @@
return hasAggregateLLVMType(RetTy);
}
+void CodeGenFunction::ConstructParamAttrList(const Decl *TargetDecl,
+ ArgTypeIterator begin,
+ ArgTypeIterator end,
+ ParamAttrListType &PAL) {
+ unsigned FuncAttrs = 0;
+
+ if (TargetDecl) {
+ if (TargetDecl->getAttr<NoThrowAttr>())
+ FuncAttrs |= llvm::ParamAttr::NoUnwind;
+ if (TargetDecl->getAttr<NoReturnAttr>())
+ FuncAttrs |= llvm::ParamAttr::NoReturn;
+ }
+
+ QualType ResTy = *begin;
+ unsigned Index = 1;
+ if (CodeGenFunction::hasAggregateLLVMType(ResTy)) {
+ PAL.push_back(llvm::ParamAttrsWithIndex::get(Index,
+ llvm::ParamAttr::StructRet));
+ ++Index;
+ } else if (ResTy->isPromotableIntegerType()) {
+ if (ResTy->isSignedIntegerType()) {
+ FuncAttrs |= llvm::ParamAttr::SExt;
+ } else if (ResTy->isUnsignedIntegerType()) {
+ FuncAttrs |= llvm::ParamAttr::ZExt;
+ }
+ }
+ if (FuncAttrs)
+ PAL.push_back(llvm::ParamAttrsWithIndex::get(0, FuncAttrs));
+ for (++begin; begin != end; ++begin, ++Index) {
+ QualType ParamType = *begin;
+ unsigned ParamAttrs = 0;
+ if (ParamType->isRecordType())
+ ParamAttrs |= llvm::ParamAttr::ByVal;
+ if (ParamType->isPromotableIntegerType()) {
+ if (ParamType->isSignedIntegerType()) {
+ ParamAttrs |= llvm::ParamAttr::SExt;
+ } else if (ParamType->isUnsignedIntegerType()) {
+ ParamAttrs |= llvm::ParamAttr::ZExt;
+ }
+ }
+ if (ParamAttrs)
+ PAL.push_back(llvm::ParamAttrsWithIndex::get(Index, ParamAttrs));
+ }
+}
+
void CodeGenFunction::EmitFunctionProlog(llvm::Function *Fn,
QualType RetTy,
const FunctionArgList &Args) {
@@ -198,8 +201,10 @@
llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size());
CGCallInfo CallInfo(ResultType, CallArgs);
+ // FIXME: Provide TargetDecl so nounwind, noreturn, etc, etc get set.
CodeGen::ParamAttrListType ParamAttrList;
- CallInfo.constructParamAttrList(ParamAttrList);
+ ConstructParamAttrList(0, CallInfo.argtypes_begin(), CallInfo.argtypes_end(),
+ ParamAttrList);
CI->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(),
ParamAttrList.size()));
Modified: cfe/trunk/lib/CodeGen/CGCall.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.h?rev=56038&r1=56037&r2=56038&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.h (original)
+++ cfe/trunk/lib/CodeGen/CGCall.h Tue Sep 9 19:32:18 2008
@@ -46,6 +46,10 @@
/// ParmVarDecl or ImplicitParamDecl.
typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
16> FunctionArgList;
+
+ // FIXME: This should be a better iterator type so that we can avoid
+ // construction of the ArgTypes smallvectors.
+ typedef llvm::SmallVector<QualType, 16>::const_iterator ArgTypeIterator;
/// CGFunctionInfo - Class to encapsulate the information about a
/// function definition.
@@ -63,21 +67,20 @@
const Decl* getDecl() const { return TheDecl; }
- void constructParamAttrList(ParamAttrListType &Args) const;
+ ArgTypeIterator argtypes_begin() const;
+ ArgTypeIterator argtypes_end() const;
};
/// CGCallInfo - Class to encapsulate the arguments and clang types
/// used in a call.
class CGCallInfo {
- QualType ResultType;
- const CallArgList &Args;
-
llvm::SmallVector<QualType, 16> ArgTypes;
public:
CGCallInfo(QualType _ResultType, const CallArgList &Args);
-
- void constructParamAttrList(ParamAttrListType &Args) const;
+
+ ArgTypeIterator argtypes_begin() const;
+ ArgTypeIterator argtypes_end() const;
};
} // end namespace CodeGen
} // end namespace clang
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=56038&r1=56037&r2=56038&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Sep 9 19:32:18 2008
@@ -140,7 +140,12 @@
/// ReturnTypeUsesSret - Return true iff the given type uses 'sret'
/// when used as a return type.
- bool ReturnTypeUsesSret(QualType RetTy);
+ static bool ReturnTypeUsesSret(QualType RetTy);
+
+ static void ConstructParamAttrList(const Decl *TargetDecl,
+ const ArgTypeIterator begin,
+ const ArgTypeIterator end,
+ ParamAttrListType &PAL);
/// EmitFunctionProlog - Emit the target specific LLVM code to load
/// the arguments for the given function. This is also responsible
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=56038&r1=56037&r2=56038&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Sep 9 19:32:18 2008
@@ -214,7 +214,10 @@
static void SetFunctionParamAttrs(const CGFunctionInfo &Info, llvm::Function *F) {
ParamAttrListType ParamAttrList;
- Info.constructParamAttrList(ParamAttrList);
+ CodeGenFunction::ConstructParamAttrList(Info.getDecl(),
+ Info.argtypes_begin(),
+ Info.argtypes_end(),
+ ParamAttrList);
F->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(),
ParamAttrList.size()));
More information about the cfe-commits
mailing list