1 //===- ARCTargetMachine.cpp - Define TargetMachine for ARC ------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // 10 //===----------------------------------------------------------------------===// 11 12 #include "ARCTargetMachine.h" 13 #include "ARC.h" 14 #include "ARCTargetTransformInfo.h" 15 #include "TargetInfo/ARCTargetInfo.h" 16 #include "llvm/CodeGen/Passes.h" 17 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" 18 #include "llvm/CodeGen/TargetPassConfig.h" 19 #include "llvm/MC/TargetRegistry.h" 20 21 using namespace llvm; 22 23 static Reloc::Model getRelocModel(Optional<Reloc::Model> RM) { 24 return RM.value_or(Reloc::Static); 25 } 26 27 /// ARCTargetMachine ctor - Create an ILP32 architecture model 28 ARCTargetMachine::ARCTargetMachine(const Target &T, const Triple &TT, 29 StringRef CPU, StringRef FS, 30 const TargetOptions &Options, 31 Optional<Reloc::Model> RM, 32 Optional<CodeModel::Model> CM, 33 CodeGenOpt::Level OL, bool JIT) 34 : LLVMTargetMachine(T, 35 "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" 36 "f32:32:32-i64:32-f64:32-a:0:32-n32", 37 TT, CPU, FS, Options, getRelocModel(RM), 38 getEffectiveCodeModel(CM, CodeModel::Small), OL), 39 TLOF(std::make_unique<TargetLoweringObjectFileELF>()), 40 Subtarget(TT, std::string(CPU), std::string(FS), *this) { 41 initAsmInfo(); 42 } 43 44 ARCTargetMachine::~ARCTargetMachine() = default; 45 46 namespace { 47 48 /// ARC Code Generator Pass Configuration Options. 49 class ARCPassConfig : public TargetPassConfig { 50 public: 51 ARCPassConfig(ARCTargetMachine &TM, PassManagerBase &PM) 52 : TargetPassConfig(TM, PM) {} 53 54 ARCTargetMachine &getARCTargetMachine() const { 55 return getTM<ARCTargetMachine>(); 56 } 57 58 bool addInstSelector() override; 59 void addPreEmitPass() override; 60 void addPreRegAlloc() override; 61 }; 62 63 } // end anonymous namespace 64 65 TargetPassConfig *ARCTargetMachine::createPassConfig(PassManagerBase &PM) { 66 return new ARCPassConfig(*this, PM); 67 } 68 69 bool ARCPassConfig::addInstSelector() { 70 addPass(createARCISelDag(getARCTargetMachine(), getOptLevel())); 71 return false; 72 } 73 74 void ARCPassConfig::addPreEmitPass() { addPass(createARCBranchFinalizePass()); } 75 76 void ARCPassConfig::addPreRegAlloc() { 77 addPass(createARCExpandPseudosPass()); 78 addPass(createARCOptAddrMode()); 79 } 80 81 // Force static initialization. 82 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCTarget() { 83 RegisterTargetMachine<ARCTargetMachine> X(getTheARCTarget()); 84 } 85 86 TargetTransformInfo 87 ARCTargetMachine::getTargetTransformInfo(const Function &F) const { 88 return TargetTransformInfo(ARCTTIImpl(this, F)); 89 } 90