2012-02-18 20:03:15 +08:00
|
|
|
//===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
|
2011-12-13 05:14:40 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2012-02-18 20:03:15 +08:00
|
|
|
// Implements the info about Hexagon target spec.
|
2011-12-13 05:14:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "HexagonTargetMachine.h"
|
|
|
|
#include "Hexagon.h"
|
|
|
|
#include "HexagonISelLowering.h"
|
2012-09-04 22:49:56 +08:00
|
|
|
#include "HexagonMachineScheduler.h"
|
2013-05-08 03:53:00 +08:00
|
|
|
#include "HexagonTargetObjectFile.h"
|
2015-08-06 02:35:37 +08:00
|
|
|
#include "HexagonTargetTransformInfo.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2016-05-10 11:21:59 +08:00
|
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
2015-02-13 18:01:29 +08:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2012-02-06 18:19:29 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2017-01-27 05:41:10 +08:00
|
|
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-10-14 03:02:59 +08:00
|
|
|
static cl::opt<bool> EnableCExtOpt("hexagon-cext", cl::Hidden, cl::ZeroOrMore,
|
|
|
|
cl::init(true), cl::desc("Enable Hexagon constant-extender optimization"));
|
|
|
|
|
2016-01-13 03:09:01 +08:00
|
|
|
static cl::opt<bool> EnableRDFOpt("rdf-opt", cl::Hidden, cl::ZeroOrMore,
|
|
|
|
cl::init(true), cl::desc("Enable RDF-based optimizations"));
|
|
|
|
|
|
|
|
static cl::opt<bool> DisableHardwareLoops("disable-hexagon-hwloops",
|
2015-03-31 21:35:12 +08:00
|
|
|
cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"));
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2016-04-29 23:49:13 +08:00
|
|
|
static cl::opt<bool> DisableAModeOpt("disable-hexagon-amodeopt",
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Hexagon Addressing Mode Optimization"));
|
|
|
|
|
2013-03-27 19:14:24 +08:00
|
|
|
static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt",
|
2015-03-31 21:35:12 +08:00
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Hexagon CFG Optimization"));
|
|
|
|
|
2016-07-29 04:01:59 +08:00
|
|
|
static cl::opt<bool> DisableHCP("disable-hcp", cl::init(false), cl::Hidden,
|
|
|
|
cl::ZeroOrMore, cl::desc("Disable Hexagon constant propagation"));
|
|
|
|
|
2015-10-17 03:43:56 +08:00
|
|
|
static cl::opt<bool> DisableStoreWidening("disable-store-widen",
|
|
|
|
cl::Hidden, cl::init(false), cl::desc("Disable store widening"));
|
|
|
|
|
2015-03-31 21:35:12 +08:00
|
|
|
static cl::opt<bool> EnableExpandCondsets("hexagon-expand-condsets",
|
|
|
|
cl::init(true), cl::Hidden, cl::ZeroOrMore,
|
|
|
|
cl::desc("Early expansion of MUX"));
|
2013-05-07 05:25:45 +08:00
|
|
|
|
2015-10-06 23:49:14 +08:00
|
|
|
static cl::opt<bool> EnableEarlyIf("hexagon-eif", cl::init(true), cl::Hidden,
|
|
|
|
cl::ZeroOrMore, cl::desc("Enable early if-conversion"));
|
|
|
|
|
2015-07-08 22:47:34 +08:00
|
|
|
static cl::opt<bool> EnableGenInsert("hexagon-insert", cl::init(true),
|
|
|
|
cl::Hidden, cl::desc("Generate \"insert\" instructions"));
|
2013-03-27 19:14:24 +08:00
|
|
|
|
2015-07-09 03:22:28 +08:00
|
|
|
static cl::opt<bool> EnableCommGEP("hexagon-commgep", cl::init(true),
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::desc("Enable commoning of GEP instructions"));
|
|
|
|
|
2015-07-15 01:07:24 +08:00
|
|
|
static cl::opt<bool> EnableGenExtract("hexagon-extract", cl::init(true),
|
|
|
|
cl::Hidden, cl::desc("Generate \"extract\" instructions"));
|
2015-07-09 03:22:28 +08:00
|
|
|
|
2015-07-21 05:23:25 +08:00
|
|
|
static cl::opt<bool> EnableGenMux("hexagon-mux", cl::init(true), cl::Hidden,
|
|
|
|
cl::desc("Enable converting conditional transfers into MUX instructions"));
|
|
|
|
|
2015-07-15 03:30:21 +08:00
|
|
|
static cl::opt<bool> EnableGenPred("hexagon-gen-pred", cl::init(true),
|
|
|
|
cl::Hidden, cl::desc("Enable conversion of arithmetic operations to "
|
|
|
|
"predicate instructions"));
|
|
|
|
|
2016-07-22 22:22:43 +08:00
|
|
|
static cl::opt<bool> EnableLoopPrefetch("hexagon-loop-prefetch",
|
|
|
|
cl::init(false), cl::Hidden, cl::ZeroOrMore,
|
|
|
|
cl::desc("Enable loop data prefetch on Hexagon"));
|
|
|
|
|
2015-10-17 04:38:54 +08:00
|
|
|
static cl::opt<bool> DisableHSDR("disable-hsdr", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Disable splitting double registers"));
|
|
|
|
|
2015-10-21 06:57:13 +08:00
|
|
|
static cl::opt<bool> EnableBitSimplify("hexagon-bit", cl::init(true),
|
|
|
|
cl::Hidden, cl::desc("Bit simplification"));
|
|
|
|
|
|
|
|
static cl::opt<bool> EnableLoopResched("hexagon-loop-resched", cl::init(true),
|
|
|
|
cl::Hidden, cl::desc("Loop rescheduling"));
|
|
|
|
|
2016-05-11 23:01:30 +08:00
|
|
|
static cl::opt<bool> HexagonNoOpt("hexagon-noopt", cl::init(false),
|
|
|
|
cl::Hidden, cl::desc("Disable backend optimizations"));
|
|
|
|
|
2016-08-02 03:36:39 +08:00
|
|
|
static cl::opt<bool> EnableVectorPrint("enable-hexagon-vector-print",
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Enable Hexagon Vector print instr pass"));
|
|
|
|
|
2018-01-27 05:17:14 +08:00
|
|
|
static cl::opt<bool> EnableVExtractOpt("hexagon-opt-vextract", cl::Hidden,
|
|
|
|
cl::ZeroOrMore, cl::init(true), cl::desc("Enable vextract optimization"));
|
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
/// HexagonTargetMachineModule - Note that this is used on hosts that
|
|
|
|
/// cannot link in a library unless there are references into the
|
|
|
|
/// library. In particular, it seems that it is not possible to get
|
|
|
|
/// things to work on Win32 without this. Though it is unused, do not
|
|
|
|
/// remove it.
|
|
|
|
extern "C" int HexagonTargetMachineModule;
|
|
|
|
int HexagonTargetMachineModule = 0;
|
|
|
|
|
2012-09-04 22:49:56 +08:00
|
|
|
static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
|
2017-08-28 23:52:54 +08:00
|
|
|
ScheduleDAGMILive *DAG =
|
|
|
|
new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>());
|
2017-08-29 00:24:22 +08:00
|
|
|
DAG->addMutation(make_unique<HexagonSubtarget::UsrOverflowMutation>());
|
|
|
|
DAG->addMutation(make_unique<HexagonSubtarget::HVXMemLatencyMutation>());
|
|
|
|
DAG->addMutation(make_unique<HexagonSubtarget::CallMutation>());
|
2017-08-28 23:52:54 +08:00
|
|
|
DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI));
|
|
|
|
return DAG;
|
2012-09-04 22:49:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static MachineSchedRegistry
|
|
|
|
SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
|
|
|
|
createVLIWMachineSched);
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2015-03-31 21:35:12 +08:00
|
|
|
namespace llvm {
|
2016-08-25 06:27:36 +08:00
|
|
|
extern char &HexagonExpandCondsetsID;
|
2018-02-20 22:29:43 +08:00
|
|
|
void initializeHexagonBitSimplifyPass(PassRegistry&);
|
2017-10-14 03:02:59 +08:00
|
|
|
void initializeHexagonConstExtendersPass(PassRegistry&);
|
2018-02-24 04:33:26 +08:00
|
|
|
void initializeHexagonConstPropagationPass(PassRegistry&);
|
2017-08-10 05:22:05 +08:00
|
|
|
void initializeHexagonEarlyIfConversionPass(PassRegistry&);
|
2016-08-25 06:27:36 +08:00
|
|
|
void initializeHexagonExpandCondsetsPass(PassRegistry&);
|
2017-06-14 00:07:36 +08:00
|
|
|
void initializeHexagonGenMuxPass(PassRegistry&);
|
2017-10-21 00:56:33 +08:00
|
|
|
void initializeHexagonHardwareLoopsPass(PassRegistry&);
|
2017-07-11 02:38:52 +08:00
|
|
|
void initializeHexagonLoopIdiomRecognizePass(PassRegistry&);
|
2017-09-22 05:48:23 +08:00
|
|
|
void initializeHexagonVectorLoopCarriedReusePass(PassRegistry&);
|
2017-06-28 02:37:16 +08:00
|
|
|
void initializeHexagonNewValueJumpPass(PassRegistry&);
|
2017-07-11 02:38:52 +08:00
|
|
|
void initializeHexagonOptAddrModePass(PassRegistry&);
|
|
|
|
void initializeHexagonPacketizerPass(PassRegistry&);
|
2017-10-30 22:11:52 +08:00
|
|
|
void initializeHexagonRDFOptPass(PassRegistry&);
|
2018-01-27 05:17:14 +08:00
|
|
|
void initializeHexagonVExtractPass(PassRegistry&);
|
2017-01-27 05:41:10 +08:00
|
|
|
Pass *createHexagonLoopIdiomPass();
|
2017-09-22 05:48:23 +08:00
|
|
|
Pass *createHexagonVectorLoopCarriedReusePass();
|
2016-08-25 06:27:36 +08:00
|
|
|
|
2015-10-21 06:57:13 +08:00
|
|
|
FunctionPass *createHexagonBitSimplify();
|
2016-04-20 02:30:18 +08:00
|
|
|
FunctionPass *createHexagonBranchRelaxation();
|
2015-10-20 01:46:01 +08:00
|
|
|
FunctionPass *createHexagonCallFrameInformation();
|
2015-07-15 01:07:24 +08:00
|
|
|
FunctionPass *createHexagonCFGOptimizer();
|
2015-07-09 03:22:28 +08:00
|
|
|
FunctionPass *createHexagonCommonGEP();
|
2017-10-14 03:02:59 +08:00
|
|
|
FunctionPass *createHexagonConstExtenders();
|
2016-07-29 04:01:59 +08:00
|
|
|
FunctionPass *createHexagonConstPropagationPass();
|
2015-07-15 01:07:24 +08:00
|
|
|
FunctionPass *createHexagonCopyToCombine();
|
2015-10-06 23:49:14 +08:00
|
|
|
FunctionPass *createHexagonEarlyIfConversion();
|
2015-07-15 01:07:24 +08:00
|
|
|
FunctionPass *createHexagonFixupHwLoops();
|
2017-12-12 02:57:54 +08:00
|
|
|
FunctionPass *createHexagonGatherPacketize();
|
2015-07-15 01:07:24 +08:00
|
|
|
FunctionPass *createHexagonGenExtract();
|
2015-07-08 22:47:34 +08:00
|
|
|
FunctionPass *createHexagonGenInsert();
|
2015-07-21 05:23:25 +08:00
|
|
|
FunctionPass *createHexagonGenMux();
|
2015-07-15 03:30:21 +08:00
|
|
|
FunctionPass *createHexagonGenPredicate();
|
2015-06-16 03:05:35 +08:00
|
|
|
FunctionPass *createHexagonHardwareLoops();
|
2015-07-15 01:07:24 +08:00
|
|
|
FunctionPass *createHexagonISelDag(HexagonTargetMachine &TM,
|
|
|
|
CodeGenOpt::Level OptLevel);
|
2015-10-21 06:57:13 +08:00
|
|
|
FunctionPass *createHexagonLoopRescheduling();
|
2015-06-16 03:05:35 +08:00
|
|
|
FunctionPass *createHexagonNewValueJump();
|
2015-10-20 03:10:48 +08:00
|
|
|
FunctionPass *createHexagonOptimizeSZextends();
|
2016-04-29 23:49:13 +08:00
|
|
|
FunctionPass *createHexagonOptAddrMode();
|
2015-06-16 03:05:35 +08:00
|
|
|
FunctionPass *createHexagonPacketizer();
|
2015-07-15 01:07:24 +08:00
|
|
|
FunctionPass *createHexagonPeephole();
|
2016-01-13 03:09:01 +08:00
|
|
|
FunctionPass *createHexagonRDFOpt();
|
2015-07-15 01:07:24 +08:00
|
|
|
FunctionPass *createHexagonSplitConst32AndConst64();
|
2015-10-17 04:38:54 +08:00
|
|
|
FunctionPass *createHexagonSplitDoubleRegs();
|
2015-10-17 03:43:56 +08:00
|
|
|
FunctionPass *createHexagonStoreWidening();
|
2016-08-02 03:36:39 +08:00
|
|
|
FunctionPass *createHexagonVectorPrint();
|
2018-01-27 05:17:14 +08:00
|
|
|
FunctionPass *createHexagonVExtract();
|
2015-06-23 17:49:53 +08:00
|
|
|
} // end namespace llvm;
|
2015-03-31 21:35:12 +08:00
|
|
|
|
2016-05-19 06:04:49 +08:00
|
|
|
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
|
|
|
|
if (!RM.hasValue())
|
|
|
|
return Reloc::Static;
|
|
|
|
return *RM;
|
|
|
|
}
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2017-08-03 10:16:21 +08:00
|
|
|
static CodeModel::Model getEffectiveCodeModel(Optional<CodeModel::Model> CM) {
|
|
|
|
if (CM)
|
|
|
|
return *CM;
|
|
|
|
return CodeModel::Small;
|
|
|
|
}
|
|
|
|
|
2017-01-27 05:41:10 +08:00
|
|
|
extern "C" void LLVMInitializeHexagonTarget() {
|
|
|
|
// Register the target.
|
|
|
|
RegisterTargetMachine<HexagonTargetMachine> X(getTheHexagonTarget());
|
2017-06-14 00:07:36 +08:00
|
|
|
|
|
|
|
PassRegistry &PR = *PassRegistry::getPassRegistry();
|
2018-02-20 22:29:43 +08:00
|
|
|
initializeHexagonBitSimplifyPass(PR);
|
2017-10-14 03:02:59 +08:00
|
|
|
initializeHexagonConstExtendersPass(PR);
|
2018-02-24 04:33:26 +08:00
|
|
|
initializeHexagonConstPropagationPass(PR);
|
2017-08-10 05:22:05 +08:00
|
|
|
initializeHexagonEarlyIfConversionPass(PR);
|
2017-06-14 00:07:36 +08:00
|
|
|
initializeHexagonGenMuxPass(PR);
|
2017-10-21 00:56:33 +08:00
|
|
|
initializeHexagonHardwareLoopsPass(PR);
|
2017-07-11 02:38:52 +08:00
|
|
|
initializeHexagonLoopIdiomRecognizePass(PR);
|
2017-09-22 05:48:23 +08:00
|
|
|
initializeHexagonVectorLoopCarriedReusePass(PR);
|
2017-06-28 02:37:16 +08:00
|
|
|
initializeHexagonNewValueJumpPass(PR);
|
2017-07-11 02:38:52 +08:00
|
|
|
initializeHexagonOptAddrModePass(PR);
|
|
|
|
initializeHexagonPacketizerPass(PR);
|
2017-10-30 22:11:52 +08:00
|
|
|
initializeHexagonRDFOptPass(PR);
|
2018-01-27 05:17:14 +08:00
|
|
|
initializeHexagonVExtractPass(PR);
|
2017-01-27 05:41:10 +08:00
|
|
|
}
|
|
|
|
|
2015-06-12 03:41:26 +08:00
|
|
|
HexagonTargetMachine::HexagonTargetMachine(const Target &T, const Triple &TT,
|
2011-12-13 05:14:40 +08:00
|
|
|
StringRef CPU, StringRef FS,
|
2012-03-17 17:24:09 +08:00
|
|
|
const TargetOptions &Options,
|
2016-05-19 06:04:49 +08:00
|
|
|
Optional<Reloc::Model> RM,
|
2017-08-03 10:16:21 +08:00
|
|
|
Optional<CodeModel::Model> CM,
|
|
|
|
CodeGenOpt::Level OL, bool JIT)
|
2016-02-12 22:47:38 +08:00
|
|
|
// Specify the vector alignment explicitly. For v512x1, the calculated
|
|
|
|
// alignment would be 512*alignment(i1), which is 512 bytes, instead of
|
|
|
|
// the required minimum of 64 bytes.
|
2017-10-13 06:57:28 +08:00
|
|
|
: LLVMTargetMachine(
|
2017-08-03 10:16:21 +08:00
|
|
|
T,
|
|
|
|
"e-m:e-p:32:32:32-a:0-n16:32-"
|
|
|
|
"i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-"
|
|
|
|
"v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048",
|
|
|
|
TT, CPU, FS, Options, getEffectiveRelocModel(RM),
|
|
|
|
getEffectiveCodeModel(CM), (HexagonNoOpt ? CodeGenOpt::None : OL)),
|
2015-08-06 02:35:37 +08:00
|
|
|
TLOF(make_unique<HexagonTargetObjectFile>()) {
|
2016-08-25 06:27:36 +08:00
|
|
|
initializeHexagonExpandCondsetsPass(*PassRegistry::getPassRegistry());
|
2015-08-06 02:35:37 +08:00
|
|
|
initAsmInfo();
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2015-08-06 02:35:37 +08:00
|
|
|
const HexagonSubtarget *
|
|
|
|
HexagonTargetMachine::getSubtargetImpl(const Function &F) const {
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
AttributeList FnAttrs = F.getAttributes();
|
2015-08-06 02:35:37 +08:00
|
|
|
Attribute CPUAttr =
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
FnAttrs.getAttribute(AttributeList::FunctionIndex, "target-cpu");
|
2015-08-06 02:35:37 +08:00
|
|
|
Attribute FSAttr =
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-22 00:57:19 +08:00
|
|
|
FnAttrs.getAttribute(AttributeList::FunctionIndex, "target-features");
|
2015-08-06 02:35:37 +08:00
|
|
|
|
|
|
|
std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
|
|
|
|
? CPUAttr.getValueAsString().str()
|
|
|
|
: TargetCPU;
|
|
|
|
std::string FS = !FSAttr.hasAttribute(Attribute::None)
|
|
|
|
? FSAttr.getValueAsString().str()
|
|
|
|
: TargetFS;
|
|
|
|
|
|
|
|
auto &I = SubtargetMap[CPU + FS];
|
|
|
|
if (!I) {
|
|
|
|
// This needs to be done before we create a new subtarget since any
|
|
|
|
// creation will depend on the TM and the code generation flags on the
|
|
|
|
// function that reside in TargetOptions.
|
|
|
|
resetTargetOptions(F);
|
|
|
|
I = llvm::make_unique<HexagonSubtarget>(TargetTriple, CPU, FS, *this);
|
|
|
|
}
|
|
|
|
return I.get();
|
|
|
|
}
|
|
|
|
|
2017-01-27 05:41:10 +08:00
|
|
|
void HexagonTargetMachine::adjustPassManager(PassManagerBuilder &PMB) {
|
|
|
|
PMB.addExtension(
|
|
|
|
PassManagerBuilder::EP_LateLoopOptimizations,
|
|
|
|
[&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
|
|
|
|
PM.add(createHexagonLoopIdiomPass());
|
|
|
|
});
|
2017-09-22 05:48:23 +08:00
|
|
|
PMB.addExtension(
|
|
|
|
PassManagerBuilder::EP_LoopOptimizerEnd,
|
|
|
|
[&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
|
|
|
|
PM.add(createHexagonVectorLoopCarriedReusePass());
|
|
|
|
});
|
2017-01-27 05:41:10 +08: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
2017-12-23 02:21:59 +08:00
|
|
|
TargetTransformInfo
|
|
|
|
HexagonTargetMachine::getTargetTransformInfo(const Function &F) {
|
|
|
|
return TargetTransformInfo(HexagonTTIImpl(this, F));
|
2015-08-06 02:35:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 07:37:18 +08:00
|
|
|
HexagonTargetMachine::~HexagonTargetMachine() {}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
namespace {
|
|
|
|
/// Hexagon Code Generator Pass Configuration Options.
|
|
|
|
class HexagonPassConfig : public TargetPassConfig {
|
|
|
|
public:
|
2017-05-31 05:36:41 +08:00
|
|
|
HexagonPassConfig(HexagonTargetMachine &TM, PassManagerBase &PM)
|
2016-05-28 04:48:39 +08:00
|
|
|
: TargetPassConfig(TM, PM) {}
|
2012-02-03 13:12:41 +08:00
|
|
|
|
|
|
|
HexagonTargetMachine &getHexagonTargetMachine() const {
|
|
|
|
return getTM<HexagonTargetMachine>();
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
ScheduleDAGInstrs *
|
|
|
|
createMachineScheduler(MachineSchedContext *C) const override {
|
2013-09-20 13:14:41 +08:00
|
|
|
return createVLIWMachineSched(C);
|
|
|
|
}
|
|
|
|
|
2015-07-09 03:22:28 +08:00
|
|
|
void addIRPasses() override;
|
2014-04-29 15:58:16 +08:00
|
|
|
bool addInstSelector() override;
|
2014-12-12 05:26:47 +08:00
|
|
|
void addPreRegAlloc() override;
|
|
|
|
void addPostRegAlloc() override;
|
|
|
|
void addPreSched2() override;
|
|
|
|
void addPreEmitPass() override;
|
2012-02-03 13:12:41 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2012-02-04 10:56:59 +08:00
|
|
|
TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
|
2017-05-31 05:36:41 +08:00
|
|
|
return new HexagonPassConfig(*this, PM);
|
2012-02-03 13:12:41 +08:00
|
|
|
}
|
|
|
|
|
2015-07-09 03:22:28 +08:00
|
|
|
void HexagonPassConfig::addIRPasses() {
|
|
|
|
TargetPassConfig::addIRPasses();
|
|
|
|
bool NoOpt = (getOptLevel() == CodeGenOpt::None);
|
2015-07-09 22:51:21 +08:00
|
|
|
|
2018-01-25 01:48:11 +08:00
|
|
|
if (!NoOpt) {
|
|
|
|
addPass(createConstantPropagationPass());
|
|
|
|
addPass(createDeadCodeEliminationPass());
|
|
|
|
}
|
|
|
|
|
2017-05-19 01:21:13 +08:00
|
|
|
addPass(createAtomicExpandPass());
|
2015-07-15 01:07:24 +08:00
|
|
|
if (!NoOpt) {
|
2016-07-22 22:22:43 +08:00
|
|
|
if (EnableLoopPrefetch)
|
|
|
|
addPass(createLoopDataPrefetchPass());
|
2015-07-15 01:07:24 +08:00
|
|
|
if (EnableCommGEP)
|
|
|
|
addPass(createHexagonCommonGEP());
|
|
|
|
// Replace certain combinations of shifts and ands with extracts.
|
|
|
|
if (EnableGenExtract)
|
|
|
|
addPass(createHexagonGenExtract());
|
|
|
|
}
|
2015-07-09 03:22:28 +08:00
|
|
|
}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addInstSelector() {
|
2013-06-20 05:36:55 +08:00
|
|
|
HexagonTargetMachine &TM = getHexagonTargetMachine();
|
2013-05-07 05:25:45 +08:00
|
|
|
bool NoOpt = (getOptLevel() == CodeGenOpt::None);
|
2013-03-27 19:14:24 +08:00
|
|
|
|
2015-10-20 03:10:48 +08:00
|
|
|
if (!NoOpt)
|
|
|
|
addPass(createHexagonOptimizeSZextends());
|
|
|
|
|
2013-05-07 05:25:45 +08:00
|
|
|
addPass(createHexagonISelDag(TM, getOptLevel()));
|
2013-03-27 19:14:24 +08:00
|
|
|
|
2013-05-07 05:25:45 +08:00
|
|
|
if (!NoOpt) {
|
2018-01-27 05:17:14 +08:00
|
|
|
if (EnableVExtractOpt)
|
|
|
|
addPass(createHexagonVExtract());
|
2015-07-15 03:30:21 +08:00
|
|
|
// Create logical operations on predicate registers.
|
|
|
|
if (EnableGenPred)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonGenPredicate());
|
2015-10-21 06:57:13 +08:00
|
|
|
// Rotate loops to expose bit-simplification opportunities.
|
|
|
|
if (EnableLoopResched)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonLoopRescheduling());
|
2015-10-17 04:38:54 +08:00
|
|
|
// Split double registers.
|
|
|
|
if (!DisableHSDR)
|
|
|
|
addPass(createHexagonSplitDoubleRegs());
|
2015-10-21 06:57:13 +08:00
|
|
|
// Bit simplification.
|
|
|
|
if (EnableBitSimplify)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonBitSimplify());
|
2013-03-27 19:14:24 +08:00
|
|
|
addPass(createHexagonPeephole());
|
2016-07-29 04:01:59 +08:00
|
|
|
// Constant propagation.
|
|
|
|
if (!DisableHCP) {
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonConstPropagationPass());
|
|
|
|
addPass(&UnreachableMachineBlockElimID);
|
2016-07-29 04:01:59 +08:00
|
|
|
}
|
2015-07-08 22:47:34 +08:00
|
|
|
if (EnableGenInsert)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonGenInsert());
|
2015-10-06 23:49:14 +08:00
|
|
|
if (EnableEarlyIf)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonEarlyIfConversion());
|
2013-05-07 05:25:45 +08:00
|
|
|
}
|
2013-03-27 19:14:24 +08:00
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-12 05:26:47 +08:00
|
|
|
void HexagonPassConfig::addPreRegAlloc() {
|
2015-10-17 03:43:56 +08:00
|
|
|
if (getOptLevel() != CodeGenOpt::None) {
|
2017-10-14 03:02:59 +08:00
|
|
|
if (EnableCExtOpt)
|
|
|
|
addPass(createHexagonConstExtenders());
|
2016-08-25 06:27:36 +08:00
|
|
|
if (EnableExpandCondsets)
|
|
|
|
insertPass(&RegisterCoalescerID, &HexagonExpandCondsetsID);
|
2015-10-17 03:43:56 +08:00
|
|
|
if (!DisableStoreWidening)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonStoreWidening());
|
2013-05-07 05:25:45 +08:00
|
|
|
if (!DisableHardwareLoops)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonHardwareLoops());
|
2015-10-17 03:43:56 +08:00
|
|
|
}
|
2016-07-30 00:44:44 +08:00
|
|
|
if (TM->getOptLevel() >= CodeGenOpt::Default)
|
|
|
|
addPass(&MachinePipelinerID);
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2014-12-12 05:26:47 +08:00
|
|
|
void HexagonPassConfig::addPostRegAlloc() {
|
2016-01-13 03:09:01 +08:00
|
|
|
if (getOptLevel() != CodeGenOpt::None) {
|
|
|
|
if (EnableRDFOpt)
|
|
|
|
addPass(createHexagonRDFOpt());
|
2013-05-07 05:25:45 +08:00
|
|
|
if (!DisableHexagonCFGOpt)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonCFGOptimizer());
|
2016-04-29 23:49:13 +08:00
|
|
|
if (!DisableAModeOpt)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonOptAddrMode());
|
2016-01-13 03:09:01 +08:00
|
|
|
}
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2014-12-12 05:26:47 +08:00
|
|
|
void HexagonPassConfig::addPreSched2() {
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonCopyToCombine());
|
2013-05-08 03:53:00 +08:00
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(&IfConverterID);
|
2015-02-03 06:11:43 +08:00
|
|
|
addPass(createHexagonSplitConst32AndConst64());
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2014-12-12 05:26:47 +08:00
|
|
|
void HexagonPassConfig::addPreEmitPass() {
|
2013-05-07 05:25:45 +08:00
|
|
|
bool NoOpt = (getOptLevel() == CodeGenOpt::None);
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2013-05-07 05:25:45 +08:00
|
|
|
if (!NoOpt)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonNewValueJump());
|
2012-05-12 13:10:30 +08:00
|
|
|
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonBranchRelaxation());
|
2016-04-20 02:30:18 +08:00
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// Create Packets.
|
2013-05-07 05:25:45 +08:00
|
|
|
if (!NoOpt) {
|
|
|
|
if (!DisableHardwareLoops)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonFixupHwLoops());
|
2015-07-21 05:23:25 +08:00
|
|
|
// Generate MUX from pairs of conditional transfers.
|
|
|
|
if (EnableGenMux)
|
2017-06-09 05:25:36 +08:00
|
|
|
addPass(createHexagonGenMux());
|
2017-12-12 02:57:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create packets for 2 instructions that consitute a gather instruction.
|
|
|
|
// Do this regardless of the opt level.
|
|
|
|
addPass(createHexagonGatherPacketize(), false);
|
2015-07-21 05:23:25 +08:00
|
|
|
|
2017-12-12 02:57:54 +08:00
|
|
|
if (!NoOpt)
|
2014-12-12 05:26:47 +08:00
|
|
|
addPass(createHexagonPacketizer(), false);
|
2017-12-12 02:57:54 +08:00
|
|
|
|
2016-08-02 03:36:39 +08:00
|
|
|
if (EnableVectorPrint)
|
|
|
|
addPass(createHexagonVectorPrint(), false);
|
2015-10-20 01:46:01 +08:00
|
|
|
|
|
|
|
// Add CFI instructions if necessary.
|
|
|
|
addPass(createHexagonCallFrameInformation(), false);
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|