llvm.org GIT mirror llvm / f70e0c2
Clean up a lot of the code I added yesterday by exposing the IntrinsicLowering implementation from the TargetMachine directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10636 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
21 changed file(s) with 80 addition(s) and 111 deletion(s). Raw diff Collapse all Expand all
2121 class FunctionPass;
2222 class InstrForest;
2323 class InstructionNode;
24 class IntrinsicLowering;
2524 class MachineCodeForInstruction;
2625 class MachineInstr;
2726 class TargetMachine;
3938 extern bool ThisIsAChainRule (int eruleno);
4039
4140
42 //************************ Exported Functions ******************************/
43
4441
4542 //---------------------------------------------------------------------------
4643 // Function: createInstructionSelectionPass
5047 // Return a pass that performs machine dependent instruction selection.
5148 //---------------------------------------------------------------------------
5249
53 FunctionPass *createInstructionSelectionPass(TargetMachine &Target,
54 IntrinsicLowering &IL);
50 FunctionPass *createInstructionSelectionPass(TargetMachine &Target);
5551
56
57 //************************ Exported Data Types *****************************/
5852
5953
6054 //---------------------------------------------------------------------------
3232 #ifndef LLVM_INTRINSICLOWERING_H
3333 #define LLVM_INTRINSICLOWERING_H
3434
35 #include "llvm/Intrinsics.h"
36
3537 namespace llvm {
3638 class CallInst;
3739
3232 #ifndef LLVM_INTRINSICLOWERING_H
3333 #define LLVM_INTRINSICLOWERING_H
3434
35 #include "llvm/Intrinsics.h"
36
3537 namespace llvm {
3638 class CallInst;
3739
3030 class FunctionPassManager;
3131 class PassManager;
3232 class Pass;
33 class IntrinsicLowering;
3334
3435 //===----------------------------------------------------------------------===//
3536 ///
3940 ///
4041 class TargetMachine {
4142 const std::string Name;
42 const TargetData DataLayout; // Calculates type size & alignment
43 const TargetData DataLayout; // Calculates type size & alignment
44 IntrinsicLowering *IL; // Specifies how to lower intrinsic calls
4345
4446 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT
4547 void operator=(const TargetMachine&); // DO NOT IMPLEMENT
46 protected:
47 TargetMachine(const std::string &name, // Can only create subclasses...
48 protected: // Can only create subclasses...
49 TargetMachine(const std::string &name, IntrinsicLowering *IL,
4850 bool LittleEndian = false,
4951 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
5052 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
5153 unsigned char LongAl = 8, unsigned char IntAl = 4,
52 unsigned char ShortAl = 2, unsigned char ByteAl = 1)
53 : Name(name), DataLayout(name, LittleEndian,
54 PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
55 IntAl, ShortAl, ByteAl) {}
54 unsigned char ShortAl = 2, unsigned char ByteAl = 1);
5655 public:
57 virtual ~TargetMachine() {}
56 virtual ~TargetMachine();
5857
5958 const std::string &getName() const { return Name; }
59
60 // getIntrinsicLowering - This method returns a reference to an
61 // IntrinsicLowering instance which should be used by the code generator to
62 // lower unknown intrinsic functions to the equivalent LLVM expansion.
63 IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
6064
6165 // Interfaces to the major aspects of target machine information:
6266 // -- Instruction opcode and operand information
1515
1616 #include "llvm/CodeGen/InstrSelection.h"
1717 #include "llvm/Function.h"
18 #include "llvm/Intrinsics.h"
1918 #include "llvm/IntrinsicLowering.h"
2019 #include "llvm/iPHINode.h"
2120 #include "llvm/iOther.h"
6766 //
6867 class InstructionSelection : public FunctionPass {
6968 TargetMachine &Target;
70 IntrinsicLowering &IL;
7169 void InsertCodeForPhis(Function &F);
7270 void InsertPhiElimInstructions(BasicBlock *BB,
7371 const std::vector& CpVec);
7573 void PostprocessMachineCodeForTree(InstructionNode* instrNode,
7674 int ruleForNode, short* nts);
7775 public:
78 InstructionSelection(TargetMachine &TM, IntrinsicLowering &il)
79 : Target(TM), IL(il) {}
76 InstructionSelection(TargetMachine &TM) : Target(TM) {}
8077
8178 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
8279 AU.setPreservesCFG();
144141 default:
145142 // All other intrinsic calls we must lower.
146143 Instruction *Before = CI->getPrev();
147 IL.LowerIntrinsicCall(CI);
144 Target.getIntrinsicLowering().LowerIntrinsicCall(CI);
148145 if (Before) { // Move iterator to instruction after call
149146 I = Before; ++I;
150147 } else {
414411 // createInstructionSelectionPass - Public entrypoint for instruction selection
415412 // and this file as a whole...
416413 //
417 FunctionPass *llvm::createInstructionSelectionPass(TargetMachine &T,
418 IntrinsicLowering &IL) {
419 return new InstructionSelection(T, IL);
420 }
414 FunctionPass *llvm::createInstructionSelectionPass(TargetMachine &TM) {
415 return new InstructionSelection(TM);
416 }
1212
1313 #include "llvm/IntrinsicLowering.h"
1414 #include "llvm/Constant.h"
15 #include "llvm/Intrinsics.h"
1615 #include "llvm/Module.h"
1716 #include "llvm/Type.h"
1817 #include "llvm/iOther.h"
1616 #include "llvm/DerivedTypes.h"
1717 #include "llvm/Instructions.h"
1818 #include "llvm/IntrinsicLowering.h"
19 #include "llvm/Intrinsics.h"
2019 #include "llvm/Support/GetElementPtrTypeIterator.h"
2120 #include "Support/Statistic.h"
2221 #include "Support/Debug.h"
1515
1616 #include "llvm/CodeGen/InstrSelection.h"
1717 #include "llvm/Function.h"
18 #include "llvm/Intrinsics.h"
1918 #include "llvm/IntrinsicLowering.h"
2019 #include "llvm/iPHINode.h"
2120 #include "llvm/iOther.h"
6766 //
6867 class InstructionSelection : public FunctionPass {
6968 TargetMachine &Target;
70 IntrinsicLowering &IL;
7169 void InsertCodeForPhis(Function &F);
7270 void InsertPhiElimInstructions(BasicBlock *BB,
7371 const std::vector& CpVec);
7573 void PostprocessMachineCodeForTree(InstructionNode* instrNode,
7674 int ruleForNode, short* nts);
7775 public:
78 InstructionSelection(TargetMachine &TM, IntrinsicLowering &il)
79 : Target(TM), IL(il) {}
76 InstructionSelection(TargetMachine &TM) : Target(TM) {}
8077
8178 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
8279 AU.setPreservesCFG();
144141 default:
145142 // All other intrinsic calls we must lower.
146143 Instruction *Before = CI->getPrev();
147 IL.LowerIntrinsicCall(CI);
144 Target.getIntrinsicLowering().LowerIntrinsicCall(CI);
148145 if (Before) { // Move iterator to instruction after call
149146 I = Before; ++I;
150147 } else {
414411 // createInstructionSelectionPass - Public entrypoint for instruction selection
415412 // and this file as a whole...
416413 //
417 FunctionPass *llvm::createInstructionSelectionPass(TargetMachine &T,
418 IntrinsicLowering &IL) {
419 return new InstructionSelection(T, IL);
420 }
414 FunctionPass *llvm::createInstructionSelectionPass(TargetMachine &TM) {
415 return new InstructionSelection(TM);
416 }
1717
1818 namespace llvm {
1919 class TargetMachine;
20 class IntrinsicLowering;
2120
2221 class SparcJITInfo : public TargetJITInfo {
2322 TargetMachine &TM;
24 IntrinsicLowering &IL;
2523 public:
26 SparcJITInfo(TargetMachine &tm, IntrinsicLowering &il) : TM(tm), IL(il) {}
24 SparcJITInfo(TargetMachine &tm) : TM(tm) {}
2725
2826 /// addPassesToJITCompile - Add passes to the specified pass manager to
2927 /// implement a fast dynamic compiler for this target. Return true if this
115115
116116
117117 SparcTargetMachine::SparcTargetMachine(IntrinsicLowering *il)
118 : TargetMachine("UltraSparc-Native", false),
119 IL(il ? il : new DefaultIntrinsicLowering()),
118 : TargetMachine("UltraSparc-Native", il, false),
120119 schedInfo(*this),
121120 regInfo(*this),
122121 frameInfo(*this),
123122 cacheInfo(*this),
124 jitInfo(*this, *IL) {
125 }
126
127 SparcTargetMachine::~SparcTargetMachine() {
128 delete IL;
123 jitInfo(*this) {
129124 }
130125
131126 // addPassesToEmitAssembly - This method controls the entire code generation
170165 PM.add(new PrintFunctionPass("Input code to instr. selection:\n",
171166 &std::cerr));
172167
173 PM.add(createInstructionSelectionPass(*this, *IL));
168 PM.add(createInstructionSelectionPass(*this));
174169
175170 if (!DisableSched)
176171 PM.add(createInstructionSchedulingWithSSAPass(*this));
237232 //PM.add(createLICMPass());
238233 //PM.add(createGCSEPass());
239234
240 PM.add(createInstructionSelectionPass(TM, IL));
235 PM.add(createInstructionSelectionPass(TM));
241236
242237 PM.add(getRegisterAllocator(TM));
243238 PM.add(createPrologEpilogInsertionPass());
2323
2424 namespace llvm {
2525 class PassManager;
26 class IntrinsicLowering;
2726
2827 class SparcTargetMachine : public TargetMachine {
29 IntrinsicLowering *IL;
3028 SparcInstrInfo instrInfo;
3129 SparcSchedInfo schedInfo;
3230 SparcRegInfo regInfo;
3533 SparcJITInfo jitInfo;
3634 public:
3735 SparcTargetMachine(IntrinsicLowering *IL);
38 ~SparcTargetMachine();
3936
4037 virtual const TargetInstrInfo &getInstrInfo() const { return instrInfo; }
4138 virtual const TargetSchedInfo &getSchedInfo() const { return schedInfo; }
1414 #include "llvm/Target/TargetMachine.h"
1515 #include "llvm/Target/TargetCacheInfo.h"
1616 #include "llvm/Type.h"
17
18 namespace llvm {
17 #include "llvm/IntrinsicLowering.h"
18 using namespace llvm;
1919
2020 //---------------------------------------------------------------------------
21 // class TargetMachine
22 //
23 // Purpose:
24 // Machine description.
25 //
26 //---------------------------------------------------------------------------
21 // TargetMachine Class
22 //
23 TargetMachine::TargetMachine(const std::string &name, IntrinsicLowering *il,
24 bool LittleEndian,
25 unsigned char PtrSize, unsigned char PtrAl,
26 unsigned char DoubleAl, unsigned char FloatAl,
27 unsigned char LongAl, unsigned char IntAl,
28 unsigned char ShortAl, unsigned char ByteAl)
29 : Name(name), DataLayout(name, LittleEndian,
30 PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
31 IntAl, ShortAl, ByteAl) {
32 IL = il ? il : new DefaultIntrinsicLowering();
33 }
2734
2835
29 // function TargetMachine::findOptimalStorageSize
30 //
36
37 TargetMachine::~TargetMachine() {
38 delete IL;
39 }
40
41
42
43
3144 unsigned TargetMachine::findOptimalStorageSize(const Type *Ty) const {
3245 // All integer types smaller than ints promote to 4 byte integers.
3346 if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4)
3851
3952
4053 //---------------------------------------------------------------------------
41 // class TargetCacheInfo
42 //
43 // Purpose:
44 // Describes properties of the target cache architecture.
45 //---------------------------------------------------------------------------
54 // TargetCacheInfo Class
55 //
4656
4757 void TargetCacheInfo::Initialize() {
4858 numLevels = 2;
5060 cacheSizes.push_back(1 << 15); cacheSizes.push_back(1 << 20);
5161 cacheAssoc.push_back(1); cacheAssoc.push_back(4);
5262 }
53
54 } // End llvm namespace
118118 /// into a machine code representation using pattern matching and a machine
119119 /// description file.
120120 ///
121 FunctionPass *llvm::createX86PatternInstructionSelector(TargetMachine &TM,
122 IntrinsicLowering &IL) {
121 FunctionPass *llvm::createX86PatternInstructionSelector(TargetMachine &TM) {
123122 return new ISel(TM);
124123 }
1717 #include "llvm/DerivedTypes.h"
1818 #include "llvm/Function.h"
1919 #include "llvm/Instructions.h"
20 #include "llvm/Intrinsics.h"
2120 #include "llvm/IntrinsicLowering.h"
2221 #include "llvm/Pass.h"
2322 #include "llvm/CodeGen/MachineConstantPool.h"
5857 namespace {
5958 struct ISel : public FunctionPass, InstVisitor {
6059 TargetMachine &TM;
61 IntrinsicLowering &IL;
6260 MachineFunction *F; // The function we are compiling into
6361 MachineBasicBlock *BB; // The current MBB we are compiling
6462 int VarArgsFrameIndex; // FrameIndex for start of varargs area
6866 // MBBMap - Mapping between LLVM BB -> Machine BB
6967 std::map MBBMap;
7068
71 ISel(TargetMachine &tm, IntrinsicLowering &il)
72 : TM(tm), IL(il), F(0), BB(0) {}
69 ISel(TargetMachine &tm) : TM(tm), F(0), BB(0) {}
7370
7471 /// runOnFunction - Top level implementation of instruction selection for
7572 /// the entire function.
11151112 default:
11161113 // All other intrinsic calls we must lower.
11171114 Instruction *Before = CI->getPrev();
1118 IL.LowerIntrinsicCall(CI);
1115 TM.getIntrinsicLowering().LowerIntrinsicCall(CI);
11191116 if (Before) { // Move iterator to instruction after call
11201117 I = Before; ++I;
11211118 } else {
21952192 /// into a machine code representation is a very simple peep-hole fashion. The
21962193 /// generated code sucks but the implementation is nice and simple.
21972194 ///
2198 FunctionPass *llvm::createX86SimpleInstructionSelector(TargetMachine &TM,
2199 IntrinsicLowering &IL) {
2200 return new ISel(TM, IL);
2201 }
2195 FunctionPass *llvm::createX86SimpleInstructionSelector(TargetMachine &TM) {
2196 return new ISel(TM);
2197 }
2626 /// into a machine code representation in a very simple peep-hole fashion. The
2727 /// generated code sucks but the implementation is nice and simple.
2828 ///
29 FunctionPass *createX86SimpleInstructionSelector(TargetMachine &TM,
30 IntrinsicLowering &IL);
29 FunctionPass *createX86SimpleInstructionSelector(TargetMachine &TM);
3130
3231 /// createX86PatternInstructionSelector - This pass converts an LLVM function
3332 /// into a machine code representation using pattern matching and a machine
3433 /// description file.
3534 ///
36 FunctionPass *createX86PatternInstructionSelector(TargetMachine &TM,
37 IntrinsicLowering &IL);
35 FunctionPass *createX86PatternInstructionSelector(TargetMachine &TM);
3836
3937 /// createX86SSAPeepholeOptimizerPass - Create a pass to perform SSA-based X86
4038 /// specific peephole optimizations.
118118 /// into a machine code representation using pattern matching and a machine
119119 /// description file.
120120 ///
121 FunctionPass *llvm::createX86PatternInstructionSelector(TargetMachine &TM,
122 IntrinsicLowering &IL) {
121 FunctionPass *llvm::createX86PatternInstructionSelector(TargetMachine &TM) {
123122 return new ISel(TM);
124123 }
1717 #include "llvm/DerivedTypes.h"
1818 #include "llvm/Function.h"
1919 #include "llvm/Instructions.h"
20 #include "llvm/Intrinsics.h"
2120 #include "llvm/IntrinsicLowering.h"
2221 #include "llvm/Pass.h"
2322 #include "llvm/CodeGen/MachineConstantPool.h"
5857 namespace {
5958 struct ISel : public FunctionPass, InstVisitor {
6059 TargetMachine &TM;
61 IntrinsicLowering &IL;
6260 MachineFunction *F; // The function we are compiling into
6361 MachineBasicBlock *BB; // The current MBB we are compiling
6462 int VarArgsFrameIndex; // FrameIndex for start of varargs area
6866 // MBBMap - Mapping between LLVM BB -> Machine BB
6967 std::map MBBMap;
7068
71 ISel(TargetMachine &tm, IntrinsicLowering &il)
72 : TM(tm), IL(il), F(0), BB(0) {}
69 ISel(TargetMachine &tm) : TM(tm), F(0), BB(0) {}
7370
7471 /// runOnFunction - Top level implementation of instruction selection for
7572 /// the entire function.
11151112 default:
11161113 // All other intrinsic calls we must lower.
11171114 Instruction *Before = CI->getPrev();
1118 IL.LowerIntrinsicCall(CI);
1115 TM.getIntrinsicLowering().LowerIntrinsicCall(CI);
11191116 if (Before) { // Move iterator to instruction after call
11201117 I = Before; ++I;
11211118 } else {
21952192 /// into a machine code representation is a very simple peep-hole fashion. The
21962193 /// generated code sucks but the implementation is nice and simple.
21972194 ///
2198 FunctionPass *llvm::createX86SimpleInstructionSelector(TargetMachine &TM,
2199 IntrinsicLowering &IL) {
2200 return new ISel(TM, IL);
2201 }
2195 FunctionPass *llvm::createX86SimpleInstructionSelector(TargetMachine &TM) {
2196 return new ISel(TM);
2197 }
2121
2222 class X86JITInfo : public TargetJITInfo {
2323 TargetMachine &TM;
24 IntrinsicLowering &IL;
2524 public:
26 X86JITInfo(TargetMachine &tm, IntrinsicLowering &il) : TM(tm), IL(il) {}
25 X86JITInfo(TargetMachine &tm) : TM(tm) {}
2726
2827 /// addPassesToJITCompile - Add passes to the specified pass manager to
2928 /// implement a fast dynamic compiler for this target. Return true if this
3635 /// overwriting OLD with a branch to NEW. This is used for self-modifying
3736 /// code.
3837 ///
39 virtual void replaceMachineCodeForFunction (void *Old, void *New);
38 virtual void replaceMachineCodeForFunction(void *Old, void *New);
4039
4140 /// getJITStubForFunction - Create or return a stub for the specified
4241 /// function. This stub acts just like the specified function, except that
4444
4545 /// X86TargetMachine ctor - Create an ILP32 architecture model
4646 ///
47 X86TargetMachine::X86TargetMachine(const Module &M, IntrinsicLowering *il)
48 : TargetMachine("X86", true, 4, 4, 4, 4, 4),
49 IL(il ? il : new DefaultIntrinsicLowering()),
47 X86TargetMachine::X86TargetMachine(const Module &M, IntrinsicLowering *IL)
48 : TargetMachine("X86", IL, true, 4, 4, 4, 4, 4),
5049 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4),
51 JITInfo(*this, *IL) {
52 }
53
54 X86TargetMachine::~X86TargetMachine() {
55 delete IL;
50 JITInfo(*this) {
5651 }
5752
5853
7166 PM.add(createCFGSimplificationPass());
7267
7368 if (NoPatternISel)
74 PM.add(createX86SimpleInstructionSelector(*this, *IL));
69 PM.add(createX86SimpleInstructionSelector(*this));
7570 else
76 PM.add(createX86PatternInstructionSelector(*this, *IL));
71 PM.add(createX86PatternInstructionSelector(*this));
7772
7873 // Run optional SSA-based machine code optimizations next...
7974 if (!NoSSAPeephole)
126121 PM.add(createCFGSimplificationPass());
127122
128123 if (NoPatternISel)
129 PM.add(createX86SimpleInstructionSelector(TM, IL));
124 PM.add(createX86SimpleInstructionSelector(TM));
130125 else
131 PM.add(createX86PatternInstructionSelector(TM, IL));
126 PM.add(createX86PatternInstructionSelector(TM));
132127
133128 // Run optional SSA-based machine code optimizations next...
134129 if (!NoSSAPeephole)
2323 class IntrinsicLowering;
2424
2525 class X86TargetMachine : public TargetMachine {
26 IntrinsicLowering *IL;
2726 X86InstrInfo InstrInfo;
2827 TargetFrameInfo FrameInfo;
2928 X86JITInfo JITInfo;
3029 public:
3130 X86TargetMachine(const Module &M, IntrinsicLowering *IL);
32 ~X86TargetMachine();
3331
3432 virtual const X86InstrInfo &getInstrInfo() const { return InstrInfo; }
3533 virtual const TargetFrameInfo &getFrameInfo() const { return FrameInfo; }
1212
1313 #include "llvm/IntrinsicLowering.h"
1414 #include "llvm/Constant.h"
15 #include "llvm/Intrinsics.h"
1615 #include "llvm/Module.h"
1716 #include "llvm/Type.h"
1817 #include "llvm/iOther.h"