1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

(Re-landing) Expose a TargetMachine::getTargetTransformInfo function

Re-land r321234.  It had to be reverted because it broke the shared
library build.  The shared library build broke because there was a
missing LLVMBuild dependency from lib/Passes (which calls
TargetMachine::getTargetIRAnalysis) to lib/Target.  As far as I can
tell, this problem was always there but was somehow masked
before (perhaps because TargetMachine::getTargetIRAnalysis was a
virtual function).

Original commit message:

This makes the TargetMachine interface a bit simpler.  We still need
the std::function in TargetIRAnalysis to avoid having to add a
dependency from Analysis to Target.

See discussion:
http://lists.llvm.org/pipermail/llvm-dev/2017-December/119749.html

I avoided adding all of the backend owners to this review since the
change is simple, but let me know if you feel differently about this.

Reviewers: echristo, MatzeB, hfinkel

Reviewed By: hfinkel

Subscribers: jholewinski, jfb, arsenm, dschuff, mcrosier, sdardis, nemanjai, nhaehnle, javed.absar, sbc100, jgravelle-google, aheejin, kbarton, llvm-commits

Differential Revision: https://reviews.llvm.org/D41464

llvm-svn: 321375
This commit is contained in:
Sanjoy Das 2017-12-22 18:21:59 +00:00
parent db06df90f8
commit df40ece177
30 changed files with 84 additions and 89 deletions

View File

@ -24,6 +24,7 @@
namespace llvm { namespace llvm {
class Function;
class GlobalValue; class GlobalValue;
class MachineModuleInfo; class MachineModuleInfo;
class Mangler; class Mangler;
@ -38,6 +39,7 @@ class PassManagerBuilder;
class Target; class Target;
class TargetIntrinsicInfo; class TargetIntrinsicInfo;
class TargetIRAnalysis; class TargetIRAnalysis;
class TargetTransformInfo;
class TargetLoweringObjectFile; class TargetLoweringObjectFile;
class TargetPassConfig; class TargetPassConfig;
class TargetSubtargetInfo; class TargetSubtargetInfo;
@ -204,7 +206,13 @@ public:
/// This is used to construct the new pass manager's target IR analysis pass, /// This is used to construct the new pass manager's target IR analysis pass,
/// set up appropriately for this target machine. Even the old pass manager /// set up appropriately for this target machine. Even the old pass manager
/// uses this to answer queries about the IR. /// uses this to answer queries about the IR.
virtual TargetIRAnalysis getTargetIRAnalysis(); TargetIRAnalysis getTargetIRAnalysis();
/// \brief Return a TargetTransformInfo for a given function.
///
/// The returned TargetTransformInfo is specialized to the subtarget
/// corresponding to \p F.
virtual TargetTransformInfo getTargetTransformInfo(const Function &F);
/// Allow the target to modify the pass manager, e.g. by calling /// Allow the target to modify the pass manager, e.g. by calling
/// PassManagerBuilder::addExtension. /// PassManagerBuilder::addExtension.
@ -280,11 +288,11 @@ protected: // Can only create subclasses.
void initAsmInfo(); void initAsmInfo();
public: public:
/// \brief Get a TargetIRAnalysis implementation for the target. /// \brief Get a TargetTransformInfo implementation for the target.
/// ///
/// This analysis will produce a TTI result which uses the common code /// The TTI returned uses the common code generator to answer queries about
/// generator to answer queries about the IR. /// the IR.
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
/// Create a pass configuration object to be used by addPassToEmitX methods /// Create a pass configuration object to be used by addPassToEmitX methods
/// for generating a pipeline of CodeGen passes. /// for generating a pipeline of CodeGen passes.

View File

@ -81,10 +81,9 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
this->OptLevel = OL; this->OptLevel = OL;
} }
TargetIRAnalysis LLVMTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { LLVMTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(BasicTTIImpl(this, F)); return TargetTransformInfo(BasicTTIImpl(this, F));
});
} }
/// addPassesToX helper drives creation and initialization of TargetPassConfig. /// addPassesToX helper drives creation and initialization of TargetPassConfig.

View File

@ -19,4 +19,4 @@
type = Library type = Library
name = Passes name = Passes
parent = Libraries parent = Libraries
required_libraries = Analysis CodeGen Core IPO InstCombine Scalar Support TransformUtils Vectorize Instrumentation required_libraries = Analysis CodeGen Core IPO InstCombine Scalar Support Target TransformUtils Vectorize Instrumentation

View File

@ -346,10 +346,9 @@ public:
} // end anonymous namespace } // end anonymous namespace
TargetIRAnalysis AArch64TargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { AArch64TargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(AArch64TTIImpl(this, F)); return TargetTransformInfo(AArch64TTIImpl(this, F));
});
} }
TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) { TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) {

View File

@ -44,8 +44,7 @@ public:
// Pass Pipeline Configuration // Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
/// \brief Get the TargetIRAnalysis for this target. TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetIRAnalysis getTargetIRAnalysis() override;
TargetLoweringObjectFile* getObjFileLowering() const override { TargetLoweringObjectFile* getObjFileLowering() const override {
return TLOF.get(); return TLOF.get();

View File

@ -571,10 +571,9 @@ public:
} // end anonymous namespace } // end anonymous namespace
TargetIRAnalysis AMDGPUTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { AMDGPUTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(AMDGPUTTIImpl(this, F)); return TargetTransformInfo(AMDGPUTTIImpl(this, F));
});
} }
void AMDGPUPassConfig::addEarlyCSEOrGVNPass() { void AMDGPUPassConfig::addEarlyCSEOrGVNPass() {
@ -898,4 +897,3 @@ void GCNPassConfig::addPreEmitPass() {
TargetPassConfig *GCNTargetMachine::createPassConfig(PassManagerBase &PM) { TargetPassConfig *GCNTargetMachine::createPassConfig(PassManagerBase &PM) {
return new GCNPassConfig(*this, PM); return new GCNPassConfig(*this, PM);
} }

View File

@ -55,7 +55,7 @@ public:
const AMDGPUIntrinsicInfo *getIntrinsicInfo() const override { const AMDGPUIntrinsicInfo *getIntrinsicInfo() const override {
return &IntrinsicInfo; return &IntrinsicInfo;
} }
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetLoweringObjectFile *getObjFileLowering() const override { TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get(); return TLOF.get();

View File

@ -88,8 +88,7 @@ extern "C" void LLVMInitializeARCTarget() {
RegisterTargetMachine<ARCTargetMachine> X(getTheARCTarget()); RegisterTargetMachine<ARCTargetMachine> X(getTheARCTarget());
} }
TargetIRAnalysis ARCTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { ARCTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(ARCTTIImpl(this, F)); return TargetTransformInfo(ARCTTIImpl(this, F));
});
} }

View File

@ -40,7 +40,7 @@ public:
// Pass Pipeline Configuration // Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetLoweringObjectFile *getObjFileLowering() const override { TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get(); return TLOF.get();
} }

View File

@ -283,10 +283,9 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
return I.get(); return I.get();
} }
TargetIRAnalysis ARMBaseTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { ARMBaseTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(ARMTTIImpl(this, F)); return TargetTransformInfo(ARMTTIImpl(this, F));
});
} }
ARMLETargetMachine::ARMLETargetMachine(const Target &T, const Triple &TT, ARMLETargetMachine::ARMLETargetMachine(const Target &T, const Triple &TT,

View File

@ -53,8 +53,7 @@ public:
const ARMSubtarget *getSubtargetImpl() const = delete; const ARMSubtarget *getSubtargetImpl() const = delete;
bool isLittleEndian() const { return isLittle; } bool isLittleEndian() const { return isLittle; }
/// \brief Get the TargetIRAnalysis for this target. TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetIRAnalysis getTargetIRAnalysis() override;
// Pass Pipeline Configuration // Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetPassConfig *createPassConfig(PassManagerBase &PM) override;

View File

@ -258,10 +258,9 @@ void HexagonTargetMachine::adjustPassManager(PassManagerBuilder &PMB) {
}); });
} }
TargetIRAnalysis HexagonTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { HexagonTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(HexagonTTIImpl(this, F)); return TargetTransformInfo(HexagonTTIImpl(this, F));
});
} }

View File

@ -39,7 +39,7 @@ public:
void adjustPassManager(PassManagerBuilder &PMB) override; void adjustPassManager(PassManagerBuilder &PMB) override;
TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
HexagonTargetObjectFile *getObjFileLowering() const override { HexagonTargetObjectFile *getObjFileLowering() const override {
return static_cast<HexagonTargetObjectFile*>(TLOF.get()); return static_cast<HexagonTargetObjectFile*>(TLOF.get());

View File

@ -74,10 +74,9 @@ LanaiTargetMachine::LanaiTargetMachine(const Target &T, const Triple &TT,
initAsmInfo(); initAsmInfo();
} }
TargetIRAnalysis LanaiTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { LanaiTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(LanaiTTIImpl(this, F)); return TargetTransformInfo(LanaiTTIImpl(this, F));
});
} }
namespace { namespace {

View File

@ -42,7 +42,7 @@ public:
return &Subtarget; return &Subtarget;
} }
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
// Pass Pipeline Configuration // Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &pass_manager) override; TargetPassConfig *createPassConfig(PassManagerBase &pass_manager) override;

View File

@ -259,17 +259,16 @@ void MipsPassConfig::addPreRegAlloc() {
addPass(createMipsOptimizePICCallPass()); addPass(createMipsOptimizePICCallPass());
} }
TargetIRAnalysis MipsTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { MipsTargetMachine::getTargetTransformInfo(const Function &F) {
if (Subtarget->allowMixed16_32()) { if (Subtarget->allowMixed16_32()) {
DEBUG(errs() << "No Target Transform Info Pass Added\n"); DEBUG(errs() << "No Target Transform Info Pass Added\n");
// FIXME: This is no longer necessary as the TTI returned is per-function. // FIXME: This is no longer necessary as the TTI returned is per-function.
return TargetTransformInfo(F.getParent()->getDataLayout()); return TargetTransformInfo(F.getParent()->getDataLayout());
} }
DEBUG(errs() << "Target Transform Info Pass Added\n"); DEBUG(errs() << "Target Transform Info Pass Added\n");
return TargetTransformInfo(BasicTTIImpl(this, F)); return TargetTransformInfo(BasicTTIImpl(this, F));
});
} }
// Implemented by targets that want to run passes immediately before // Implemented by targets that want to run passes immediately before

View File

@ -44,7 +44,7 @@ public:
CodeGenOpt::Level OL, bool JIT, bool isLittle); CodeGenOpt::Level OL, bool JIT, bool isLittle);
~MipsTargetMachine() override; ~MipsTargetMachine() override;
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
const MipsSubtarget *getSubtargetImpl() const { const MipsSubtarget *getSubtargetImpl() const {
if (Subtarget) if (Subtarget)

View File

@ -180,10 +180,9 @@ void NVPTXTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
}); });
} }
TargetIRAnalysis NVPTXTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { NVPTXTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(NVPTXTTIImpl(this, F)); return TargetTransformInfo(NVPTXTTIImpl(this, F));
});
} }
void NVPTXPassConfig::addEarlyCSEOrGVNPass() { void NVPTXPassConfig::addEarlyCSEOrGVNPass() {

View File

@ -63,7 +63,7 @@ public:
void adjustPassManager(PassManagerBuilder &) override; void adjustPassManager(PassManagerBuilder &) override;
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
bool isMachineVerifierClean() const override { bool isMachineVerifierClean() const override {
return false; return false;

View File

@ -451,8 +451,7 @@ void PPCPassConfig::addPreEmitPass() {
addPass(createPPCBranchSelectionPass(), false); addPass(createPPCBranchSelectionPass(), false);
} }
TargetIRAnalysis PPCTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { PPCTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(PPCTTIImpl(this, F)); return TargetTransformInfo(PPCTTIImpl(this, F));
});
} }

View File

@ -49,7 +49,7 @@ public:
// Pass Pipeline Configuration // Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetLoweringObjectFile *getObjFileLowering() const override { TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get(); return TLOF.get();

View File

@ -257,8 +257,7 @@ TargetPassConfig *SystemZTargetMachine::createPassConfig(PassManagerBase &PM) {
return new SystemZPassConfig(*this, PM); return new SystemZPassConfig(*this, PM);
} }
TargetIRAnalysis SystemZTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { SystemZTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(SystemZTTIImpl(this, F)); return TargetTransformInfo(SystemZTTIImpl(this, F));
});
} }

View File

@ -44,7 +44,7 @@ public:
// Override LLVMTargetMachine // Override LLVMTargetMachine
TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetLoweringObjectFile *getObjFileLowering() const override { TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get(); return TLOF.get();

View File

@ -219,10 +219,8 @@ CodeGenOpt::Level TargetMachine::getOptLevel() const { return OptLevel; }
void TargetMachine::setOptLevel(CodeGenOpt::Level Level) { OptLevel = Level; } void TargetMachine::setOptLevel(CodeGenOpt::Level Level) { OptLevel = Level; }
TargetIRAnalysis TargetMachine::getTargetIRAnalysis() { TargetTransformInfo TargetMachine::getTargetTransformInfo(const Function &F) {
return TargetIRAnalysis([](const Function &F) { return TargetTransformInfo(F.getParent()->getDataLayout());
return TargetTransformInfo(F.getParent()->getDataLayout());
});
} }
void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name, void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name,
@ -244,3 +242,10 @@ MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV) const {
getNameWithPrefix(NameStr, GV, TLOF->getMangler()); getNameWithPrefix(NameStr, GV, TLOF->getMangler());
return TLOF->getContext().getOrCreateSymbol(NameStr); return TLOF->getContext().getOrCreateSymbol(NameStr);
} }
TargetIRAnalysis TargetMachine::getTargetIRAnalysis() {
// Since Analysis can't depend on Target, use a std::function to invert the
// dependency.
return TargetIRAnalysis(
[this](const Function &F) { return this->getTargetTransformInfo(F); });
}

View File

@ -146,10 +146,9 @@ public:
}; };
} // end anonymous namespace } // end anonymous namespace
TargetIRAnalysis WebAssemblyTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { WebAssemblyTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(WebAssemblyTTIImpl(this, F)); return TargetTransformInfo(WebAssemblyTTIImpl(this, F));
});
} }
TargetPassConfig * TargetPassConfig *

View File

@ -43,8 +43,7 @@ public:
return TLOF.get(); return TLOF.get();
} }
/// \brief Get the TargetIRAnalysis for this target. TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetIRAnalysis getTargetIRAnalysis() override;
bool usesPhysRegsForPEI() const override { return false; } bool usesPhysRegsForPEI() const override { return false; }
}; };

View File

@ -281,10 +281,9 @@ UseVZeroUpper("x86-use-vzeroupper", cl::Hidden,
// X86 TTI query. // X86 TTI query.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
TargetIRAnalysis X86TargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { X86TargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(X86TTIImpl(this, F)); return TargetTransformInfo(X86TTIImpl(this, F));
});
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -45,7 +45,7 @@ public:
// attributes of each function. // attributes of each function.
const X86Subtarget *getSubtargetImpl() const = delete; const X86Subtarget *getSubtargetImpl() const = delete;
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
// Set up the pass pipeline. // Set up the pass pipeline.
TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetPassConfig *createPassConfig(PassManagerBase &PM) override;

View File

@ -108,8 +108,7 @@ extern "C" void LLVMInitializeXCoreTarget() {
RegisterTargetMachine<XCoreTargetMachine> X(getTheXCoreTarget()); RegisterTargetMachine<XCoreTargetMachine> X(getTheXCoreTarget());
} }
TargetIRAnalysis XCoreTargetMachine::getTargetIRAnalysis() { TargetTransformInfo
return TargetIRAnalysis([this](const Function &F) { XCoreTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(XCoreTTIImpl(this, F)); return TargetTransformInfo(XCoreTTIImpl(this, F));
});
} }

View File

@ -43,7 +43,7 @@ public:
// Pass Pipeline Configuration // Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override; TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetIRAnalysis getTargetIRAnalysis() override; TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetLoweringObjectFile *getObjFileLowering() const override { TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get(); return TLOF.get();