[cfe-commits] r65761 - /cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Daniel Dunbar
daniel at zuster.org
Sat Feb 28 20:46:24 PST 2009
Author: ddunbar
Date: Sat Feb 28 22:46:24 2009
New Revision: 65761
URL: http://llvm.org/viewvc/llvm-project?rev=65761&view=rev
Log:
Obj-C non fragile ABI: Add GetInterfaceEHType for getting the Obj-C
exception typeinfo metadata, and a few other EH related types/functions.
- No functionality change.
Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=65761&r1=65760&r2=65761&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sat Feb 28 22:46:24 2009
@@ -297,7 +297,10 @@
/// exception personality function.
llvm::Value *EHPersonalityPtr;
- llvm::Function *UnwindResumeOrRethrowFn;
+ llvm::Function *UnwindResumeOrRethrowFn, *ObjCBeginCatchFn, *ObjCEndCatchFn;
+
+ const llvm::StructType *EHTypeTy;
+ const llvm::Type *EHTypePtrTy;
ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule &cgm);
~ObjCNonFragileABITypesHelper(){}
@@ -613,7 +616,10 @@
llvm::GlobalVariable* ObjCEmptyVtableVar;
/// MetaClassReferences - uniqued meta class references.
llvm::DenseMap<IdentifierInfo*, llvm::GlobalVariable*> MetaClassReferences;
-
+
+ /// EHTypeReferences - uniqued class ehtype references.
+ llvm::DenseMap<IdentifierInfo*, llvm::GlobalVariable*> EHTypeReferences;
+
/// FinishNonFragileABIModule - Write out global data structures at the end of
/// processing a translation unit.
void FinishNonFragileABIModule();
@@ -698,7 +704,11 @@
/// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
/// for the given selector.
llvm::Value *EmitSelector(CGBuilderTy &Builder, Selector Sel);
-
+
+ /// GetInterfaceEHType - Get the ehtype for the given Objective-C
+ /// interface. The return value has type EHTypePtrTy.
+ llvm::Value *GetInterfaceEHType(const ObjCInterfaceType *IT);
+
public:
CGObjCNonFragileABIMac(CodeGen::CodeGenModule &cgm);
// FIXME. All stubs for now!
@@ -3373,6 +3383,7 @@
"__objc_personality_v0");
EHPersonalityPtr = llvm::ConstantExpr::getBitCast(Personality, Int8PtrTy);
+
Params.clear();
Params.push_back(Int8PtrTy);
UnwindResumeOrRethrowFn =
@@ -3380,6 +3391,30 @@
Params,
false),
"_Unwind_Resume_or_Rethrow");
+ ObjCBeginCatchFn =
+ CGM.CreateRuntimeFunction(llvm::FunctionType::get(Int8PtrTy,
+ Params,
+ false),
+ "objc_begin_catch");
+
+ Params.clear();
+ ObjCEndCatchFn =
+ CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy,
+ Params,
+ false),
+ "objc_end_catch");
+
+ // struct objc_typeinfo {
+ // const void** vtable; // objc_ehtype_vtable + 2
+ // const char* name; // c++ typeinfo string
+ // Class cls;
+ // };
+ EHTypeTy = llvm::StructType::get(llvm::PointerType::getUnqual(Int8PtrTy),
+ Int8PtrTy,
+ ClassnfABIPtrTy,
+ NULL);
+ CGM.getModule().addTypeName("struct._objc_typeinfo", CategorynfABITy);
+ EHTypePtrTy = llvm::PointerType::getUnqual(EHTypeTy);
}
llvm::Function *CGObjCNonFragileABIMac::ModuleInitFunction() {
@@ -4830,6 +4865,41 @@
// Clear the insertion point to indicate we are in unreachable code.
CGF.Builder.ClearInsertionPoint();
}
+
+llvm::Value *
+CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceType *IT) {
+ const ObjCInterfaceDecl *ID = IT->getDecl();
+ llvm::GlobalVariable * &Entry = EHTypeReferences[ID->getIdentifier()];
+ if (Entry)
+ return Entry;
+
+ std::string ClassName("\01_OBJC_CLASS_$_" + ID->getNameAsString());
+ std::string VTableName = "objc_ehtype_vtable";
+ llvm::GlobalVariable *VTableGV =
+ CGM.getModule().getGlobalVariable(VTableName);
+ if (!VTableGV)
+ VTableGV = new llvm::GlobalVariable(ObjCTypes.Int8PtrTy, false,
+ llvm::GlobalValue::ExternalLinkage,
+ 0, VTableName, &CGM.getModule());
+
+ llvm::Value *VTableIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, 2);
+
+ std::vector<llvm::Constant*> Values(3);
+ Values[0] = llvm::ConstantExpr::getGetElementPtr(VTableGV, &VTableIdx, 1);
+ Values[1] = GetClassName(ID->getIdentifier());
+ Values[2] = GetClassGlobal(ClassName);
+ llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.EHTypeTy, Values);
+
+ Entry =
+ new llvm::GlobalVariable(ObjCTypes.EHTypeTy, false,
+ llvm::GlobalValue::WeakLinkage,
+ Init,
+ (std::string("OBJC_EHTYPE_$_") +
+ ID->getIdentifier()->getName()),
+ &CGM.getModule());
+
+ return Entry;
+}
/* *** */
More information about the cfe-commits
mailing list