1 // Copyright 2020 The SwiftShader Authors. All Rights Reserved. 2 // 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 #ifndef rr_LLVMAsm_hpp 16 #define rr_LLVMAsm_hpp 17 18 #ifdef ENABLE_RR_EMIT_ASM_FILE 19 20 # include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" 21 # include <string> 22 # include <vector> 23 24 namespace rr { 25 namespace AsmFile { 26 27 // Generate a unique name for the asm file 28 std::string generateFilename(const std::string &emitDir, std::string routineName); 29 30 // Emit an asm file for the current module 31 bool emitAsmFile(const std::string &filename, llvm::orc::JITTargetMachineBuilder builder, llvm::Module &module); 32 33 // Rewrites the previously generated asm file, adding extra useful information. 34 // In particular, it prepends the final resolved location (address) of each instruction. 35 // NOTE: Doing this is error-prone since we parse text, and are thus dependent on the 36 // exact format of LLVM's assembly output. It would be nice if LLVM's asm output included 37 // at least the 0-based relative address of each instruction. 38 void fixupAsmFile(const std::string &filename, std::vector<const void *> addresses); 39 40 } // namespace AsmFile 41 } // namespace rr 42 43 #endif // ENABLE_RR_EMIT_ASM_FILE 44 45 #endif // rr_LLVMAsm_hpp 46