1 //===- llvm/Codegen/LinkAllCodegenComponents.h ------------------*- 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 // This header file pulls in all codegen related passes for tools like lli and 10 // llc that need this functionality. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CODEGEN_LINKALLCODEGENCOMPONENTS_H 15 #define LLVM_CODEGEN_LINKALLCODEGENCOMPONENTS_H 16 17 #include "llvm/IR/BuiltinGCs.h" 18 #include "llvm/CodeGen/Passes.h" 19 #include "llvm/CodeGen/SchedulerRegistry.h" 20 #include "llvm/Target/TargetMachine.h" 21 #include <cstdlib> 22 23 namespace { 24 struct ForceCodegenLinking { 25 ForceCodegenLinking() { 26 // We must reference the passes in such a way that compilers will not 27 // delete it all as dead code, even with whole program optimization, 28 // yet is effectively a NO-OP. As the compiler isn't smart enough 29 // to know that getenv() never returns -1, this will do the job. 30 // This is so that globals in the translation units where these functions 31 // are defined are forced to be initialized, populating various 32 // registries. 33 if (std::getenv("bar") != (char*) -1) 34 return; 35 36 (void) llvm::createFastRegisterAllocator(); 37 (void) llvm::createBasicRegisterAllocator(); 38 (void) llvm::createGreedyRegisterAllocator(); 39 (void) llvm::createDefaultPBQPRegisterAllocator(); 40 41 llvm::linkAllBuiltinGCs(); 42 43 (void) llvm::createBURRListDAGScheduler(nullptr, 44 llvm::CodeGenOpt::Default); 45 (void) llvm::createSourceListDAGScheduler(nullptr, 46 llvm::CodeGenOpt::Default); 47 (void) llvm::createHybridListDAGScheduler(nullptr, 48 llvm::CodeGenOpt::Default); 49 (void) llvm::createFastDAGScheduler(nullptr, llvm::CodeGenOpt::Default); 50 (void) llvm::createDefaultScheduler(nullptr, llvm::CodeGenOpt::Default); 51 (void) llvm::createVLIWDAGScheduler(nullptr, llvm::CodeGenOpt::Default); 52 53 } 54 } ForceCodegenLinking; // Force link by creating a global definition. 55 } 56 57 #endif 58