[cfe-commits] r66292 - in /cfe/trunk/lib/CodeGen: CodeGenModule.cpp CodeGenModule.h
Daniel Dunbar
daniel at zuster.org
Fri Mar 6 14:13:30 PST 2009
Author: ddunbar
Date: Fri Mar 6 16:13:30 2009
New Revision: 66292
URL: http://llvm.org/viewvc/llvm-project?rev=66292&view=rev
Log:
(LLVM svn up) Generalize RuntimeFunctions to RuntimeGlobals and add
CodeGenModule::CreateRuntimeVariable.
- No real functionality change; although we now assert on silly
things like:
--
int objc_exception_throw;
void f0() { @throw(@"A"); }
--
instead of accepting it.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=66292&r1=66291&r2=66292&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Mar 6 16:13:30 2009
@@ -66,44 +66,47 @@
EmitCtorList(GlobalDtors, "llvm.global_dtors");
EmitAnnotations();
EmitLLVMUsed();
- BindRuntimeFunctions();
+ BindRuntimeGlobals();
}
-void CodeGenModule::BindRuntimeFunctions() {
+void CodeGenModule::BindRuntimeGlobals() {
// Deal with protecting runtime function names.
- for (unsigned i = 0, e = RuntimeFunctions.size(); i < e; ++i) {
- llvm::Function *Fn = RuntimeFunctions[i].first;
- const std::string &Name = RuntimeFunctions[i].second;
+ for (unsigned i = 0, e = RuntimeGlobals.size(); i < e; ++i) {
+ llvm::GlobalValue *GV = RuntimeGlobals[i].first;
+ const std::string &Name = RuntimeGlobals[i].second;
- // Discard unused runtime functions.
- if (Fn->use_empty()) {
- Fn->eraseFromParent();
+ // Discard unused runtime declarations.
+ if (GV->isDeclaration() && GV->use_empty()) {
+ GV->eraseFromParent();
continue;
}
// See if there is a conflict against a function.
- llvm::Function *Conflict = TheModule.getFunction(Name);
+ llvm::GlobalValue *Conflict = TheModule.getNamedValue(Name);
if (Conflict) {
// Decide which version to take. If the conflict is a definition
// we are forced to take that, otherwise assume the runtime
// knows best.
+
+ // FIXME: This will fail phenomenally when the conflict is the
+ // wrong type of value. Just bail on it for now. This should
+ // really reuse something inside the LLVM Linker code.
+ assert(GV->getValueID() == Conflict->getValueID() &&
+ "Unable to resolve conflict between globals of different types.");
if (!Conflict->isDeclaration()) {
llvm::Value *Casted =
- llvm::ConstantExpr::getBitCast(Conflict, Fn->getType());
- Fn->replaceAllUsesWith(Casted);
- Fn->eraseFromParent();
+ llvm::ConstantExpr::getBitCast(Conflict, GV->getType());
+ GV->replaceAllUsesWith(Casted);
+ GV->eraseFromParent();
} else {
- Fn->takeName(Conflict);
+ GV->takeName(Conflict);
llvm::Value *Casted =
- llvm::ConstantExpr::getBitCast(Fn, Conflict->getType());
+ llvm::ConstantExpr::getBitCast(GV, Conflict->getType());
Conflict->replaceAllUsesWith(Casted);
Conflict->eraseFromParent();
}
- } else {
- // FIXME: There still may be conflicts with aliases and
- // variables.
- Fn->setName(Name);
- }
+ } else
+ GV->setName(Name);
}
}
@@ -882,10 +885,21 @@
llvm::Function *Fn = llvm::Function::Create(FTy,
llvm::Function::ExternalLinkage,
"", &TheModule);
- RuntimeFunctions.push_back(std::make_pair(Fn, Name));
+ RuntimeGlobals.push_back(std::make_pair(Fn, Name));
return Fn;
}
+llvm::GlobalVariable *
+CodeGenModule::CreateRuntimeVariable(const llvm::Type *Ty,
+ const std::string &Name) {
+ llvm::GlobalVariable *GV =
+ new llvm::GlobalVariable(Ty, /*Constant=*/false,
+ llvm::GlobalValue::ExternalLinkage,
+ 0, "", &TheModule);
+ RuntimeGlobals.push_back(std::make_pair(GV, Name));
+ return GV;
+}
+
void CodeGenModule::UpdateCompletedType(const TagDecl *TD) {
// Make sure that this type is translated.
Types.UpdateCompletedType(TD);
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=66292&r1=66291&r2=66292&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Fri Mar 6 16:13:30 2009
@@ -82,10 +82,11 @@
llvm::Function *MemMoveFn;
llvm::Function *MemSetFn;
- /// RuntimeFunctions - List of runtime functions whose names must be protected
- /// from introducing conflicts. These functions should be created unnamed, we
- /// will name them and patch up conflicts when we release the module.
- std::vector< std::pair<llvm::Function*, std::string> > RuntimeFunctions;
+ /// RuntimeGlobal - List of runtime globals whose names must be
+ /// protected from introducing conflicts. These globals should be
+ /// created unnamed, we will name them and patch up conflicts when
+ /// we release the module.
+ std::vector< std::pair<llvm::GlobalValue*, std::string> > RuntimeGlobals;
/// GlobalDeclMap - Mapping of decl names (represented as unique
/// character pointers from either the identifier table or the set
@@ -241,6 +242,10 @@
/// protected from collisions.
llvm::Function *CreateRuntimeFunction(const llvm::FunctionType *Ty,
const std::string &Name);
+ /// CreateRuntimeVariable - Create a new runtime global variable
+ /// whose name must be protected from collisions.
+ llvm::GlobalVariable *CreateRuntimeVariable(const llvm::Type *Ty,
+ const std::string &Name);
void UpdateCompletedType(const TagDecl *D);
@@ -340,7 +345,7 @@
/// references to global which may otherwise be optimized out.
void EmitLLVMUsed(void);
- void BindRuntimeFunctions();
+ void BindRuntimeGlobals();
/// MayDeferGeneration - Determine if the given decl can be emitted
/// lazily; this is only relevant for definitions. The given decl
More information about the cfe-commits
mailing list