llvm.org GIT mirror llvm / 2704834
Implement a basic VectorTargetTransformInfo interface to be used by the loop and bb vectorizers for modeling the cost of instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166593 91177308-0d34-0410-b5e6-96231b3b80d8 Nadav Rotem 8 years ago
15 changed file(s) with 100 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
4646 virtual unsigned getJumpBufSize() const;
4747 };
4848
49 class VectorTargetTransformImpl : public VectorTargetTransformInfo { };
49 class VectorTargetTransformImpl : public VectorTargetTransformInfo {
50 private:
51 const TargetLowering *TLI;
52
53 public:
54 explicit VectorTargetTransformImpl(const TargetLowering *TL) : TLI(TL) {}
55
56 virtual ~VectorTargetTransformImpl() {}
57
58 virtual unsigned getInstrCost(unsigned Opcode, Type *Ty1, Type *Ty2) const;
59
60 virtual unsigned getBroadcastCost(Type *Tp) const;
61
62 virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
63 unsigned Alignment,
64 unsigned AddressSpace) const;
65 };
5066
5167 } // end llvm namespace
5268
5353 TargetTransformInfo(const TargetTransformInfo &T) :
5454 ImmutablePass(ID), STTI(T.STTI), VTTI(T.VTTI) { }
5555
56 const ScalarTargetTransformInfo* getScalarTargetTransformInfo() {
56 const ScalarTargetTransformInfo* getScalarTargetTransformInfo() const {
5757 return STTI;
5858 }
59 const VectorTargetTransformInfo* getVectorTargetTransformInfo() {
59 const VectorTargetTransformInfo* getVectorTargetTransformInfo() const {
6060 return VTTI;
6161 }
6262
118118 }
119119 };
120120
121 /// VectorTargetTransformInfo - This interface is used by the vectorizers
122 /// to estimate the profitability of vectorization for different instructions.
121123 class VectorTargetTransformInfo {
122 // TODO: define an interface for VectorTargetTransformInfo.
124 public:
125 virtual ~VectorTargetTransformInfo() {}
126
127 /// Returns the expected cost of the instruction opcode. The opcode is one of
128 /// the enums like Instruction::Add. The type arguments are the type of the
129 /// operation.
130 /// Most instructions only use the first type and in that case the second
131 /// operand is ignored.
132 ///
133 /// Exceptions:
134 /// * Br instructions do not use any of the types.
135 /// * Select instructions pass the return type as Ty1 and the selector as Ty2.
136 /// * Cast instructions pass the destination as Ty1 and the source as Ty2.
137 /// * Insert/Extract element pass only the vector type as Ty1.
138 /// * ShuffleVector, Load, Store do not use this call.
139 virtual unsigned getInstrCost(unsigned Opcode,
140 Type *Ty1 = 0,
141 Type *Ty2 = 0) const {
142 return 1;
143 }
144
145 /// Returns the cost of a vector broadcast of a scalar at place zero to a
146 /// vector of type 'Tp'.
147 virtual unsigned getBroadcastCost(Type *Tp) const {
148 return 1;
149 }
150
151 /// Returns the cost of Load and Store instructions.
152 virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
153 unsigned Alignment,
154 unsigned AddressSpace) const {
155 return 1;
156 }
157
123158 };
124159
125160 } // End llvm namespace
7171 TLInfo(*this),
7272 TSInfo(*this),
7373 FrameLowering(Subtarget),
74 STTI(&TLInfo) {
74 STTI(&TLInfo), VTTI(&TLInfo) {
7575 if (!Subtarget.hasARMOps())
7676 report_fatal_error("CPU: '" + Subtarget.getCPUString() + "' does not "
7777 "support ARM mode execution!");
105105 FrameLowering(Subtarget.hasThumb2()
106106 ? new ARMFrameLowering(Subtarget)
107107 : (ARMFrameLowering*)new Thumb1FrameLowering(Subtarget)),
108 STTI(&TLInfo){
108 STTI(&TLInfo), VTTI(&TLInfo) {
109109 }
110110
111111 namespace {
4343 TLInfo(*this),
4444 TSInfo(*this),
4545 InstrItins(Subtarget.getInstrItineraryData()),
46 STTI(&TLInfo){
46 STTI(&TLInfo), VTTI(&TLInfo) {
4747 }
4848
4949 //===----------------------------------------------------------------------===//
7474 TSInfo(*this),
7575 FrameLowering(Subtarget),
7676 InstrItins(&Subtarget.getInstrItineraryData()),
77 STTI(&TLInfo) {
77 STTI(&TLInfo), VTTI(&TLInfo) {
7878 setMCUseCFI(false);
7979 }
8080
4141 InstrInfo(*this),
4242 FrameLowering(Subtarget),
4343 TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this),
44 InstrItins(Subtarget.getInstrItineraryData()), STTI(&TLInfo) {
44 InstrItins(Subtarget.getInstrItineraryData()),
45 STTI(&TLInfo), VTTI(&TLInfo) {
4546 }
4647
4748 namespace {
3535 // FIXME: Check DataLayout string.
3636 DL("e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"),
3737 InstrInfo(*this), TLInfo(*this), TSInfo(*this),
38 FrameLowering(Subtarget), STTI(&TLInfo) { }
38 FrameLowering(Subtarget), STTI(&TLInfo), VTTI(&TLInfo) { }
3939
4040 namespace {
4141 /// MSP430 Code Generator Pass Configuration Options.
5252 InstrInfo(MipsInstrInfo::create(*this)),
5353 FrameLowering(MipsFrameLowering::create(*this, Subtarget)),
5454 TLInfo(*this), TSInfo(*this), JITInfo(),
55 ELFWriterInfo(false, isLittle), STTI(&TLInfo) {
55 ELFWriterInfo(false, isLittle), STTI(&TLInfo), VTTI(&TLInfo) {
5656 }
5757
5858 void MipsebTargetMachine::anchor() { }
3939 MipsJITInfo JITInfo;
4040 MipsELFWriterInfo ELFWriterInfo;
4141 ScalarTargetTransformImpl STTI;
42 VectorTargetTransformInfo VTTI;
42 VectorTargetTransformImpl VTTI;
4343
4444 public:
4545 MipsTargetMachine(const Target &T, StringRef TT,
7272 Subtarget(TT, CPU, FS, is64bit),
7373 DL(Subtarget.getDataLayout()),
7474 InstrInfo(*this), TLInfo(*this), TSInfo(*this), FrameLowering(*this,is64bit),
75 STTI(&TLInfo)
75 STTI(&TLInfo), VTTI(&TLInfo)
7676 /*FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0)*/ {
7777 }
7878
4343 FrameLowering(Subtarget), JITInfo(*this, is64Bit),
4444 TLInfo(*this), TSInfo(*this),
4545 InstrItins(Subtarget.getInstrItineraryData()),
46 STTI(&TLInfo){
46 STTI(&TLInfo), VTTI(&TLInfo) {
4747
4848 // The binutils for the BG/P are too old for CFI.
4949 if (Subtarget.isBGP())
3535 DL(Subtarget.getDataLayout()),
3636 InstrInfo(Subtarget),
3737 TLInfo(*this), TSInfo(*this),
38 FrameLowering(Subtarget),STTI(&TLInfo) {
38 FrameLowering(Subtarget), STTI(&TLInfo), VTTI(&TLInfo) {
3939 }
4040
4141 namespace {
1010 #include "llvm/Target/TargetLowering.h"
1111
1212 using namespace llvm;
13
14 //===----------------------------------------------------------------------===//
15 //
16 // Calls used by scalar transformations.
17 //
18 //===----------------------------------------------------------------------===//
1319
1420 bool ScalarTargetTransformImpl::isLegalAddImmediate(int64_t imm) const {
1521 return TLI->isLegalAddImmediate(imm);
4046 unsigned ScalarTargetTransformImpl::getJumpBufSize() const {
4147 return TLI->getJumpBufSize();
4248 }
49
50 //===----------------------------------------------------------------------===//
51 //
52 // Calls used by the vectorizers.
53 //
54 //===----------------------------------------------------------------------===//
55
56 unsigned
57 VectorTargetTransformImpl::getInstrCost(unsigned Opcode, Type *Ty1,
58 Type *Ty2) const {
59 return 1;
60 }
61
62 unsigned
63 VectorTargetTransformImpl::getBroadcastCost(Type *Tp) const {
64 return 1;
65 }
66
67 unsigned
68 VectorTargetTransformImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
69 unsigned Alignment,
70 unsigned AddressSpace) const {
71 return 1;
72 }
4848 TSInfo(*this),
4949 TLInfo(*this),
5050 JITInfo(*this),
51 STTI(&TLInfo) {
51 STTI(&TLInfo), VTTI(&TLInfo) {
5252 }
5353
5454 void X86_64TargetMachine::anchor() { }
6565 TSInfo(*this),
6666 TLInfo(*this),
6767 JITInfo(*this),
68 STTI(&TLInfo) {
68 STTI(&TLInfo), VTTI(&TLInfo){
6969 }
7070
7171 /// X86TargetMachine ctor - Create an X86 target.
3131 InstrInfo(),
3232 FrameLowering(Subtarget),
3333 TLInfo(*this),
34 TSInfo(*this), STTI(&TLInfo) {
34 TSInfo(*this), STTI(&TLInfo), VTTI(&TLInfo) {
3535 }
3636
3737 namespace {