38 #include "tce_config.h"
40 #include "llvm/IR/PassManager.h"
41 #include "llvm/CodeGen/TargetRegisterInfo.h"
42 #include "llvm/CodeGen/SelectionDAGNodes.h"
43 #include "llvm/MC/MCContext.h"
44 #include "llvm/MC/MCStreamer.h"
45 #include "llvm/MC/MCInstPrinter.h"
46 #include "llvm/CodeGen/MachineModuleInfo.h"
47 #include "llvm/ADT/APFloat.h"
63 #include <llvm/Transforms/Scalar.h>
83 const llvm::MCAsmInfo& mai,
const llvm::MCInstrInfo& mii,
84 const llvm::MCRegisterInfo& mri) :
llvm::MCInstPrinter(mai, mii, mri) {}
90 std::pair<const char*, uint64_t>
92 return std::make_pair(
nullptr, 0);
96 const MCInst*, uint64_t, StringRef,
97 const MCSubtargetInfo&, raw_ostream&)
override {}
111 const MCAsmInfo &MAI,
112 const MCInstrInfo &MII,
113 const MCRegisterInfo &MRI) {
118 RegisterTargetMachine<TCETargetMachine> Y(
TheTCETarget);
126 TargetRegistry::RegisterMCInstPrinter(
128 TargetRegistry::RegisterMCInstPrinter(
145 const Target &T,
const Triple& TTriple,
146 const llvm::StringRef& CPU,
const llvm::StringRef& FS,
148 Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
bool) :
150 RM?*RM:Reloc::
Model::Static, CM?*CM:CodeModel::Small, OL),
153 plugin_(NULL), pluginTool_(NULL) {
188 std::make_pair(llvm::ISD::SIGN_EXTEND_INREG, MVT::i16));
191 std::make_pair(llvm::ISD::SIGN_EXTEND_INREG, MVT::i8));
194 missingOps_.insert(std::make_pair(llvm::ISD::FSQRT, MVT::f32));
206 dataLayoutStr += target.
is64bit() ?
"e-p:64:64:64" :
"e-p:32:32:32";
208 dataLayoutStr +=
"E-p:32:32:32";
212 dataLayoutStr +=
"-i1:8:64";
213 dataLayoutStr +=
"-i8:8:64";
214 dataLayoutStr +=
"-i16:16:64";
215 dataLayoutStr +=
"-i32:32:64";
216 dataLayoutStr +=
"-i64:64:64";
217 dataLayoutStr +=
"-f16:16:64";
218 dataLayoutStr +=
"-f32:32:64";
220 dataLayoutStr +=
"-i1:8:8";
221 dataLayoutStr +=
"-i8:8:32";
222 dataLayoutStr +=
"-i16:16:32";
223 dataLayoutStr +=
"-i32:32:32";
224 dataLayoutStr +=
"-i64:64:64";
225 dataLayoutStr +=
"-f16:16:16";
226 dataLayoutStr +=
"-f32:32:32";
228 dataLayoutStr +=
"-f64:64:64";
229 dataLayoutStr +=
"-v64:64:64";
230 dataLayoutStr +=
"-v128:128:128";
231 dataLayoutStr +=
"-v256:256:256";
232 dataLayoutStr +=
"-v512:512:512";
233 dataLayoutStr +=
"-v1024:1024:1024";
234 #if LLVM_HAS_CUSTOM_VECTOR_EXTENSION == 2
235 dataLayoutStr +=
"-v2048:2048:2048";
236 dataLayoutStr +=
"-v4096:4096:4096";
240 dl->reset(dataLayoutStr.c_str());
271 ->hasOperation(
"hwloop"))
272 addPass(createHardwareLoopsPass());
283 CodeGenOpt::Level OptLevel = getOptLevel();
286 if (OptLevel != CodeGenOpt::None) {
289 addPass(createInternalizePass());
318 const std::set<std::pair<unsigned, llvm::MVT::SimpleValueType> >*
330 const std::set<std::pair<unsigned, llvm::MVT::SimpleValueType> >*
339 const std::set<std::pair<unsigned, llvm::MVT::SimpleValueType> >*
346 PassManagerBase &PM) {
351 tpc->setEnableTailMerge(
false);
362 switch (vt.SimpleTy) {
372 default:
assert(
false &&
"Not implemented or supported.");
383 int fpBitWidth =
static_cast<int>(
384 llvm::APFloat::getSizeInBits(fp.getSemantics()));
393 std::pair<int64_t, uint64_t> moveImm{
394 std::numeric_limits<int64_t>::max(),
395 std::numeric_limits<uint64_t>::min() };
398 if (rf->width() != 32)
continue;
401 if (!MCC::busConnectedToRF(*bus, *rf)
402 || bus->immediateWidth() == 0) {
406 if (bus->immediateWidth() >= 32) {
407 moveImm.first = -(1ll << (32-1));
408 moveImm.second = (1ll << 32)-1;
411 std::pair<int64_t, uint64_t> imm =
412 MathTools::bitsToIntegerRange<int64_t, uint64_t>(
413 bus->immediateWidth(),
416 moveImm.first = std::min(moveImm.first, imm.first);
417 moveImm.second = std::max(moveImm.second, imm.second);
424 int supportedWidth = it->supportedWidth(*iu);
425 if (supportedWidth >= 32) {
426 moveImm.first = -(1ll << (32-1));
427 moveImm.second = (1ll << 32)-1;
430 std::pair<int64_t, uint64_t> imm =
431 MathTools::bitsToIntegerRange<int64_t, uint64_t>(
432 supportedWidth, iu->signExtends());
434 moveImm.first = std::min(moveImm.first, imm.first);
435 moveImm.second = std::max(moveImm.second, imm.second);
443 if (!MCC::rfConnected(*rf))
continue;
457 int laneCount = vt.getVectorElementCount().getKnownMinValue();
459 int laneSize = vt.getScalarSizeInBits();
460 int vecSize = laneCount * laneSize;
461 TCEString relaxedName =
"LD"; relaxedName << laneSize <<
"X" << laneCount;
462 TCEString strictName =
"LD"; strictName << vecSize;
463 bool allowStrict = vecSize <= align;
467 for (
int i = 0; i < fuNav.count(); i++) {
468 auto fu = fuNav.
item(i);
469 if (fu->hasOperation(relaxedName) && fu->hasAddressSpace()) {
470 auto as = fu->addressSpace();
471 if (as->hasNumericalId(asid)) {
477 if (fu->hasOperation(strictName) && fu->hasAddressSpace()) {
478 auto as = fu->addressSpace();
479 if (as->hasNumericalId(asid)) {