forked from OSchip/llvm-project
Pull out code shared between GV forward-decl and definition processing.
This gives us only a single call site for setValueNameMergingDuplicates. The next stage is the start merging them together. llvm-svn: 14811
This commit is contained in:
parent
70ef57d001
commit
42dd47437e
|
@ -591,7 +591,7 @@ static void setValueName(Value *V, char *NameStr) {
|
||||||
// allowed to be redefined in the specified context. If the name is a new name
|
// allowed to be redefined in the specified context. If the name is a new name
|
||||||
// for the typeplane, false is returned.
|
// for the typeplane, false is returned.
|
||||||
//
|
//
|
||||||
static bool setValueNameMergingDuplicates(GlobalValue *V, char *NameStr) {
|
static bool setValueNameMergingDuplicates(GlobalVariable *V, char *NameStr) {
|
||||||
if (NameStr == 0) return false;
|
if (NameStr == 0) return false;
|
||||||
|
|
||||||
std::string Name(NameStr); // Copy string
|
std::string Name(NameStr); // Copy string
|
||||||
|
@ -609,21 +609,19 @@ static bool setValueNameMergingDuplicates(GlobalValue *V, char *NameStr) {
|
||||||
// 1. If at least one of the globals is uninitialized or
|
// 1. If at least one of the globals is uninitialized or
|
||||||
// 2. If both initializers have the same value.
|
// 2. If both initializers have the same value.
|
||||||
//
|
//
|
||||||
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
|
if (!EGV->hasInitializer() || !V->hasInitializer() ||
|
||||||
if (!EGV->hasInitializer() || !GV->hasInitializer() ||
|
EGV->getInitializer() == V->getInitializer()) {
|
||||||
EGV->getInitializer() == GV->getInitializer()) {
|
|
||||||
|
// Make sure the existing global version gets the initializer! Make
|
||||||
// Make sure the existing global version gets the initializer! Make
|
// sure that it also gets marked const if the new version is.
|
||||||
// sure that it also gets marked const if the new version is.
|
if (V->hasInitializer() && !EGV->hasInitializer())
|
||||||
if (GV->hasInitializer() && !EGV->hasInitializer())
|
EGV->setInitializer(V->getInitializer());
|
||||||
EGV->setInitializer(GV->getInitializer());
|
if (V->isConstant())
|
||||||
if (GV->isConstant())
|
EGV->setConstant(true);
|
||||||
EGV->setConstant(true);
|
EGV->setLinkage(V->getLinkage());
|
||||||
EGV->setLinkage(GV->getLinkage());
|
|
||||||
|
delete V; // Destroy the duplicate!
|
||||||
delete GV; // Destroy the duplicate!
|
return true; // They are equivalent!
|
||||||
return true; // They are equivalent!
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,7 +634,26 @@ static bool setValueNameMergingDuplicates(GlobalValue *V, char *NameStr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
|
||||||
|
/// this is a declaration, otherwise it is a definition.
|
||||||
|
static void ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
|
||||||
|
bool isConstantGlobal, const Type *Ty,
|
||||||
|
Constant *Initializer) {
|
||||||
|
// Global declarations appear in Constant Pool
|
||||||
|
GlobalVariable *GV = new GlobalVariable(Ty, isConstantGlobal, Linkage,
|
||||||
|
Initializer);
|
||||||
|
if (!setValueNameMergingDuplicates(GV, NameStr)) { // If not redefining...
|
||||||
|
CurModule.CurrentModule->getGlobalList().push_back(GV);
|
||||||
|
int Slot = InsertValue(GV, CurModule.Values);
|
||||||
|
|
||||||
|
if (Slot != -1) {
|
||||||
|
CurModule.DeclareNewGlobalValue(GV, ValID::create(Slot));
|
||||||
|
} else {
|
||||||
|
CurModule.DeclareNewGlobalValue(GV,
|
||||||
|
ValID::create((char*)GV->getName().c_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// setTypeName - Set the specified type to the name given. The name may be
|
// setTypeName - Set the specified type to the name given. The name may be
|
||||||
// null potentially, in which case this is a noop. The string passed in is
|
// null potentially, in which case this is a noop. The string passed in is
|
||||||
|
@ -1443,41 +1460,11 @@ ConstPool : ConstPool OptAssign TYPE TypesV { // Types can be defined in the co
|
||||||
| ConstPool FunctionProto { // Function prototypes can be in const pool
|
| ConstPool FunctionProto { // Function prototypes can be in const pool
|
||||||
}
|
}
|
||||||
| ConstPool OptAssign OptLinkage GlobalType ConstVal {
|
| ConstPool OptAssign OptLinkage GlobalType ConstVal {
|
||||||
const Type *Ty = $5->getType();
|
if ($5 == 0) ThrowException("Global value initializer is not a constant!");
|
||||||
// Global declarations appear in Constant Pool
|
ParseGlobalVariable($2, $3, $4, $5->getType(), $5);
|
||||||
Constant *Initializer = $5;
|
|
||||||
if (Initializer == 0)
|
|
||||||
ThrowException("Global value initializer is not a constant!");
|
|
||||||
|
|
||||||
GlobalVariable *GV = new GlobalVariable(Ty, $4, $3, Initializer);
|
|
||||||
if (!setValueNameMergingDuplicates(GV, $2)) { // If not redefining...
|
|
||||||
CurModule.CurrentModule->getGlobalList().push_back(GV);
|
|
||||||
int Slot = InsertValue(GV, CurModule.Values);
|
|
||||||
|
|
||||||
if (Slot != -1) {
|
|
||||||
CurModule.DeclareNewGlobalValue(GV, ValID::create(Slot));
|
|
||||||
} else {
|
|
||||||
CurModule.DeclareNewGlobalValue(GV, ValID::create(
|
|
||||||
(char*)GV->getName().c_str()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
| ConstPool OptAssign EXTERNAL GlobalType Types {
|
| ConstPool OptAssign EXTERNAL GlobalType Types {
|
||||||
const Type *Ty = *$5;
|
ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, *$5, 0);
|
||||||
// Global declarations appear in Constant Pool
|
|
||||||
GlobalVariable *GV = new GlobalVariable(Ty,$4,GlobalValue::ExternalLinkage);
|
|
||||||
if (!setValueNameMergingDuplicates(GV, $2)) { // If not redefining...
|
|
||||||
CurModule.CurrentModule->getGlobalList().push_back(GV);
|
|
||||||
int Slot = InsertValue(GV, CurModule.Values);
|
|
||||||
|
|
||||||
if (Slot != -1) {
|
|
||||||
CurModule.DeclareNewGlobalValue(GV, ValID::create(Slot));
|
|
||||||
} else {
|
|
||||||
assert(GV->hasName() && "Not named and not numbered!?");
|
|
||||||
CurModule.DeclareNewGlobalValue(GV, ValID::create(
|
|
||||||
(char*)GV->getName().c_str()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete $5;
|
delete $5;
|
||||||
}
|
}
|
||||||
| ConstPool TARGET TargetDefinition {
|
| ConstPool TARGET TargetDefinition {
|
||||||
|
|
Loading…
Reference in New Issue