[cfe-commits] r50892 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h lib/Sema/SemaExpr.cpp test/Parser/ocu_vector_components.c
Chris Lattner
clattner at apple.com
Fri May 9 09:32:11 PDT 2008
On May 8, 2008, at 11:41 PM, Nate Begeman wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=50892&view=rev
> Log:
> Extend vector member references to include {.hi, .lo, .e, .o} which
> return a
> vector of the same element type and half the width, with the high,
> low, even,
> and odd elements respectively.
>
> Allow member references to member references, so that .hi.hi gives
> you the high
> quarter of a vector. This is fairly convenient syntax for some
> insert/extract
> operations.
Nice.
> +++ cfe/trunk/include/clang/AST/Expr.h Fri May 9 01:41:27 2008
> @@ -23,6 +23,8 @@
> #include "llvm/ADT/APFloat.h"
> #include <vector>
>
> +class llvm::Constant;
libast shouldn't depend on vmcore as we discussed.
> +++ cfe/trunk/lib/AST/Expr.cpp Fri May 9 01:41:27 2008
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri May 9 01:41:27 2008
> @@ -460,9 +460,28 @@
> EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
> // Emit the base vector as an l-value.
> LValue Base = EmitLValue(E->getBase());
> +
> + if (Base.isExtVectorElt()) {
> + llvm::Constant *BaseElts = Base.getExtVectorElts();
> + llvm::Constant *ExprElts = E->getEncodedElementAccess();
> +
> + llvm::SmallVector<llvm::Constant *, 8> Indices;
> +
> + for (unsigned i = 0, e = E->getNumElements(); i != e; ++i) {
> + unsigned Idx = ExtVectorElementExpr::getAccessedFieldNo(i,
> ExprElts);
> +
> + if (isa<llvm::ConstantAggregateZero>(BaseElts))
> +
> Indices.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0));
> + else
> + Indices.push_back(cast<llvm::ConstantInt>(BaseElts-
> >getOperand(Idx)));
> + }
> + llvm::Constant *NewElts =
> llvm::ConstantVector::get(&Indices[0], Indices.size());
> + return LValue::MakeExtVectorElt(Base.getExtVectorAddr(),
> NewElts);
> + }
> +
> assert(Base.isSimple() && "Can only subscript lvalue vectors
> here!");
>
> - return LValue::MakeExtVectorElt(Base.getAddress(),
> + return LValue::MakeExtVectorElt(Base.getAddress(),
> E->getEncodedElementAccess());
Please handle the 'simple' case first, so that the code is nested less:
if (issimple) {
..
return dosimplestuff();
}
assert(isextvectorelet)
...
Can you use your new predicate instead of checking
ConstantAggregateZero explicitly here? Maybe this issue goes away
when you switch to SmallVector in the AST.
Overall, very nice!
-Chris
More information about the cfe-commits
mailing list