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"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
|
|
|
#include "llvm/Transforms/Scalar.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"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
static cl::
|
|
|
|
opt<bool> DisableHardwareLoops(
|
|
|
|
"disable-hexagon-hwloops", cl::Hidden,
|
|
|
|
cl::desc("Disable Hardware Loops for Hexagon target"));
|
|
|
|
|
2012-09-04 22:49:56 +08:00
|
|
|
static cl::
|
|
|
|
opt<bool> DisableHexagonMISched("disable-hexagon-misched",
|
|
|
|
cl::Hidden, cl::ZeroOrMore, cl::init(false),
|
|
|
|
cl::desc("Disable Hexagon MI Scheduling"));
|
|
|
|
|
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) {
|
|
|
|
return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler());
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2011-12-13 05:14:40 +08:00
|
|
|
Reloc::Model RM,
|
|
|
|
CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
|
|
|
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
|
2012-10-09 00:38:25 +08:00
|
|
|
DL("e-p:32:32:32-"
|
2012-05-11 04:20:25 +08:00
|
|
|
"i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
|
|
|
|
"f64:64:64-f32:32:32-a0:0-n32") ,
|
2011-12-17 03:08:59 +08:00
|
|
|
Subtarget(TT, CPU, FS), InstrInfo(Subtarget), TLInfo(*this),
|
2011-12-13 05:14:40 +08:00
|
|
|
TSInfo(*this),
|
|
|
|
FrameLowering(Subtarget),
|
2012-10-19 07:22:48 +08:00
|
|
|
InstrItins(&Subtarget.getInstrItineraryData()),
|
2012-10-25 01:22:41 +08:00
|
|
|
STTI(&TLInfo), VTTI(&TLInfo) {
|
2011-12-13 05:14:40 +08:00
|
|
|
setMCUseCFI(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// addPassesForOptimizations - Allow the backend (target) to add Target
|
|
|
|
// Independent Optimization passes to the Pass Manager.
|
|
|
|
bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {
|
|
|
|
|
|
|
|
PM.add(createConstantPropagationPass());
|
|
|
|
PM.add(createLoopSimplifyPass());
|
|
|
|
PM.add(createDeadCodeEliminationPass());
|
|
|
|
PM.add(createConstantPropagationPass());
|
|
|
|
PM.add(createLoopUnrollPass());
|
2012-10-19 07:22:48 +08:00
|
|
|
PM.add(createLoopStrengthReducePass());
|
2011-12-13 05:14:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
// Enable MI scheduler.
|
|
|
|
if (!DisableHexagonMISched) {
|
|
|
|
enablePass(&MachineSchedulerID);
|
|
|
|
MachineSchedRegistry::setDefault(createVLIWMachineSched);
|
|
|
|
}
|
|
|
|
}
|
2012-02-03 13:12:41 +08:00
|
|
|
|
|
|
|
HexagonTargetMachine &getHexagonTargetMachine() const {
|
|
|
|
return getTM<HexagonTargetMachine>();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool addInstSelector();
|
|
|
|
virtual bool addPreRegAlloc();
|
|
|
|
virtual bool addPostRegAlloc();
|
|
|
|
virtual bool addPreSched2();
|
|
|
|
virtual bool addPreEmitPass();
|
|
|
|
};
|
|
|
|
} // 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() {
|
2012-07-03 03:48:31 +08:00
|
|
|
addPass(createHexagonRemoveExtendOps(getHexagonTargetMachine()));
|
|
|
|
addPass(createHexagonISelDag(getHexagonTargetMachine()));
|
|
|
|
addPass(createHexagonPeephole());
|
2011-12-13 05:14:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addPreRegAlloc() {
|
2011-12-13 05:14:40 +08:00
|
|
|
if (!DisableHardwareLoops) {
|
2012-07-03 03:48:31 +08:00
|
|
|
addPass(createHexagonHardwareLoops());
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addPostRegAlloc() {
|
2012-07-03 03:48:31 +08:00
|
|
|
addPass(createHexagonCFGOptimizer(getHexagonTargetMachine()));
|
2011-12-13 05:14:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addPreSched2() {
|
2012-07-03 03:48:37 +08:00
|
|
|
addPass(&IfConverterID);
|
2011-12-13 05:14:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-03 13:12:41 +08:00
|
|
|
bool HexagonPassConfig::addPreEmitPass() {
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
if (!DisableHardwareLoops) {
|
2012-07-03 03:48:31 +08:00
|
|
|
addPass(createHexagonFixupHwLoops());
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
2012-07-03 03:48:31 +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.
|
2012-07-03 03:48:31 +08:00
|
|
|
addPass(createHexagonExpandPredSpillCode(getHexagonTargetMachine()));
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
// Split up TFRcondsets into conditional transfers.
|
2012-07-03 03:48:31 +08:00
|
|
|
addPass(createHexagonSplitTFRCondSets(getHexagonTargetMachine()));
|
2011-12-13 05:14:40 +08:00
|
|
|
|
2012-05-04 05:52:53 +08:00
|
|
|
// Create Packets.
|
2012-07-03 03:48:31 +08:00
|
|
|
addPass(createHexagonPacketizer());
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
return false;
|
|
|
|
}
|