Thanks for pointing this out, Eric! r221668 cleans up the dead code. <br><br><div>Jingyue</div><br><div class="gmail_quote">On Mon Nov 10 2014 at 7:18:13 PM Eric Christopher <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You don't appear to need to cache the TargetMachine, TargetSubtargetInfo, or TargetLoweringInfo, can you please remove these and the associated code to initialize them?<br><div><br></div><div>Thanks.</div><div><br></div><div>-eric</div><br><div class="gmail_quote">On Mon Nov 10 2014 at 10:33:02 AM Jingyue Wu <<a href="mailto:jingyue@google.com" target="_blank">jingyue@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jingyue<br>
Date: Mon Nov 10 12:38:25 2014<br>
New Revision: 221619<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=221619&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=221619&view=rev</a><br>
Log:<br>
[NVPTX] Add an NVPTX-specific TargetTransformInfo<br>
<br>
Summary:<br>
It currently only implements hasBranchDivergence, and will be extended<br>
in later diffs.<br>
<br>
Split from D6188.<br>
<br>
Test Plan: make check-all<br>
<br>
Reviewers: jholewinski<br>
<br>
Reviewed By: jholewinski<br>
<br>
Subscribers: llvm-commits, meheff, eliben, jholewinski<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D6195" target="_blank">http://reviews.llvm.org/D6195</a><br>
<br>
Added:<br>
    llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetTransformInfo.cpp<br>
Modified:<br>
    llvm/trunk/lib/Target/NVPTX/<u></u>CMakeLists.txt<br>
    llvm/trunk/lib/Target/NVPTX/<u></u>NVPTX.h<br>
    llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetMachine.cpp<br>
    llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetMachine.h<br>
<br>
Modified: llvm/trunk/lib/Target/NVPTX/<u></u>CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/CMakeLists.txt?rev=221619&r1=221618&r2=221619&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/Target/<u></u>NVPTX/CMakeLists.txt?rev=<u></u>221619&r1=221618&r2=221619&<u></u>view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/Target/NVPTX/<u></u>CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/Target/NVPTX/<u></u>CMakeLists.txt Mon Nov 10 12:38:25 2014<br>
@@ -9,27 +9,28 @@ tablegen(LLVM NVPTXGenSubtargetInfo.inc<br>
 add_public_tablegen_target(<u></u>NVPTXCommonTableGen)<br>
<br>
 set(NVPTXCodeGen_sources<br>
+  NVPTXAllocaHoisting.cpp<br>
+  NVPTXAsmPrinter.cpp<br>
+  NVPTXAssignValidGlobalNames.<u></u>cpp<br>
   NVPTXFavorNonGenericAddrSpaces<u></u>.cpp<br>
   NVPTXFrameLowering.cpp<br>
-  NVPTXInstrInfo.cpp<br>
+  NVPTXGenericToNVVM.cpp<br>
   NVPTXISelDAGToDAG.cpp<br>
   NVPTXISelLowering.cpp<br>
+  NVPTXImageOptimizer.cpp<br>
+  NVPTXInstrInfo.cpp<br>
+  NVPTXLowerAggrCopies.cpp<br>
+  NVPTXLowerStructArgs.cpp<br>
+  NVPTXMCExpr.cpp<br>
+  NVPTXPrologEpilogPass.cpp<br>
   NVPTXRegisterInfo.cpp<br>
+  NVPTXReplaceImageHandles.cpp<br>
   NVPTXSubtarget.cpp<br>
   NVPTXTargetMachine.cpp<br>
-  NVPTXLowerAggrCopies.cpp<br>
-  NVPTXutil.cpp<br>
-  NVPTXAllocaHoisting.cpp<br>
-  NVPTXAsmPrinter.cpp<br>
+  NVPTXTargetTransformInfo.cpp<br>
   NVPTXUtilities.cpp<br>
+  NVPTXutil.cpp<br>
   NVVMReflect.cpp<br>
-  NVPTXGenericToNVVM.cpp<br>
-  NVPTXAssignValidGlobalNames.<u></u>cpp<br>
-  NVPTXPrologEpilogPass.cpp<br>
-  NVPTXMCExpr.cpp<br>
-  NVPTXReplaceImageHandles.cpp<br>
-  NVPTXImageOptimizer.cpp<br>
-  NVPTXLowerStructArgs.cpp<br>
   )<br>
<br>
 add_llvm_target(NVPTXCodeGen ${NVPTXCodeGen_sources})<br>
<br>
Modified: llvm/trunk/lib/Target/NVPTX/<u></u>NVPTX.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTX.h?rev=221619&r1=221618&r2=221619&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/Target/<u></u>NVPTX/NVPTX.h?rev=221619&r1=<u></u>221618&r2=221619&view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/Target/NVPTX/<u></u>NVPTX.h (original)<br>
+++ llvm/trunk/lib/Target/NVPTX/<u></u>NVPTX.h Mon Nov 10 12:38:25 2014<br>
@@ -59,6 +59,7 @@ inline static const char *NVPTXCondCodeT<br>
   llvm_unreachable("Unknown condition code");<br>
 }<br>
<br>
+ImmutablePass *<u></u>createNVPTXTargetTransformInfo<u></u>Pass(const NVPTXTargetMachine *TM);<br>
 FunctionPass *<br>
 createNVPTXISelDag(<u></u>NVPTXTargetMachine &TM, llvm::CodeGenOpt::Level OptLevel);<br>
 ModulePass *<u></u>createNVPTXAssignValidGlobalNa<u></u>mesPass();<br>
<br>
Modified: llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetMachine.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXTargetMachine.cpp?rev=221619&r1=221618&r2=221619&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/Target/<u></u>NVPTX/NVPTXTargetMachine.cpp?<u></u>rev=221619&r1=221618&r2=<u></u>221619&view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetMachine.cpp (original)<br>
+++ llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetMachine.cpp Mon Nov 10 12:38:25 2014<br>
@@ -121,6 +121,14 @@ TargetPassConfig *NVPTXTargetMachine::cr<br>
   return PassConfig;<br>
 }<br>
<br>
+void NVPTXTargetMachine::<u></u>addAnalysisPasses(<u></u>PassManagerBase &PM) {<br>
+  // Add first the target-independent BasicTTI pass, then our NVPTX pass. This<br>
+  // allows the NVPTX pass to delegate to the target independent layer when<br>
+  // appropriate.<br>
+  PM.add(<u></u>createBasicTargetTransformInfo<u></u>Pass(this));<br>
+  PM.add(<u></u>createNVPTXTargetTransformInfo<u></u>Pass(this));<br>
+}<br>
+<br>
 void NVPTXPassConfig::addIRPasses() {<br>
   // The following passes are known to not play well with virtual regs hanging<br>
   // around after register allocation (which in our case, is *all* registers).<br>
<br>
Modified: llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetMachine.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXTargetMachine.h?rev=221619&r1=221618&r2=221619&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/Target/<u></u>NVPTX/NVPTXTargetMachine.h?<u></u>rev=221619&r1=221618&r2=<u></u>221619&view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetMachine.h (original)<br>
+++ llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetMachine.h Mon Nov 10 12:38:25 2014<br>
@@ -49,6 +49,9 @@ public:<br>
     return true;<br>
   }<br>
<br>
+  /// \brief Register NVPTX analysis passes with a pass manager.<br>
+  void addAnalysisPasses(<u></u>PassManagerBase &PM) override;<br>
+<br>
 }; // NVPTXTargetMachine.<br>
<br>
 class NVPTXTargetMachine32 : public NVPTXTargetMachine {<br>
<br>
Added: llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetTransformInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp?rev=221619&view=auto" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/Target/<u></u>NVPTX/<u></u>NVPTXTargetTransformInfo.cpp?<u></u>rev=221619&view=auto</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetTransformInfo.cpp (added)<br>
+++ llvm/trunk/lib/Target/NVPTX/<u></u>NVPTXTargetTransformInfo.cpp Mon Nov 10 12:38:25 2014<br>
@@ -0,0 +1,90 @@<br>
+//===-- NVPTXTargetTransformInfo.cpp - NVPTX specific TTI pass ---------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<u></u>------------------------------<u></u>----------------===//<br>
+//<br>
+// \file<br>
+// This file implements a TargetTransformInfo analysis pass specific to the<br>
+// NVPTX target machine. It uses the target's detailed information to provide<br>
+// more precise answers to certain TTI queries, while letting the target<br>
+// independent and default TTI implementations handle the rest.<br>
+//<br>
+//===------------------------<u></u>------------------------------<u></u>----------------===//<br>
+<br>
+#include "NVPTXTargetMachine.h"<br>
+#include "llvm/Analysis/LoopInfo.h"<br>
+#include "llvm/Analysis/<u></u>TargetTransformInfo.h"<br>
+#include "llvm/Analysis/ValueTracking.<u></u>h"<br>
+#include "llvm/Support/Debug.h"<br>
+#include "llvm/Target/CostTable.h"<br>
+#include "llvm/Target/TargetLowering.h"<br>
+using namespace llvm;<br>
+<br>
+#define DEBUG_TYPE "NVPTXtti"<br>
+<br>
+// Declare the pass initialization routine locally as target-specific passes<br>
+// don't have a target-wide initialization entry point, and so we rely on the<br>
+// pass constructor initialization.<br>
+namespace llvm {<br>
+void initializeNVPTXTTIPass(<u></u>PassRegistry &);<br>
+}<br>
+<br>
+namespace {<br>
+<br>
+class NVPTXTTI final : public ImmutablePass, public TargetTransformInfo {<br>
+  const NVPTXTargetMachine *TM;<br>
+  const NVPTXSubtarget *ST;<br>
+  const NVPTXTargetLowering *TLI;<br>
+<br>
+  /// Estimate the overhead of scalarizing an instruction. Insert and Extract<br>
+  /// are set if the result needs to be inserted and/or extracted from vectors.<br>
+  unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;<br>
+<br>
+public:<br>
+  NVPTXTTI() : ImmutablePass(ID), TM(nullptr), ST(nullptr), TLI(nullptr) {<br>
+    llvm_unreachable("This pass cannot be directly constructed");<br>
+  }<br>
+<br>
+  NVPTXTTI(const NVPTXTargetMachine *TM)<br>
+      : ImmutablePass(ID), TM(TM), ST(TM->getSubtargetImpl()),<br>
+        TLI(TM->getSubtargetImpl()-><u></u>getTargetLowering()) {<br>
+    initializeNVPTXTTIPass(*<u></u>PassRegistry::getPassRegistry(<u></u>));<br>
+  }<br>
+<br>
+  void initializePass() override { pushTTIStack(this); }<br>
+<br>
+  void getAnalysisUsage(AnalysisUsage &AU) const override {<br>
+    TargetTransformInfo::<u></u>getAnalysisUsage(AU);<br>
+  }<br>
+<br>
+  /// Pass identification.<br>
+  static char ID;<br>
+<br>
+  /// Provide necessary pointer adjustments for the two base classes.<br>
+  void *getAdjustedAnalysisPointer(<u></u>const void *ID) override {<br>
+    if (ID == &TargetTransformInfo::ID)<br>
+      return (TargetTransformInfo *)this;<br>
+    return this;<br>
+  }<br>
+<br>
+  bool hasBranchDivergence() const override;<br>
+<br>
+  /// @}<br>
+};<br>
+<br>
+} // end anonymous namespace<br>
+<br>
+INITIALIZE_AG_PASS(NVPTXTTI, TargetTransformInfo, "NVPTXtti",<br>
+                   "NVPTX Target Transform Info", true, true, false)<br>
+char NVPTXTTI::ID = 0;<br>
+<br>
+ImmutablePass *<br>
+llvm::<u></u>createNVPTXTargetTransformInfo<u></u>Pass(const NVPTXTargetMachine *TM) {<br>
+  return new NVPTXTTI(TM);<br>
+}<br>
+<br>
+bool NVPTXTTI::hasBranchDivergence(<u></u>) const { return true; }<br>
<br>
<br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
</blockquote></div>
</blockquote></div>