Implement a basic VectorTargetTransformInfo interface to be used by the loop and...
authorNadav Rotem <nrotem@apple.com>
Wed, 24 Oct 2012 17:22:41 +0000 (17:22 +0000)
committerNadav Rotem <nrotem@apple.com>
Wed, 24 Oct 2012 17:22:41 +0000 (17:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166593 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
include/llvm/Target/TargetTransformImpl.h
include/llvm/TargetTransformInfo.h
lib/Target/ARM/ARMTargetMachine.cpp
lib/Target/CellSPU/SPUTargetMachine.cpp
lib/Target/Hexagon/HexagonTargetMachine.cpp
lib/Target/MBlaze/MBlazeTargetMachine.cpp
lib/Target/MSP430/MSP430TargetMachine.cpp
lib/Target/Mips/MipsTargetMachine.cpp
lib/Target/Mips/MipsTargetMachine.h
lib/Target/NVPTX/NVPTXTargetMachine.cpp
lib/Target/PowerPC/PPCTargetMachine.cpp
lib/Target/Sparc/SparcTargetMachine.cpp
lib/Target/TargetTransformImpl.cpp
lib/Target/X86/X86TargetMachine.cpp
lib/Target/XCore/XCoreTargetMachine.cpp

index 7648f4f935c4fc10136a77caab40ab26986fbb43..ec39f9968e010dbcaae4e383b86ba6c80aa94c4f 100644 (file)
@@ -47,7 +47,23 @@ public:
   virtual unsigned getJumpBufSize() const;
 };
 
-class VectorTargetTransformImpl : public VectorTargetTransformInfo { };
+class VectorTargetTransformImpl : public VectorTargetTransformInfo {
+private:
+  const TargetLowering *TLI;
+
+public:
+  explicit VectorTargetTransformImpl(const TargetLowering *TL) : TLI(TL) {}
+  
+  virtual ~VectorTargetTransformImpl() {}
+
+  virtual unsigned getInstrCost(unsigned Opcode, Type *Ty1, Type *Ty2) const;
+
+  virtual unsigned getBroadcastCost(Type *Tp) const;
+
+  virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
+                                   unsigned Alignment,
+                                   unsigned AddressSpace) const;
+};
 
 } // end llvm namespace
 
index 82fc14dbd7434e0d33509965e772c93308c7ebb1..96470c30ca587bbb0a39d168a63cd5f3407e6144 100644 (file)
@@ -54,10 +54,10 @@ public:
   TargetTransformInfo(const TargetTransformInfo &T) :
     ImmutablePass(ID), STTI(T.STTI), VTTI(T.VTTI) { }
 
-  const ScalarTargetTransformInfo* getScalarTargetTransformInfo() {
+  const ScalarTargetTransformInfo* getScalarTargetTransformInfo() const {
     return STTI;
   }
-  const VectorTargetTransformInfo* getVectorTargetTransformInfo() {
+  const VectorTargetTransformInfo* getVectorTargetTransformInfo() const {
     return VTTI;
   }
 
@@ -119,8 +119,43 @@ public:
   }
 };
 
+/// VectorTargetTransformInfo - This interface is used by the vectorizers
+/// to estimate the profitability of vectorization for different instructions.
 class VectorTargetTransformInfo {
-  // TODO: define an interface for VectorTargetTransformInfo.
+public:
+  virtual ~VectorTargetTransformInfo() {}
+
+  /// Returns the expected cost of the instruction opcode. The opcode is one of
+  /// the enums like Instruction::Add. The type arguments are the type of the
+  /// operation.
+  /// Most instructions only use the first type and in that case the second
+  /// operand is ignored.
+  ///
+  /// Exceptions:
+  /// * Br instructions do not use any of the types.
+  /// * Select instructions pass the return type as Ty1 and the selector as Ty2.
+  /// * Cast instructions pass the destination as Ty1 and the source as Ty2.
+  /// * Insert/Extract element pass only the vector type as Ty1.
+  /// * ShuffleVector, Load, Store do not use this call.
+  virtual unsigned getInstrCost(unsigned Opcode,
+                                Type *Ty1 = 0,
+                                Type *Ty2 = 0) const {
+    return 1;
+  }
+
+  /// Returns the cost of a vector broadcast of a scalar at place zero to a
+  /// vector of type 'Tp'.
+  virtual unsigned getBroadcastCost(Type *Tp) const {
+    return 1;
+  }
+
+  /// Returns the cost of Load and Store instructions. 
+  virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
+                                   unsigned Alignment,
+                                   unsigned AddressSpace) const {
+    return 1;
+  }
+
 };
 
 } // End llvm namespace
index c51ae24c50e3b996dcb414e90be1b041ae92784f..fdff55edfe833e7d2c9d564e58908b89da1c935f 100644 (file)
@@ -72,7 +72,7 @@ ARMTargetMachine::ARMTargetMachine(const Target &T, StringRef TT,
     TLInfo(*this),
     TSInfo(*this),
     FrameLowering(Subtarget),
-    STTI(&TLInfo) {
+    STTI(&TLInfo), VTTI(&TLInfo) {
   if (!Subtarget.hasARMOps())
     report_fatal_error("CPU: '" + Subtarget.getCPUString() + "' does not "
                        "support ARM mode execution!");
@@ -106,7 +106,7 @@ ThumbTargetMachine::ThumbTargetMachine(const Target &T, StringRef TT,
     FrameLowering(Subtarget.hasThumb2()
               ? new ARMFrameLowering(Subtarget)
               : (ARMFrameLowering*)new Thumb1FrameLowering(Subtarget)),
-    STTI(&TLInfo){
+    STTI(&TLInfo), VTTI(&TLInfo) {
 }
 
 namespace {
index e92ad01e1d5aaf814badfba5c82de7968b885373..918316572a2e71073397e24bd539e17ffa193ff3 100644 (file)
@@ -44,7 +44,7 @@ SPUTargetMachine::SPUTargetMachine(const Target &T, StringRef TT,
     TLInfo(*this),
     TSInfo(*this),
     InstrItins(Subtarget.getInstrItineraryData()),
-    STTI(&TLInfo){
+    STTI(&TLInfo), VTTI(&TLInfo) {
 }
 
 //===----------------------------------------------------------------------===//
index 353542a8097e2d05ab35999eeae7dc49d09fd133..30866e9eeba8eb562c99c57001fb554663f6538a 100644 (file)
@@ -75,7 +75,7 @@ HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
     TSInfo(*this),
     FrameLowering(Subtarget),
     InstrItins(&Subtarget.getInstrItineraryData()),
-    STTI(&TLInfo) {
+    STTI(&TLInfo), VTTI(&TLInfo) {
   setMCUseCFI(false);
 }
 
index cb5f46062d99081f24743dbd37c74be5390743f4..1ae2baa19833beb4e07f02911f96981e24c3c556 100644 (file)
@@ -42,7 +42,8 @@ MBlazeTargetMachine(const Target &T, StringRef TT,
     InstrInfo(*this),
     FrameLowering(Subtarget),
     TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this),
-    InstrItins(Subtarget.getInstrItineraryData()), STTI(&TLInfo) {
+    InstrItins(Subtarget.getInstrItineraryData()),
+    STTI(&TLInfo), VTTI(&TLInfo) {
 }
 
 namespace {
index 29ea68121621503a3b358a3338b3d5ad297b3ae1..13e37b373533e169d76fb52b1ebcec3558b55c37 100644 (file)
@@ -36,7 +36,7 @@ MSP430TargetMachine::MSP430TargetMachine(const Target &T,
     // FIXME: Check DataLayout string.
     DL("e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"),
     InstrInfo(*this), TLInfo(*this), TSInfo(*this),
-    FrameLowering(Subtarget), STTI(&TLInfo) { }
+    FrameLowering(Subtarget), STTI(&TLInfo), VTTI(&TLInfo) { }
 
 namespace {
 /// MSP430 Code Generator Pass Configuration Options.
index 4c3981d9f68b0a61aeacb52f107a9a8726975a5d..7d73866562b455f43b9e25bfca7f0075d9d6cf99 100644 (file)
@@ -53,7 +53,7 @@ MipsTargetMachine(const Target &T, StringRef TT,
     InstrInfo(MipsInstrInfo::create(*this)),
     FrameLowering(MipsFrameLowering::create(*this, Subtarget)),
     TLInfo(*this), TSInfo(*this), JITInfo(),
-    ELFWriterInfo(false, isLittle), STTI(&TLInfo) {
+    ELFWriterInfo(false, isLittle), STTI(&TLInfo), VTTI(&TLInfo) {
 }
 
 void MipsebTargetMachine::anchor() { }
index 60822d0c055f22f34213e23e1725a45700059d7b..a62db327e5fbaa34980ecb9900059b797c5cf55f 100644 (file)
@@ -40,7 +40,7 @@ class MipsTargetMachine : public LLVMTargetMachine {
   MipsJITInfo JITInfo;
   MipsELFWriterInfo   ELFWriterInfo;
   ScalarTargetTransformImpl STTI;
-  VectorTargetTransformInfo VTTI; 
+  VectorTargetTransformImpl VTTI;
 
 public:
   MipsTargetMachine(const Target &T, StringRef TT,
index 7519b4a083176a38c22fc02f9cb45ffd8346699b..cbb490003d374ff760b4e8fb44de2af9acc7d8f7 100644 (file)
@@ -73,7 +73,7 @@ NVPTXTargetMachine::NVPTXTargetMachine(const Target &T,
   Subtarget(TT, CPU, FS, is64bit),
   DL(Subtarget.getDataLayout()),
   InstrInfo(*this), TLInfo(*this), TSInfo(*this), FrameLowering(*this,is64bit),
-  STTI(&TLInfo)
+  STTI(&TLInfo), VTTI(&TLInfo)
 /*FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0)*/ {
 }
 
index b86138347537694d546ede379c5903feda8ca93d..3fc977ee2b41841a27f5fa2eeb49d976ac714c37 100644 (file)
@@ -44,7 +44,7 @@ PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT,
     FrameLowering(Subtarget), JITInfo(*this, is64Bit),
     TLInfo(*this), TSInfo(*this),
     InstrItins(Subtarget.getInstrItineraryData()),
-    STTI(&TLInfo){
+    STTI(&TLInfo), VTTI(&TLInfo) {
 
   // The binutils for the BG/P are too old for CFI.
   if (Subtarget.isBGP())
index 1d8cc771ddf2fd2f6271b03916a7d08b9cabcf7a..45c962471ddaa285b692cfb956c0612442198c39 100644 (file)
@@ -36,7 +36,7 @@ SparcTargetMachine::SparcTargetMachine(const Target &T, StringRef TT,
     DL(Subtarget.getDataLayout()),
     InstrInfo(Subtarget),
     TLInfo(*this), TSInfo(*this),
-    FrameLowering(Subtarget),STTI(&TLInfo) {
+    FrameLowering(Subtarget), STTI(&TLInfo), VTTI(&TLInfo) {
 }
 
 namespace {
index 1cb5edab9d0c7a2ad5eeac42ceca29a23bc1d2b4..cee736bd716809b2cc7316c2997de9fdcba26cf9 100644 (file)
 
 using namespace llvm;
 
+//===----------------------------------------------------------------------===//
+//
+// Calls used by scalar transformations.
+//
+//===----------------------------------------------------------------------===//
+
 bool ScalarTargetTransformImpl::isLegalAddImmediate(int64_t imm) const {
   return TLI->isLegalAddImmediate(imm);
 }
@@ -41,3 +47,27 @@ unsigned ScalarTargetTransformImpl::getJumpBufAlignment() const {
 unsigned ScalarTargetTransformImpl::getJumpBufSize() const {
   return TLI->getJumpBufSize();
 }
+
+//===----------------------------------------------------------------------===//
+//
+// Calls used by the vectorizers.
+//
+//===----------------------------------------------------------------------===//
+
+unsigned
+VectorTargetTransformImpl::getInstrCost(unsigned Opcode, Type *Ty1,
+                                        Type *Ty2) const {
+  return 1;
+}
+
+unsigned
+VectorTargetTransformImpl::getBroadcastCost(Type *Tp) const {
+  return 1;
+}
+
+unsigned
+VectorTargetTransformImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
+                                           unsigned Alignment,
+                                           unsigned AddressSpace) const {
+  return 1;
+}
index 655ede79ba3c5fa6798ba77c618ebfd5bd45e217..48f9bba1fc968cb88f3e6e3d55e9be99cdd83dcd 100644 (file)
@@ -49,7 +49,7 @@ X86_32TargetMachine::X86_32TargetMachine(const Target &T, StringRef TT,
     TSInfo(*this),
     TLInfo(*this),
     JITInfo(*this),
-    STTI(&TLInfo) {
+    STTI(&TLInfo), VTTI(&TLInfo) {
 }
 
 void X86_64TargetMachine::anchor() { }
@@ -66,7 +66,7 @@ X86_64TargetMachine::X86_64TargetMachine(const Target &T, StringRef TT,
     TSInfo(*this),
     TLInfo(*this),
     JITInfo(*this),
-    STTI(&TLInfo) {
+    STTI(&TLInfo), VTTI(&TLInfo){
 }
 
 /// X86TargetMachine ctor - Create an X86 target.
index 0b7e3e10d4b01088b3aa59e5d0be0a201995899e..d5a932c5189d990b03f30058372848f7159589d6 100644 (file)
@@ -32,7 +32,7 @@ XCoreTargetMachine::XCoreTargetMachine(const Target &T, StringRef TT,
     InstrInfo(),
     FrameLowering(Subtarget),
     TLInfo(*this),
-    TSInfo(*this), STTI(&TLInfo) {
+    TSInfo(*this), STTI(&TLInfo), VTTI(&TLInfo) {
 }
 
 namespace {