aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-03-19 05:19:41 +0000
committerChris Lattner <sabre@nondot.org>2008-03-19 05:19:41 +0000
commit3e593cdb98ae2db09532a7a6838e9b2740866c89 (patch)
tree19f923e0c9fa7e1cc4fed5860d6cb178b11f2213 /clang/lib/CodeGen
parent3f8392626b558e5714ccb68d244fe92efee627b9 (diff)
downloadllvm-3e593cdb98ae2db09532a7a6838e9b2740866c89.zip
llvm-3e593cdb98ae2db09532a7a6838e9b2740866c89.tar.gz
llvm-3e593cdb98ae2db09532a7a6838e9b2740866c89.tar.bz2
simplify the clang codegen by using the new Builder.CreateStructGEP method.
llvm-svn: 48534
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp35
-rw-r--r--clang/lib/CodeGen/CGExprAgg.cpp11
-rw-r--r--clang/lib/CodeGen/CGExprComplex.cpp19
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp7
4 files changed, 23 insertions, 49 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 932a5c5..1642e2d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -367,13 +367,9 @@ LValue CodeGenFunction::EmitUnaryOpLValue(const UnaryOperator *E) {
case UnaryOperator::Real:
case UnaryOperator::Imag:
LValue LV = EmitLValue(E->getSubExpr());
-
- llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
- llvm::Constant *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty,
- E->getOpcode() == UnaryOperator::Imag);
- llvm::Value *Ops[] = {Zero, Idx};
- return LValue::MakeAddr(Builder.CreateGEP(LV.getAddress(), Ops, Ops+2,
- "idx"));
+ unsigned Idx = E->getOpcode() == UnaryOperator::Imag;
+ return LValue::MakeAddr(Builder.CreateStructGEP(LV.getAddress(),
+ Idx, "idx"));
}
}
@@ -490,9 +486,11 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
llvm::Value *V;
unsigned idx = CGM.getTypes().getLLVMFieldNo(Field);
- if (Field->isBitField()) {
- const llvm::Type * FieldTy = ConvertType(Field->getType());
- const llvm::PointerType * BaseTy =
+ if (!Field->isBitField()) {
+ V = Builder.CreateStructGEP(BaseValue, idx, "tmp");
+ } else {
+ const llvm::Type *FieldTy = ConvertType(Field->getType());
+ const llvm::PointerType *BaseTy =
cast<llvm::PointerType>(BaseValue->getType());
unsigned AS = BaseTy->getAddressSpace();
BaseValue = Builder.CreateBitCast(BaseValue,
@@ -501,11 +499,8 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
V = Builder.CreateGEP(BaseValue,
llvm::ConstantInt::get(llvm::Type::Int32Ty, idx),
"tmp");
- } else {
- llvm::Value *Idxs[2] = { llvm::Constant::getNullValue(llvm::Type::Int32Ty),
- llvm::ConstantInt::get(llvm::Type::Int32Ty, idx) };
- V = Builder.CreateGEP(BaseValue,Idxs, Idxs + 2, "tmp");
}
+
// Match union field type.
if (isUnion) {
const llvm::Type * FieldTy = ConvertType(Field->getType());
@@ -519,13 +514,13 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
}
}
- if (Field->isBitField()) {
- CodeGenTypes::BitFieldInfo bitFieldInfo =
- CGM.getTypes().getBitFieldInfo(Field);
- return LValue::MakeBitfield(V, bitFieldInfo.Begin, bitFieldInfo.Size,
- Field->getType()->isSignedIntegerType());
- } else
+ if (!Field->isBitField())
return LValue::MakeAddr(V);
+
+ CodeGenTypes::BitFieldInfo bitFieldInfo =
+ CGM.getTypes().getBitFieldInfo(Field);
+ return LValue::MakeBitfield(V, bitFieldInfo.Begin, bitFieldInfo.Size,
+ Field->getType()->isSignedIntegerType());
}
//===--------------------------------------------------------------------===//
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 325ac21..f57c2ed 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -268,15 +268,9 @@ void AggExprEmitter::EmitNonConstInit(InitListExpr *E) {
if (const llvm::ArrayType *AType = dyn_cast<llvm::ArrayType>(DestType)) {
unsigned NumInitElements = E->getNumInits();
- llvm::Value *Idxs[] = {
- llvm::Constant::getNullValue(llvm::Type::Int32Ty),
- NULL
- };
- llvm::Value *NextVal = NULL;
unsigned i;
for (i = 0; i != NumInitElements; ++i) {
- Idxs[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i);
- NextVal = Builder.CreateGEP(DestPtr, Idxs, Idxs + 2,".array");
+ llvm::Value *NextVal = Builder.CreateStructGEP(DestPtr, i, ".array");
Expr *Init = E->getInit(i);
if (isa<InitListExpr>(Init))
CGF.EmitAggExpr(Init, NextVal, VolatileDest);
@@ -289,8 +283,7 @@ void AggExprEmitter::EmitNonConstInit(InitListExpr *E) {
QualType QType = E->getInit(0)->getType();
const llvm::Type *EType = AType->getElementType();
for (/*Do not initialize i*/; i < NumArrayElements; ++i) {
- Idxs[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i);
- NextVal = Builder.CreateGEP(DestPtr, Idxs, Idxs + 2,".array");
+ llvm::Value *NextVal = Builder.CreateStructGEP(DestPtr, i, ".array");
if (EType->isFirstClassType())
Builder.CreateStore(llvm::Constant::getNullValue(EType), NextVal);
else
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp
index b1de935..e25ee95 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -185,15 +185,11 @@ public:
/// load the real and imaginary pieces, returning them as Real/Imag.
ComplexPairTy ComplexExprEmitter::EmitLoadOfComplex(llvm::Value *SrcPtr,
bool isVolatile) {
- llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
- llvm::Constant *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
-
llvm::SmallString<64> Name(SrcPtr->getNameStart(),
SrcPtr->getNameStart()+SrcPtr->getNameLen());
Name += ".realp";
- llvm::Value *Ops[] = {Zero, Zero};
- llvm::Value *RealPtr = Builder.CreateGEP(SrcPtr, Ops, Ops+2, Name.c_str());
+ llvm::Value *RealPtr = Builder.CreateStructGEP(SrcPtr, 0, Name.c_str());
Name.pop_back(); // .realp -> .real
llvm::Value *Real = Builder.CreateLoad(RealPtr, isVolatile, Name.c_str());
@@ -201,8 +197,7 @@ ComplexPairTy ComplexExprEmitter::EmitLoadOfComplex(llvm::Value *SrcPtr,
Name.resize(Name.size()-4); // .real -> .imagp
Name += "imagp";
- Ops[1] = One; // { Ops = { Zero, One }
- llvm::Value *ImagPtr = Builder.CreateGEP(SrcPtr, Ops, Ops+2, Name.c_str());
+ llvm::Value *ImagPtr = Builder.CreateStructGEP(SrcPtr, 1, Name.c_str());
Name.pop_back(); // .imagp -> .imag
llvm::Value *Imag = Builder.CreateLoad(ImagPtr, isVolatile, Name.c_str());
@@ -213,14 +208,8 @@ ComplexPairTy ComplexExprEmitter::EmitLoadOfComplex(llvm::Value *SrcPtr,
/// specified value pointer.
void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, llvm::Value *Ptr,
bool isVolatile) {
- llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
- llvm::Constant *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
-
- llvm::Value *Ops[] = {Zero, Zero};
- llvm::Value *RealPtr = Builder.CreateGEP(Ptr, Ops, Ops+2, "real");
-
- Ops[1] = One; // { Ops = { Zero, One }
- llvm::Value *ImagPtr = Builder.CreateGEP(Ptr, Ops, Ops+2, "imag");
+ llvm::Value *RealPtr = Builder.CreateStructGEP(Ptr, 0, "real");
+ llvm::Value *ImagPtr = Builder.CreateStructGEP(Ptr, 1, "imag");
Builder.CreateStore(Val.first, RealPtr, isVolatile);
Builder.CreateStore(Val.second, ImagPtr, isVolatile);
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 892712a..2d42f8f 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -524,10 +524,7 @@ Value *ScalarExprEmitter::VisitImplicitCastExpr(const ImplicitCastExpr *E) {
isa<llvm::ArrayType>(cast<llvm::PointerType>(V->getType())
->getElementType()) &&
"Doesn't support VLAs yet!");
- llvm::Constant *Idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
-
- llvm::Value *Ops[] = {Idx0, Idx0};
- V = Builder.CreateGEP(V, Ops, Ops+2, "arraydecay");
+ V = Builder.CreateStructGEP(V, 0, "arraydecay");
// The resultant pointer type can be implicitly casted to other pointer
// types as well, for example void*.
@@ -597,7 +594,7 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
if (isa<llvm::PointerType>(InVal->getType())) {
// FIXME: This isn't right for VLAs.
NextVal = llvm::ConstantInt::get(llvm::Type::Int32Ty, AmountVal);
- NextVal = Builder.CreateGEP(InVal, NextVal);
+ NextVal = Builder.CreateGEP(InVal, NextVal, "ptrincdec");
} else {
// Add the inc/dec to the real part.
if (isa<llvm::IntegerType>(InVal->getType()))