1 /* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LIBLLVMBACKEND_TARGET_MACHINE_BUILDER_H 17 #define LIBLLVMBACKEND_TARGET_MACHINE_BUILDER_H 18 19 #include <llvm/Target/TargetMachine.h> 20 21 namespace ark::llvmbackend { 22 23 class TargetMachineBuilder { 24 public: 25 TargetMachineBuilder &SetFeatures(const std::vector<std::string> &features); 26 SetOptLevel(llvm::CodeGenOpt::Level level)27 TargetMachineBuilder &SetOptLevel(llvm::CodeGenOpt::Level level) 28 { 29 optlevel_ = level; 30 return *this; 31 } 32 SetCPU(std::string cpu)33 TargetMachineBuilder &SetCPU(std::string cpu) 34 { 35 cpu_ = std::move(cpu); 36 return *this; 37 } 38 SetTriple(llvm::Triple triple)39 TargetMachineBuilder &SetTriple(llvm::Triple triple) 40 { 41 triple_ = std::move(triple); 42 return *this; 43 } 44 45 llvm::Expected<std::unique_ptr<llvm::TargetMachine>> Build(); 46 47 private: 48 std::string features_; 49 llvm::CodeGenOpt::Level optlevel_ {llvm::CodeGenOpt::Level::Default}; 50 std::string cpu_; 51 llvm::Triple triple_; 52 }; 53 } // namespace ark::llvmbackend 54 #endif // LIBLLVMBACKEND_TARGET_MACHINE_BUILDER_H 55