Skip to content

Commit

Permalink
(Re-landing) Expose a TargetMachine::getTargetTransformInfo function
Browse files Browse the repository at this point in the history
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321375 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
sanjoy committed Dec 22, 2017
1 parent c1fce70 commit b166e67
Show file tree
Hide file tree
Showing 30 changed files with 85 additions and 90 deletions.
18 changes: 13 additions & 5 deletions include/llvm/Target/TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace llvm {

class Function;
class GlobalValue;
class MachineModuleInfo;
class Mangler;
Expand All @@ -38,6 +39,7 @@ class PassManagerBuilder;
class Target;
class TargetIntrinsicInfo;
class TargetIRAnalysis;
class TargetTransformInfo;
class TargetLoweringObjectFile;
class TargetPassConfig;
class TargetSubtargetInfo;
Expand Down Expand Up @@ -204,7 +206,13 @@ class TargetMachine {
/// 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
/// 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
/// PassManagerBuilder::addExtension.
Expand Down Expand Up @@ -280,11 +288,11 @@ class LLVMTargetMachine : public TargetMachine {
void initAsmInfo();

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
/// generator to answer queries about the IR.
TargetIRAnalysis getTargetIRAnalysis() override;
/// The TTI returned uses the common code generator to answer queries about
/// the IR.
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

/// Create a pass configuration object to be used by addPassToEmitX methods
/// for generating a pipeline of CodeGen passes.
Expand Down
7 changes: 3 additions & 4 deletions lib/CodeGen/LLVMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
this->OptLevel = OL;
}

TargetIRAnalysis LLVMTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(BasicTTIImpl(this, F));
});
TargetTransformInfo
LLVMTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(BasicTTIImpl(this, F));
}

/// addPassesToX helper drives creation and initialization of TargetPassConfig.
Expand Down
2 changes: 1 addition & 1 deletion lib/Passes/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
type = Library
name = Passes
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
7 changes: 3 additions & 4 deletions lib/Target/AArch64/AArch64TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,9 @@ class AArch64PassConfig : public TargetPassConfig {

} // end anonymous namespace

TargetIRAnalysis AArch64TargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(AArch64TTIImpl(this, F));
});
TargetTransformInfo
AArch64TargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(AArch64TTIImpl(this, F));
}

TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) {
Expand Down
3 changes: 1 addition & 2 deletions lib/Target/AArch64/AArch64TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class AArch64TargetMachine : public LLVMTargetMachine {
// Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;

/// \brief Get the TargetIRAnalysis for this target.
TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

TargetLoweringObjectFile* getObjFileLowering() const override {
return TLOF.get();
Expand Down
8 changes: 3 additions & 5 deletions lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,9 @@ class GCNPassConfig final : public AMDGPUPassConfig {

} // end anonymous namespace

TargetIRAnalysis AMDGPUTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(AMDGPUTTIImpl(this, F));
});
TargetTransformInfo
AMDGPUTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(AMDGPUTTIImpl(this, F));
}

void AMDGPUPassConfig::addEarlyCSEOrGVNPass() {
Expand Down Expand Up @@ -898,4 +897,3 @@ void GCNPassConfig::addPreEmitPass() {
TargetPassConfig *GCNTargetMachine::createPassConfig(PassManagerBase &PM) {
return new GCNPassConfig(*this, PM);
}

2 changes: 1 addition & 1 deletion lib/Target/AMDGPU/AMDGPUTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AMDGPUTargetMachine : public LLVMTargetMachine {
const AMDGPUIntrinsicInfo *getIntrinsicInfo() const override {
return &IntrinsicInfo;
}
TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get();
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/ARC/ARCTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ extern "C" void LLVMInitializeARCTarget() {
RegisterTargetMachine<ARCTargetMachine> X(getTheARCTarget());
}

TargetIRAnalysis ARCTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(ARCTTIImpl(this, F));
});
TargetTransformInfo
ARCTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(ARCTTIImpl(this, F));
}
2 changes: 1 addition & 1 deletion lib/Target/ARC/ARCTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ARCTargetMachine : public LLVMTargetMachine {
// Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;

TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;
TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get();
}
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/ARM/ARMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,9 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
return I.get();
}

TargetIRAnalysis ARMBaseTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(ARMTTIImpl(this, F));
});
TargetTransformInfo
ARMBaseTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(ARMTTIImpl(this, F));
}

ARMLETargetMachine::ARMLETargetMachine(const Target &T, const Triple &TT,
Expand Down
3 changes: 1 addition & 2 deletions lib/Target/ARM/ARMTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class ARMBaseTargetMachine : public LLVMTargetMachine {
const ARMSubtarget *getSubtargetImpl() const = delete;
bool isLittleEndian() const { return isLittle; }

/// \brief Get the TargetIRAnalysis for this target.
TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

// Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/Hexagon/HexagonTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ void HexagonTargetMachine::adjustPassManager(PassManagerBuilder &PMB) {
});
}

TargetIRAnalysis HexagonTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(HexagonTTIImpl(this, F));
});
TargetTransformInfo
HexagonTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(HexagonTTIImpl(this, F));
}


Expand Down
2 changes: 1 addition & 1 deletion lib/Target/Hexagon/HexagonTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HexagonTargetMachine : public LLVMTargetMachine {

void adjustPassManager(PassManagerBuilder &PMB) override;
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

HexagonTargetObjectFile *getObjFileLowering() const override {
return static_cast<HexagonTargetObjectFile*>(TLOF.get());
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/Lanai/LanaiTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ LanaiTargetMachine::LanaiTargetMachine(const Target &T, const Triple &TT,
initAsmInfo();
}

TargetIRAnalysis LanaiTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(LanaiTTIImpl(this, F));
});
TargetTransformInfo
LanaiTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(LanaiTTIImpl(this, F));
}

namespace {
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/Lanai/LanaiTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LanaiTargetMachine : public LLVMTargetMachine {
return &Subtarget;
}

TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

// Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &pass_manager) override;
Expand Down
21 changes: 10 additions & 11 deletions lib/Target/Mips/MipsTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,16 @@ void MipsPassConfig::addPreRegAlloc() {
addPass(createMipsOptimizePICCallPass());
}

TargetIRAnalysis MipsTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
if (Subtarget->allowMixed16_32()) {
DEBUG(errs() << "No Target Transform Info Pass Added\n");
// FIXME: This is no longer necessary as the TTI returned is per-function.
return TargetTransformInfo(F.getParent()->getDataLayout());
}

DEBUG(errs() << "Target Transform Info Pass Added\n");
return TargetTransformInfo(BasicTTIImpl(this, F));
});
TargetTransformInfo
MipsTargetMachine::getTargetTransformInfo(const Function &F) {
if (Subtarget->allowMixed16_32()) {
DEBUG(errs() << "No Target Transform Info Pass Added\n");
// FIXME: This is no longer necessary as the TTI returned is per-function.
return TargetTransformInfo(F.getParent()->getDataLayout());
}

DEBUG(errs() << "Target Transform Info Pass Added\n");
return TargetTransformInfo(BasicTTIImpl(this, F));
}

// Implemented by targets that want to run passes immediately before
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/Mips/MipsTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MipsTargetMachine : public LLVMTargetMachine {
CodeGenOpt::Level OL, bool JIT, bool isLittle);
~MipsTargetMachine() override;

TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

const MipsSubtarget *getSubtargetImpl() const {
if (Subtarget)
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/NVPTX/NVPTXTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ void NVPTXTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
});
}

TargetIRAnalysis NVPTXTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(NVPTXTTIImpl(this, F));
});
TargetTransformInfo
NVPTXTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(NVPTXTTIImpl(this, F));
}

void NVPTXPassConfig::addEarlyCSEOrGVNPass() {
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/NVPTX/NVPTXTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class NVPTXTargetMachine : public LLVMTargetMachine {

void adjustPassManager(PassManagerBuilder &) override;

TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

bool isMachineVerifierClean() const override {
return false;
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/PowerPC/PPCTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ void PPCPassConfig::addPreEmitPass() {
addPass(createPPCBranchSelectionPass(), false);
}

TargetIRAnalysis PPCTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(PPCTTIImpl(this, F));
});
TargetTransformInfo
PPCTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(PPCTTIImpl(this, F));
}
2 changes: 1 addition & 1 deletion lib/Target/PowerPC/PPCTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PPCTargetMachine final : public LLVMTargetMachine {
// Pass Pipeline Configuration
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;

TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get();
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/SystemZ/SystemZTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ TargetPassConfig *SystemZTargetMachine::createPassConfig(PassManagerBase &PM) {
return new SystemZPassConfig(*this, PM);
}

TargetIRAnalysis SystemZTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(SystemZTTIImpl(this, F));
});
TargetTransformInfo
SystemZTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(SystemZTTIImpl(this, F));
}
2 changes: 1 addition & 1 deletion lib/Target/SystemZ/SystemZTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SystemZTargetMachine : public LLVMTargetMachine {

// Override LLVMTargetMachine
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get();
Expand Down
13 changes: 9 additions & 4 deletions lib/Target/TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@ CodeGenOpt::Level TargetMachine::getOptLevel() const { return OptLevel; }

void TargetMachine::setOptLevel(CodeGenOpt::Level Level) { OptLevel = Level; }

TargetIRAnalysis TargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([](const Function &F) {
return TargetTransformInfo(F.getParent()->getDataLayout());
});
TargetTransformInfo TargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(F.getParent()->getDataLayout());
}

void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name,
Expand All @@ -244,3 +242,10 @@ MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV) const {
getNameWithPrefix(NameStr, GV, TLOF->getMangler());
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); });
}
7 changes: 3 additions & 4 deletions lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ class WebAssemblyPassConfig final : public TargetPassConfig {
};
} // end anonymous namespace

TargetIRAnalysis WebAssemblyTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(WebAssemblyTTIImpl(this, F));
});
TargetTransformInfo
WebAssemblyTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(WebAssemblyTTIImpl(this, F));
}

TargetPassConfig *
Expand Down
3 changes: 1 addition & 2 deletions lib/Target/WebAssembly/WebAssemblyTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class WebAssemblyTargetMachine final : public LLVMTargetMachine {
return TLOF.get();
}

/// \brief Get the TargetIRAnalysis for this target.
TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

bool usesPhysRegsForPEI() const override { return false; }
};
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/X86/X86TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ UseVZeroUpper("x86-use-vzeroupper", cl::Hidden,
// X86 TTI query.
//===----------------------------------------------------------------------===//

TargetIRAnalysis X86TargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(X86TTIImpl(this, F));
});
TargetTransformInfo
X86TargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(X86TTIImpl(this, F));
}

//===----------------------------------------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/X86/X86TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class X86TargetMachine final : public LLVMTargetMachine {
// attributes of each function.
const X86Subtarget *getSubtargetImpl() const = delete;

TargetIRAnalysis getTargetIRAnalysis() override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;

// Set up the pass pipeline.
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
Expand Down
7 changes: 3 additions & 4 deletions lib/Target/XCore/XCoreTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ extern "C" void LLVMInitializeXCoreTarget() {
RegisterTargetMachine<XCoreTargetMachine> X(getTheXCoreTarget());
}

TargetIRAnalysis XCoreTargetMachine::getTargetIRAnalysis() {
return TargetIRAnalysis([this](const Function &F) {
return TargetTransformInfo(XCoreTTIImpl(this, F));
});
TargetTransformInfo
XCoreTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(XCoreTTIImpl(this, F));
}
Loading

0 comments on commit b166e67

Please sign in to comment.