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"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/PassManager.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"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2013-05-07 05:25:45 +08:00
|
|
|
static cl:: opt<bool> DisableHardwareLoops("disable-hexagon-hwloops",
|
|
|
|
cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"));
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2013-05-07 05:25:45 +08:00
|
|
|
static cl::opt<bool> DisableHexagonMISched("disable-hexagon-misched",
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Hexagon MI Scheduling"));
|
2012-09-04 22:49:56 +08:00
|
|
|
|
2013-03-27 19:14:24 +08:00
|
|
|
static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt",
|
2013-05-07 05:25:45 +08:00
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Hexagon CFG Optimization"));
|
|
|
|
|
2013-03-27 19:14:24 +08:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
extern "C" void LLVMInitializeHexagonTarget() {
|
|
|
|
// Register the target.
|
|
|
|
RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
|
|
|
|
}
|
|
|
|
|
2012-09-04 22:49:56 +08:00
|
|
|
static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
|
2014-04-22 04:32:32 +08:00
|
|
|
return new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>());
|
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
|
|
|
|
|
|
|
/// HexagonTargetMachine ctor - Create an ILP32 architecture model.
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Hexagon_TODO: Do I need an aggregate alignment?
|
|
|
|
///
|
|
|
|
HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
|
|
|
|
StringRef CPU, StringRef FS,
|
2012-03-17 17:24:09 +08:00
|
|
|
const TargetOptions &Options,
|
2014-06-27 08:13:43 +08:00
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
2011-12-13 05:14:40 +08:00
|
|
|
CodeGenOpt::Level OL)
|
2014-06-27 08:13:43 +08:00
|
|
|
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
|
2014-11-13 17:26:31 +08:00
|
|
|
TLOF(make_unique<HexagonTargetObjectFile>()),
|
2014-06-27 08:27:40 +08:00
|
|
|
Subtarget(TT, CPU, FS, *this) {
|
2013-05-13 09:16:13 +08:00
|
|
|
initAsmInfo();
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
namespace {
|
|
|
|
/// Hexagon Code Generator Pass Configuration Options.
|
|
|
|
class HexagonPassConfig : public TargetPassConfig {
|
|
|
|
public:
|
2012-02-04 10:56:59 +08:00
|
|
|
HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
|
2012-09-04 22:49:56 +08:00
|
|
|
: TargetPassConfig(TM, PM) {
|
2013-09-20 13:14:41 +08:00
|
|
|
// FIXME: Rather than calling enablePass(&MachineSchedulerID) below, define
|
|
|
|
// HexagonSubtarget::enableMachineScheduler() { return true; }.
|
|
|
|
// That will bypass the SelectionDAG VLIW scheduler, which is probably just
|
|
|
|
// hurting compile time and will be removed eventually anyway.
|
|
|
|
if (DisableHexagonMISched)
|
|
|
|
disablePass(&MachineSchedulerID);
|
|
|
|
else
|
2012-09-04 22:49:56 +08:00
|
|
|
enablePass(&MachineSchedulerID);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
bool addInstSelector() override;
|
|
|
|
bool addPreRegAlloc() override;
|
|
|
|
bool addPostRegAlloc() override;
|
|
|
|
bool addPreSched2() override;
|
|
|
|
bool addPreEmitPass() override;
|
2012-02-03 13:12:41 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2012-02-04 10:56:59 +08:00
|
|
|
TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
|
|
|
|
return new HexagonPassConfig(this, PM);
|
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
|
|
|
|
2013-05-07 05:25:45 +08:00
|
|
|
if (!NoOpt)
|
|
|
|
addPass(createHexagonRemoveExtendArgs(TM));
|
2013-03-27 19:14:24 +08:00
|
|
|
|
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) {
|
2013-03-27 19:14:24 +08:00
|
|
|
addPass(createHexagonPeephole());
|
2013-05-07 05:25:45 +08:00
|
|
|
printAndVerify("After hexagon peephole pass");
|
|
|
|
}
|
2013-03-27 19:14:24 +08:00
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addPreRegAlloc() {
|
2013-05-07 05:25:45 +08:00
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
|
|
|
if (!DisableHardwareLoops)
|
|
|
|
addPass(createHexagonHardwareLoops());
|
2011-12-13 05:14:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addPostRegAlloc() {
|
2013-05-07 05:25:45 +08:00
|
|
|
const HexagonTargetMachine &TM = getHexagonTargetMachine();
|
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
|
|
|
if (!DisableHexagonCFGOpt)
|
|
|
|
addPass(createHexagonCFGOptimizer(TM));
|
|
|
|
return false;
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addPreSched2() {
|
2013-05-08 03:53:00 +08:00
|
|
|
const HexagonTargetMachine &TM = getHexagonTargetMachine();
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
addPass(createHexagonCopyToCombine());
|
2013-05-08 03:53:00 +08:00
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
|
|
|
addPass(&IfConverterID);
|
2014-05-22 06:42:07 +08:00
|
|
|
addPass(createHexagonSplitConst32AndConst64(TM));
|
|
|
|
printAndVerify("After hexagon split const32/64 pass");
|
2013-05-08 03:53:00 +08:00
|
|
|
return true;
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addPreEmitPass() {
|
2013-05-07 05:25:45 +08:00
|
|
|
const HexagonTargetMachine &TM = getHexagonTargetMachine();
|
|
|
|
bool NoOpt = (getOptLevel() == CodeGenOpt::None);
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2013-05-07 05:25:45 +08:00
|
|
|
if (!NoOpt)
|
2013-03-27 19:14:24 +08:00
|
|
|
addPass(createHexagonNewValueJump());
|
2012-05-12 13:10:30 +08:00
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
// Expand Spill code for predicate registers.
|
2013-05-07 05:25:45 +08:00
|
|
|
addPass(createHexagonExpandPredSpillCode(TM));
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
// Split up TFRcondsets into conditional transfers.
|
2013-05-07 05:25:45 +08:00
|
|
|
addPass(createHexagonSplitTFRCondSets(TM));
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// Create Packets.
|
2013-05-07 05:25:45 +08:00
|
|
|
if (!NoOpt) {
|
|
|
|
if (!DisableHardwareLoops)
|
|
|
|
addPass(createHexagonFixupHwLoops());
|
2013-03-27 19:14:24 +08:00
|
|
|
addPass(createHexagonPacketizer());
|
2013-05-07 05:25:45 +08:00
|
|
|
}
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
return false;
|
|
|
|
}
|