[cfe-commits] r62438 - in /cfe/trunk: include/clang/AST/APValue.h lib/AST/APValue.cpp lib/CodeGen/CGExprConstant.cpp
Nate Begeman
natebegeman at mac.com
Sat Jan 17 17:01:34 PST 2009
Author: sampo
Date: Sat Jan 17 19:01:34 2009
New Revision: 62438
URL: http://llvm.org/viewvc/llvm-project?rev=62438&view=rev
Log:
Add support for vectors to APValue. Vector constant evaluator and tests coming.
Modified:
cfe/trunk/include/clang/AST/APValue.h
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
Modified: cfe/trunk/include/clang/AST/APValue.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=62438&r1=62437&r2=62438&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/APValue.h (original)
+++ cfe/trunk/include/clang/AST/APValue.h Sat Jan 17 19:01:34 2009
@@ -32,7 +32,8 @@
Float,
ComplexInt,
ComplexFloat,
- LValue
+ LValue,
+ Vector
};
private:
ValueKind Kind;
@@ -50,6 +51,11 @@
Expr* Base;
uint64_t Offset;
};
+ struct Vec {
+ APValue *Elts;
+ unsigned NumElts;
+ ~Vec() { delete[] Elts; }
+ };
enum {
MaxSize = (sizeof(ComplexAPSInt) > sizeof(ComplexAPFloat) ?
@@ -68,6 +74,9 @@
explicit APValue(const APFloat &F) : Kind(Uninitialized) {
MakeFloat(); setFloat(F);
}
+ explicit APValue(const APValue *E, unsigned N) : Kind(Uninitialized) {
+ MakeVector(); setVector(E, N);
+ }
APValue(const APSInt &R, const APSInt &I) : Kind(Uninitialized) {
MakeComplexInt(); setComplexInt(R, I);
}
@@ -91,6 +100,7 @@
bool isComplexInt() const { return Kind == ComplexInt; }
bool isComplexFloat() const { return Kind == ComplexFloat; }
bool isLValue() const { return Kind == LValue; }
+ bool isVector() const { return Kind == Vector; }
void print(llvm::raw_ostream &OS) const;
void dump() const;
@@ -111,6 +121,15 @@
return const_cast<APValue*>(this)->getFloat();
}
+ APValue &getVectorElt(unsigned i) const {
+ assert(isVector() && "Invalid accessor");
+ return ((Vec*)(void*)Data)->Elts[i];
+ }
+ unsigned getVectorLength() const {
+ assert(isVector() && "Invalid accessor");
+ return ((Vec*)(void *)Data)->NumElts;
+ }
+
APSInt &getComplexIntReal() {
assert(isComplexInt() && "Invalid accessor");
return ((ComplexAPSInt*)(void*)Data)->Real;
@@ -160,6 +179,13 @@
assert(isFloat() && "Invalid accessor");
*(APFloat*)(void*)Data = F;
}
+ void setVector(const APValue *E, unsigned N) {
+ assert(isVector() && "Invalid accessor");
+ ((Vec*)(void*)Data)->Elts = new APValue[N];
+ ((Vec*)(void*)Data)->NumElts = N;
+ for (unsigned i = 0; i != N; ++i)
+ ((Vec*)(void*)Data)->Elts[i] = E[i];
+ }
void setComplexInt(const APSInt &R, const APSInt &I) {
assert(isComplexInt() && "Invalid accessor");
((ComplexAPSInt*)(void*)Data)->Real = R;
@@ -190,6 +216,11 @@
new ((APFloat*)(void*)Data) APFloat(0.0);
Kind = Float;
}
+ void MakeVector() {
+ assert(isUninit() && "Bad state change");
+ new ((Vec*)(void*)Data) Vec();
+ Kind = Vector;
+ }
void MakeComplexInt() {
assert(isUninit() && "Bad state change");
new ((ComplexAPSInt*)(void*)Data) ComplexAPSInt();
Modified: cfe/trunk/lib/AST/APValue.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/APValue.cpp?rev=62438&r1=62437&r2=62438&view=diff
==============================================================================
--- cfe/trunk/lib/AST/APValue.cpp (original)
+++ cfe/trunk/lib/AST/APValue.cpp Sat Jan 17 19:01:34 2009
@@ -23,6 +23,8 @@
MakeInt();
else if (RHS.isFloat())
MakeFloat();
+ else if (RHS.isVector())
+ MakeVector();
else if (RHS.isComplexInt())
MakeComplexInt();
else if (RHS.isComplexFloat())
@@ -34,6 +36,8 @@
setInt(RHS.getInt());
else if (isFloat())
setFloat(RHS.getFloat());
+ else if (isVector())
+ setVector(((Vec*)(void*)RHS.Data)->Elts, RHS.getVectorLength());
else if (isComplexInt())
setComplexInt(RHS.getComplexIntReal(), RHS.getComplexIntImag());
else if (isComplexFloat())
@@ -48,6 +52,8 @@
((APSInt*)(void*)Data)->~APSInt();
else if (Kind == Float)
((APFloat*)(void*)Data)->~APFloat();
+ else if (Kind == Vector)
+ ((Vec*)(void*)Data)->~Vec();
else if (Kind == ComplexInt)
((ComplexAPSInt*)(void*)Data)->~ComplexAPSInt();
else if (Kind == ComplexFloat)
@@ -55,6 +61,7 @@
else if (Kind == LValue) {
((LV*)(void*)Data)->~LV();
}
+ Kind = Uninitialized;
}
void APValue::dump() const {
@@ -83,6 +90,9 @@
case Float:
OS << "Float: " << GetApproxValue(getFloat());
return;
+ case Vector:
+ OS << "Vector: <todo>";
+ return;
case ComplexInt:
OS << "ComplexInt: " << getComplexIntReal() << ", " << getComplexIntImag();
return;
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=62438&r1=62437&r2=62438&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sat Jan 17 19:01:34 2009
@@ -697,6 +697,19 @@
return llvm::ConstantStruct::get(Complex, 2);
}
+ case APValue::Vector: {
+ llvm::SmallVector<llvm::Constant *, 4> Inits;
+ unsigned NumElts = Result.Val.getVectorLength();
+
+ for (unsigned i = 0; i != NumElts; ++i) {
+ APValue &Elt = Result.Val.getVectorElt(i);
+ if (Elt.isInt())
+ Inits.push_back(llvm::ConstantInt::get(Elt.getInt()));
+ else
+ Inits.push_back(llvm::ConstantFP::get(Elt.getFloat()));
+ }
+ return llvm::ConstantVector::get(&Inits[0], Inits.size());
+ }
}
}
More information about the cfe-commits
mailing list