mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-06 04:31:08 +00:00
Use the intrinsic lowering functionality
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10626 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
09c692bcef
commit
f8742b3e03
@ -14,11 +14,14 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/CodeGen/InstrSelection.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
|
#include "llvm/Intrinsics.h"
|
||||||
|
#include "llvm/IntrinsicLowering.h"
|
||||||
#include "llvm/iPHINode.h"
|
#include "llvm/iPHINode.h"
|
||||||
|
#include "llvm/iOther.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/CodeGen/InstrForest.h"
|
#include "llvm/CodeGen/InstrForest.h"
|
||||||
#include "llvm/CodeGen/InstrSelection.h"
|
|
||||||
#include "llvm/CodeGen/InstrSelectionSupport.h"
|
#include "llvm/CodeGen/InstrSelectionSupport.h"
|
||||||
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
||||||
#include "llvm/CodeGen/MachineFunction.h"
|
#include "llvm/CodeGen/MachineFunction.h"
|
||||||
@ -26,13 +29,12 @@
|
|||||||
#include "llvm/Target/TargetRegInfo.h"
|
#include "llvm/Target/TargetRegInfo.h"
|
||||||
#include "Support/CommandLine.h"
|
#include "Support/CommandLine.h"
|
||||||
#include "Support/LeakDetector.h"
|
#include "Support/LeakDetector.h"
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
std::vector<MachineInstr*>
|
std::vector<MachineInstr*>
|
||||||
FixConstantOperandsForInstr(Instruction* vmInstr, MachineInstr* minstr,
|
FixConstantOperandsForInstr(Instruction *I, MachineInstr *MI,
|
||||||
TargetMachine& target);
|
TargetMachine &TM);
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
@ -66,6 +68,7 @@ namespace {
|
|||||||
//
|
//
|
||||||
class InstructionSelection : public FunctionPass {
|
class InstructionSelection : public FunctionPass {
|
||||||
TargetMachine &Target;
|
TargetMachine &Target;
|
||||||
|
IntrinsicLowering &IL;
|
||||||
void InsertCodeForPhis(Function &F);
|
void InsertCodeForPhis(Function &F);
|
||||||
void InsertPhiElimInstructions(BasicBlock *BB,
|
void InsertPhiElimInstructions(BasicBlock *BB,
|
||||||
const std::vector<MachineInstr*>& CpVec);
|
const std::vector<MachineInstr*>& CpVec);
|
||||||
@ -73,7 +76,8 @@ namespace {
|
|||||||
void PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
void PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
||||||
int ruleForNode, short* nts);
|
int ruleForNode, short* nts);
|
||||||
public:
|
public:
|
||||||
InstructionSelection(TargetMachine &T) : Target(T) {}
|
InstructionSelection(TargetMachine &TM, IntrinsicLowering &il)
|
||||||
|
: Target(TM), IL(il) {}
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.setPreservesCFG();
|
AU.setPreservesCFG();
|
||||||
@ -84,7 +88,6 @@ namespace {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
|
|
||||||
TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
|
TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
|
||||||
Value *s1, Value *s2, const std::string &name)
|
Value *s1, Value *s2, const std::string &name)
|
||||||
@ -118,10 +121,37 @@ TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
|
|||||||
LeakDetector::removeGarbageObject(this);
|
LeakDetector::removeGarbageObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End llvm namespace
|
bool InstructionSelection::runOnFunction(Function &F) {
|
||||||
|
// First pass - Walk the function, lowering any calls to intrinsic functions
|
||||||
|
// which the instruction selector cannot handle.
|
||||||
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||||
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
|
||||||
|
if (CallInst *CI = dyn_cast<CallInst>(I++))
|
||||||
|
if (Function *F = CI->getCalledFunction())
|
||||||
|
switch (F->getIntrinsicID()) {
|
||||||
|
#undef va_start
|
||||||
|
#undef va_copy
|
||||||
|
#undef va_end
|
||||||
|
case Intrinsic::va_start:
|
||||||
|
case Intrinsic::va_copy:
|
||||||
|
case Intrinsic::va_end:
|
||||||
|
// We directly implement these intrinsics. Note that this knowledge
|
||||||
|
// is incestuously entangled with the code in
|
||||||
|
// SparcInstrSelection.cpp and must be updated when it is updated.
|
||||||
|
// Since ALL of the code in this library is incestuously intertwined
|
||||||
|
// with it already and sparc specific, we will live with this.
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// All other intrinsic calls we must lower.
|
||||||
|
Instruction *Before = CI->getPrev();
|
||||||
|
IL.LowerIntrinsicCall(CI);
|
||||||
|
if (Before) { // Move iterator to instruction after call
|
||||||
|
I = Before; ++I;
|
||||||
|
} else {
|
||||||
|
I = BB->begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool InstructionSelection::runOnFunction(Function &F)
|
|
||||||
{
|
|
||||||
//
|
//
|
||||||
// Build the instruction trees to be given as inputs to BURG.
|
// Build the instruction trees to be given as inputs to BURG.
|
||||||
//
|
//
|
||||||
@ -384,8 +414,7 @@ InstructionSelection::PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
|||||||
// createInstructionSelectionPass - Public entrypoint for instruction selection
|
// createInstructionSelectionPass - Public entrypoint for instruction selection
|
||||||
// and this file as a whole...
|
// and this file as a whole...
|
||||||
//
|
//
|
||||||
FunctionPass *createInstructionSelectionPass(TargetMachine &T) {
|
FunctionPass *llvm::createInstructionSelectionPass(TargetMachine &T,
|
||||||
return new InstructionSelection(T);
|
IntrinsicLowering &IL) {
|
||||||
|
return new InstructionSelection(T, IL);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End llvm namespace
|
|
||||||
|
@ -14,11 +14,14 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/CodeGen/InstrSelection.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
|
#include "llvm/Intrinsics.h"
|
||||||
|
#include "llvm/IntrinsicLowering.h"
|
||||||
#include "llvm/iPHINode.h"
|
#include "llvm/iPHINode.h"
|
||||||
|
#include "llvm/iOther.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/CodeGen/InstrForest.h"
|
#include "llvm/CodeGen/InstrForest.h"
|
||||||
#include "llvm/CodeGen/InstrSelection.h"
|
|
||||||
#include "llvm/CodeGen/InstrSelectionSupport.h"
|
#include "llvm/CodeGen/InstrSelectionSupport.h"
|
||||||
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
||||||
#include "llvm/CodeGen/MachineFunction.h"
|
#include "llvm/CodeGen/MachineFunction.h"
|
||||||
@ -26,13 +29,12 @@
|
|||||||
#include "llvm/Target/TargetRegInfo.h"
|
#include "llvm/Target/TargetRegInfo.h"
|
||||||
#include "Support/CommandLine.h"
|
#include "Support/CommandLine.h"
|
||||||
#include "Support/LeakDetector.h"
|
#include "Support/LeakDetector.h"
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
std::vector<MachineInstr*>
|
std::vector<MachineInstr*>
|
||||||
FixConstantOperandsForInstr(Instruction* vmInstr, MachineInstr* minstr,
|
FixConstantOperandsForInstr(Instruction *I, MachineInstr *MI,
|
||||||
TargetMachine& target);
|
TargetMachine &TM);
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
@ -66,6 +68,7 @@ namespace {
|
|||||||
//
|
//
|
||||||
class InstructionSelection : public FunctionPass {
|
class InstructionSelection : public FunctionPass {
|
||||||
TargetMachine &Target;
|
TargetMachine &Target;
|
||||||
|
IntrinsicLowering &IL;
|
||||||
void InsertCodeForPhis(Function &F);
|
void InsertCodeForPhis(Function &F);
|
||||||
void InsertPhiElimInstructions(BasicBlock *BB,
|
void InsertPhiElimInstructions(BasicBlock *BB,
|
||||||
const std::vector<MachineInstr*>& CpVec);
|
const std::vector<MachineInstr*>& CpVec);
|
||||||
@ -73,7 +76,8 @@ namespace {
|
|||||||
void PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
void PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
||||||
int ruleForNode, short* nts);
|
int ruleForNode, short* nts);
|
||||||
public:
|
public:
|
||||||
InstructionSelection(TargetMachine &T) : Target(T) {}
|
InstructionSelection(TargetMachine &TM, IntrinsicLowering &il)
|
||||||
|
: Target(TM), IL(il) {}
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.setPreservesCFG();
|
AU.setPreservesCFG();
|
||||||
@ -84,7 +88,6 @@ namespace {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
|
|
||||||
TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
|
TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
|
||||||
Value *s1, Value *s2, const std::string &name)
|
Value *s1, Value *s2, const std::string &name)
|
||||||
@ -118,10 +121,37 @@ TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
|
|||||||
LeakDetector::removeGarbageObject(this);
|
LeakDetector::removeGarbageObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End llvm namespace
|
bool InstructionSelection::runOnFunction(Function &F) {
|
||||||
|
// First pass - Walk the function, lowering any calls to intrinsic functions
|
||||||
|
// which the instruction selector cannot handle.
|
||||||
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||||
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
|
||||||
|
if (CallInst *CI = dyn_cast<CallInst>(I++))
|
||||||
|
if (Function *F = CI->getCalledFunction())
|
||||||
|
switch (F->getIntrinsicID()) {
|
||||||
|
#undef va_start
|
||||||
|
#undef va_copy
|
||||||
|
#undef va_end
|
||||||
|
case Intrinsic::va_start:
|
||||||
|
case Intrinsic::va_copy:
|
||||||
|
case Intrinsic::va_end:
|
||||||
|
// We directly implement these intrinsics. Note that this knowledge
|
||||||
|
// is incestuously entangled with the code in
|
||||||
|
// SparcInstrSelection.cpp and must be updated when it is updated.
|
||||||
|
// Since ALL of the code in this library is incestuously intertwined
|
||||||
|
// with it already and sparc specific, we will live with this.
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// All other intrinsic calls we must lower.
|
||||||
|
Instruction *Before = CI->getPrev();
|
||||||
|
IL.LowerIntrinsicCall(CI);
|
||||||
|
if (Before) { // Move iterator to instruction after call
|
||||||
|
I = Before; ++I;
|
||||||
|
} else {
|
||||||
|
I = BB->begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool InstructionSelection::runOnFunction(Function &F)
|
|
||||||
{
|
|
||||||
//
|
//
|
||||||
// Build the instruction trees to be given as inputs to BURG.
|
// Build the instruction trees to be given as inputs to BURG.
|
||||||
//
|
//
|
||||||
@ -384,8 +414,7 @@ InstructionSelection::PostprocessMachineCodeForTree(InstructionNode* instrNode,
|
|||||||
// createInstructionSelectionPass - Public entrypoint for instruction selection
|
// createInstructionSelectionPass - Public entrypoint for instruction selection
|
||||||
// and this file as a whole...
|
// and this file as a whole...
|
||||||
//
|
//
|
||||||
FunctionPass *createInstructionSelectionPass(TargetMachine &T) {
|
FunctionPass *llvm::createInstructionSelectionPass(TargetMachine &T,
|
||||||
return new InstructionSelection(T);
|
IntrinsicLowering &IL) {
|
||||||
|
return new InstructionSelection(T, IL);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End llvm namespace
|
|
||||||
|
Loading…
Reference in New Issue
Block a user