[cfe-commits] r48970 - in /cfe/trunk/lib/CodeGen: CGExpr.cpp CGExprScalar.cpp CodeGenFunction.cpp CodeGenModule.cpp CodeGenTypes.cpp
Chris Lattner
sabre at nondot.org
Sun Mar 30 16:25:33 PDT 2008
Author: lattner
Date: Sun Mar 30 18:25:33 2008
New Revision: 48970
URL: http://llvm.org/viewvc/llvm-project?rev=48970&view=rev
Log:
some cleanups on top of David's patch. There are still two
remaining open issues I've communicated to him:
1) self can be assigned to, and his patch didn't handle it correctly.
2) CollectObjCIvarTypes is N^2 (because each subclass reprocesses
all parent class ivars) and flattens classes. If A derives from B,
and both have an int, I'd expect to get { {i32}, i32}, not { i32, i32}.
David, please review.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=48970&r1=48969&r2=48970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sun Mar 30 18:25:33 2008
@@ -82,7 +82,7 @@
LValue CodeGenFunction::EmitLValue(const Expr *E) {
switch (E->getStmtClass()) {
default: {
- printf("Statement class: %d\n", E->getStmtClass());
+ printf("Statement class: %d\n", E->getStmtClass());
WarnUnsupported(E, "l-value expression");
llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
return LValue::MakeAddr(llvm::UndefValue::get(Ty));
@@ -566,32 +566,27 @@
// a class without recompiling all of the subclasses. If this is the case
// then the CGObjCRuntime subclass must return true to LateBoundIvars and
// implement the lookup itself.
- if(CGM.getObjCRuntime()->LateBoundIVars()) {
+ if (CGM.getObjCRuntime()->LateBoundIVars()) {
assert(0 && "FIXME: Implement support for late-bound instance variables");
return LValue(); // Not reached.
}
- else {
- // Get a structure type for the object
- QualType ExprTy = E->getBase()->getType();
- const llvm::Type *ObjectType = ConvertType(ExprTy);
- //TODO: Add a special case for isa (index 0)
- // Work out which index the ivar is
- const ObjCIvarDecl *Decl = E->getDecl();
- unsigned Index = CGM.getTypes().getLLVMFieldNo(Decl);
+
+ // Get a structure type for the object
+ QualType ExprTy = E->getBase()->getType();
+ const llvm::Type *ObjectType = ConvertType(ExprTy);
+ // TODO: Add a special case for isa (index 0)
+ // Work out which index the ivar is
+ const ObjCIvarDecl *Decl = E->getDecl();
+ unsigned Index = CGM.getTypes().getLLVMFieldNo(Decl);
- // Get object pointer
- llvm::Value * Object = EmitLValue(E->getBase()).getAddress();
- // Coerce object pointer to correct type.
- if (Object->getType() != ObjectType) {
- Object = Builder.CreateBitCast(Object, ObjectType);
- }
- // Get the correct element
- llvm::Value * Element = Builder.CreateStructGEP(Object,
- Index,
- Decl->getName());
- // Element = Builder.CreateLoad(Element);
- return LValue::MakeAddr(Element);
- }
+ // Get object pointer and coerce object pointer to correct type.
+ llvm::Value *Object = EmitLValue(E->getBase()).getAddress();
+ if (Object->getType() != ObjectType)
+ Object = Builder.CreateBitCast(Object, ObjectType);
+
+ // Return a pointer to the right element.
+ return LValue::MakeAddr(Builder.CreateStructGEP(Object, Index,
+ Decl->getName()));
}
RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType,
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=48970&r1=48969&r2=48970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sun Mar 30 18:25:33 2008
@@ -19,7 +19,6 @@
#include "llvm/GlobalVariable.h"
#include "llvm/Intrinsics.h"
#include "llvm/Support/Compiler.h"
-#include "llvm/ValueSymbolTable.h"
#include <cstdarg>
using namespace clang;
@@ -51,7 +50,6 @@
Builder(CGF.Builder),
Runtime(CGF.CGM.getObjCRuntime()) {
}
-
//===--------------------------------------------------------------------===//
// Utilities
@@ -127,7 +125,7 @@
return EmitLoadOfLValue(E);
}
Value *VisitObjCMessageExpr(ObjCMessageExpr *E);
- Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
+ Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { return EmitLoadOfLValue(E);}
Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E);
Value *VisitMemberExpr(Expr *E) { return EmitLoadOfLValue(E); }
Value *VisitOCUVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); }
@@ -451,22 +449,18 @@
return llvm::UndefValue::get(CGF.ConvertType(E->getType()));
}
-Value *ScalarExprEmitter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
- return Builder.CreateLoad(CGF.EmitObjCIvarRefLValue(E).getAddress());
-}
-
Value *ScalarExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
// Only the lookup mechanism and first two arguments of the method
// implementation vary between runtimes. We can get the receiver and
// arguments in generic code.
// Find the receiver
- llvm::Value * Receiver = CGF.EmitScalarExpr(E->getReceiver());
+ llvm::Value *Receiver = CGF.EmitScalarExpr(E->getReceiver());
// Process the arguments
- unsigned int ArgC = E->getNumArgs();
+ unsigned ArgC = E->getNumArgs();
llvm::SmallVector<llvm::Value*, 16> Args;
- for(unsigned i=0 ; i<ArgC ; i++) {
+ for (unsigned i = 0; i != ArgC; ++i) {
Expr *ArgExpr = E->getArg(i);
QualType ArgTy = ArgExpr->getType();
if (!CGF.hasAggregateLLVMType(ArgTy)) {
@@ -489,13 +483,11 @@
llvm::Constant *Selector = CGF.CGM.GetAddrOfConstantString(SelStr);
llvm::Value *SelPtr = Builder.CreateStructGEP(Selector, 0);
- return Runtime->generateMessageSend(Builder,
- ConvertType(E->getType()),
- CGF.CurFn->getValueSymbolTable().lookup("self"),
- Receiver,
- SelPtr,
- &Args[0],
- Args.size());
+ return Runtime->generateMessageSend(Builder, ConvertType(E->getType()),
+ // FIXME: Self can be assigned to!
+ CGF.CurFn->arg_begin(),
+ Receiver, SelPtr,
+ &Args[0], Args.size());
}
Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=48970&r1=48969&r2=48970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sun Mar 30 18:25:33 2008
@@ -26,7 +26,7 @@
CodeGenFunction::CodeGenFunction(CodeGenModule &cgm)
: CGM(cgm), Target(CGM.getContext().Target), SwitchInsn(NULL),
- CaseRangeBlock(NULL) {}
+ CaseRangeBlock(NULL) {}
ASTContext &CodeGenFunction::getContext() const {
return CGM.getContext();
@@ -64,11 +64,11 @@
for (unsigned i=0 ; i<OMD->param_size() ; i++) {
ParamTypes.push_back(ConvertType(OMD->getParamDecl(i)->getType()));
}
- CurFn = CGM.getObjCRuntime()->MethodPreamble(ConvertType(OMD->getResultType()),
- llvm::PointerType::getUnqual(llvm::Type::Int32Ty),
- ParamTypes.begin(),
- OMD->param_size(),
- OMD->isVariadic());
+ CurFn =CGM.getObjCRuntime()->MethodPreamble(ConvertType(OMD->getResultType()),
+ llvm::PointerType::getUnqual(llvm::Type::Int32Ty),
+ ParamTypes.begin(),
+ OMD->param_size(),
+ OMD->isVariadic());
llvm::BasicBlock *EntryBB = new llvm::BasicBlock("entry", CurFn);
// Create a marker to make it easy to insert allocas into the entryblock
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=48970&r1=48969&r2=48970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Mar 30 18:25:33 2008
@@ -41,9 +41,8 @@
CodeGenModule::~CodeGenModule() {
llvm::Function *ObjCInitFunction = Runtime->ModuleInitFunction();
- if (ObjCInitFunction) {
+ if (ObjCInitFunction)
AddGlobalCtor(ObjCInitFunction);
- }
EmitGlobalCtors();
delete Runtime;
}
@@ -80,15 +79,15 @@
/// called on module load, if any have been registered with AddGlobalCtor.
void CodeGenModule::EmitGlobalCtors() {
if (GlobalCtors.empty()) return;
+
// Get the type of @llvm.global_ctors
std::vector<const llvm::Type*> CtorFields;
CtorFields.push_back(llvm::IntegerType::get(32));
// Constructor function type
std::vector<const llvm::Type*> VoidArgs;
- llvm::FunctionType* CtorFuncTy = llvm::FunctionType::get(
- llvm::Type::VoidTy,
- VoidArgs,
- false);
+ llvm::FunctionType* CtorFuncTy =
+ llvm::FunctionType::get(llvm::Type::VoidTy, VoidArgs, false);
+
// i32, function type pair
const llvm::Type *FPType = llvm::PointerType::getUnqual(CtorFuncTy);
llvm::StructType* CtorStructTy =
@@ -120,7 +119,6 @@
GlobalCtorsVal->setInitializer(llvm::ConstantArray::get(GlobalCtorsTy,
CtorValues));
-
}
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=48970&r1=48969&r2=48970&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Sun Mar 30 18:25:33 2008
@@ -148,16 +148,14 @@
/// Objective-C object, in the order that they appear. Used to create LLVM
/// structures corresponding to Objective-C objects.
void CodeGenTypes::CollectObjCIvarTypes(ObjCInterfaceDecl *ObjCClass,
- std::vector<const llvm::Type*> &IvarTypes) {
+ std::vector<const llvm::Type*> &IvarTypes) {
ObjCInterfaceDecl *SuperClass = ObjCClass->getSuperClass();
- if(SuperClass) {
+ if (SuperClass)
CollectObjCIvarTypes(SuperClass, IvarTypes);
- }
- for(ObjCInterfaceDecl::ivar_iterator ivar=ObjCClass->ivar_begin() ;
- ivar != ObjCClass->ivar_end() ;
- ivar++) {
- IvarTypes.push_back(ConvertType((*ivar)->getType()));
- ObjCIvarInfo[*ivar] = IvarTypes.size() - 1;
+ for (ObjCInterfaceDecl::ivar_iterator I = ObjCClass->ivar_begin(),
+ E = ObjCClass->ivar_end(); I != E; ++I) {
+ IvarTypes.push_back(ConvertType((*I)->getType()));
+ ObjCIvarInfo[*I] = IvarTypes.size() - 1;
}
}
@@ -420,8 +418,7 @@
/// getLLVMFieldNo - Return llvm::StructType element number
/// that corresponds to the field FD.
unsigned CodeGenTypes::getLLVMFieldNo(const FieldDecl *FD) {
- llvm::DenseMap<const FieldDecl *, unsigned>::iterator
- I = FieldInfo.find(FD);
+ llvm::DenseMap<const FieldDecl*, unsigned>::iterator I = FieldInfo.find(FD);
assert (I != FieldInfo.end() && "Unable to find field info");
return I->second;
}
@@ -429,7 +426,7 @@
unsigned CodeGenTypes::getLLVMFieldNo(const ObjCIvarDecl *OID) {
llvm::DenseMap<const ObjCIvarDecl*, unsigned>::iterator
I = ObjCIvarInfo.find(OID);
- assert (I != ObjCIvarInfo.end() && "Unable to find field info");
+ assert(I != ObjCIvarInfo.end() && "Unable to find field info");
return I->second;
}
More information about the cfe-commits
mailing list