[cfe-commits] r69244 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Frontend/PCHBitCodes.h lib/AST/Expr.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/exprs.c test/PCH/exprs.h
Douglas Gregor
dgregor at apple.com
Wed Apr 15 17:01:46 PDT 2009
Author: dgregor
Date: Wed Apr 15 19:01:45 2009
New Revision: 69244
URL: http://llvm.org/viewvc/llvm-project?rev=69244&view=rev
Log:
PCH support for ShuffleVectorExpr and BlockDeclRefExpr
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/test/PCH/exprs.c
cfe/trunk/test/PCH/exprs.h
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=69244&r1=69243&r2=69244&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 15 19:01:45 2009
@@ -1718,7 +1718,17 @@
for (unsigned i = 0; i < nexpr; i++)
SubExprs[i] = args[i];
}
-
+
+ /// \brief Build an empty vector-shuffle expression.
+ explicit ShuffleVectorExpr(EmptyShell Empty)
+ : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
+
+ SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
+ void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
+
+ SourceLocation getRParenLoc() const { return RParenLoc; }
+ void setRParenLoc(SourceLocation L) { RParenLoc = L; }
+
virtual SourceRange getSourceRange() const {
return SourceRange(BuiltinLoc, RParenLoc);
}
@@ -1746,6 +1756,8 @@
return cast<Expr>(SubExprs[Index]);
}
+ void setExprs(Expr ** Exprs, unsigned NumExprs);
+
unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
assert((N < NumExprs - 2) && "Shuffle idx out of range!");
return getExpr(N+2)->getIntegerConstantExprValue(Ctx).getZExtValue();
@@ -2452,13 +2464,24 @@
public:
BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) :
Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {}
+
+ // \brief Build an empty reference to a declared variable in a
+ // block.
+ explicit BlockDeclRefExpr(EmptyShell Empty)
+ : Expr(BlockDeclRefExprClass, Empty) { }
ValueDecl *getDecl() { return D; }
const ValueDecl *getDecl() const { return D; }
+ void setDecl(ValueDecl *VD) { D = VD; }
+
+ SourceLocation getLocation() const { return Loc; }
+ void setLocation(SourceLocation L) { Loc = L; }
+
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
bool isByRef() const { return IsByRef; }
-
+ void setByRef(bool BR) { IsByRef = BR; }
+
static bool classof(const Stmt *T) {
return T->getStmtClass() == BlockDeclRefExprClass;
}
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69244&r1=69243&r2=69244&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 15 19:01:45 2009
@@ -434,7 +434,11 @@
/// \brief A ChooseExpr record.
EXPR_CHOOSE,
/// \brief A GNUNullExpr record.
- EXPR_GNU_NULL
+ EXPR_GNU_NULL,
+ /// \brief A ShuffleVectorExpr record.
+ EXPR_SHUFFLE_VECTOR,
+ /// FIXME: BlockExpr
+ EXPR_BLOCK_DECL_REF
};
/// @}
}
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=69244&r1=69243&r2=69244&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Apr 15 19:01:45 2009
@@ -1500,6 +1500,15 @@
return getCond()->getIntegerConstantExprValue(C) != 0;
}
+void ShuffleVectorExpr::setExprs(Expr ** Exprs, unsigned NumExprs) {
+ if (NumExprs)
+ delete [] SubExprs;
+
+ SubExprs = new Stmt* [NumExprs];
+ this->NumExprs = NumExprs;
+ memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs);
+}
+
void SizeOfAlignOfExpr::Destroy(ASTContext& C) {
// Override default behavior of traversing children. If this has a type
// operand and the type is a variable-length array, the child iteration
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69244&r1=69243&r2=69244&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 15 19:01:45 2009
@@ -262,6 +262,8 @@
unsigned VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
unsigned VisitChooseExpr(ChooseExpr *E);
unsigned VisitGNUNullExpr(GNUNullExpr *E);
+ unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E);
+ unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
};
}
@@ -483,6 +485,23 @@
return 0;
}
+unsigned PCHStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
+ VisitExpr(E);
+ unsigned NumExprs = Record[Idx++];
+ E->setExprs(&ExprStack[ExprStack.size() - NumExprs], NumExprs);
+ E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ return NumExprs;
+}
+
+unsigned PCHStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
+ VisitExpr(E);
+ E->setDecl(cast<ValueDecl>(Reader.GetDecl(Record[Idx++])));
+ E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setByRef(Record[Idx++]);
+ return 0;
+}
+
// FIXME: use the diagnostics machinery
static bool Error(const char *Str) {
std::fprintf(stderr, "%s\n", Str);
@@ -2016,6 +2035,15 @@
case pch::EXPR_GNU_NULL:
E = new (Context) GNUNullExpr(Empty);
break;
+
+ case pch::EXPR_SHUFFLE_VECTOR:
+ E = new (Context) ShuffleVectorExpr(Empty);
+ break;
+
+ case pch::EXPR_BLOCK_DECL_REF:
+ // FIXME: untested until we have statement and block support
+ E = new (Context) BlockDeclRefExpr(Empty);
+ break;
}
// We hit an EXPR_STOP, so we're done with this expression.
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69244&r1=69243&r2=69244&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 15 19:01:45 2009
@@ -469,6 +469,8 @@
void VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
void VisitChooseExpr(ChooseExpr *E);
void VisitGNUNullExpr(GNUNullExpr *E);
+ void VisitShuffleVectorExpr(ShuffleVectorExpr *E);
+ void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
};
}
@@ -683,6 +685,24 @@
Code = pch::EXPR_GNU_NULL;
}
+void PCHStmtWriter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
+ VisitExpr(E);
+ Record.push_back(E->getNumSubExprs());
+ for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I)
+ Writer.WriteSubExpr(E->getExpr(I));
+ Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
+ Writer.AddSourceLocation(E->getRParenLoc(), Record);
+ Code = pch::EXPR_SHUFFLE_VECTOR;
+}
+
+void PCHStmtWriter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
+ VisitExpr(E);
+ Writer.AddDeclRef(E->getDecl(), Record);
+ Writer.AddSourceLocation(E->getLocation(), Record);
+ Record.push_back(E->isByRef());
+ Code = pch::EXPR_BLOCK_DECL_REF;
+}
+
//===----------------------------------------------------------------------===//
// PCHWriter Implementation
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/test/PCH/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.c?rev=69244&r1=69243&r2=69244&view=diff
==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Wed Apr 15 19:01:45 2009
@@ -72,3 +72,6 @@
// GNUNullExpr FIXME: needs C++
//null_type null = __null;
+
+// ShuffleVectorExpr
+shuffle_expr *vec_ptr = &vec2;
Modified: cfe/trunk/test/PCH/exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=69244&r1=69243&r2=69244&view=diff
==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 15 19:01:45 2009
@@ -58,7 +58,7 @@
// ExtVectorElementExpr
typedef __attribute__(( ext_vector_type(2) )) double double2;
-double2 vec2;
+extern double2 vec2, vec2b;
typedef typeof(vec2.x) ext_vector_element;
// TypesCompatibleExpr
@@ -69,3 +69,6 @@
// GNUNullExpr FIXME: needs C++
// typedef typeof(__null) null_type;
+
+// ShuffleVectorExpr
+typedef typeof(__builtin_shufflevector(vec2, vec2b, 2, 1)) shuffle_expr;
More information about the cfe-commits
mailing list