<div dir="ltr">Hi Krzysztof,<div><br></div><div><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
- TLOF(make_unique<HexagonTargetObjectFile>()),<br>
- Subtarget(TT, CPU, FS, *this) {<br>
- initAsmInfo();<br>
+ TLOF(make_unique<HexagonTargetObjectFile>()) {<br>
+ initAsmInfo();<br>
}<br>
<br>
+const HexagonSubtarget *<br>
+HexagonTargetMachine::getSubtargetImpl(const Function &F) const {<br>
+ AttributeSet FnAttrs = F.getAttributes();<br>
+ Attribute CPUAttr =<br>
+ FnAttrs.getAttribute(AttributeSet::FunctionIndex, "target-cpu");<br>
+ Attribute FSAttr =<br>
+ FnAttrs.getAttribute(AttributeSet::FunctionIndex, "target-features");<br>
+<br>
+ std::string CPU = !CPUAttr.hasAttribute(Attribute::None)<br>
+ ? CPUAttr.getValueAsString().str()<br>
+ : TargetCPU;<br>
+ std::string FS = !FSAttr.hasAttribute(Attribute::None)<br>
+ ? FSAttr.getValueAsString().str()<br>
+ : TargetFS;<br>
+<br>
+ auto &I = SubtargetMap[CPU + FS];<br>
+ if (!I) {<br>
+ // This needs to be done before we create a new subtarget since any<br>
+ // creation will depend on the TM and the code generation flags on the<br>
+ // function that reside in TargetOptions.<br>
+ resetTargetOptions(F);<br>
+ I = llvm::make_unique<HexagonSubtarget>(TargetTriple, CPU, FS, *this);<br>
+ }<br>
+ return I.get();<br>
+}<br>
+<br></blockquote><div><br></div><div>Are you actually planning on supporting subtarget features for different subtargets on functions? Otherwise there's no reason to do this and you can just have:</div><div><br></div><div>getSubtargetImpl(const Function &F) const {</div><div> return &Subtarget;</div><div>}</div><div><br></div><div>-eric</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+TargetIRAnalysis HexagonTargetMachine::getTargetIRAnalysis() {<br>
+ return TargetIRAnalysis([this](Function &F) {<br>
+ return TargetTransformInfo(HexagonTTIImpl(this, F));<br>
+ });<br>
+}<br>
+<br>
+<br>
HexagonTargetMachine::~HexagonTargetMachine() {}<br>
<br>
namespace {<br>
<br>
Modified: llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h?rev=244089&r1=244088&r2=244089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h?rev=244089&r1=244088&r2=244089&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h (original)<br>
+++ llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h Wed Aug 5 13:35:37 2015<br>
@@ -24,7 +24,7 @@ class Module;<br>
<br>
class HexagonTargetMachine : public LLVMTargetMachine {<br>
std::unique_ptr<TargetLoweringObjectFile> TLOF;<br>
- HexagonSubtarget Subtarget;<br>
+ mutable StringMap<std::unique_ptr<HexagonSubtarget>> SubtargetMap;<br>
<br>
public:<br>
HexagonTargetMachine(const Target &T, const Triple &TT, StringRef CPU,<br>
@@ -32,12 +32,12 @@ public:<br>
Reloc::Model RM, CodeModel::Model CM,<br>
CodeGenOpt::Level OL);<br>
~HexagonTargetMachine() override;<br>
- const HexagonSubtarget *getSubtargetImpl(const Function &) const override {<br>
- return &Subtarget;<br>
- }<br>
+ const HexagonSubtarget *getSubtargetImpl(const Function &F) const override;<br>
+<br>
static unsigned getModuleMatchQuality(const Module &M);<br>
<br>
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;<br>
+ TargetIRAnalysis getTargetIRAnalysis() override;<br>
<br>
TargetLoweringObjectFile *getObjFileLowering() const override {<br>
return TLOF.get();<br>
<br>
Added: llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp?rev=244089&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp?rev=244089&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp (added)<br>
+++ llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp Wed Aug 5 13:35:37 2015<br>
@@ -0,0 +1,44 @@<br>
+//===-- HexagonTargetTransformInfo.cpp - Hexagon 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>
+/// \file<br>
+/// This file implements a TargetTransformInfo analysis pass specific to the<br>
+/// Hexagon 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>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "HexagonTargetTransformInfo.h"<br>
+#include "llvm/Support/Debug.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+#define DEBUG_TYPE "hexagontti"<br>
+<br>
+TargetTransformInfo::PopcntSupportKind<br>
+HexagonTTIImpl::getPopcntSupport(unsigned IntTyWidthInBit) const {<br>
+ // Return Fast Hardware support as every input < 64 bits will be promoted<br>
+ // to 64 bits.<br>
+ return TargetTransformInfo::PSK_FastHardware;<br>
+}<br>
+<br>
+// The Hexagon target can unroll loops with run-time trip counts.<br>
+void HexagonTTIImpl::getUnrollingPreferences(Loop *L,<br>
+ TTI::UnrollingPreferences &UP) {<br>
+ UP.Runtime = UP.Partial = true;<br>
+}<br>
+<br>
+unsigned HexagonTTIImpl::getNumberOfRegisters(bool vector) const {<br>
+ if (vector) {<br>
+ // While its true that v60 has vector registers,<br>
+ // we do not want to advertise it through this API<br>
+ // as it enables LOOP and SLP vectorization.<br>
+ return 0;<br>
+ }<br>
+ return 32;<br>
+}<br>
<br>
Added: llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h?rev=244089&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h?rev=244089&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h (added)<br>
+++ llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h Wed Aug 5 13:35:37 2015<br>
@@ -0,0 +1,70 @@<br>
+//===-- HexagonTargetTransformInfo.cpp - Hexagon 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>
+/// \file<br>
+/// This file implements a TargetTransformInfo analysis pass specific to the<br>
+/// Hexagon 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>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H<br>
+#define LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H<br>
+<br>
+#include "Hexagon.h"<br>
+#include "HexagonTargetMachine.h"<br>
+#include "llvm/Analysis/TargetTransformInfo.h"<br>
+#include "llvm/CodeGen/BasicTTIImpl.h"<br>
+#include "llvm/Target/TargetLowering.h"<br>
+<br>
+namespace llvm {<br>
+<br>
+class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> {<br>
+ typedef BasicTTIImplBase<HexagonTTIImpl> BaseT;<br>
+ typedef TargetTransformInfo TTI;<br>
+ friend BaseT;<br>
+<br>
+ const HexagonSubtarget *ST;<br>
+ const HexagonTargetLowering *TLI;<br>
+<br>
+ const HexagonSubtarget *getST() const { return ST; }<br>
+ const HexagonTargetLowering *getTLI() const { return TLI; }<br>
+<br>
+public:<br>
+ explicit HexagonTTIImpl(const HexagonTargetMachine *TM, Function &F)<br>
+ : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),<br>
+ TLI(ST->getTargetLowering()) {}<br>
+<br>
+ // Provide value semantics. MSVC requires that we spell all of these out.<br>
+ HexagonTTIImpl(const HexagonTTIImpl &Arg)<br>
+ : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}<br>
+ HexagonTTIImpl(HexagonTTIImpl &&Arg)<br>
+ : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),<br>
+ TLI(std::move(Arg.TLI)) {}<br>
+<br>
+ /// \name Scalar TTI Implementations<br>
+ /// @{<br>
+<br>
+ TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;<br>
+<br>
+ // The Hexagon target can unroll loops with run-time trip counts.<br>
+ void getUnrollingPreferences(Loop *L, TTI::UnrollingPreferences &UP);<br>
+<br>
+ /// @}<br>
+<br>
+ /// \name Vector TTI Implementations<br>
+ /// @{<br>
+<br>
+ unsigned getNumberOfRegisters(bool vector) const;<br>
+<br>
+ /// @}<br>
+};<br>
+<br>
+} // end namespace llvm<br>
+<br>
+#endif<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div>