Intel SPMD Program Compiler  1.9.1
Macros | Functions
builtins.cpp File Reference

Definitions of functions related to setting up the standard library and other builtins. More...

#include "builtins.h"
#include "type.h"
#include "util.h"
#include "sym.h"
#include "expr.h"
#include "llvmutil.h"
#include "module.h"
#include "ctx.h"
#include <math.h>
#include <stdlib.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Intrinsics.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/Linker.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/ADT/Triple.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Bitcode/ReaderWriter.h>
Include dependency graph for builtins.cpp:

Go to the source code of this file.

Macros

#define EXPORT_MODULE_COND_WARN(export_module, warnings)
 
#define EXPORT_MODULE(export_module)
 

Functions

int yyparse ()
 
yy_buffer_state * yy_scan_string (const char *)
 
static const TypelLLVMTypeToISPCType (const llvm::Type *t, bool intAsUnsigned)
 
static void lCreateSymbol (const std::string &name, const Type *returnType, llvm::SmallVector< const Type *, 8 > &argTypes, const llvm::FunctionType *ftype, llvm::Function *func, SymbolTable *symbolTable)
 
static bool lCreateISPCSymbol (llvm::Function *func, SymbolTable *symbolTable)
 
static void lAddModuleSymbols (llvm::Module *module, SymbolTable *symbolTable)
 
static void lCheckModuleIntrinsics (llvm::Module *module)
 
static void lSetInternalFunctions (llvm::Module *module)
 
void AddBitcodeToModule (const unsigned char *bitcode, int length, llvm::Module *module, SymbolTable *symbolTable, bool warn)
 
static void lDefineConstantInt (const char *name, int val, llvm::Module *module, SymbolTable *symbolTable)
 
static void lDefineConstantIntFunc (const char *name, int val, llvm::Module *module, SymbolTable *symbolTable)
 
static void lDefineProgramIndex (llvm::Module *module, SymbolTable *symbolTable)
 
void DefineStdlib (SymbolTable *symbolTable, llvm::LLVMContext *ctx, llvm::Module *module, bool includeStdlibISPC)
 

Detailed Description

Definitions of functions related to setting up the standard library and other builtins.

Definition in file builtins.cpp.

Macro Definition Documentation

#define EXPORT_MODULE (   export_module)
Value:
extern unsigned char export_module[]; \
extern int export_module##_length; \
AddBitcodeToModule(export_module, export_module##_length, \
module, symbolTable, true);

Referenced by DefineStdlib().

#define EXPORT_MODULE_COND_WARN (   export_module,
  warnings 
)
Value:
extern unsigned char export_module[]; \
extern int export_module##_length; \
AddBitcodeToModule(export_module, export_module##_length, \
module, symbolTable, warnings);

Referenced by DefineStdlib().

Function Documentation

void AddBitcodeToModule ( const unsigned char *  bitcode,
int  length,
llvm::Module *  module,
SymbolTable symbolTable,
bool  warn 
)

This utility function takes serialized binary LLVM bitcode and adds its definitions to the given module. Functions in the bitcode that can be mapped to ispc functions are also added to the symbol table.

Parameters
bitcodeBinary LLVM bitcode (e.g. the contents of a *.bc file)
lengthLength of the bitcode buffer
moduleModule to link the bitcode into
symbolTableSymbol table to add definitions to

Definition at line 794 of file builtins.cpp.

References Assert, Globals::ctx, Debug(), Error(), g, Target::getISA(), lAddModuleSymbols(), lCheckModuleIntrinsics(), lSetInternalFunctions(), m, Module::module, Globals::target, VerifyDataLayoutCompatibility(), and Warning().

Referenced by lInitDispatchModule().

void DefineStdlib ( SymbolTable symbolTable,
llvm::LLVMContext *  ctx,
llvm::Module *  module,
bool  includeStdlib 
)

Adds declarations and definitions of ispc standard library functions and types to the given module.

Parameters
symbolTableSymbolTable in which to add symbol definitions for stdlib stuff
ctxllvm::LLVMContext to use for getting types and the like for standard library definitions
moduleModule in which to add the declarations/definitions
includeStdlibIndicates whether the definitions from the stdlib.ispc file should be added to the module.

Definition at line 1113 of file builtins.cpp.

References Assert, Target::AVX, Target::AVX11, Target::AVX2, EXPORT_MODULE, EXPORT_MODULE_COND_WARN, Opt::fastMaskedVload, FATAL, Globals::forceAlignment, g, Target::GENERIC, Target::getDataTypeWidth(), Target::getISA(), Target::getMaskBitCount(), Target::getVectorWidth(), Target::hasHalf(), Target::hasRand(), Target::hasRcpd(), Target::hasRsqrtd(), Target::hasTranscendentals(), Target::hasTrigonometry(), Target::is32Bit(), Target::KNL_AVX512, lDefineConstantInt(), lDefineConstantIntFunc(), lDefineProgramIndex(), LLVMInt32(), Globals::Math_ISPC, Globals::Math_ISPCFast, Globals::Math_SVML, Globals::Math_System, Globals::mathLib, Globals::opt, Target::SKX_AVX512, Target::SSE2, Target::SSE4, Globals::target, yy_scan_string(), and yyparse().

Referenced by Module::CompileFile().

static void lAddModuleSymbols ( llvm::Module *  module,
SymbolTable symbolTable 
)
static

Given an LLVM module, create ispc symbols for the functions in the module.

Definition at line 274 of file builtins.cpp.

References Assert, and lCreateISPCSymbol().

Referenced by AddBitcodeToModule().

static void lCheckModuleIntrinsics ( llvm::Module *  module)
static

In many of the builtins-*.ll files, we have declarations of various LLVM intrinsics that are then used in the implementation of various target- specific functions. This function loops over all of the intrinsic declarations and makes sure that the signature we have in our .ll file matches the signature of the actual intrinsic.

Definition at line 299 of file builtins.cpp.

References Assert, Globals::ctx, and g.

Referenced by AddBitcodeToModule().

static bool lCreateISPCSymbol ( llvm::Function *  func,
SymbolTable symbolTable 
)
static

Given an LLVM function declaration, synthesize the equivalent ispc symbol for the function (if possible). Returns true on success, false on failure.

Definition at line 196 of file builtins.cpp.

References SymbolTable::AddFunction(), Debug(), Type::Equal(), Symbol::function, g, Target::getMaskBitCount(), lCreateSymbol(), lLLVMTypeToISPCType(), SourcePos::name, Globals::target, AtomicType::VaryingBool, and AtomicType::VaryingInt32.

Referenced by lAddModuleSymbols().

static void lCreateSymbol ( const std::string &  name,
const Type returnType,
llvm::SmallVector< const Type *, 8 > &  argTypes,
const llvm::FunctionType *  ftype,
llvm::Function *  func,
SymbolTable symbolTable 
)
static
static void lDefineConstantInt ( const char *  name,
int  val,
llvm::Module *  module,
SymbolTable symbolTable 
)
static

Utility routine that defines a constant int32 with given value, adding the symbol to both the ispc symbol table and the given LLVM module.

Definition at line 939 of file builtins.cpp.

References SymbolTable::AddVariable(), Assert, Symbol::constValue, Module::diBuilder, g, Globals::generateDebuggingSymbols, Type::GetDIType(), LLVMTypes::Int32Type, LLVMInt32(), m, SC_STATIC, Symbol::storagePtr, Symbol::type, and AtomicType::UniformInt32.

Referenced by DefineStdlib().

static void lDefineConstantIntFunc ( const char *  name,
int  val,
llvm::Module *  module,
SymbolTable symbolTable 
)
static
static void lDefineProgramIndex ( llvm::Module *  module,
SymbolTable symbolTable 
)
static
static const Type* lLLVMTypeToISPCType ( const llvm::Type *  t,
bool  intAsUnsigned 
)
static

Given an LLVM type, try to find the equivalent ispc type. Note that this is an under-constrained problem due to LLVM's type representations carrying less information than ispc's. (For example, LLVM doesn't distinguish between signed and unsigned integers in its types.)

Because this function is only used for generating ispc declarations of functions defined in LLVM bitcode in the builtins-*.ll files, in practice we can get enough of what we need for the relevant cases to make things work, partially with the help of the intAsUnsigned parameter, which indicates whether LLVM integer types should be treated as being signed or unsigned.

Definition at line 96 of file builtins.cpp.

References LLVMTypes::BoolType, LLVMTypes::DoublePointerType, LLVMTypes::DoubleType, LLVMTypes::DoubleVectorPointerType, LLVMTypes::DoubleVectorType, LLVMTypes::FloatPointerType, LLVMTypes::FloatType, LLVMTypes::FloatVectorPointerType, LLVMTypes::FloatVectorType, PointerType::GetUniform(), LLVMTypes::Int16PointerType, LLVMTypes::Int16Type, LLVMTypes::Int16VectorPointerType, LLVMTypes::Int16VectorType, LLVMTypes::Int32PointerType, LLVMTypes::Int32Type, LLVMTypes::Int32VectorPointerType, LLVMTypes::Int32VectorType, LLVMTypes::Int64PointerType, LLVMTypes::Int64Type, LLVMTypes::Int64VectorPointerType, LLVMTypes::Int64VectorType, LLVMTypes::Int8PointerType, LLVMTypes::Int8Type, LLVMTypes::Int8VectorPointerType, LLVMTypes::Int8VectorType, LLVMTypes::MaskType, AtomicType::UniformBool, AtomicType::UniformDouble, AtomicType::UniformFloat, AtomicType::UniformInt16, AtomicType::UniformInt32, AtomicType::UniformInt64, AtomicType::UniformInt8, AtomicType::UniformUInt16, AtomicType::UniformUInt32, AtomicType::UniformUInt64, AtomicType::UniformUInt8, AtomicType::VaryingBool, AtomicType::VaryingDouble, AtomicType::VaryingFloat, AtomicType::VaryingInt16, AtomicType::VaryingInt32, AtomicType::VaryingInt64, AtomicType::VaryingInt8, AtomicType::VaryingUInt16, AtomicType::VaryingUInt32, AtomicType::VaryingUInt64, AtomicType::VaryingUInt8, AtomicType::Void, and LLVMTypes::VoidType.

Referenced by lCreateISPCSymbol().

static void lSetInternalFunctions ( llvm::Module *  module)
static

We'd like to have all of these functions declared as 'internal' in their respective bitcode files so that if they aren't needed by the user's program they are elimiated from the final output. However, if we do so, then they aren't brought in by the LinkModules() call below since they aren't yet used by anything in the module they're being linked with (in LLVM 3.1, at least).

Therefore, we don't declare them as internal when we first define them, but instead mark them as internal after they've been linked in. This is admittedly a kludge.

Definition at line 338 of file builtins.cpp.

References g, Target::markFuncWithTargetAttr(), and Globals::target.

Referenced by AddBitcodeToModule().

yy_buffer_state* yy_scan_string ( const char *  )

Referenced by DefineStdlib().

int yyparse ( )

Referenced by DefineStdlib().