mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-28 03:25:23 +00:00
* Stop making a global for each constant that cannot live in an instruction;
it will be converted to a MachineConstantPool index during instruction selection * This is now eligible to become a FunctionPass since it does not have any side effects outside of the function it is processing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9773 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -34,38 +34,16 @@ namespace {
|
|||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// PreSelection Pass - Specialize LLVM code for the current target machine.
|
// PreSelection Pass - Specialize LLVM code for the current target machine.
|
||||||
//
|
//
|
||||||
class PreSelection : public Pass, public InstVisitor<PreSelection> {
|
class PreSelection : public FunctionPass, public InstVisitor<PreSelection> {
|
||||||
const TargetInstrInfo &instrInfo;
|
const TargetInstrInfo &instrInfo;
|
||||||
Module *TheModule;
|
|
||||||
|
|
||||||
std::map<const Constant*, GlobalVariable*> gvars;
|
|
||||||
|
|
||||||
GlobalVariable* getGlobalForConstant(Constant* CV) {
|
|
||||||
std::map<const Constant*, GlobalVariable*>::iterator I = gvars.find(CV);
|
|
||||||
if (I != gvars.end()) return I->second; // global exists so return it
|
|
||||||
|
|
||||||
return I->second = new GlobalVariable(CV->getType(), true,
|
|
||||||
GlobalValue::InternalLinkage, CV,
|
|
||||||
"immcst", TheModule);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PreSelection(const TargetMachine &T)
|
PreSelection(const TargetMachine &T)
|
||||||
: instrInfo(T.getInstrInfo()), TheModule(0) {}
|
: instrInfo(T.getInstrInfo()) {}
|
||||||
|
|
||||||
// run - apply this pass to the entire Module
|
// runOnFunction - apply this pass to each Function
|
||||||
bool run(Module &M) {
|
bool runOnFunction(Function &F) {
|
||||||
TheModule = &M;
|
visit(F);
|
||||||
|
|
||||||
// Build reverse map for pre-existing global constants so we can find them
|
|
||||||
for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
|
|
||||||
if (I->hasInitializer() && I->isConstant())
|
|
||||||
gvars[I->getInitializer()] = I;
|
|
||||||
|
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
|
||||||
visit(*I);
|
|
||||||
|
|
||||||
gvars.clear();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,10 +65,12 @@ namespace {
|
|||||||
Instruction& insertBefore);
|
Instruction& insertBefore);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if 0
|
||||||
// Register the pass...
|
// Register the pass...
|
||||||
RegisterOpt<PreSelection> X("preselect",
|
RegisterPass<PreSelection> X("preselect",
|
||||||
"Specialize LLVM code for a target machine",
|
"Specialize LLVM code for a target machine"
|
||||||
createPreSelectionPass);
|
createPreselectionPass);
|
||||||
|
#endif
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
@@ -184,10 +164,8 @@ PreSelection::visitOneOperand(Instruction &I, Value* Op, unsigned opNum,
|
|||||||
I.setOperand(opNum, computeConst); // replace expr operand with result
|
I.setOperand(opNum, computeConst); // replace expr operand with result
|
||||||
} else if (instrInfo.ConstantTypeMustBeLoaded(CV)) {
|
} else if (instrInfo.ConstantTypeMustBeLoaded(CV)) {
|
||||||
// load address of constant into a register, then load the constant
|
// load address of constant into a register, then load the constant
|
||||||
GetElementPtrInst* gep = getGlobalAddr(getGlobalForConstant(CV),
|
// this is now done during instruction selection
|
||||||
insertBefore);
|
// the constant will live in the MachineConstantPool later on
|
||||||
LoadInst* ldI = new LoadInst(gep, "loadConst", &insertBefore);
|
|
||||||
I.setOperand(opNum, ldI); // replace operand with copy in v.reg.
|
|
||||||
} else if (instrInfo.ConstantMayNotFitInImmedField(CV, &I)) {
|
} else if (instrInfo.ConstantMayNotFitInImmedField(CV, &I)) {
|
||||||
// put the constant into a virtual register using a cast
|
// put the constant into a virtual register using a cast
|
||||||
CastInst* castI = new CastInst(CV, CV->getType(), "copyConst",
|
CastInst* castI = new CastInst(CV, CV->getType(), "copyConst",
|
||||||
@@ -263,6 +241,6 @@ void PreSelection::visitCallInst(CallInst &I) {
|
|||||||
// createPreSelectionPass - Public entrypoint for pre-selection pass
|
// createPreSelectionPass - Public entrypoint for pre-selection pass
|
||||||
// and this file as a whole...
|
// and this file as a whole...
|
||||||
//
|
//
|
||||||
Pass* createPreSelectionPass(TargetMachine &T) {
|
FunctionPass* createPreSelectionPass(const TargetMachine &TM) {
|
||||||
return new PreSelection(T);
|
return new PreSelection(TM);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user