From f8742b3e033ff69649a3a76c12e28a1428858880 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 28 Dec 2003 09:43:35 +0000 Subject: [PATCH] Use the intrinsic lowering functionality git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10626 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/InstrSelection/InstrSelection.cpp | 59 ++++++++++++++----- .../SparcV9/InstrSelection/InstrSelection.cpp | 59 ++++++++++++++----- 2 files changed, 88 insertions(+), 30 deletions(-) diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp index 760976509c1..2c340dbebc6 100644 --- a/lib/CodeGen/InstrSelection/InstrSelection.cpp +++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp @@ -14,11 +14,14 @@ // //===----------------------------------------------------------------------===// +#include "llvm/CodeGen/InstrSelection.h" #include "llvm/Function.h" +#include "llvm/Intrinsics.h" +#include "llvm/IntrinsicLowering.h" #include "llvm/iPHINode.h" +#include "llvm/iOther.h" #include "llvm/Pass.h" #include "llvm/CodeGen/InstrForest.h" -#include "llvm/CodeGen/InstrSelection.h" #include "llvm/CodeGen/InstrSelectionSupport.h" #include "llvm/CodeGen/MachineCodeForInstruction.h" #include "llvm/CodeGen/MachineFunction.h" @@ -26,13 +29,12 @@ #include "llvm/Target/TargetRegInfo.h" #include "Support/CommandLine.h" #include "Support/LeakDetector.h" -#include namespace llvm { - -std::vector -FixConstantOperandsForInstr(Instruction* vmInstr, MachineInstr* minstr, - TargetMachine& target); + std::vector + FixConstantOperandsForInstr(Instruction *I, MachineInstr *MI, + TargetMachine &TM); +} namespace { //===--------------------------------------------------------------------===// @@ -66,6 +68,7 @@ namespace { // class InstructionSelection : public FunctionPass { TargetMachine &Target; + IntrinsicLowering &IL; void InsertCodeForPhis(Function &F); void InsertPhiElimInstructions(BasicBlock *BB, const std::vector& CpVec); @@ -73,7 +76,8 @@ namespace { void PostprocessMachineCodeForTree(InstructionNode* instrNode, int ruleForNode, short* nts); public: - InstructionSelection(TargetMachine &T) : Target(T) {} + InstructionSelection(TargetMachine &TM, IntrinsicLowering &il) + : Target(TM), IL(il) {} virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); @@ -84,7 +88,6 @@ namespace { }; } -namespace llvm { TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi, Value *s1, Value *s2, const std::string &name) @@ -118,10 +121,37 @@ TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi, 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(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. // @@ -384,8 +414,7 @@ InstructionSelection::PostprocessMachineCodeForTree(InstructionNode* instrNode, // createInstructionSelectionPass - Public entrypoint for instruction selection // and this file as a whole... // -FunctionPass *createInstructionSelectionPass(TargetMachine &T) { - return new InstructionSelection(T); +FunctionPass *llvm::createInstructionSelectionPass(TargetMachine &T, + IntrinsicLowering &IL) { + return new InstructionSelection(T, IL); } - -} // End llvm namespace diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp index 760976509c1..2c340dbebc6 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp @@ -14,11 +14,14 @@ // //===----------------------------------------------------------------------===// +#include "llvm/CodeGen/InstrSelection.h" #include "llvm/Function.h" +#include "llvm/Intrinsics.h" +#include "llvm/IntrinsicLowering.h" #include "llvm/iPHINode.h" +#include "llvm/iOther.h" #include "llvm/Pass.h" #include "llvm/CodeGen/InstrForest.h" -#include "llvm/CodeGen/InstrSelection.h" #include "llvm/CodeGen/InstrSelectionSupport.h" #include "llvm/CodeGen/MachineCodeForInstruction.h" #include "llvm/CodeGen/MachineFunction.h" @@ -26,13 +29,12 @@ #include "llvm/Target/TargetRegInfo.h" #include "Support/CommandLine.h" #include "Support/LeakDetector.h" -#include namespace llvm { - -std::vector -FixConstantOperandsForInstr(Instruction* vmInstr, MachineInstr* minstr, - TargetMachine& target); + std::vector + FixConstantOperandsForInstr(Instruction *I, MachineInstr *MI, + TargetMachine &TM); +} namespace { //===--------------------------------------------------------------------===// @@ -66,6 +68,7 @@ namespace { // class InstructionSelection : public FunctionPass { TargetMachine &Target; + IntrinsicLowering &IL; void InsertCodeForPhis(Function &F); void InsertPhiElimInstructions(BasicBlock *BB, const std::vector& CpVec); @@ -73,7 +76,8 @@ namespace { void PostprocessMachineCodeForTree(InstructionNode* instrNode, int ruleForNode, short* nts); public: - InstructionSelection(TargetMachine &T) : Target(T) {} + InstructionSelection(TargetMachine &TM, IntrinsicLowering &il) + : Target(TM), IL(il) {} virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); @@ -84,7 +88,6 @@ namespace { }; } -namespace llvm { TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi, Value *s1, Value *s2, const std::string &name) @@ -118,10 +121,37 @@ TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi, 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(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. // @@ -384,8 +414,7 @@ InstructionSelection::PostprocessMachineCodeForTree(InstructionNode* instrNode, // createInstructionSelectionPass - Public entrypoint for instruction selection // and this file as a whole... // -FunctionPass *createInstructionSelectionPass(TargetMachine &T) { - return new InstructionSelection(T); +FunctionPass *llvm::createInstructionSelectionPass(TargetMachine &T, + IntrinsicLowering &IL) { + return new InstructionSelection(T, IL); } - -} // End llvm namespace