1e1c38dd5SZi Xuan Wu //===--- CSKYTargetMachine.cpp - Define TargetMachine for CSKY ------------===// 2e1c38dd5SZi Xuan Wu // 3e1c38dd5SZi Xuan Wu // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e1c38dd5SZi Xuan Wu // See https://llvm.org/LICENSE.txt for license information. 5e1c38dd5SZi Xuan Wu // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e1c38dd5SZi Xuan Wu // 7e1c38dd5SZi Xuan Wu //===----------------------------------------------------------------------===// 8e1c38dd5SZi Xuan Wu // 9e1c38dd5SZi Xuan Wu // Implements the info about CSKY target spec. 10e1c38dd5SZi Xuan Wu // 11e1c38dd5SZi Xuan Wu //===----------------------------------------------------------------------===// 12e1c38dd5SZi Xuan Wu 13e1c38dd5SZi Xuan Wu #include "CSKYTargetMachine.h" 14e1c38dd5SZi Xuan Wu #include "TargetInfo/CSKYTargetInfo.h" 15e1c38dd5SZi Xuan Wu #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" 16e1c38dd5SZi Xuan Wu #include "llvm/CodeGen/TargetPassConfig.h" 17e1c38dd5SZi Xuan Wu #include "llvm/Support/TargetRegistry.h" 18e1c38dd5SZi Xuan Wu 19e1c38dd5SZi Xuan Wu using namespace llvm; 20e1c38dd5SZi Xuan Wu 21e1c38dd5SZi Xuan Wu extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTarget() { 22e1c38dd5SZi Xuan Wu RegisterTargetMachine<CSKYTargetMachine> X(getTheCSKYTarget()); 23e1c38dd5SZi Xuan Wu } 24e1c38dd5SZi Xuan Wu 25e1c38dd5SZi Xuan Wu static std::string computeDataLayout(const Triple &TT) { 26e1c38dd5SZi Xuan Wu std::string Ret; 27e1c38dd5SZi Xuan Wu 28e1c38dd5SZi Xuan Wu // Only support little endian for now. 29e1c38dd5SZi Xuan Wu // TODO: Add support for big endian. 30e1c38dd5SZi Xuan Wu Ret += "e"; 31e1c38dd5SZi Xuan Wu 32e1c38dd5SZi Xuan Wu // CSKY is always 32-bit target with the CSKYv2 ABI as prefer now. 33e1c38dd5SZi Xuan Wu // It's a 4-byte aligned stack with ELF mangling only. 34e1c38dd5SZi Xuan Wu Ret += "-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32" 35e1c38dd5SZi Xuan Wu "-v128:32:32-a:0:32-Fi32-n32"; 36e1c38dd5SZi Xuan Wu 37e1c38dd5SZi Xuan Wu return Ret; 38e1c38dd5SZi Xuan Wu } 39e1c38dd5SZi Xuan Wu 40e1c38dd5SZi Xuan Wu CSKYTargetMachine::CSKYTargetMachine(const Target &T, const Triple &TT, 41e1c38dd5SZi Xuan Wu StringRef CPU, StringRef FS, 42e1c38dd5SZi Xuan Wu const TargetOptions &Options, 43e1c38dd5SZi Xuan Wu Optional<Reloc::Model> RM, 44e1c38dd5SZi Xuan Wu Optional<CodeModel::Model> CM, 45e1c38dd5SZi Xuan Wu CodeGenOpt::Level OL, bool JIT) 46e1c38dd5SZi Xuan Wu : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options, 47*8a20e2b3SKazu Hirata RM.getValueOr(Reloc::Static), 48e1c38dd5SZi Xuan Wu getEffectiveCodeModel(CM, CodeModel::Small), OL), 49e1c38dd5SZi Xuan Wu TLOF(std::make_unique<TargetLoweringObjectFileELF>()) { 50e1c38dd5SZi Xuan Wu initAsmInfo(); 51e1c38dd5SZi Xuan Wu } 52e1c38dd5SZi Xuan Wu 53e1c38dd5SZi Xuan Wu namespace { 54e1c38dd5SZi Xuan Wu class CSKYPassConfig : public TargetPassConfig { 55e1c38dd5SZi Xuan Wu public: 56e1c38dd5SZi Xuan Wu CSKYPassConfig(CSKYTargetMachine &TM, PassManagerBase &PM) 57e1c38dd5SZi Xuan Wu : TargetPassConfig(TM, PM) {} 58e1c38dd5SZi Xuan Wu 59e1c38dd5SZi Xuan Wu CSKYTargetMachine &getCSKYTargetMachine() const { 60e1c38dd5SZi Xuan Wu return getTM<CSKYTargetMachine>(); 61e1c38dd5SZi Xuan Wu } 62e1c38dd5SZi Xuan Wu }; 63e1c38dd5SZi Xuan Wu 64e1c38dd5SZi Xuan Wu } // namespace 65e1c38dd5SZi Xuan Wu 66e1c38dd5SZi Xuan Wu TargetPassConfig *CSKYTargetMachine::createPassConfig(PassManagerBase &PM) { 67e1c38dd5SZi Xuan Wu return new CSKYPassConfig(*this, PM); 68e1c38dd5SZi Xuan Wu } 69