[cfe-commits] r48534 - in /cfe/trunk/lib/CodeGen: CGExpr.cpp CGExprAgg.cpp CGExprComplex.cpp CGExprScalar.cpp
Chris Lattner
sabre at nondot.org
Tue Mar 18 22:19:41 PDT 2008
Author: lattner
Date: Wed Mar 19 00:19:41 2008
New Revision: 48534
URL: http://llvm.org/viewvc/llvm-project?rev=48534&view=rev
Log:
simplify the clang codegen by using the new Builder.CreateStructGEP method.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=48534&r1=48533&r2=48534&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Mar 19 00:19:41 2008
@@ -367,13 +367,9 @@
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 @@
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 @@
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 @@
}
}
- 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());
}
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=48534&r1=48533&r2=48534&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Wed Mar 19 00:19:41 2008
@@ -268,15 +268,9 @@
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 @@
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
Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=48534&r1=48533&r2=48534&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Wed Mar 19 00:19:41 2008
@@ -185,15 +185,11 @@
/// 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 @@
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 @@
/// 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);
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=48534&r1=48533&r2=48534&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Mar 19 00:19:41 2008
@@ -524,10 +524,7 @@
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 @@
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()))
More information about the cfe-commits
mailing list