12d1f6d67SPete Couperus //===- ARCTargetMachine.cpp - Define TargetMachine for ARC ------*- C++ -*-===//
22d1f6d67SPete Couperus //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
62d1f6d67SPete Couperus //
72d1f6d67SPete Couperus //===----------------------------------------------------------------------===//
82d1f6d67SPete Couperus //
92d1f6d67SPete Couperus //
102d1f6d67SPete Couperus //===----------------------------------------------------------------------===//
112d1f6d67SPete Couperus
122d1f6d67SPete Couperus #include "ARCTargetMachine.h"
132d1f6d67SPete Couperus #include "ARC.h"
142d1f6d67SPete Couperus #include "ARCTargetTransformInfo.h"
157f9a008aSRichard Trieu #include "TargetInfo/ARCTargetInfo.h"
162d1f6d67SPete Couperus #include "llvm/CodeGen/Passes.h"
172d1f6d67SPete Couperus #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
182d1f6d67SPete Couperus #include "llvm/CodeGen/TargetPassConfig.h"
1989b57061SReid Kleckner #include "llvm/MC/TargetRegistry.h"
202d1f6d67SPete Couperus
212d1f6d67SPete Couperus using namespace llvm;
222d1f6d67SPete Couperus
getRelocModel(Optional<Reloc::Model> RM)232d1f6d67SPete Couperus static Reloc::Model getRelocModel(Optional<Reloc::Model> RM) {
24*129b531cSKazu Hirata return RM.value_or(Reloc::Static);
252d1f6d67SPete Couperus }
262d1f6d67SPete Couperus
272d1f6d67SPete Couperus /// ARCTargetMachine ctor - Create an ILP32 architecture model
ARCTargetMachine(const Target & T,const Triple & TT,StringRef CPU,StringRef FS,const TargetOptions & Options,Optional<Reloc::Model> RM,Optional<CodeModel::Model> CM,CodeGenOpt::Level OL,bool JIT)282d1f6d67SPete Couperus ARCTargetMachine::ARCTargetMachine(const Target &T, const Triple &TT,
292d1f6d67SPete Couperus StringRef CPU, StringRef FS,
302d1f6d67SPete Couperus const TargetOptions &Options,
312d1f6d67SPete Couperus Optional<Reloc::Model> RM,
322d1f6d67SPete Couperus Optional<CodeModel::Model> CM,
332d1f6d67SPete Couperus CodeGenOpt::Level OL, bool JIT)
34bb8507e6SMatthias Braun : LLVMTargetMachine(T,
35bb8507e6SMatthias Braun "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
362d1f6d67SPete Couperus "f32:32:32-i64:32-f64:32-a:0:32-n32",
372d1f6d67SPete Couperus TT, CPU, FS, Options, getRelocModel(RM),
38ca29c271SDavid Green getEffectiveCodeModel(CM, CodeModel::Small), OL),
390eaee545SJonas Devlieghere TLOF(std::make_unique<TargetLoweringObjectFileELF>()),
40800a0f81SFangrui Song Subtarget(TT, std::string(CPU), std::string(FS), *this) {
412d1f6d67SPete Couperus initAsmInfo();
422d1f6d67SPete Couperus }
432d1f6d67SPete Couperus
442d1f6d67SPete Couperus ARCTargetMachine::~ARCTargetMachine() = default;
452d1f6d67SPete Couperus
462d1f6d67SPete Couperus namespace {
472d1f6d67SPete Couperus
482d1f6d67SPete Couperus /// ARC Code Generator Pass Configuration Options.
492d1f6d67SPete Couperus class ARCPassConfig : public TargetPassConfig {
502d1f6d67SPete Couperus public:
ARCPassConfig(ARCTargetMachine & TM,PassManagerBase & PM)512d1f6d67SPete Couperus ARCPassConfig(ARCTargetMachine &TM, PassManagerBase &PM)
522d1f6d67SPete Couperus : TargetPassConfig(TM, PM) {}
532d1f6d67SPete Couperus
getARCTargetMachine() const542d1f6d67SPete Couperus ARCTargetMachine &getARCTargetMachine() const {
552d1f6d67SPete Couperus return getTM<ARCTargetMachine>();
562d1f6d67SPete Couperus }
572d1f6d67SPete Couperus
582d1f6d67SPete Couperus bool addInstSelector() override;
592d1f6d67SPete Couperus void addPreEmitPass() override;
602d1f6d67SPete Couperus void addPreRegAlloc() override;
612d1f6d67SPete Couperus };
622d1f6d67SPete Couperus
632d1f6d67SPete Couperus } // end anonymous namespace
642d1f6d67SPete Couperus
createPassConfig(PassManagerBase & PM)652d1f6d67SPete Couperus TargetPassConfig *ARCTargetMachine::createPassConfig(PassManagerBase &PM) {
662d1f6d67SPete Couperus return new ARCPassConfig(*this, PM);
672d1f6d67SPete Couperus }
682d1f6d67SPete Couperus
addInstSelector()692d1f6d67SPete Couperus bool ARCPassConfig::addInstSelector() {
702d1f6d67SPete Couperus addPass(createARCISelDag(getARCTargetMachine(), getOptLevel()));
712d1f6d67SPete Couperus return false;
722d1f6d67SPete Couperus }
732d1f6d67SPete Couperus
addPreEmitPass()742d1f6d67SPete Couperus void ARCPassConfig::addPreEmitPass() { addPass(createARCBranchFinalizePass()); }
752d1f6d67SPete Couperus
addPreRegAlloc()76b062239dSPete Couperus void ARCPassConfig::addPreRegAlloc() {
77b062239dSPete Couperus addPass(createARCExpandPseudosPass());
78b062239dSPete Couperus addPass(createARCOptAddrMode());
79b062239dSPete Couperus }
802d1f6d67SPete Couperus
812d1f6d67SPete Couperus // Force static initialization.
LLVMInitializeARCTarget()820dbcb363STom Stellard extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCTarget() {
832d1f6d67SPete Couperus RegisterTargetMachine<ARCTargetMachine> X(getTheARCTarget());
842d1f6d67SPete Couperus }
852d1f6d67SPete Couperus
8626d11ca4SSanjoy Das TargetTransformInfo
getTargetTransformInfo(const Function & F) const87c4b1a63aSJameson Nash ARCTargetMachine::getTargetTransformInfo(const Function &F) const {
882d1f6d67SPete Couperus return TargetTransformInfo(ARCTTIImpl(this, F));
892d1f6d67SPete Couperus }
90