From 961891d6bb24cbf3cffbd0d1489836f2b17149fd Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Wed, 23 Mar 2011 18:39:12 +0000 Subject: [PATCH] Remove the redundant loads / stores to globals that we were generating for selectors (GNU runtimes). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128156 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCGNU.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index dc91ec764c..99132d6967 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -521,9 +521,12 @@ llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel, Types.push_back(TypedSelector(TypeEncoding, SelValue)); } - if (lval) - return SelValue; - return Builder.CreateLoad(SelValue); + if (lval) { + llvm::Value *tmp = Builder.CreateAlloca(SelValue->getType()); + Builder.CreateStore(SelValue, tmp); + return tmp; + } + return SelValue; } llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel, @@ -1906,16 +1909,12 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() { llvm::Constant *Idxs[] = {Zeros[0], llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), i), Zeros[0]}; // FIXME: We're generating redundant loads and stores here! - llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy, - true, llvm::GlobalValue::InternalLinkage, - llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2), - ".objc_sel_ptr"); + llvm::Constant *SelPtr = llvm::ConstantExpr::getGetElementPtr(SelectorList, + Idxs, 2); // If selectors are defined as an opaque type, cast the pointer to this // type. - if (isSelOpaque) { - SelPtr = llvm::ConstantExpr::getBitCast(SelPtr, + SelPtr = llvm::ConstantExpr::getBitCast(SelPtr, llvm::PointerType::getUnqual(SelectorTy)); - } SelectorAliases[i]->replaceAllUsesWith(SelPtr); SelectorAliases[i]->eraseFromParent(); } -- 2.40.0