[cfe-commits] r41660 - in /cfe/trunk/CodeGen: CGExpr.cpp CGExprComplex.cpp CGExprScalar.cpp CGStmt.cpp CodeGenFunction.h
Chris Lattner
sabre at nondot.org
Fri Aug 31 15:49:20 PDT 2007
Author: lattner
Date: Fri Aug 31 17:49:20 2007
New Revision: 41660
URL: http://llvm.org/viewvc/llvm-project?rev=41660&view=rev
Log:
Generalize RValue to handle complex better, generalize EmitCompoundStmt to
support any sort of expr, add a new EmitAnyExpr routine.
Modified:
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/CodeGen/CGExprComplex.cpp
cfe/trunk/CodeGen/CGExprScalar.cpp
cfe/trunk/CodeGen/CGStmt.cpp
cfe/trunk/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=41660&r1=41659&r2=41660&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Fri Aug 31 17:49:20 2007
@@ -44,6 +44,22 @@
return EmitComplexToScalarConversion(EmitComplexExpr(E), E->getType(),BoolTy);
}
+/// EmitAnyExpr - Emit code to compute the specified expression which can have
+/// any type. The result is returned as an RValue struct. If this is an
+/// aggregate expression, the aggloc/agglocvolatile arguments indicate where
+/// the result should be returned.
+RValue CodeGenFunction::EmitAnyExpr(const Expr *E, llvm::Value *AggLoc,
+ bool isAggLocVolatile) {
+ if (!hasAggregateLLVMType(E->getType()))
+ return RValue::get(EmitScalarExpr(E));
+ else if (E->getType()->isComplexType())
+ return RValue::getComplex(EmitComplexExpr(E));
+
+ EmitAggExpr(E, AggLoc, isAggLocVolatile);
+ return RValue::getAggregate(AggLoc);
+}
+
+
//===----------------------------------------------------------------------===//
// LValue Expression Emission
//===----------------------------------------------------------------------===//
@@ -185,7 +201,7 @@
// Read/modify/write the vector, inserting the new element.
// FIXME: Volatility.
llvm::Value *Vec = Builder.CreateLoad(Dst.getVectorAddr(), "tmp");
- Vec = Builder.CreateInsertElement(Vec, Src.getVal(),
+ Vec = Builder.CreateInsertElement(Vec, Src.getScalarVal(),
Dst.getVectorIdx(), "vecins");
Builder.CreateStore(Vec, Dst.getVectorAddr());
return;
@@ -201,14 +217,14 @@
llvm::Value *DstAddr = Dst.getAddress();
assert(Src.isScalar() && "Can't emit an agg store with this method");
// FIXME: Handle volatility etc.
- const llvm::Type *SrcTy = Src.getVal()->getType();
+ const llvm::Type *SrcTy = Src.getScalarVal()->getType();
const llvm::Type *AddrTy =
cast<llvm::PointerType>(DstAddr->getType())->getElementType();
if (AddrTy != SrcTy)
DstAddr = Builder.CreateBitCast(DstAddr, llvm::PointerType::get(SrcTy),
"storetmp");
- Builder.CreateStore(Src.getVal(), DstAddr);
+ Builder.CreateStore(Src.getScalarVal(), DstAddr);
}
void CodeGenFunction::EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst,
@@ -219,7 +235,7 @@
// FIXME: Volatility.
unsigned EncFields = Dst.getOCUVectorElts();
- llvm::Value *SrcVal = Src.getVal();
+ llvm::Value *SrcVal = Src.getScalarVal();
if (const VectorType *VTy = Ty->getAsVectorType()) {
unsigned NumSrcElts = VTy->getNumElements();
@@ -425,6 +441,8 @@
llvm::Value *V = Builder.CreateCall(Callee, &Args[0], &Args[0]+Args.size());
if (V->getType() != llvm::Type::VoidTy)
V->setName("call");
+ else if (E->getType()->isComplexType())
+ return RValue::getComplex(LoadComplexFromAddr(Args[0], false));
else if (hasAggregateLLVMType(E->getType()))
// Struct return.
return RValue::getAggregate(Args[0]);
Modified: cfe/trunk/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprComplex.cpp?rev=41660&r1=41659&r2=41660&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/CodeGen/CGExprComplex.cpp Fri Aug 31 17:49:20 2007
@@ -239,8 +239,7 @@
ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) {
- llvm::Value *AggPtr = CGF.EmitCallExpr(E).getAggregateAddr();
- return EmitLoadOfComplex(AggPtr, false);
+ return CGF.EmitCallExpr(E).getComplexVal();
}
/// EmitComplexToComplexCast - Emit a cast from complex value Val to DestType.
@@ -511,3 +510,9 @@
ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));
Emitter.EmitStoreOfComplex(Val, DestAddr, DestIsVolatile);
}
+
+/// LoadComplexFromAddr - Load a complex number from the specified address.
+ComplexPairTy CodeGenFunction::LoadComplexFromAddr(llvm::Value *SrcAddr,
+ bool SrcIsVolatile) {
+ return ComplexExprEmitter(*this).EmitLoadOfComplex(SrcAddr, SrcIsVolatile);
+}
Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=41660&r1=41659&r2=41660&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Fri Aug 31 17:49:20 2007
@@ -51,7 +51,7 @@
LValue EmitLValue(const Expr *E) { return CGF.EmitLValue(E); }
Value *EmitLoadOfLValue(LValue LV, QualType T) {
- return CGF.EmitLoadOfLValue(LV, T).getVal();
+ return CGF.EmitLoadOfLValue(LV, T).getScalarVal();
}
/// EmitLoadOfLValue - Given an expression with complex type that represents a
@@ -126,7 +126,7 @@
Value *EmitCastExpr(const Expr *E, QualType T);
Value *VisitCallExpr(const CallExpr *E) {
- return CGF.EmitCallExpr(E).getVal();
+ return CGF.EmitCallExpr(E).getScalarVal();
}
Value *VisitStmtExpr(const StmtExpr *E);
@@ -440,7 +440,7 @@
}
Value *ScalarExprEmitter::VisitStmtExpr(const StmtExpr *E) {
- return CGF.EmitCompoundStmt(*E->getSubStmt(), true).getVal();
+ return CGF.EmitCompoundStmt(*E->getSubStmt(), true).getScalarVal();
}
@@ -453,7 +453,7 @@
LValue LV = EmitLValue(E->getSubExpr());
// FIXME: Handle volatile!
Value *InVal = CGF.EmitLoadOfLValue(LV, // false
- E->getSubExpr()->getType()).getVal();
+ E->getSubExpr()->getType()).getScalarVal();
int AmountVal = isInc ? 1 : -1;
Modified: cfe/trunk/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGStmt.cpp?rev=41660&r1=41659&r2=41660&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/CodeGen/CGStmt.cpp Fri Aug 31 17:49:20 2007
@@ -63,7 +63,8 @@
/// EmitCompoundStmt - Emit a compound statement {..} node. If GetLast is true,
/// this captures the expression result of the last sub-statement and returns it
/// (for use by the statement expression extension).
-RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast) {
+RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
+ llvm::Value *AggLoc, bool isAggVol) {
// FIXME: handle vla's etc.
if (S.body_empty() || !isa<Expr>(S.body_back())) GetLast = false;
@@ -74,15 +75,8 @@
if (!GetLast)
return RValue::get(0);
-
- const Expr *Last = cast<Expr>(S.body_back());
- if (!hasAggregateLLVMType(Last->getType()))
- return RValue::get(EmitScalarExpr(Last));
- assert(0 && "Unimp");
- //else if (Last->getType()->isComplexType())
- // EmitComplexExpr(Last);
- //else
- // EmitAggExpr(E, 0, false);
+
+ return EmitAnyExpr(cast<Expr>(S.body_back()), AggLoc);
}
void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB) {
Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=41660&r1=41659&r2=41660&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Fri Aug 31 17:49:20 2007
@@ -71,44 +71,65 @@
/// RValue - This trivial value class is used to represent the result of an
-/// expression that is evaluated. It can be one of two things: either a simple
-/// LLVM SSA value, or the address of an aggregate value in memory. These two
-/// possibilities are discriminated by isAggregate/isScalar.
+/// expression that is evaluated. It can be one of three things: either a
+/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
+/// address of an aggregate value in memory.
class RValue {
- llvm::Value *V;
+ llvm::Value *V1, *V2;
// TODO: Encode this into the low bit of pointer for more efficient
// return-by-value.
- bool IsAggregate;
+ enum { Scalar, Complex, Aggregate } Flavor;
// FIXME: Aggregate rvalues need to retain information about whether they are
// volatile or not.
public:
- bool isAggregate() const { return IsAggregate; }
- bool isScalar() const { return !IsAggregate; }
-
- /// getVal() - Return the Value* of this scalar value.
- llvm::Value *getVal() const {
- assert(!isAggregate() && "Not a scalar!");
- return V;
+ bool isScalar() const { return Flavor == Scalar; }
+ bool isComplex() const { return Flavor == Complex; }
+ bool isAggregate() const { return Flavor == Aggregate; }
+
+ /// getScalar() - Return the Value* of this scalar value.
+ llvm::Value *getScalarVal() const {
+ assert(isScalar() && "Not a scalar!");
+ return V1;
}
+ /// getComplexVal - Return the real/imag components of this complex value.
+ ///
+ std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
+ return std::pair<llvm::Value *, llvm::Value *>(V1, V2);
+ }
+
/// getAggregateAddr() - Return the Value* of the address of the aggregate.
llvm::Value *getAggregateAddr() const {
assert(isAggregate() && "Not an aggregate!");
- return V;
+ return V1;
}
static RValue get(llvm::Value *V) {
RValue ER;
- ER.V = V;
- ER.IsAggregate = false;
+ ER.V1 = V;
+ ER.Flavor = Scalar;
+ return ER;
+ }
+ static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
+ RValue ER;
+ ER.V1 = V1;
+ ER.V2 = V2;
+ ER.Flavor = Complex;
+ return ER;
+ }
+ static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
+ RValue ER;
+ ER.V1 = C.first;
+ ER.V2 = C.second;
+ ER.Flavor = Complex;
return ER;
}
static RValue getAggregate(llvm::Value *V) {
RValue ER;
- ER.V = V;
- ER.IsAggregate = true;
+ ER.V1 = V;
+ ER.Flavor = Aggregate;
return ER;
}
};
@@ -249,6 +270,12 @@
/// expression and compare the result against zero, returning an Int1Ty value.
llvm::Value *EvaluateExprAsBool(const Expr *E);
+ /// EmitAnyExpr - Emit code to compute the specified expression which can have
+ /// any type. The result is returned as an RValue struct. If this is an
+ /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
+ /// the result should be returned.
+ RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
+ bool isAggLocVolatile = false);
//===--------------------------------------------------------------------===//
// Declaration Emission
@@ -265,7 +292,8 @@
//===--------------------------------------------------------------------===//
void EmitStmt(const Stmt *S);
- RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false);
+ RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
+ llvm::Value *AggLoc = 0, bool isAggVol = false);
void EmitLabelStmt(const LabelStmt &S);
void EmitGotoStmt(const GotoStmt &S);
void EmitIfStmt(const IfStmt &S);
@@ -364,6 +392,8 @@
/// of complex type, storing into the specified Value*.
void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
bool DestIsVolatile);
+ /// LoadComplexFromAddr - Load a complex number from the specified address.
+ ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
};
} // end namespace CodeGen
} // end namespace clang
More information about the cfe-commits
mailing list