ad38eaf95f07bc94ef804ecced6b082bee7711b7
[oota-llvm.git] / include / llvm / Target / TargetTransformImpl.h
1 //=- llvm/Target/TargetTransformImpl.h - Target Loop Trans Info----*- C++ -*-=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the target-specific implementations of the
11 // TargetTransform interfaces.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TARGET_TARGET_TRANSFORMATION_IMPL_H
16 #define LLVM_TARGET_TARGET_TRANSFORMATION_IMPL_H
17
18 #include "llvm/TargetTransformInfo.h"
19 #include "llvm/CodeGen/ValueTypes.h"
20
21 namespace llvm {
22
23 class TargetLowering;
24
25 /// ScalarTargetTransformInfo - This is a default implementation for the
26 /// ScalarTargetTransformInfo interface. Different targets can implement
27 /// this interface differently.
28 class ScalarTargetTransformImpl : public ScalarTargetTransformInfo {
29 protected:
30   const TargetLowering *TLI;
31
32 public:
33   /// Ctor
34   explicit ScalarTargetTransformImpl(const TargetLowering *TL) : TLI(TL) {}
35
36   virtual bool isLegalAddImmediate(int64_t imm) const;
37
38   virtual bool isLegalICmpImmediate(int64_t imm) const;
39
40   virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const;
41
42   virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const;
43
44   virtual bool isTypeLegal(Type *Ty) const;
45
46   virtual unsigned getJumpBufAlignment() const;
47
48   virtual unsigned getJumpBufSize() const;
49
50   virtual bool shouldBuildLookupTables() const;
51 };
52
53 class VectorTargetTransformImpl : public VectorTargetTransformInfo {
54 protected:
55   const TargetLowering *TLI;
56
57   /// Estimate the cost of type-legalization and the legalized type.
58   std::pair<unsigned, MVT> getTypeLegalizationCost(Type *Ty) const;
59
60   /// Estimate the overhead of scalarizing an instruction. Insert and Extract
61   /// are set if the result needs to be inserted and/or extracted from vectors.
62   unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;
63
64   // Get the ISD node that corresponds to the Instruction class opcode.
65   int InstructionOpcodeToISD(unsigned Opcode) const;
66
67 public:
68   explicit VectorTargetTransformImpl(const TargetLowering *TL) : TLI(TL) {}
69
70   virtual ~VectorTargetTransformImpl() {}
71
72   virtual unsigned getInstrCost(unsigned Opcode, Type *Ty1, Type *Ty2) const;
73
74   virtual unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty) const;
75
76   virtual unsigned getBroadcastCost(Type *Tp) const;
77
78   virtual unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
79                                     Type *Src) const;
80
81   virtual unsigned getCFInstrCost(unsigned Opcode) const;
82
83   virtual unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
84                                       Type *CondTy) const;
85
86   virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
87                                       unsigned Index) const;
88
89   virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
90                                    unsigned Alignment,
91                                    unsigned AddressSpace) const;
92
93   virtual unsigned getNumberOfParts(Type *Tp) const;
94 };
95
96 } // end llvm namespace
97
98 #endif