mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage - Minimize redundant isa<GlobalValue> usage - Correct isa<Constant> for GlobalValue subclass - Remove tabs - Fix coments refering to ConstantPointerRef git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14937 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e253cf60fd
commit
3271ed554a
@ -79,7 +79,7 @@ static struct PerModuleInfo {
|
|||||||
// GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
|
// GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
|
||||||
// references to global values. Global values may be referenced before they
|
// references to global values. Global values may be referenced before they
|
||||||
// are defined, and if so, the temporary object that they represent is held
|
// are defined, and if so, the temporary object that they represent is held
|
||||||
// here. This is used for forward references of ConstantPointerRefs.
|
// here. This is used for forward references of GlobalValues.
|
||||||
//
|
//
|
||||||
typedef std::map<std::pair<const PointerType *,
|
typedef std::map<std::pair<const PointerType *,
|
||||||
ValID>, GlobalValue*> GlobalRefsType;
|
ValID>, GlobalValue*> GlobalRefsType;
|
||||||
@ -282,10 +282,10 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
|
|||||||
case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
|
case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
|
||||||
if (!ConstantUInt::isValueValidForType(Ty, D.UConstPool64)) {
|
if (!ConstantUInt::isValueValidForType(Ty, D.UConstPool64)) {
|
||||||
if (!ConstantSInt::isValueValidForType(Ty, D.ConstPool64)) {
|
if (!ConstantSInt::isValueValidForType(Ty, D.ConstPool64)) {
|
||||||
ThrowException("Integral constant '" + utostr(D.UConstPool64) +
|
ThrowException("Integral constant '" + utostr(D.UConstPool64) +
|
||||||
"' is invalid or out of range!");
|
"' is invalid or out of range!");
|
||||||
} else { // This is really a signed reference. Transmogrify.
|
} else { // This is really a signed reference. Transmogrify.
|
||||||
return ConstantSInt::get(Ty, D.ConstPool64);
|
return ConstantSInt::get(Ty, D.ConstPool64);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ConstantUInt::get(Ty, D.UConstPool64);
|
return ConstantUInt::get(Ty, D.UConstPool64);
|
||||||
@ -452,15 +452,15 @@ static void ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
|
|||||||
// resolver table
|
// resolver table
|
||||||
InsertValue(V, *FutureLateResolvers);
|
InsertValue(V, *FutureLateResolvers);
|
||||||
} else {
|
} else {
|
||||||
if (DID.Type == ValID::NameVal)
|
if (DID.Type == ValID::NameVal)
|
||||||
ThrowException("Reference to an invalid definition: '" +DID.getName()+
|
ThrowException("Reference to an invalid definition: '" +DID.getName()+
|
||||||
"' of type '" + V->getType()->getDescription() + "'",
|
"' of type '" + V->getType()->getDescription() + "'",
|
||||||
PHI->second.second);
|
PHI->second.second);
|
||||||
else
|
else
|
||||||
ThrowException("Reference to an invalid definition: #" +
|
ThrowException("Reference to an invalid definition: #" +
|
||||||
itostr(DID.Num) + " of type '" +
|
itostr(DID.Num) + " of type '" +
|
||||||
V->getType()->getDescription() + "'",
|
V->getType()->getDescription() + "'",
|
||||||
PHI->second.second);
|
PHI->second.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -643,7 +643,7 @@ static bool setTypeName(const Type *T, char *NameStr) {
|
|||||||
|
|
||||||
// Any other kind of (non-equivalent) redefinition is an error.
|
// Any other kind of (non-equivalent) redefinition is an error.
|
||||||
ThrowException("Redefinition of type named '" + Name + "' in the '" +
|
ThrowException("Redefinition of type named '" + Name + "' in the '" +
|
||||||
T->getDescription() + "' type plane!");
|
T->getDescription() + "' type plane!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -703,8 +703,8 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
|
|||||||
|
|
||||||
for (unsigned i = 0; i != UpRefs.size(); ++i) {
|
for (unsigned i = 0; i != UpRefs.size(); ++i) {
|
||||||
UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
|
UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
|
||||||
<< UpRefs[i].second->getDescription() << ") = "
|
<< UpRefs[i].second->getDescription() << ") = "
|
||||||
<< (TypeContains(Ty, UpRefs[i].second) ? "true" : "false") << "\n");
|
<< (TypeContains(Ty, UpRefs[i].second) ? "true" : "false") << "\n");
|
||||||
if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
|
if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
|
||||||
// Decrement level of upreference
|
// Decrement level of upreference
|
||||||
unsigned Level = --UpRefs[i].NestingLevel;
|
unsigned Level = --UpRefs[i].NestingLevel;
|
||||||
@ -721,7 +721,7 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
|
|||||||
UR_OUT(" * Type '" << OldName << "' refined upreference to: "
|
UR_OUT(" * Type '" << OldName << "' refined upreference to: "
|
||||||
<< (const void*)Ty << ", " << Ty->getDescription() << "\n");
|
<< (const void*)Ty << ", " << Ty->getDescription() << "\n");
|
||||||
}
|
}
|
||||||
UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
|
UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
|
||||||
--i; // Do not skip the next element...
|
--i; // Do not skip the next element...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1025,7 +1025,7 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
|
|||||||
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
|
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
|
||||||
std::vector<const Type*> Params;
|
std::vector<const Type*> Params;
|
||||||
mapto($3->begin(), $3->end(), std::back_inserter(Params),
|
mapto($3->begin(), $3->end(), std::back_inserter(Params),
|
||||||
std::mem_fun_ref(&PATypeHolder::get));
|
std::mem_fun_ref(&PATypeHolder::get));
|
||||||
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
|
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
|
||||||
if (isVarArg) Params.pop_back();
|
if (isVarArg) Params.pop_back();
|
||||||
|
|
||||||
@ -1040,7 +1040,7 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
|
|||||||
| '{' TypeListI '}' { // Structure type?
|
| '{' TypeListI '}' { // Structure type?
|
||||||
std::vector<const Type*> Elements;
|
std::vector<const Type*> Elements;
|
||||||
mapto($2->begin(), $2->end(), std::back_inserter(Elements),
|
mapto($2->begin(), $2->end(), std::back_inserter(Elements),
|
||||||
std::mem_fun_ref(&PATypeHolder::get));
|
std::mem_fun_ref(&PATypeHolder::get));
|
||||||
|
|
||||||
$$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
|
$$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
|
||||||
delete $2;
|
delete $2;
|
||||||
@ -1093,15 +1093,15 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
|
|||||||
// Verify that we have the correct size...
|
// Verify that we have the correct size...
|
||||||
if (NumElements != -1 && NumElements != (int)$3->size())
|
if (NumElements != -1 && NumElements != (int)$3->size())
|
||||||
ThrowException("Type mismatch: constant sized array initialized with " +
|
ThrowException("Type mismatch: constant sized array initialized with " +
|
||||||
utostr($3->size()) + " arguments, but has size of " +
|
utostr($3->size()) + " arguments, but has size of " +
|
||||||
itostr(NumElements) + "!");
|
itostr(NumElements) + "!");
|
||||||
|
|
||||||
// Verify all elements are correct type!
|
// Verify all elements are correct type!
|
||||||
for (unsigned i = 0; i < $3->size(); i++) {
|
for (unsigned i = 0; i < $3->size(); i++) {
|
||||||
if (ETy != (*$3)[i]->getType())
|
if (ETy != (*$3)[i]->getType())
|
||||||
ThrowException("Element #" + utostr(i) + " is not of type '" +
|
ThrowException("Element #" + utostr(i) + " is not of type '" +
|
||||||
ETy->getDescription() +"' as required!\nIt is of type '"+
|
ETy->getDescription() +"' as required!\nIt is of type '"+
|
||||||
(*$3)[i]->getType()->getDescription() + "'.");
|
(*$3)[i]->getType()->getDescription() + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$$ = ConstantArray::get(ATy, *$3);
|
$$ = ConstantArray::get(ATy, *$3);
|
||||||
@ -1116,7 +1116,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
|
|||||||
int NumElements = ATy->getNumElements();
|
int NumElements = ATy->getNumElements();
|
||||||
if (NumElements != -1 && NumElements != 0)
|
if (NumElements != -1 && NumElements != 0)
|
||||||
ThrowException("Type mismatch: constant sized array initialized with 0"
|
ThrowException("Type mismatch: constant sized array initialized with 0"
|
||||||
" arguments, but has size of " + itostr(NumElements) +"!");
|
" arguments, but has size of " + itostr(NumElements) +"!");
|
||||||
$$ = ConstantArray::get(ATy, std::vector<Constant*>());
|
$$ = ConstantArray::get(ATy, std::vector<Constant*>());
|
||||||
delete $1;
|
delete $1;
|
||||||
}
|
}
|
||||||
@ -1131,15 +1131,15 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
|
|||||||
char *EndStr = UnEscapeLexed($3, true);
|
char *EndStr = UnEscapeLexed($3, true);
|
||||||
if (NumElements != -1 && NumElements != (EndStr-$3))
|
if (NumElements != -1 && NumElements != (EndStr-$3))
|
||||||
ThrowException("Can't build string constant of size " +
|
ThrowException("Can't build string constant of size " +
|
||||||
itostr((int)(EndStr-$3)) +
|
itostr((int)(EndStr-$3)) +
|
||||||
" when array has size " + itostr(NumElements) + "!");
|
" when array has size " + itostr(NumElements) + "!");
|
||||||
std::vector<Constant*> Vals;
|
std::vector<Constant*> Vals;
|
||||||
if (ETy == Type::SByteTy) {
|
if (ETy == Type::SByteTy) {
|
||||||
for (char *C = $3; C != EndStr; ++C)
|
for (char *C = $3; C != EndStr; ++C)
|
||||||
Vals.push_back(ConstantSInt::get(ETy, *C));
|
Vals.push_back(ConstantSInt::get(ETy, *C));
|
||||||
} else if (ETy == Type::UByteTy) {
|
} else if (ETy == Type::UByteTy) {
|
||||||
for (char *C = $3; C != EndStr; ++C)
|
for (char *C = $3; C != EndStr; ++C)
|
||||||
Vals.push_back(ConstantUInt::get(ETy, (unsigned char)*C));
|
Vals.push_back(ConstantUInt::get(ETy, (unsigned char)*C));
|
||||||
} else {
|
} else {
|
||||||
free($3);
|
free($3);
|
||||||
ThrowException("Cannot build string arrays of non byte sized elements!");
|
ThrowException("Cannot build string arrays of non byte sized elements!");
|
||||||
@ -1195,7 +1195,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
|
|||||||
ThrowException("Global const reference must be a pointer type!");
|
ThrowException("Global const reference must be a pointer type!");
|
||||||
|
|
||||||
// ConstExprs can exist in the body of a function, thus creating
|
// ConstExprs can exist in the body of a function, thus creating
|
||||||
// ConstantPointerRefs whenever they refer to a variable. Because we are in
|
// GlobalValues whenever they refer to a variable. Because we are in
|
||||||
// the context of a function, getValNonImprovising will search the functions
|
// the context of a function, getValNonImprovising will search the functions
|
||||||
// symbol table instead of the module symbol table for the global symbol,
|
// symbol table instead of the module symbol table for the global symbol,
|
||||||
// which throws things all off. To get around this, we just tell
|
// which throws things all off. To get around this, we just tell
|
||||||
@ -1218,35 +1218,34 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
|
|||||||
|
|
||||||
// First check to see if the forward references value is already created!
|
// First check to see if the forward references value is already created!
|
||||||
PerModuleInfo::GlobalRefsType::iterator I =
|
PerModuleInfo::GlobalRefsType::iterator I =
|
||||||
CurModule.GlobalRefs.find(std::make_pair(PT, $2));
|
CurModule.GlobalRefs.find(std::make_pair(PT, $2));
|
||||||
|
|
||||||
if (I != CurModule.GlobalRefs.end()) {
|
if (I != CurModule.GlobalRefs.end()) {
|
||||||
V = I->second; // Placeholder already exists, use it...
|
V = I->second; // Placeholder already exists, use it...
|
||||||
$2.destroy();
|
$2.destroy();
|
||||||
} else {
|
} else {
|
||||||
std::string Name;
|
std::string Name;
|
||||||
if ($2.Type == ValID::NameVal) Name = $2.Name;
|
if ($2.Type == ValID::NameVal) Name = $2.Name;
|
||||||
|
|
||||||
// Create the forward referenced global.
|
// Create the forward referenced global.
|
||||||
GlobalValue *GV;
|
GlobalValue *GV;
|
||||||
if (const FunctionType *FTy =
|
if (const FunctionType *FTy =
|
||||||
dyn_cast<FunctionType>(PT->getElementType())) {
|
dyn_cast<FunctionType>(PT->getElementType())) {
|
||||||
GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
|
GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
|
||||||
CurModule.CurrentModule);
|
CurModule.CurrentModule);
|
||||||
} else {
|
} else {
|
||||||
GV = new GlobalVariable(PT->getElementType(), false,
|
GV = new GlobalVariable(PT->getElementType(), false,
|
||||||
GlobalValue::ExternalLinkage, 0,
|
GlobalValue::ExternalLinkage, 0,
|
||||||
Name, CurModule.CurrentModule);
|
Name, CurModule.CurrentModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep track of the fact that we have a forward ref to recycle it
|
// Keep track of the fact that we have a forward ref to recycle it
|
||||||
CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, $2), GV));
|
CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, $2), GV));
|
||||||
V = GV;
|
V = GV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalValue *GV = cast<GlobalValue>(V);
|
$$ = cast<GlobalValue>(V);
|
||||||
$$ = ConstantPointerRef::get(GV);
|
|
||||||
delete $1; // Free the type handle
|
delete $1; // Free the type handle
|
||||||
}
|
}
|
||||||
| Types ConstExpr {
|
| Types ConstExpr {
|
||||||
@ -1730,12 +1729,12 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
|
|||||||
std::vector<Value*>::iterator ArgI = $5->begin(), ArgE = $5->end();
|
std::vector<Value*>::iterator ArgI = $5->begin(), ArgE = $5->end();
|
||||||
|
|
||||||
for (; ArgI != ArgE && I != E; ++ArgI, ++I)
|
for (; ArgI != ArgE && I != E; ++ArgI, ++I)
|
||||||
if ((*ArgI)->getType() != *I)
|
if ((*ArgI)->getType() != *I)
|
||||||
ThrowException("Parameter " +(*ArgI)->getName()+ " is not of type '" +
|
ThrowException("Parameter " +(*ArgI)->getName()+ " is not of type '" +
|
||||||
(*I)->getDescription() + "'!");
|
(*I)->getDescription() + "'!");
|
||||||
|
|
||||||
if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
|
if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
|
||||||
ThrowException("Invalid number of parameters detected!");
|
ThrowException("Invalid number of parameters detected!");
|
||||||
|
|
||||||
$$ = new InvokeInst(V, Normal, Except, *$5);
|
$$ = new InvokeInst(V, Normal, Except, *$5);
|
||||||
}
|
}
|
||||||
@ -1891,7 +1890,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
|||||||
$$->op_reserve($2->size()*2);
|
$$->op_reserve($2->size()*2);
|
||||||
while ($2->begin() != $2->end()) {
|
while ($2->begin() != $2->end()) {
|
||||||
if ($2->front().first->getType() != Ty)
|
if ($2->front().first->getType() != Ty)
|
||||||
ThrowException("All elements of a PHI node must be of the same type!");
|
ThrowException("All elements of a PHI node must be of the same type!");
|
||||||
cast<PHINode>($$)->addIncoming($2->front().first, $2->front().second);
|
cast<PHINode>($$)->addIncoming($2->front().first, $2->front().second);
|
||||||
$2->pop_front();
|
$2->pop_front();
|
||||||
}
|
}
|
||||||
@ -1937,12 +1936,12 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
|
|||||||
std::vector<Value*>::iterator ArgI = $5->begin(), ArgE = $5->end();
|
std::vector<Value*>::iterator ArgI = $5->begin(), ArgE = $5->end();
|
||||||
|
|
||||||
for (; ArgI != ArgE && I != E; ++ArgI, ++I)
|
for (; ArgI != ArgE && I != E; ++ArgI, ++I)
|
||||||
if ((*ArgI)->getType() != *I)
|
if ((*ArgI)->getType() != *I)
|
||||||
ThrowException("Parameter " +(*ArgI)->getName()+ " is not of type '" +
|
ThrowException("Parameter " +(*ArgI)->getName()+ " is not of type '" +
|
||||||
(*I)->getDescription() + "'!");
|
(*I)->getDescription() + "'!");
|
||||||
|
|
||||||
if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
|
if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
|
||||||
ThrowException("Invalid number of parameters detected!");
|
ThrowException("Invalid number of parameters detected!");
|
||||||
|
|
||||||
$$ = new CallInst(V, *$5);
|
$$ = new CallInst(V, *$5);
|
||||||
}
|
}
|
||||||
@ -1995,7 +1994,7 @@ MemoryInst : MALLOC Types {
|
|||||||
| OptVolatile LOAD Types ValueRef {
|
| OptVolatile LOAD Types ValueRef {
|
||||||
if (!isa<PointerType>($3->get()))
|
if (!isa<PointerType>($3->get()))
|
||||||
ThrowException("Can't load from nonpointer type: " +
|
ThrowException("Can't load from nonpointer type: " +
|
||||||
(*$3)->getDescription());
|
(*$3)->getDescription());
|
||||||
$$ = new LoadInst(getVal(*$3, $4), "", $1);
|
$$ = new LoadInst(getVal(*$3, $4), "", $1);
|
||||||
delete $3;
|
delete $3;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user