[cfe-commits] r55970 - in /cfe/trunk/lib/CodeGen: CGCall.cpp CGCall.h CGExpr.cpp CGObjC.cpp CGObjCGNU.cpp CGObjCMac.cpp CGObjCRuntime.h CGValue.h CodeGenFunction.h
Daniel Dunbar
daniel at zuster.org
Mon Sep 8 18:06:48 PDT 2008
Author: ddunbar
Date: Mon Sep 8 20:06:48 2008
New Revision: 55970
URL: http://llvm.org/viewvc/llvm-project?rev=55970&view=rev
Log:
Change CodeGen to emit calls using (RValue,Type) list:
- Add CodeGenFunction::EmitAnyExprToTemp
o Like EmitAnyExpr, but emits aggregates to a temporary location if
none is available. Seems like this should be simpler (even aside
from using first class aggregates).
- Killed CodeGenFunction::EmitCallArg (just append the pair)
- Conversion of RValues to actual call arguments is now isolated in
CodeGenFunction::EmitCall.
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGCall.h
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
cfe/trunk/lib/CodeGen/CGValue.h
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Sep 8 20:06:48 2008
@@ -102,8 +102,7 @@
/***/
-CGCallInfo::CGCallInfo(QualType _ResultType,
- const llvm::SmallVector<std::pair<llvm::Value*, QualType>, 16> &_Args)
+CGCallInfo::CGCallInfo(QualType _ResultType, const CallArgList &_Args)
: ResultType(_ResultType),
Args(_Args) {
ArgTypes.push_back(ResultType);
Modified: cfe/trunk/lib/CodeGen/CGCall.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.h?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.h (original)
+++ cfe/trunk/lib/CodeGen/CGCall.h Mon Sep 8 20:06:48 2008
@@ -17,6 +17,8 @@
#include "clang/AST/Type.h"
+#include "CGValue.h"
+
namespace llvm {
class Function;
struct ParamAttrsWithIndex;
@@ -36,7 +38,7 @@
/// CallArgList - Type for representing both the value and type of
/// arguments in a call.
- typedef llvm::SmallVector<std::pair<llvm::Value*, QualType>, 16> CallArgList;
+ typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
/// CGFunctionInfo - Class to encapsulate the information about a
/// function definition.
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Sep 8 20:06:48 2008
@@ -57,6 +57,17 @@
return RValue::getAggregate(AggLoc);
}
+/// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result
+/// will always be accessible even if no aggregate location is
+/// provided.
+RValue CodeGenFunction::EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc,
+ bool isAggLocVolatile) {
+ if (!AggLoc && hasAggregateLLVMType(E->getType()) &&
+ !E->getType()->isAnyComplexType())
+ AggLoc = CreateTempAlloca(ConvertType(E->getType()), "agg.tmp");
+ return EmitAnyExpr(E, AggLoc, isAggLocVolatile);
+}
+
/// getAccessedFieldNo - Given an encoded value and a result number, return
/// the input field number being accessed.
unsigned CodeGenFunction::getAccessedFieldNo(unsigned Idx,
@@ -840,48 +851,12 @@
CallArgList Args;
for (CallExpr::const_arg_iterator I = ArgBeg; I != ArgEnd; ++I)
- EmitCallArg(*I, Args);
+ Args.push_back(std::make_pair(EmitAnyExprToTemp(*I),
+ I->getType()));
return EmitCall(Callee, ResultType, Args);
}
-// FIXME: Merge the following two functions.
-void CodeGenFunction::EmitCallArg(RValue RV, QualType Ty,
- CallArgList &Args) {
- llvm::Value *ArgValue;
-
- if (RV.isScalar()) {
- ArgValue = RV.getScalarVal();
- } else if (RV.isComplex()) {
- // Make a temporary alloca to pass the argument.
- ArgValue = CreateTempAlloca(ConvertType(Ty));
- StoreComplexToAddr(RV.getComplexVal(), ArgValue, false);
- } else {
- ArgValue = RV.getAggregateAddr();
- }
-
- Args.push_back(std::make_pair(ArgValue, Ty));
-}
-
-void CodeGenFunction::EmitCallArg(const Expr *E, CallArgList &Args) {
- QualType ArgTy = E->getType();
- llvm::Value *ArgValue;
-
- if (!hasAggregateLLVMType(ArgTy)) {
- // Scalar argument is passed by-value.
- ArgValue = EmitScalarExpr(E);
- } else if (ArgTy->isAnyComplexType()) {
- // Make a temporary alloca to pass the argument.
- ArgValue = CreateTempAlloca(ConvertType(ArgTy));
- EmitComplexExprIntoAddr(E, ArgValue, false);
- } else {
- ArgValue = CreateTempAlloca(ConvertType(ArgTy));
- EmitAggExpr(E, ArgValue, false);
- }
-
- Args.push_back(std::make_pair(ArgValue, E->getType()));
-}
-
RValue CodeGenFunction::EmitCall(llvm::Value *Callee,
QualType ResultType,
const CallArgList &CallArgs) {
@@ -898,8 +873,18 @@
}
for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end();
- I != E; ++I)
- Args.push_back(I->first);
+ I != E; ++I) {
+ RValue RV = I->first;
+ if (RV.isScalar()) {
+ Args.push_back(RV.getScalarVal());
+ } else if (RV.isComplex()) {
+ // Make a temporary alloca to pass the argument.
+ Args.push_back(CreateTempAlloca(ConvertType(I->second)));
+ StoreComplexToAddr(RV.getComplexVal(), Args.back(), false);
+ } else {
+ Args.push_back(RV.getAggregateAddr());
+ }
+ }
llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size());
CGCallInfo CallInfo(ResultType, CallArgs);
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Mon Sep 8 20:06:48 2008
@@ -83,7 +83,7 @@
CallArgList Args;
for (CallExpr::const_arg_iterator i = E->arg_begin(), e = E->arg_end();
i != e; ++i)
- EmitCallArg(*i, Args);
+ Args.push_back(std::make_pair(EmitAnyExprToTemp(*i), (*i)->getType()));
if (isSuperMessage) {
// super is only valid in an Objective-C method
@@ -268,7 +268,7 @@
}
CallArgList Args;
- EmitCallArg(Src, E->getType(), Args);
+ Args.push_back(std::make_pair(Src, E->getType()));
CGM.getObjCRuntime().GenerateMessageSend(*this, getContext().VoidTy, S,
EmitScalarExpr(E->getBase()),
false, Args);
@@ -316,15 +316,16 @@
llvm::Value *Collection = EmitScalarExpr(S.getCollection());
CallArgList Args;
- Args.push_back(std::make_pair(StatePtr,
+ Args.push_back(std::make_pair(RValue::get(StatePtr),
getContext().getPointerType(StateTy)));
- Args.push_back(std::make_pair(ItemsPtr,
+ Args.push_back(std::make_pair(RValue::get(ItemsPtr),
getContext().getPointerType(ItemsTy)));
const llvm::Type *UnsignedLongLTy = ConvertType(getContext().UnsignedLongTy);
llvm::Constant *Count = llvm::ConstantInt::get(UnsignedLongLTy, NumItems);
- Args.push_back(std::make_pair(Count, getContext().UnsignedLongTy));
+ Args.push_back(std::make_pair(RValue::get(Count),
+ getContext().UnsignedLongTy));
RValue CountRV =
CGM.getObjCRuntime().GenerateMessageSend(*this,
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Mon Sep 8 20:06:48 2008
@@ -28,6 +28,7 @@
#include "llvm/Target/TargetData.h"
#include <map>
using namespace clang;
+using namespace CodeGen;
using llvm::dyn_cast;
// The version of the runtime that this class targets. Must match the version
@@ -281,9 +282,9 @@
// Call the method
CallArgList ActualArgs;
- ActualArgs.push_back(std::make_pair(Receiver,
+ ActualArgs.push_back(std::make_pair(RValue::get(Receiver),
CGF.getContext().getObjCIdType()));
- ActualArgs.push_back(std::make_pair(cmd,
+ ActualArgs.push_back(std::make_pair(RValue::get(cmd),
CGF.getContext().getObjCSelType()));
ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
return CGF.EmitCall(imp, ResultType, ActualArgs);
@@ -328,9 +329,9 @@
// Call the method.
CallArgList ActualArgs;
- ActualArgs.push_back(std::make_pair(Receiver,
+ ActualArgs.push_back(std::make_pair(RValue::get(Receiver),
CGF.getContext().getObjCIdType()));
- ActualArgs.push_back(std::make_pair(cmd,
+ ActualArgs.push_back(std::make_pair(RValue::get(cmd),
CGF.getContext().getObjCSelType()));
ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
return CGF.EmitCall(imp, ResultType, ActualArgs);
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Sep 8 20:06:48 2008
@@ -26,6 +26,7 @@
#include <sstream>
using namespace clang;
+using namespace CodeGen;
namespace {
@@ -438,7 +439,7 @@
const ObjCInterfaceDecl *Class,
llvm::Value *Receiver,
bool IsClassMessage,
- const CallArgList &CallArgs) {
+ const CodeGen::CallArgList &CallArgs) {
// Create and init a super structure; this is a (receiver, class)
// pair we will pass to objc_msgSendSuper.
llvm::Value *ObjCSuper =
@@ -493,8 +494,9 @@
bool IsSuper,
const CallArgList &CallArgs) {
CallArgList ActualArgs;
- ActualArgs.push_back(std::make_pair(Arg0, Arg0Ty));
- ActualArgs.push_back(std::make_pair(EmitSelector(CGF.Builder, Sel),
+ ActualArgs.push_back(std::make_pair(RValue::get(Arg0), Arg0Ty));
+ ActualArgs.push_back(std::make_pair(RValue::get(EmitSelector(CGF.Builder,
+ Sel)),
CGF.getContext().getObjCSelType()));
ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Mon Sep 8 20:06:48 2008
@@ -21,6 +21,7 @@
#include <string>
#include "CGValue.h"
+#include "CGCall.h"
namespace llvm {
class Constant;
@@ -31,9 +32,9 @@
}
namespace clang {
- namespace CodeGen {
- class CodeGenFunction;
- }
+namespace CodeGen {
+ class CodeGenFunction;
+}
class ObjCCategoryImplDecl;
class ObjCImplementationDecl;
@@ -43,8 +44,6 @@
class ObjCProtocolDecl;
class Selector;
- typedef llvm::SmallVector<std::pair<llvm::Value*, QualType>, 16> CallArgList;
-
namespace CodeGen {
class CodeGenModule;
Modified: cfe/trunk/lib/CodeGen/CGValue.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGValue.h?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGValue.h (original)
+++ cfe/trunk/lib/CodeGen/CGValue.h Mon Sep 8 20:06:48 2008
@@ -17,6 +17,11 @@
#include "clang/AST/Type.h"
+namespace llvm {
+ class Constant;
+ class Value;
+}
+
namespace clang {
class ObjCPropertyRefExpr;
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=55970&r1=55969&r2=55970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Sep 8 20:06:48 2008
@@ -175,6 +175,12 @@
RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
bool isAggLocVolatile = false);
+ /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result
+ /// will always be accessible even if no aggregate location is
+ /// provided.
+ RValue EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc = 0,
+ bool isAggLocVolatile = false);
+
/// isDummyBlock - Return true if BB is an empty basic block
/// with no predecessors.
static bool isDummyBlock(const llvm::BasicBlock *BB);
@@ -308,14 +314,6 @@
// Scalar Expression Emission
//===--------------------------------------------------------------------===//
- /// EmitCallArg - Emit the given expression and append the result
- /// onto the given Args list.
- void EmitCallArg(const Expr *E, CallArgList &Args);
-
- /// EmitCallArg - Append the appropriate call argument for the given
- /// rvalue and type onto the Args list.
- void EmitCallArg(RValue RV, QualType Ty, CallArgList &Args);
-
/// EmitCall - Generate a call of the given function, expecting the
/// given result type, and using the given argument list which
/// specifies both the LLVM arguments and the types they were
More information about the cfe-commits
mailing list