[cfe-commits] r49217 - /cfe/trunk/lib/CodeGen/CGObjCEtoile.cpp
Chris Lattner
sabre at nondot.org
Fri Apr 4 09:00:03 PDT 2008
Author: lattner
Date: Fri Apr 4 10:59:59 2008
New Revision: 49217
URL: http://llvm.org/viewvc/llvm-project?rev=49217&view=rev
Log:
updates from David.
Modified:
cfe/trunk/lib/CodeGen/CGObjCEtoile.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjCEtoile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCEtoile.cpp?rev=49217&r1=49216&r2=49217&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCEtoile.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCEtoile.cpp Fri Apr 4 10:59:59 2008
@@ -11,7 +11,6 @@
//
//===----------------------------------------------------------------------===//
-#include <stdarg.h>
#include "CGObjCRuntime.h"
#include "llvm/Module.h"
#include "llvm/Support/Compiler.h"
@@ -74,15 +73,21 @@
PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
// Object type
- llvm::OpaqueType *OpaqueObjTy = llvm::OpaqueType::get();
+ llvm::PATypeHolder OpaqueObjTy = llvm::OpaqueType::get();
llvm::Type *OpaqueIdTy = llvm::PointerType::getUnqual(OpaqueObjTy);
- IdTy = llvm::PointerType::getUnqual(llvm::StructType::get(OpaqueIdTy, NULL));
- OpaqueObjTy->refineAbstractTypeTo(IdTy);
+ IdTy = llvm::StructType::get(OpaqueIdTy, NULL);
+ llvm::cast<llvm::OpaqueType>(OpaqueObjTy.get())->refineAbstractTypeTo(IdTy);
+ IdTy = llvm::cast<llvm::StructType>(OpaqueObjTy.get());
+ IdTy = llvm::PointerType::getUnqual(IdTy);
// Call structure type.
- llvm::OpaqueType *OpaqueSlotTy = llvm::OpaqueType::get();
- CallTy = llvm::StructType::get(llvm::PointerType::getUnqual(OpaqueSlotTy),
- SelectorTy, IdTy, NULL);
+ llvm::PATypeHolder OpaqueSlotTy = llvm::OpaqueType::get();
+ CallTy = llvm::StructType::get(
+ llvm::PointerType::getUnqual(OpaqueSlotTy),
+ SelectorTy,
+ IdTy,
+ NULL);
+ //CallTy = llvm::PointerType::getUnqual(CallTy);
// IMP type
std::vector<const llvm::Type*> IMPArgs;
@@ -91,10 +96,16 @@
IMPTy = llvm::FunctionType::get(IdTy, IMPArgs, true);
// Slot type
- SlotTy = llvm::StructType::get(IntTy, IMPTy, PtrToInt8Ty, PtrToInt8Ty,
- llvm::Type::Int32Ty, NULL);
- OpaqueSlotTy->refineAbstractTypeTo(SlotTy);
- SlotTy = llvm::PointerType::getUnqual(SlotTy);
+ SlotTy = llvm::StructType::get(IntTy,
+ IMPTy,
+ PtrToInt8Ty,
+ PtrToInt8Ty,
+ llvm::Type::Int32Ty,
+ NULL);
+ llvm::cast<llvm::OpaqueType>(
+ OpaqueSlotTy.get())->refineAbstractTypeTo(SlotTy);
+ SlotTy = llvm::PointerType::getUnqual(
+ llvm::cast<llvm::StructType>(OpaqueSlotTy.get()));
// Lookup function type
std::vector<const llvm::Type*> LookupFunctionArgs;
@@ -102,12 +113,13 @@
LookupFunctionArgs.push_back(IdTy);
LookupFunctionArgs.push_back(SelectorTy);
LookupFunctionArgs.push_back(IdTy);
- LookupFunctionTy = llvm::FunctionType::get(SlotTy, LookupFunctionArgs, false);
+ LookupFunctionTy =
+ llvm::FunctionType::get(SlotTy, LookupFunctionArgs, false);
LookupFunctionTy = llvm::PointerType::getUnqual(LookupFunctionTy);
}
-// Looks up the selector for the specified name / type pair.
+/// Looks up the selector for the specified name / type pair.
llvm::Value *CGObjCEtoile::getSelector(llvm::LLVMFoldingBuilder &Builder,
llvm::Value *SelName,
llvm::Value *SelTypes)
@@ -117,20 +129,28 @@
SelTypes = llvm::ConstantPointerNull::get(PtrToInt8Ty);
}
llvm::Constant *SelFunction =
- TheModule.getOrInsertFunction("lookup_typed_selector", SelectorTy,
- PtrToInt8Ty, PtrToInt8Ty, NULL);
+ TheModule.getOrInsertFunction("lookup_typed_selector",
+ SelectorTy,
+ PtrToInt8Ty,
+ PtrToInt8Ty,
+ NULL);
llvm::SmallVector<llvm::Value*, 2> Args;
Args.push_back(SelName);
Args.push_back(SelTypes);
return Builder.CreateCall(SelFunction, Args.begin(), Args.end());
}
-#define SET(structure, index, value) do {\
- llvm::Value *element_ptr = Builder.CreateStructGEP(structure, index);\
- Builder.CreateStore(value, element_ptr);} while(0)
+static void SetField(llvm::LLVMFoldingBuilder &Builder,
+ llvm::Value *Structure,
+ unsigned Index,
+ llvm::Value *Value) {
+ llvm::Value *element_ptr = Builder.CreateStructGEP(Structure, Index);
+ Builder.CreateStore(Value, element_ptr);
+}
// Generate code for a message send expression on the Etoile runtime.
// BIG FAT WARNING: Much of this code will need factoring out later.
-llvm::Value *CGObjCEtoile::generateMessageSend(llvm::LLVMFoldingBuilder &Builder,
+llvm::Value *CGObjCEtoile::generateMessageSend(
+ llvm::LLVMFoldingBuilder &Builder,
const llvm::Type *ReturnTy,
llvm::Value *Sender,
llvm::Value *Receiver,
@@ -172,9 +192,9 @@
// Create the call structure
llvm::Value *Call = Builder.CreateAlloca(CallTy);
- SET(Call, 0, Slot);
- SET(Call, 1, cmd);
- SET(Call, 2, Sender);
+ SetField(Builder, Call, 0, Slot);
+ SetField(Builder, Call, 1, cmd);
+ SetField(Builder, Call, 2, Sender);
// Get the IMP from the slot and call it
// TODO: Property load / store optimisations
@@ -194,6 +214,8 @@
return Builder.CreateCall(IMP, Args.begin(), Args.end());
}
+/// Generates an LLVM Function object corresponding to the Objective-C method,
+/// including the implicit arguments.
llvm::Function *CGObjCEtoile::MethodPreamble(
const llvm::Type *ReturnTy,
const llvm::Type *SelfTy,
@@ -207,7 +229,8 @@
for (unsigned i=0; i<ArgC ; i++) {
Args.push_back(ArgTy[i]);
}
- llvm::FunctionType *MethodTy = llvm::FunctionType::get(ReturnTy, Args, isVarArg);
+ llvm::FunctionType *MethodTy =
+ llvm::FunctionType::get(ReturnTy, Args, isVarArg);
llvm::Function *Method = new llvm::Function(MethodTy,
llvm::GlobalValue::InternalLinkage,
".objc.method",
More information about the cfe-commits
mailing list