2012-02-18 12:03:15 +00:00
|
|
|
//===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
|
2011-12-12 21:14:40 +00: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 12:03:15 +00:00
|
|
|
// Implements the info about Hexagon target spec.
|
2011-12-12 21:14:40 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "HexagonTargetMachine.h"
|
|
|
|
#include "Hexagon.h"
|
|
|
|
#include "HexagonISelLowering.h"
|
2012-09-04 14:49:56 +00:00
|
|
|
#include "HexagonMachineScheduler.h"
|
2013-05-07 19:53:00 +00:00
|
|
|
#include "HexagonTargetObjectFile.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2015-02-13 10:01:29 +00:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2012-02-06 10:19:29 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2013-05-06 21:25:45 +00:00
|
|
|
static cl:: opt<bool> DisableHardwareLoops("disable-hexagon-hwloops",
|
|
|
|
cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"));
|
2011-12-12 21:14:40 +00:00
|
|
|
|
2013-05-06 21:25:45 +00: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 14:49:56 +00:00
|
|
|
|
2013-03-27 11:14:24 +00:00
|
|
|
static cl::opt<bool> DisableHexagonCFGOpt("disable-hexagon-cfgopt",
|
2013-05-06 21:25:45 +00:00
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Hexagon CFG Optimization"));
|
|
|
|
|
2013-03-27 11:14:24 +00:00
|
|
|
|
2011-12-12 21:14:40 +00: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 14:49:56 +00:00
|
|
|
static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
|
2014-04-21 20:32:32 +00:00
|
|
|
return new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>());
|
2012-09-04 14:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static MachineSchedRegistry
|
|
|
|
SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
|
|
|
|
createVLIWMachineSched);
|
2011-12-12 21:14:40 +00: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 09:24:09 +00:00
|
|
|
const TargetOptions &Options,
|
2014-06-27 00:13:43 +00:00
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
2011-12-12 21:14:40 +00:00
|
|
|
CodeGenOpt::Level OL)
|
2014-06-27 00:13:43 +00:00
|
|
|
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
|
2014-11-13 09:26:31 +00:00
|
|
|
TLOF(make_unique<HexagonTargetObjectFile>()),
|
2015-01-26 19:03:15 +00:00
|
|
|
DL("e-m:e-p:32:32-i1:32-i64:64-a:0-n32"), Subtarget(TT, CPU, FS, *this) {
|
2013-05-13 01:16:13 +00:00
|
|
|
initAsmInfo();
|
2011-12-12 21:14:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 23:37:18 +00:00
|
|
|
HexagonTargetMachine::~HexagonTargetMachine() {}
|
|
|
|
|
2012-02-03 05:12:41 +00:00
|
|
|
namespace {
|
|
|
|
/// Hexagon Code Generator Pass Configuration Options.
|
|
|
|
class HexagonPassConfig : public TargetPassConfig {
|
|
|
|
public:
|
2012-02-04 02:56:59 +00:00
|
|
|
HexagonPassConfig(HexagonTargetMachine *TM, PassManagerBase &PM)
|
2012-09-04 14:49:56 +00:00
|
|
|
: TargetPassConfig(TM, PM) {
|
2013-09-20 05:14:41 +00: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 14:49:56 +00:00
|
|
|
enablePass(&MachineSchedulerID);
|
|
|
|
}
|
2012-02-03 05:12:41 +00:00
|
|
|
|
|
|
|
HexagonTargetMachine &getHexagonTargetMachine() const {
|
|
|
|
return getTM<HexagonTargetMachine>();
|
|
|
|
}
|
|
|
|
|
2014-04-29 07:58:16 +00:00
|
|
|
ScheduleDAGInstrs *
|
|
|
|
createMachineScheduler(MachineSchedContext *C) const override {
|
2013-09-20 05:14:41 +00:00
|
|
|
return createVLIWMachineSched(C);
|
|
|
|
}
|
|
|
|
|
2014-04-29 07:58:16 +00:00
|
|
|
bool addInstSelector() override;
|
2014-12-11 21:26:47 +00:00
|
|
|
void addPreRegAlloc() override;
|
|
|
|
void addPostRegAlloc() override;
|
|
|
|
void addPreSched2() override;
|
|
|
|
void addPreEmitPass() override;
|
2012-02-03 05:12:41 +00:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2012-02-04 02:56:59 +00:00
|
|
|
TargetPassConfig *HexagonTargetMachine::createPassConfig(PassManagerBase &PM) {
|
|
|
|
return new HexagonPassConfig(this, PM);
|
2012-02-03 05:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HexagonPassConfig::addInstSelector() {
|
2013-06-19 21:36:55 +00:00
|
|
|
HexagonTargetMachine &TM = getHexagonTargetMachine();
|
2013-05-06 21:25:45 +00:00
|
|
|
bool NoOpt = (getOptLevel() == CodeGenOpt::None);
|
2013-03-27 11:14:24 +00:00
|
|
|
|
2013-05-06 21:25:45 +00:00
|
|
|
if (!NoOpt)
|
|
|
|
addPass(createHexagonRemoveExtendArgs(TM));
|
2013-03-27 11:14:24 +00:00
|
|
|
|
2013-05-06 21:25:45 +00:00
|
|
|
addPass(createHexagonISelDag(TM, getOptLevel()));
|
2013-03-27 11:14:24 +00:00
|
|
|
|
2013-05-06 21:25:45 +00:00
|
|
|
if (!NoOpt) {
|
2013-03-27 11:14:24 +00:00
|
|
|
addPass(createHexagonPeephole());
|
2013-05-06 21:25:45 +00:00
|
|
|
printAndVerify("After hexagon peephole pass");
|
|
|
|
}
|
2013-03-27 11:14:24 +00:00
|
|
|
|
2011-12-12 21:14:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-11 21:26:47 +00:00
|
|
|
void HexagonPassConfig::addPreRegAlloc() {
|
2013-05-06 21:25:45 +00:00
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
|
|
|
if (!DisableHardwareLoops)
|
2014-12-11 21:26:47 +00:00
|
|
|
addPass(createHexagonHardwareLoops(), false);
|
2011-12-12 21:14:40 +00:00
|
|
|
}
|
|
|
|
|
2014-12-11 21:26:47 +00:00
|
|
|
void HexagonPassConfig::addPostRegAlloc() {
|
2013-05-06 21:25:45 +00:00
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
|
|
|
if (!DisableHexagonCFGOpt)
|
2015-02-02 18:46:27 +00:00
|
|
|
addPass(createHexagonCFGOptimizer(), false);
|
2011-12-12 21:14:40 +00:00
|
|
|
}
|
|
|
|
|
2014-12-11 21:26:47 +00:00
|
|
|
void HexagonPassConfig::addPreSched2() {
|
|
|
|
addPass(createHexagonCopyToCombine(), false);
|
2013-05-07 19:53:00 +00:00
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
2014-12-11 21:26:47 +00:00
|
|
|
addPass(&IfConverterID, false);
|
2015-02-02 22:11:43 +00:00
|
|
|
addPass(createHexagonSplitConst32AndConst64());
|
2011-12-12 21:14:40 +00:00
|
|
|
}
|
|
|
|
|
2014-12-11 21:26:47 +00:00
|
|
|
void HexagonPassConfig::addPreEmitPass() {
|
2013-05-06 21:25:45 +00:00
|
|
|
bool NoOpt = (getOptLevel() == CodeGenOpt::None);
|
2011-12-12 21:14:40 +00:00
|
|
|
|
2013-05-06 21:25:45 +00:00
|
|
|
if (!NoOpt)
|
2014-12-11 21:26:47 +00:00
|
|
|
addPass(createHexagonNewValueJump(), false);
|
2012-05-12 05:10:30 +00:00
|
|
|
|
2011-12-12 21:14:40 +00:00
|
|
|
// Expand Spill code for predicate registers.
|
2015-02-02 18:46:31 +00:00
|
|
|
addPass(createHexagonExpandPredSpillCode(), false);
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
// Split up TFRcondsets into conditional transfers.
|
2015-02-02 22:28:44 +00:00
|
|
|
addPass(createHexagonSplitTFRCondSets(), false);
|
2011-12-12 21:14:40 +00:00
|
|
|
|
2012-05-03 21:52:53 +00:00
|
|
|
// Create Packets.
|
2013-05-06 21:25:45 +00:00
|
|
|
if (!NoOpt) {
|
|
|
|
if (!DisableHardwareLoops)
|
2014-12-11 21:26:47 +00:00
|
|
|
addPass(createHexagonFixupHwLoops(), false);
|
|
|
|
addPass(createHexagonPacketizer(), false);
|
2013-05-06 21:25:45 +00:00
|
|
|
}
|
2011-12-12 21:14:40 +00:00
|
|
|
}
|