forked from OSchip/llvm-project
simplify the clang codegen by using the new Builder.CreateStructGEP method.
llvm-svn: 48534
This commit is contained in:
parent
3f8392626b
commit
3e593cdb98
|
@ -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());
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()))
|
||||
|
|
Loading…
Reference in New Issue