2003-09-30 20:37:50 +02:00
|
|
|
//===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
|
2005-04-21 22:59:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:59:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-18 14:38:31 +02:00
|
|
|
//
|
2006-09-04 06:14:57 +02:00
|
|
|
// This file defines the TargetMachine and LLVMTargetMachine classes.
|
2001-09-18 14:38:31 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TARGET_TARGETMACHINE_H
|
|
|
|
#define LLVM_TARGET_TARGETMACHINE_H
|
|
|
|
|
2012-12-03 18:02:12 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-06-11 21:41:26 +02:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2015-03-12 01:07:24 +01:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2012-07-02 21:48:45 +02:00
|
|
|
#include "llvm/Pass.h"
|
2012-03-25 20:09:44 +02:00
|
|
|
#include "llvm/Support/CodeGen.h"
|
2011-12-02 23:16:29 +01:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2009-08-11 22:42:37 +02:00
|
|
|
#include <string>
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2012-04-08 19:20:55 +02:00
|
|
|
class GlobalValue;
|
2017-01-11 02:45:03 +01:00
|
|
|
class Mangler;
|
2009-08-22 22:48:53 +02:00
|
|
|
class MCAsmInfo;
|
2011-06-29 03:14:12 +02:00
|
|
|
class MCContext;
|
2015-03-19 23:36:32 +01:00
|
|
|
class MCInstrInfo;
|
|
|
|
class MCRegisterInfo;
|
2015-03-19 23:36:37 +01:00
|
|
|
class MCSubtargetInfo;
|
2014-02-19 21:30:41 +01:00
|
|
|
class MCSymbol;
|
2017-01-11 02:45:03 +01:00
|
|
|
class raw_pwrite_stream;
|
2017-01-26 17:49:08 +01:00
|
|
|
class PassManagerBuilder;
|
2011-06-29 03:14:12 +02:00
|
|
|
class Target;
|
2009-02-05 02:49:45 +01:00
|
|
|
class TargetIntrinsicInfo;
|
2017-01-11 02:45:03 +01:00
|
|
|
class TargetIRAnalysis;
|
|
|
|
class TargetLoweringObjectFile;
|
2012-02-03 06:12:41 +01:00
|
|
|
class TargetPassConfig;
|
2011-07-01 23:01:15 +02:00
|
|
|
class TargetSubtargetInfo;
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2013-11-09 13:26:54 +01:00
|
|
|
// The old pass manager infrastructure is hidden in a legacy namespace now.
|
|
|
|
namespace legacy {
|
|
|
|
class PassManagerBase;
|
|
|
|
}
|
|
|
|
using legacy::PassManagerBase;
|
|
|
|
|
2002-12-28 21:13:29 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Primary interface to the complete machine description for the target
|
|
|
|
/// machine. All target-specific information should be accessible through this
|
|
|
|
/// interface.
|
2005-04-21 22:59:05 +02:00
|
|
|
///
|
2003-06-03 17:28:40 +02:00
|
|
|
class TargetMachine {
|
2006-09-03 20:44:26 +02:00
|
|
|
protected: // Can only create subclasses.
|
2015-03-12 01:07:24 +01:00
|
|
|
TargetMachine(const Target &T, StringRef DataLayoutString,
|
2015-06-11 21:41:26 +02:00
|
|
|
const Triple &TargetTriple, StringRef CPU, StringRef FS,
|
2015-03-12 01:07:24 +01:00
|
|
|
const TargetOptions &Options);
|
2005-07-12 05:04:49 +02:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// The Target that this machine was created for.
|
2009-07-15 22:24:03 +02:00
|
|
|
const Target &TheTarget;
|
2010-10-16 10:25:21 +02:00
|
|
|
|
2015-07-24 18:04:22 +02:00
|
|
|
/// DataLayout for the target: keep ABI type size and alignment.
|
|
|
|
///
|
|
|
|
/// The DataLayout is created based on the string representation provided
|
|
|
|
/// during construction. It is kept here only to avoid reparsing the string
|
|
|
|
/// but should not really be used during compilation, because it has an
|
|
|
|
/// internal cache that is context specific.
|
2015-03-12 01:07:24 +01:00
|
|
|
const DataLayout DL;
|
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Triple string, CPU name, and target feature strings the TargetMachine
|
|
|
|
/// instance is created with.
|
2015-06-11 21:41:26 +02:00
|
|
|
Triple TargetTriple;
|
2011-07-08 03:53:10 +02:00
|
|
|
std::string TargetCPU;
|
|
|
|
std::string TargetFS;
|
|
|
|
|
2016-06-30 20:25:11 +02:00
|
|
|
Reloc::Model RM = Reloc::Static;
|
|
|
|
CodeModel::Model CMModel = CodeModel::Default;
|
|
|
|
CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
|
2011-07-19 08:37:02 +02:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Contains target specific asm information.
|
2009-08-22 22:48:53 +02:00
|
|
|
const MCAsmInfo *AsmInfo;
|
2015-04-08 22:16:23 +02:00
|
|
|
|
2015-03-19 23:36:32 +01:00
|
|
|
const MCRegisterInfo *MRI;
|
|
|
|
const MCInstrInfo *MII;
|
2015-03-19 23:36:37 +01:00
|
|
|
const MCSubtargetInfo *STI;
|
2010-05-26 23:48:55 +02:00
|
|
|
|
2013-12-07 02:49:19 +01:00
|
|
|
unsigned RequireStructuredCFG : 1;
|
2015-11-30 22:56:16 +01:00
|
|
|
unsigned O0WantsFastISel : 1;
|
2010-05-26 23:48:55 +02:00
|
|
|
|
2001-09-18 14:38:31 +02:00
|
|
|
public:
|
[TM] Restore default TargetOptions in TargetMachine::resetTargetOptions.
Summary:
Previously if you had
* a function with the fast-math-enabled attr, followed by
* a function without the fast-math attr,
the second function would inherit the first function's fast-math-ness.
This means that mixing fast-math and non-fast-math functions in a module
was completely broken unless you explicitly annotated every
non-fast-math function with "unsafe-fp-math"="false". This appears to
have been broken since r176986 (March 2013), when the resetTargetOptions
function was introduced.
This patch tests the correct behavior as best we can. I don't think I
can test FPDenormalMode and NoTrappingFPMath, because they aren't used
in any backends during function lowering. Surprisingly, I also can't
find any uses at all of LessPreciseFPMAD affecting generated code.
The NVPTX/fast-math.ll test changes are an expected result of fixing
this bug. When FMA is disabled, we emit add as "add.rn.f32", which
prevents fma combining. Before this patch, fast-math was enabled in all
functions following the one which explicitly enabled it on itself, so we
were emitting plain "add.f32" where we should have generated
"add.rn.f32".
Reviewers: mkuper
Subscribers: hfinkel, majnemer, jholewinski, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28507
llvm-svn: 291618
2017-01-11 00:43:04 +01:00
|
|
|
const TargetOptions DefaultOptions;
|
2014-08-04 23:25:44 +02:00
|
|
|
mutable TargetOptions Options;
|
|
|
|
|
2017-01-11 02:45:03 +01:00
|
|
|
TargetMachine(const TargetMachine &) = delete;
|
|
|
|
void operator=(const TargetMachine &) = delete;
|
2003-12-28 22:23:38 +01:00
|
|
|
virtual ~TargetMachine();
|
2002-10-29 22:12:46 +01:00
|
|
|
|
2009-07-15 22:24:03 +02:00
|
|
|
const Target &getTarget() const { return TheTarget; }
|
2009-07-15 14:11:05 +02:00
|
|
|
|
2015-06-16 15:15:50 +02:00
|
|
|
const Triple &getTargetTriple() const { return TargetTriple; }
|
2014-08-30 18:48:02 +02:00
|
|
|
StringRef getTargetCPU() const { return TargetCPU; }
|
|
|
|
StringRef getTargetFeatureString() const { return TargetFS; }
|
2011-07-08 03:53:10 +02:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Virtual method implemented by subclasses that returns a reference to that
|
|
|
|
/// target's TargetSubtargetInfo-derived member variable.
|
2014-09-26 04:57:05 +02:00
|
|
|
virtual const TargetSubtargetInfo *getSubtargetImpl(const Function &) const {
|
2015-03-21 05:22:23 +01:00
|
|
|
return nullptr;
|
2014-09-18 02:34:14 +02:00
|
|
|
}
|
2014-11-13 10:26:31 +01:00
|
|
|
virtual TargetLoweringObjectFile *getObjFileLowering() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-01-09 17:21:47 +01:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// This method returns a pointer to the specified type of
|
2014-08-04 23:25:44 +02:00
|
|
|
/// TargetSubtargetInfo. In debug builds, it verifies that the object being
|
|
|
|
/// returned is of the correct type.
|
2015-03-21 04:32:45 +01:00
|
|
|
template <typename STC> const STC &getSubtarget(const Function &F) const {
|
|
|
|
return *static_cast<const STC*>(getSubtargetImpl(F));
|
2014-09-18 02:34:14 +02:00
|
|
|
}
|
2013-03-13 23:26:59 +01:00
|
|
|
|
2015-07-24 18:04:22 +02:00
|
|
|
/// Create a DataLayout.
|
|
|
|
const DataLayout createDataLayout() const { return DL; }
|
|
|
|
|
2015-08-17 12:58:03 +02:00
|
|
|
/// Test if a DataLayout if compatible with the CodeGen for this target.
|
|
|
|
///
|
|
|
|
/// The LLVM Module owns a DataLayout that is used for the target independent
|
|
|
|
/// optimizations and code generation. This hook provides a target specific
|
|
|
|
/// check on the validity of this DataLayout.
|
|
|
|
bool isCompatibleDataLayout(const DataLayout &Candidate) const {
|
|
|
|
return DL == Candidate;
|
|
|
|
}
|
|
|
|
|
2015-07-24 18:04:22 +02:00
|
|
|
/// Get the pointer size for this target.
|
|
|
|
///
|
|
|
|
/// This is the only time the DataLayout in the TargetMachine is used.
|
|
|
|
unsigned getPointerSize() const { return DL.getPointerSize(); }
|
2015-01-26 20:03:15 +01:00
|
|
|
|
2013-03-13 23:26:59 +01:00
|
|
|
/// \brief Reset the target options based on the function's attributes.
|
2014-09-26 03:44:05 +02:00
|
|
|
// FIXME: Remove TargetOptions that affect per-function code generation
|
|
|
|
// from TargetMachine.
|
2014-09-26 03:28:10 +02:00
|
|
|
void resetTargetOptions(const Function &F) const;
|
2011-12-02 23:16:29 +01:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Return target specific asm information.
|
2009-08-22 22:48:53 +02:00
|
|
|
const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
|
2015-04-08 22:16:23 +02:00
|
|
|
|
2015-03-19 23:36:32 +01:00
|
|
|
const MCRegisterInfo *getMCRegisterInfo() const { return MRI; }
|
|
|
|
const MCInstrInfo *getMCInstrInfo() const { return MII; }
|
2015-03-19 23:36:37 +01:00
|
|
|
const MCSubtargetInfo *getMCSubtargetInfo() const { return STI; }
|
2010-10-16 10:25:21 +02:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// If intrinsic information is available, return it. If not, return null.
|
2014-08-04 23:25:23 +02:00
|
|
|
virtual const TargetIntrinsicInfo *getIntrinsicInfo() const {
|
2014-04-14 02:51:57 +02:00
|
|
|
return nullptr;
|
2005-11-01 21:06:59 +01:00
|
|
|
}
|
2003-12-20 02:22:19 +01:00
|
|
|
|
2013-12-07 02:49:19 +01:00
|
|
|
bool requiresStructuredCFG() const { return RequireStructuredCFG; }
|
|
|
|
void setRequiresStructuredCFG(bool Value) { RequireStructuredCFG = Value; }
|
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Returns the code generation relocation model. The choices are static, PIC,
|
|
|
|
/// and dynamic-no-pic, and target default.
|
2011-07-19 08:37:02 +02:00
|
|
|
Reloc::Model getRelocationModel() const;
|
2006-02-22 21:19:42 +01:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Returns the code model. The choices are small, kernel, medium, large, and
|
|
|
|
/// target default.
|
2011-07-20 09:51:56 +02:00
|
|
|
CodeModel::Model getCodeModel() const;
|
2006-07-06 03:53:36 +02:00
|
|
|
|
2016-06-27 23:33:08 +02:00
|
|
|
bool isPositionIndependent() const;
|
|
|
|
|
2016-06-28 01:15:57 +02:00
|
|
|
bool shouldAssumeDSOLocal(const Module &M, const GlobalValue *GV) const;
|
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Returns the TLS model which should be used for the given global variable.
|
2012-04-08 19:20:55 +02:00
|
|
|
TLSModel::Model getTLSModel(const GlobalValue *GV) const;
|
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Returns the optimization level: None, Less, Default, or Aggressive.
|
2011-11-16 09:38:26 +01:00
|
|
|
CodeGenOpt::Level getOptLevel() const;
|
|
|
|
|
2013-11-22 20:11:24 +01:00
|
|
|
/// \brief Overrides the optimization level.
|
2016-06-30 20:25:11 +02:00
|
|
|
void setOptLevel(CodeGenOpt::Level Level);
|
2013-11-22 20:11:24 +01:00
|
|
|
|
2012-02-03 06:12:41 +01:00
|
|
|
void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
|
2015-11-30 22:56:16 +01:00
|
|
|
bool getO0WantsFastISel() { return O0WantsFastISel; }
|
|
|
|
void setO0WantsFastISel(bool Enable) { O0WantsFastISel = Enable; }
|
2012-02-03 06:12:41 +01:00
|
|
|
|
|
|
|
bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
|
|
|
|
|
2015-02-17 21:48:01 +01:00
|
|
|
bool getUniqueSectionNames() const { return Options.UniqueSectionNames; }
|
|
|
|
|
2015-02-12 22:16:34 +01:00
|
|
|
/// Return true if data objects should be emitted into their own section,
|
|
|
|
/// corresponds to -fdata-sections.
|
|
|
|
bool getDataSections() const {
|
|
|
|
return Options.DataSections;
|
|
|
|
}
|
2010-04-13 02:36:43 +02:00
|
|
|
|
2015-02-12 22:16:34 +01:00
|
|
|
/// Return true if functions should be emitted into their own section,
|
|
|
|
/// corresponding to -ffunction-sections.
|
|
|
|
bool getFunctionSections() const {
|
|
|
|
return Options.FunctionSections;
|
|
|
|
}
|
2010-04-13 02:36:43 +02:00
|
|
|
|
2015-02-01 11:11:22 +01:00
|
|
|
/// \brief Get a \c TargetIRAnalysis appropriate for the target.
|
|
|
|
///
|
|
|
|
/// This is used to construct the new pass manager's target IR analysis pass,
|
2015-02-01 14:20:00 +01:00
|
|
|
/// set up appropriately for this target machine. Even the old pass manager
|
|
|
|
/// uses this to answer queries about the IR.
|
2015-02-01 11:11:22 +01:00
|
|
|
virtual TargetIRAnalysis getTargetIRAnalysis();
|
|
|
|
|
2017-01-26 17:49:08 +01:00
|
|
|
/// Allow the target to modify the pass manager, e.g. by calling
|
|
|
|
/// PassManagerBuilder::addExtension.
|
|
|
|
virtual void adjustPassManager(PassManagerBuilder &) {}
|
2016-04-27 21:08:24 +02:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// These enums are meant to be passed into addPassesToEmitFile to indicate
|
|
|
|
/// what type of file to emit, and returned by it to indicate what type of
|
|
|
|
/// file could actually be made.
|
2005-06-25 04:47:50 +02:00
|
|
|
enum CodeGenFileType {
|
2010-02-02 22:06:45 +01:00
|
|
|
CGFT_AssemblyFile,
|
|
|
|
CGFT_ObjectFile,
|
2010-02-03 06:55:08 +01:00
|
|
|
CGFT_Null // Do not emit any output.
|
2005-06-25 04:47:50 +02:00
|
|
|
};
|
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Add passes to the specified pass manager to get the specified file
|
|
|
|
/// emitted. Typically this will involve several steps of code generation.
|
|
|
|
/// This method should return true if emission of this file type is not
|
|
|
|
/// supported, or false on success.
|
2015-06-15 22:30:22 +02:00
|
|
|
virtual bool addPassesToEmitFile(
|
|
|
|
PassManagerBase &, raw_pwrite_stream &, CodeGenFileType,
|
2017-04-01 03:26:24 +02:00
|
|
|
bool /*DisableVerify*/ = true, AnalysisID /*StartBefore*/ = nullptr,
|
|
|
|
AnalysisID /*StartAfter*/ = nullptr, AnalysisID /*StopBefore*/ = nullptr,
|
2017-06-06 02:44:35 +02:00
|
|
|
AnalysisID /*StopAfter*/ = nullptr) {
|
2010-02-03 06:55:08 +01:00
|
|
|
return true;
|
2007-02-08 02:34:45 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Add passes to the specified pass manager to get machine code emitted with
|
|
|
|
/// the MCJIT. This method returns true if machine code is not supported. It
|
|
|
|
/// fills the MCContext Ctx pointer which can be used to build custom
|
|
|
|
/// MCStreamer.
|
2010-07-22 07:58:53 +02:00
|
|
|
///
|
2015-04-15 00:14:34 +02:00
|
|
|
virtual bool addPassesToEmitMC(PassManagerBase &, MCContext *&,
|
|
|
|
raw_pwrite_stream &,
|
2011-12-02 21:53:57 +01:00
|
|
|
bool /*DisableVerify*/ = true) {
|
2010-07-22 07:58:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-02-19 21:30:41 +01:00
|
|
|
|
2015-12-10 10:10:07 +01:00
|
|
|
/// True if subtarget inserts the final scheduling pass on its own.
|
|
|
|
///
|
|
|
|
/// Branch relaxation, which must happen after block placement, can
|
|
|
|
/// on some targets (e.g. SystemZ) expose additional post-RA
|
|
|
|
/// scheduling opportunities.
|
|
|
|
virtual bool targetSchedulesPostRAScheduling() const { return false; };
|
|
|
|
|
2014-02-19 21:30:41 +01:00
|
|
|
void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV,
|
2016-09-21 00:03:28 +02:00
|
|
|
Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
|
2016-11-22 17:17:20 +01:00
|
|
|
MCSymbol *getSymbol(const GlobalValue *GV) const;
|
2016-05-17 10:49:59 +02:00
|
|
|
|
|
|
|
/// True if the target uses physical regs at Prolog/Epilog insertion
|
|
|
|
/// time. If true (most machines), all vregs must be allocated before
|
|
|
|
/// PEI. If false (virtual-register machines), then callee-save register
|
|
|
|
/// spilling and scavenging are not needed or used.
|
|
|
|
virtual bool usesPhysRegsForPEI() const { return true; }
|
2006-09-04 06:14:57 +02:00
|
|
|
};
|
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// This class describes a target machine that is implemented with the LLVM
|
|
|
|
/// target-independent code generator.
|
2006-09-04 06:14:57 +02:00
|
|
|
///
|
|
|
|
class LLVMTargetMachine : public TargetMachine {
|
|
|
|
protected: // Can only create subclasses.
|
2015-03-12 01:07:24 +01:00
|
|
|
LLVMTargetMachine(const Target &T, StringRef DataLayoutString,
|
2015-06-11 21:41:26 +02:00
|
|
|
const Triple &TargetTriple, StringRef CPU, StringRef FS,
|
2017-01-13 15:39:03 +01:00
|
|
|
const TargetOptions &Options, Reloc::Model RM,
|
|
|
|
CodeModel::Model CM, CodeGenOpt::Level OL);
|
2010-10-16 10:25:21 +02:00
|
|
|
|
2013-05-13 03:16:13 +02:00
|
|
|
void initAsmInfo();
|
2006-09-04 06:14:57 +02:00
|
|
|
public:
|
2015-02-01 14:20:00 +01:00
|
|
|
/// \brief Get a TargetIRAnalysis implementation for the target.
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 02:37:14 +01:00
|
|
|
///
|
2015-02-01 14:20:00 +01:00
|
|
|
/// This analysis will produce a TTI result which uses the common code
|
|
|
|
/// generator to answer queries about the IR.
|
|
|
|
TargetIRAnalysis getTargetIRAnalysis() override;
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 02:37:14 +01:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Create a pass configuration object to be used by addPassToEmitX methods
|
|
|
|
/// for generating a pipeline of CodeGen passes.
|
2012-02-04 03:56:59 +01:00
|
|
|
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
|
2012-02-03 06:12:41 +01:00
|
|
|
|
2015-04-09 17:54:59 +02:00
|
|
|
/// Add passes to the specified pass manager to get the specified file
|
|
|
|
/// emitted. Typically this will involve several steps of code generation.
|
2015-06-15 22:30:22 +02:00
|
|
|
bool addPassesToEmitFile(
|
|
|
|
PassManagerBase &PM, raw_pwrite_stream &Out, CodeGenFileType FileType,
|
2017-04-01 03:26:24 +02:00
|
|
|
bool DisableVerify = true, AnalysisID StartBefore = nullptr,
|
|
|
|
AnalysisID StartAfter = nullptr, AnalysisID StopBefore = nullptr,
|
2017-06-06 02:44:35 +02:00
|
|
|
AnalysisID StopAfter = nullptr) override;
|
2010-10-16 10:25:21 +02:00
|
|
|
|
2015-04-08 22:16:23 +02:00
|
|
|
/// Add passes to the specified pass manager to get machine code emitted with
|
|
|
|
/// the MCJIT. This method returns true if machine code is not supported. It
|
|
|
|
/// fills the MCContext Ctx pointer which can be used to build custom
|
|
|
|
/// MCStreamer.
|
2014-03-05 10:10:37 +01:00
|
|
|
bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
|
2015-04-15 00:14:34 +02:00
|
|
|
raw_pwrite_stream &OS,
|
|
|
|
bool DisableVerify = true) override;
|
2017-05-31 20:41:23 +02:00
|
|
|
|
|
|
|
/// Returns true if the target is expected to pass all machine verifier
|
|
|
|
/// checks. This is a stopgap measure to fix targets one by one. We will
|
|
|
|
/// remove this at some point and always enable the verifier when
|
|
|
|
/// EXPENSIVE_CHECKS is enabled.
|
|
|
|
virtual bool isMachineVerifierClean() const { return true; }
|
2017-06-06 02:26:13 +02:00
|
|
|
|
|
|
|
/// \brief Adds an AsmPrinter pass to the pipeline that prints assembly or
|
|
|
|
/// machine code from the MI representation.
|
|
|
|
bool addAsmPrinter(PassManagerBase &PM, raw_pwrite_stream &Out,
|
|
|
|
CodeGenFileType FileTYpe, MCContext &Context);
|
2001-09-18 14:38:31 +02:00
|
|
|
};
|
|
|
|
|
2017-01-11 02:45:03 +01:00
|
|
|
} // end namespace llvm
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2017-01-11 02:45:03 +01:00
|
|
|
#endif // LLVM_TARGET_TARGETMACHINE_H
|