mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 03:24:09 +00:00
- Add a "getOrInsertGlobal" method to the Module class. This acts similarly to
"getOrInsertFunction" in that it either adds a new declaration of the global and returns it, or returns the current one -- optionally casting it to the correct type. - Use the new getOrInsertGlobal in the stack protector code. - Use "splitBasicBlock" in the stack protector code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58727 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -224,6 +224,28 @@ GlobalVariable *Module::getGlobalVariable(const std::string &Name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) {
|
||||
ValueSymbolTable &SymTab = getValueSymbolTable();
|
||||
|
||||
// See if we have a definition for the specified global already.
|
||||
GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(SymTab.lookup(Name));
|
||||
if (GV == 0) {
|
||||
// Nope, add it
|
||||
GlobalVariable *New =
|
||||
new GlobalVariable(Ty, false, GlobalVariable::ExternalLinkage, 0, Name);
|
||||
GlobalList.push_back(New);
|
||||
return New; // Return the new declaration.
|
||||
}
|
||||
|
||||
// If the variable exists but has the wrong type, return a bitcast to the
|
||||
// right type.
|
||||
if (GV->getType() != PointerType::getUnqual(Ty))
|
||||
return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty));
|
||||
|
||||
// Otherwise, we just found the existing function or a prototype.
|
||||
return GV;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Methods for easy access to the global variables in the module.
|
||||
//
|
||||
|
Reference in New Issue
Block a user