Remove AST dependency on VMCore by switching ExtVectorElementExpr off Constant.

llvm-svn: 51068
This commit is contained in:
Nate Begeman 2008-05-13 21:03:02 +00:00
parent bb3aef4ee3
commit d386215916
3 changed files with 37 additions and 31 deletions

View File

@ -21,10 +21,9 @@
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/SmallVector.h"
#include <vector>
class llvm::Constant;
namespace clang {
class IdentifierInfo;
class Selector;
@ -722,12 +721,11 @@ public:
/// getEncodedElementAccess - Encode the elements accessed into an llvm
/// aggregate Constant of ConstantInt(s).
llvm::Constant *getEncodedElementAccess() const;
void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
/// getAccessedFieldNo - Given an encoded value and a result number, return
/// the input field number being accessed.
static unsigned getAccessedFieldNo(unsigned Idx,
const llvm::Constant *Elts);
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
virtual SourceRange getSourceRange() const {
return SourceRange(getBase()->getLocStart(), AccessorLoc);

View File

@ -1057,9 +1057,9 @@ bool ExtVectorElementExpr::containsDuplicateElements() const {
}
/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
llvm::Constant *ExtVectorElementExpr::getEncodedElementAccess() const {
void ExtVectorElementExpr::getEncodedElementAccess(
llvm::SmallVectorImpl<unsigned> &Elts) const {
const char *compStr = Accessor.getName();
llvm::SmallVector<llvm::Constant *, 8> Indices;
bool isHi = !strcmp(compStr, "hi");
bool isLo = !strcmp(compStr, "lo");
@ -1080,9 +1080,8 @@ llvm::Constant *ExtVectorElementExpr::getEncodedElementAccess() const {
else
Index = ExtVectorType::getAccessorIdx(compStr[i]);
Indices.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, Index));
Elts.push_back(Index);
}
return llvm::ConstantVector::get(&Indices[0], Indices.size());
}
unsigned

View File

@ -456,33 +456,42 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
return LValue::MakeAddr(Builder.CreateGEP(Base, Idx, "arrayidx"));
}
static
llvm::Constant *GenerateConstantVector(llvm::SmallVector<unsigned, 4> &Elts) {
llvm::SmallVector<llvm::Constant *, 4> CElts;
for (unsigned i = 0, e = Elts.size(); i != e; ++i)
CElts.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, Elts[i]));
return llvm::ConstantVector::get(&CElts[0], CElts.size());
}
LValue CodeGenFunction::
EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
// Emit the base vector as an l-value.
LValue Base = EmitLValue(E->getBase());
if (Base.isExtVectorElt()) {
// Encode the element access list into a vector of unsigned indices.
llvm::SmallVector<unsigned, 4> Indices;
E->getEncodedElementAccess(Indices);
if (Base.isSimple()) {
llvm::Constant *CV = GenerateConstantVector(Indices);
return LValue::MakeExtVectorElt(Base.getAddress(), CV);
}
assert(Base.isExtVectorElt() && "Can only subscript lvalue vec elts here!");
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);
llvm::SmallVector<llvm::Constant *, 4> CElts;
for (unsigned i = 0, e = Indices.size(); i != e; ++i) {
if (isa<llvm::ConstantAggregateZero>(BaseElts))
Indices.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0));
CElts.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0));
else
Indices.push_back(cast<llvm::ConstantInt>(BaseElts->getOperand(Idx)));
CElts.push_back(BaseElts->getOperand(Indices[i]));
}
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(),
E->getEncodedElementAccess());
llvm::Constant *CV = llvm::ConstantVector::get(&CElts[0], CElts.size());
return LValue::MakeExtVectorElt(Base.getExtVectorAddr(), CV);
}
LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {