From 532485cc6c078d9e51b517c6bbd8984deb17f0fe Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Fri, 18 Apr 2008 23:43:57 +0000 Subject: [PATCH] Add support to module codegen for adding and emitting annotations git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49944 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 17 +++++++++++++++++ lib/CodeGen/CodeGenModule.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index cb34fb5a73..a5a51b19c7 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -44,6 +44,7 @@ CodeGenModule::~CodeGenModule() { if (ObjCInitFunction) AddGlobalCtor(ObjCInitFunction); EmitGlobalCtors(); + EmitAnnotations(); delete Runtime; } @@ -123,6 +124,22 @@ void CodeGenModule::EmitGlobalCtors() { +void CodeGenModule::EmitAnnotations() { + if (Annotations.empty()) + return; + + // Create a new global variable for the ConstantStruct in the Module. + llvm::Constant *Array = + llvm::ConstantArray::get(llvm::ArrayType::get(Annotations[0]->getType(), + Annotations.size()), + Annotations); + llvm::GlobalValue *gv = + new llvm::GlobalVariable(Array->getType(), false, + llvm::GlobalValue::AppendingLinkage, Array, + "llvm.global.annotations", &TheModule); + gv->setSection("llvm.metadata"); +} + /// ReplaceMapValuesWith - This is a really slow and bad function that /// searches for any entries in GlobalDeclMap that point to OldVal, changing /// them to point to NewVal. This is badbadbad, FIXME! diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 3fcb56e3c4..e192e9913e 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -59,6 +59,7 @@ class CodeGenModule { llvm::Function *MemSetFn; llvm::DenseMap GlobalDeclMap; std::vector GlobalCtors; + std::vector Annotations; llvm::StringMap CFConstantStringMap; llvm::StringMap ConstantStringMap; @@ -99,6 +100,8 @@ public: void AddGlobalCtor(llvm::Function * Ctor); void EmitGlobalCtors(void); + void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); } + void EmitAnnotations(void); void EmitObjCMethod(const ObjCMethodDecl *OMD); void EmitFunction(const FunctionDecl *FD); -- 2.40.0