mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 05:25:47 +00:00
Get this looking more like a function pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13433 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -59,14 +59,14 @@ namespace {
|
|||||||
|
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
bool run(Module &M) {
|
bool run(Module &M) {
|
||||||
// First pass, lower all unhandled intrinsics.
|
|
||||||
lowerIntrinsics(M);
|
|
||||||
|
|
||||||
doInitialization(M);
|
doInitialization(M);
|
||||||
|
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||||
if (!I->isExternal())
|
if (!I->isExternal()) {
|
||||||
|
// First pass, lower all unhandled intrinsics.
|
||||||
|
lowerIntrinsics(*I);
|
||||||
printFunction(*I);
|
printFunction(*I);
|
||||||
|
}
|
||||||
|
|
||||||
// Free memory...
|
// Free memory...
|
||||||
delete Mang;
|
delete Mang;
|
||||||
@@ -82,7 +82,7 @@ namespace {
|
|||||||
void writeOperandInternal(Value *Operand);
|
void writeOperandInternal(Value *Operand);
|
||||||
|
|
||||||
private :
|
private :
|
||||||
void lowerIntrinsics(Module &M);
|
void lowerIntrinsics(Function &F);
|
||||||
|
|
||||||
bool nameAllUsedStructureTypes(Module &M);
|
bool nameAllUsedStructureTypes(Module &M);
|
||||||
void printModule(Module *M);
|
void printModule(Module *M);
|
||||||
@@ -656,6 +656,8 @@ bool CWriter::doInitialization(Module &M) {
|
|||||||
TheModule = &M;
|
TheModule = &M;
|
||||||
FUT = &getAnalysis<FindUsedTypes>();
|
FUT = &getAnalysis<FindUsedTypes>();
|
||||||
|
|
||||||
|
IL.AddPrototypes(M);
|
||||||
|
|
||||||
// Ensure that all structure types have names...
|
// Ensure that all structure types have names...
|
||||||
bool Changed = nameAllUsedStructureTypes(M);
|
bool Changed = nameAllUsedStructureTypes(M);
|
||||||
Mang = new Mangler(M);
|
Mang = new Mangler(M);
|
||||||
@@ -776,7 +778,7 @@ bool CWriter::doInitialization(Module &M) {
|
|||||||
void CWriter::printFloatingPointConstants(Module &M) {
|
void CWriter::printFloatingPointConstants(Module &M) {
|
||||||
union {
|
union {
|
||||||
double D;
|
double D;
|
||||||
unsigned long long U;
|
uint64_t U;
|
||||||
} DBLUnion;
|
} DBLUnion;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
@@ -1219,33 +1221,32 @@ void CWriter::visitSelectInst(SelectInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CWriter::lowerIntrinsics(Module &M) {
|
void CWriter::lowerIntrinsics(Function &F) {
|
||||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
|
||||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
|
if (CallInst *CI = dyn_cast<CallInst>(I++))
|
||||||
if (CallInst *CI = dyn_cast<CallInst>(I++))
|
if (Function *F = CI->getCalledFunction())
|
||||||
if (Function *F = CI->getCalledFunction())
|
switch (F->getIntrinsicID()) {
|
||||||
switch (F->getIntrinsicID()) {
|
case Intrinsic::not_intrinsic:
|
||||||
case Intrinsic::not_intrinsic:
|
case Intrinsic::vastart:
|
||||||
case Intrinsic::vastart:
|
case Intrinsic::vacopy:
|
||||||
case Intrinsic::vacopy:
|
case Intrinsic::vaend:
|
||||||
case Intrinsic::vaend:
|
case Intrinsic::returnaddress:
|
||||||
case Intrinsic::returnaddress:
|
case Intrinsic::frameaddress:
|
||||||
case Intrinsic::frameaddress:
|
case Intrinsic::setjmp:
|
||||||
case Intrinsic::setjmp:
|
case Intrinsic::longjmp:
|
||||||
case Intrinsic::longjmp:
|
// We directly implement these intrinsics
|
||||||
// We directly implement these intrinsics
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
// All other intrinsic calls we must lower.
|
||||||
// All other intrinsic calls we must lower.
|
Instruction *Before = CI->getPrev();
|
||||||
Instruction *Before = CI->getPrev();
|
IL.LowerIntrinsicCall(CI);
|
||||||
IL.LowerIntrinsicCall(CI);
|
if (Before) { // Move iterator to instruction after call
|
||||||
if (Before) { // Move iterator to instruction after call
|
I = Before; ++I;
|
||||||
I = Before; ++I;
|
} else {
|
||||||
} else {
|
I = BB->begin();
|
||||||
I = BB->begin();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -59,14 +59,14 @@ namespace {
|
|||||||
|
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
bool run(Module &M) {
|
bool run(Module &M) {
|
||||||
// First pass, lower all unhandled intrinsics.
|
|
||||||
lowerIntrinsics(M);
|
|
||||||
|
|
||||||
doInitialization(M);
|
doInitialization(M);
|
||||||
|
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||||
if (!I->isExternal())
|
if (!I->isExternal()) {
|
||||||
|
// First pass, lower all unhandled intrinsics.
|
||||||
|
lowerIntrinsics(*I);
|
||||||
printFunction(*I);
|
printFunction(*I);
|
||||||
|
}
|
||||||
|
|
||||||
// Free memory...
|
// Free memory...
|
||||||
delete Mang;
|
delete Mang;
|
||||||
@@ -82,7 +82,7 @@ namespace {
|
|||||||
void writeOperandInternal(Value *Operand);
|
void writeOperandInternal(Value *Operand);
|
||||||
|
|
||||||
private :
|
private :
|
||||||
void lowerIntrinsics(Module &M);
|
void lowerIntrinsics(Function &F);
|
||||||
|
|
||||||
bool nameAllUsedStructureTypes(Module &M);
|
bool nameAllUsedStructureTypes(Module &M);
|
||||||
void printModule(Module *M);
|
void printModule(Module *M);
|
||||||
@@ -656,6 +656,8 @@ bool CWriter::doInitialization(Module &M) {
|
|||||||
TheModule = &M;
|
TheModule = &M;
|
||||||
FUT = &getAnalysis<FindUsedTypes>();
|
FUT = &getAnalysis<FindUsedTypes>();
|
||||||
|
|
||||||
|
IL.AddPrototypes(M);
|
||||||
|
|
||||||
// Ensure that all structure types have names...
|
// Ensure that all structure types have names...
|
||||||
bool Changed = nameAllUsedStructureTypes(M);
|
bool Changed = nameAllUsedStructureTypes(M);
|
||||||
Mang = new Mangler(M);
|
Mang = new Mangler(M);
|
||||||
@@ -776,7 +778,7 @@ bool CWriter::doInitialization(Module &M) {
|
|||||||
void CWriter::printFloatingPointConstants(Module &M) {
|
void CWriter::printFloatingPointConstants(Module &M) {
|
||||||
union {
|
union {
|
||||||
double D;
|
double D;
|
||||||
unsigned long long U;
|
uint64_t U;
|
||||||
} DBLUnion;
|
} DBLUnion;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
@@ -1219,33 +1221,32 @@ void CWriter::visitSelectInst(SelectInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CWriter::lowerIntrinsics(Module &M) {
|
void CWriter::lowerIntrinsics(Function &F) {
|
||||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
|
||||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
|
if (CallInst *CI = dyn_cast<CallInst>(I++))
|
||||||
if (CallInst *CI = dyn_cast<CallInst>(I++))
|
if (Function *F = CI->getCalledFunction())
|
||||||
if (Function *F = CI->getCalledFunction())
|
switch (F->getIntrinsicID()) {
|
||||||
switch (F->getIntrinsicID()) {
|
case Intrinsic::not_intrinsic:
|
||||||
case Intrinsic::not_intrinsic:
|
case Intrinsic::vastart:
|
||||||
case Intrinsic::vastart:
|
case Intrinsic::vacopy:
|
||||||
case Intrinsic::vacopy:
|
case Intrinsic::vaend:
|
||||||
case Intrinsic::vaend:
|
case Intrinsic::returnaddress:
|
||||||
case Intrinsic::returnaddress:
|
case Intrinsic::frameaddress:
|
||||||
case Intrinsic::frameaddress:
|
case Intrinsic::setjmp:
|
||||||
case Intrinsic::setjmp:
|
case Intrinsic::longjmp:
|
||||||
case Intrinsic::longjmp:
|
// We directly implement these intrinsics
|
||||||
// We directly implement these intrinsics
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
// All other intrinsic calls we must lower.
|
||||||
// All other intrinsic calls we must lower.
|
Instruction *Before = CI->getPrev();
|
||||||
Instruction *Before = CI->getPrev();
|
IL.LowerIntrinsicCall(CI);
|
||||||
IL.LowerIntrinsicCall(CI);
|
if (Before) { // Move iterator to instruction after call
|
||||||
if (Before) { // Move iterator to instruction after call
|
I = Before; ++I;
|
||||||
I = Before; ++I;
|
} else {
|
||||||
} else {
|
I = BB->begin();
|
||||||
I = BB->begin();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user