mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
Make the global opt optimizer work on modules with a null terminator, by
accepting the null even with a non-65535 init prio git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23434 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1144,15 +1144,17 @@ GlobalVariable *GlobalOpt::FindGlobalCtors(Module &M) {
|
|||||||
if (!CA) return 0;
|
if (!CA) return 0;
|
||||||
for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
|
||||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(CA->getOperand(i))) {
|
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(CA->getOperand(i))) {
|
||||||
|
if (isa<ConstantPointerNull>(CS->getOperand(1)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Must have a function or null ptr.
|
||||||
|
if (!isa<Function>(CS->getOperand(1)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Init priority must be standard.
|
// Init priority must be standard.
|
||||||
ConstantInt *CI = dyn_cast<ConstantInt>(CS->getOperand(0));
|
ConstantInt *CI = dyn_cast<ConstantInt>(CS->getOperand(0));
|
||||||
if (!CI || CI->getRawValue() != 65535)
|
if (!CI || CI->getRawValue() != 65535)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Must have a function or null ptr.
|
|
||||||
if (!isa<Function>(CS->getOperand(1)) &&
|
|
||||||
!isa<ConstantPointerNull>(CS->getOperand(1)))
|
|
||||||
return 0;
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1185,9 +1187,11 @@ bool GlobalOpt::OptimizeGlobalCtorsList(GlobalVariable *&GCL) {
|
|||||||
Function *F = Ctors[i];
|
Function *F = Ctors[i];
|
||||||
// Found a null terminator in the middle of the list, prune off the rest of
|
// Found a null terminator in the middle of the list, prune off the rest of
|
||||||
// the list.
|
// the list.
|
||||||
if (F == 0 && i != Ctors.size()-1) {
|
if (F == 0) {
|
||||||
|
if (i != Ctors.size()-1) {
|
||||||
Ctors.resize(i+1);
|
Ctors.resize(i+1);
|
||||||
MadeChange = true;
|
MadeChange = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1217,6 +1221,7 @@ bool GlobalOpt::OptimizeGlobalCtorsList(GlobalVariable *&GCL) {
|
|||||||
std::vector<const Type*>(), false);
|
std::vector<const Type*>(), false);
|
||||||
const PointerType *PFTy = PointerType::get(FTy);
|
const PointerType *PFTy = PointerType::get(FTy);
|
||||||
CSVals[1] = Constant::getNullValue(PFTy);
|
CSVals[1] = Constant::getNullValue(PFTy);
|
||||||
|
CSVals[0] = ConstantSInt::get(Type::IntTy, 2147483647);
|
||||||
}
|
}
|
||||||
CAList.push_back(ConstantStruct::get(CSVals));
|
CAList.push_back(ConstantStruct::get(CSVals));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user