Intel® Implicit SPMD Program Compiler (Intel® ISPC)  1.13.0
bitcode_lib.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2019, Intel Corporation
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11 
12  * Redistributions in binary form must reproduce the above copyright
13  notice, this list of conditions and the following disclaimer in the
14  documentation and/or other materials provided with the distribution.
15 
16  * Neither the name of Intel Corporation nor the names of its
17  contributors may be used to endorse or promote products derived from
18  this software without specific prior written permission.
19 
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 /** @file bitcode_lib.cpp
35  @brief BitcodeLib represents single bitcode library file (either dispatch,
36  Builtiins-c, or ISPCTarget).
37 */
38 
39 #include "bitcode_lib.h"
40 #include "target_registry.h"
41 
42 // Dispatch constructor
43 BitcodeLib::BitcodeLib(const unsigned char lib[], int size, TargetOS os)
44  : m_type(BitcodeLibType::Dispatch), m_lib(lib), m_size(size), m_os(os), m_arch(Arch::none),
45  m_target(ISPCTarget::none) {
47 }
48 // Builtins-c constructor
49 BitcodeLib::BitcodeLib(const unsigned char lib[], int size, TargetOS os, Arch arch)
50  : m_type(BitcodeLibType::Builtins_c), m_lib(lib), m_size(size), m_os(os), m_arch(arch), m_target(ISPCTarget::none) {
52 }
53 // ISPC-target constructor
54 BitcodeLib::BitcodeLib(const unsigned char lib[], int size, ISPCTarget target, TargetOS os, Arch arch)
55  : m_type(BitcodeLibType::ISPC_target), m_lib(lib), m_size(size), m_os(os), m_arch(arch), m_target(target) {
57 }
58 
59 // TODO: this is debug version: either remove or make it use friendly.
60 void BitcodeLib::print() const {
61  const char *type = nullptr;
62  std::string os = OSToString(m_os);
63  switch (m_type) {
65  type = "Dispatch";
66  printf("Type: dispatch. size: %zu, OS: %s\n", m_size, os.c_str());
67  break;
68  }
70  type = "Builtins-c";
71  std::string arch = ArchToString(m_arch);
72  printf("Type: builtins-c. size: %zu, OS: %s, arch: %s\n", m_size, os.c_str(), arch.c_str());
73  break;
74  }
76  type = "ISPC-target";
77  std::string target = ISPCTargetToString(m_target);
78  std::string arch = ArchToString(m_arch);
79  printf("Type: ispc-target. size: %zu, OS: %s, target: %s, arch(runtime) %s\n", m_size, os.c_str(),
80  target.c_str(), arch.c_str());
81  break;
82  }
83  }
84 }
85 
87 const unsigned char *BitcodeLib::getLib() const { return m_lib; }
88 const size_t BitcodeLib::getSize() const { return m_size; }
89 const TargetOS BitcodeLib::getOS() const { return m_os; }
90 const Arch BitcodeLib::getArch() const { return m_arch; }
const TargetOS getOS() const
Definition: bitcode_lib.cpp:89
std::string ArchToString(Arch arch)
ISPCTarget
Definition: target_enums.h:55
TargetOS
Definition: target_enums.h:43
Registry to handle bitcode libraries.
const ISPCTarget getISPCTarget() const
Definition: bitcode_lib.cpp:91
const Arch m_arch
Definition: bitcode_lib.h:56
void print() const
Definition: bitcode_lib.cpp:60
const unsigned char * m_lib
Definition: bitcode_lib.h:51
std::string OSToString(TargetOS os)
BitcodeLib(const unsigned char lib[], int size, TargetOS os)
Definition: bitcode_lib.cpp:43
BitcodeLibType getType() const
Definition: bitcode_lib.cpp:86
std::string ISPCTargetToString(ISPCTarget target)
const unsigned char * getLib() const
Definition: bitcode_lib.cpp:87
static void RegisterTarget(const BitcodeLib *lib)
const TargetOS m_os
Definition: bitcode_lib.h:55
const Arch getArch() const
Definition: bitcode_lib.cpp:90
BitcodeLibType m_type
Definition: bitcode_lib.h:48
a header to host BitcodeLib - a wrapper for single bitcode library.
Arch
Definition: target_enums.h:50
const size_t getSize() const
Definition: bitcode_lib.cpp:88
const ISPCTarget m_target
Definition: bitcode_lib.h:57
const size_t m_size
Definition: bitcode_lib.h:52