Intel® Implicit SPMD Program Compiler (Intel® ISPC)  1.13.0
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Module Class Reference

#include <module.h>

Collaboration diagram for Module:
Collaboration graph
[legend]

Public Types

enum  OutputType {
  Asm, Bitcode, BitcodeText, Object,
  CXX, Header, Deps, DevStub,
  HostStub
}
 
enum  OutputFlags : int {
  NoFlags = 0, GeneratePIC = 0x1, GenerateFlatDeps = 0x2, GenerateMakeRuleForDeps = 0x4,
  OutputDepsToStdout = 0x8
}
 

Public Member Functions

 Module (const char *filename)
 
int CompileFile ()
 
void AddTypeDef (const std::string &name, const Type *type, SourcePos pos)
 
void AddGlobalVariable (const std::string &name, const Type *type, Expr *initExpr, bool isConst, StorageClass storageClass, SourcePos pos)
 
void AddFunctionDeclaration (const std::string &name, const FunctionType *ftype, StorageClass sc, bool isInline, bool isNoInline, SourcePos pos)
 
void AddFunctionDefinition (const std::string &name, const FunctionType *ftype, Stmt *code)
 
void AddExportedTypes (const std::vector< std::pair< const Type *, SourcePos >> &types)
 

Static Public Member Functions

static int CompileAndOutput (const char *srcFile, Arch arch, const char *cpu, std::vector< ISPCTarget > targets, OutputFlags outputFlags, OutputType outputType, const char *outFileName, const char *headerFileName, const char *includeFileName, const char *depsFileName, const char *depsTargetName, const char *hostStubFileName, const char *devStubFileName)
 

Public Attributes

int errorCount
 
SymbolTablesymbolTable
 
llvm::Module * module
 
llvm::DIBuilder * diBuilder
 
llvm::DICompileUnit * diCompileUnit
 

Private Member Functions

bool writeOutput (OutputType ot, OutputFlags flags, const char *filename, const char *includeFileName=NULL, const char *sourceFileName=NULL, DispatchHeaderInfo *DHI=0)
 
bool writeHeader (const char *filename)
 
bool writeDispatchHeader (DispatchHeaderInfo *DHI)
 
bool writeDeps (const char *filename, bool generateMakeRule, const char *targetName=NULL, const char *srcFilename=NULL)
 
bool writeDevStub (const char *filename)
 
bool writeHostStub (const char *filename)
 
bool writeObjectFileOrAssembly (OutputType outputType, const char *filename)
 
void execPreprocessor (const char *infilename, llvm::raw_string_ostream *ostream) const
 

Static Private Member Functions

static bool writeObjectFileOrAssembly (llvm::TargetMachine *targetMachine, llvm::Module *module, OutputType outputType, const char *outFileName)
 
static bool writeBitcode (llvm::Module *module, const char *outFileName, OutputType outputType)
 

Private Attributes

const char * filename
 
ASTast
 
std::vector< std::pair< const Type *, SourcePos > > exportedTypes
 

Detailed Description

Definition at line 51 of file module.h.

Member Enumeration Documentation

◆ OutputFlags

enum Module::OutputFlags : int
Enumerator
NoFlags 
GeneratePIC 
GenerateFlatDeps 
GenerateMakeRuleForDeps 

Dependencies will be output as a flat list.

OutputDepsToStdout 

Dependencies will be output in a make rule format instead of a flat list.

Definition at line 100 of file module.h.

◆ OutputType

After a source file has been compiled, output can be generated in a number of different formats.

Enumerator
Asm 
Bitcode 

Generate text assembly language output

BitcodeText 

Generate LLVM IR bitcode output

Object 

Generate LLVM IR Text output

CXX 

Generate a native object file

Header 

Generate a C++ file

Deps 

Generate a C/C++ header file with declarations of 'export'ed functions, global variables, and the types used by them.

DevStub 

generate dependencies

HostStub 

generate device-side offload stubs generate host-side offload stubs

Definition at line 86 of file module.h.

Constructor & Destructor Documentation

◆ Module()

Module::Module ( const char *  filename)

Member Function Documentation

◆ AddExportedTypes()

void Module::AddExportedTypes ( const std::vector< std::pair< const Type *, SourcePos >> &  types)

Adds the given type to the set of types that have their definitions included in automatically generated header files.

Definition at line 802 of file module.cpp.

References Error(), and exportedTypes.

◆ AddFunctionDeclaration()

void Module::AddFunctionDeclaration ( const std::string &  name,
const FunctionType functionType,
StorageClass  storageClass,
bool  isInline,
bool  isNoInline,
SourcePos  pos 
)

◆ AddFunctionDefinition()

void Module::AddFunctionDefinition ( const std::string &  name,
const FunctionType ftype,
Stmt code 
)

Adds the function described by the declaration information and the provided statements to the module.

Definition at line 783 of file module.cpp.

References AST::AddFunction(), Assert, ast, errorCount, SymbolTable::LookupFunction(), m, Symbol::pos, ASTNode::pos, symbolTable, and Symbol::type.

◆ AddGlobalVariable()

void Module::AddGlobalVariable ( const std::string &  name,
const Type type,
Expr initExpr,
bool  isConst,
StorageClass  storageClass,
SourcePos  pos 
)

◆ AddTypeDef()

void Module::AddTypeDef ( const std::string &  name,
const Type type,
SourcePos  pos 
)

Add a named type definition to the module.

Definition at line 266 of file module.cpp.

References SymbolTable::AddType(), and symbolTable.

◆ CompileAndOutput()

int Module::CompileAndOutput ( const char *  srcFile,
Arch  arch,
const char *  cpu,
std::vector< ISPCTarget targets,
OutputFlags  outputFlags,
OutputType  outputType,
const char *  outFileName,
const char *  headerFileName,
const char *  includeFileName,
const char *  depsFileName,
const char *  depsTargetName,
const char *  hostStubFileName,
const char *  devStubFileName 
)
static

Compile the given source file, generating assembly, object file, or LLVM bitcode output, as well as (optionally) a header file with declarations of functions and types used in the ispc/application interface.

Parameters
srcFilePathname to ispc source file to compile
archTarget architecture (e.g. "x86-64")
cpuTarget CPU (e.g. "core-i7")
targetsTarget ISAs; this parameter may give a single target ISA, or may give a comma-separated list of them in case we are compiling to multiple ISAs.
generatePICIndicates whether position-independent code should be generated.
outputTypeType of output to generate (object files, assembly, LLVM bitcode.)
outFileNameBase name of output filename for object files, etc. If for example the multiple targets "sse2" and "avx" are specified in the "targets" parameter and if this parameter is "foo.o", then we'll generate multiple output files, like "foo.o", "foo_sse2.o", "foo_avx.o".
headerFileNameIf non-NULL, emit a header file suitable for inclusion from C/C++ code with declarations of types and functions exported from the given ispc source file.
includeFileNameIf non-NULL, gives the filename for the C++ backend to emit in an #include statement to get definitions of the builtins for the generic target.
Returns
Number of errors encountered when compiling srcFile.

Definition at line 2390 of file module.cpp.

References Asm, Assert, Bitcode, BitcodeText, CompileFile(), CXX, Deps, DevStub, DispatchHeaderInfo::Emit16, DispatchHeaderInfo::Emit4, DispatchHeaderInfo::Emit8, DispatchHeaderInfo::EmitBackMatter, DispatchHeaderInfo::EmitFrontMatter, DispatchHeaderInfo::EmitFuncs, DispatchHeaderInfo::EmitUnifs, Error(), errorCount, DispatchHeaderInfo::file, DispatchHeaderInfo::fn, g, GeneratePIC, Target::getISA(), Target::GetISAString(), Target::GetTargetMachine(), Header, HostStub, Target::ISAToTargetString(), ISPCTargetIsGeneric(), IsStdin(), Target::isValid(), lEmitDispatchModule(), lExtractOrCheckGlobals(), lGetExportedFunctions(), lGetTargetFileName(), lInitDispatchModule(), m, Globals::mangleFunctionsWithTarget, Module(), module, none, Target::NUM_ISAS, Object, OutputDepsToStdout, ParseISPCTarget(), Globals::printTarget, symbolTable, Globals::target, writeBitcode(), writeObjectFileOrAssembly(), and writeOutput().

Referenced by main().

◆ CompileFile()

int Module::CompileFile ( )

Compiles the source file passed to the Module constructor, adding its global variables and functions to both the llvm::Module and SymbolTable. Returns the number of errors during compilation.

Definition at line 203 of file module.cpp.

References ast, Globals::ctx, DefineStdlib(), diBuilder, errorCount, execPreprocessor(), filename, g, AST::GenerateIR(), Globals::includeStdlib, IsStdin(), Opt::level, Target::markFuncWithTargetAttr(), module, Globals::NoOmitFramePointer, Globals::opt, Optimize(), Globals::runCPP, symbolTable, Globals::target, yy_create_buffer(), yy_delete_buffer(), yy_scan_string(), yy_switch_to_buffer(), yyin, and yyparse().

Referenced by CompileAndOutput().

◆ execPreprocessor()

void Module::execPreprocessor ( const char *  infilename,
llvm::raw_string_ostream *  ostream 
) const
private

◆ writeBitcode()

bool Module::writeBitcode ( llvm::Module *  module,
const char *  outFileName,
OutputType  outputType 
)
staticprivate

Definition at line 917 of file module.cpp.

References Bitcode, and BitcodeText.

Referenced by CompileAndOutput(), and writeOutput().

◆ writeDeps()

bool Module::writeDeps ( const char *  filename,
bool  generateMakeRule,
const char *  targetName = NULL,
const char *  srcFilename = NULL 
)
private

Definition at line 1350 of file module.cpp.

References Globals::debugPrint, g, IsStdin(), lUnescapeStringInPlace(), and registeredDependencies.

Referenced by writeOutput().

◆ writeDevStub()

bool Module::writeDevStub ( const char *  filename)
private

◆ writeDispatchHeader()

bool Module::writeDispatchHeader ( DispatchHeaderInfo DHI)
private

◆ writeHeader()

bool Module::writeHeader ( const char *  filename)
private

◆ writeHostStub()

bool Module::writeHostStub ( const char *  filename)
private

◆ writeObjectFileOrAssembly() [1/2]

bool Module::writeObjectFileOrAssembly ( OutputType  outputType,
const char *  filename 
)
private

Definition at line 950 of file module.cpp.

References g, Target::GetTargetMachine(), module, and Globals::target.

Referenced by CompileAndOutput(), and writeOutput().

◆ writeObjectFileOrAssembly() [2/2]

bool Module::writeObjectFileOrAssembly ( llvm::TargetMachine *  targetMachine,
llvm::Module *  module,
OutputType  outputType,
const char *  outFileName 
)
staticprivate

Definition at line 955 of file module.cpp.

References error, Error(), FATAL, and Object.

◆ writeOutput()

bool Module::writeOutput ( OutputType  ot,
OutputFlags  flags,
const char *  filename,
const char *  includeFileName = NULL,
const char *  sourceFileName = NULL,
DispatchHeaderInfo DHI = 0 
)
private

Write the corresponding output type to the given file. Returns true on success, false if there has been an error. The given filename may be NULL, indicating that output should go to standard output.

Definition at line 815 of file module.cpp.

References Asm, Assert, Bitcode, BitcodeText, CXX, Deps, DevStub, diBuilder, Error(), FATAL, g, Globals::generateDebuggingSymbols, GenerateMakeRuleForDeps, Target::GENERIC, Target::getISA(), Target::getVectorWidth(), Header, HostStub, lStripUnusedDebugInfo(), module, Object, Globals::target, Warning(), writeBitcode(), WriteCXXFile(), writeDeps(), writeDevStub(), writeDispatchHeader(), writeHeader(), writeHostStub(), and writeObjectFileOrAssembly().

Referenced by CompileAndOutput().

Member Data Documentation

◆ ast

AST* Module::ast
private

Definition at line 160 of file module.h.

Referenced by AddFunctionDefinition(), CompileFile(), and Module().

◆ diBuilder

llvm::DIBuilder* Module::diBuilder

◆ diCompileUnit

llvm::DICompileUnit* Module::diCompileUnit

◆ errorCount

int Module::errorCount

Total number of errors encountered during compilation.

Definition at line 144 of file module.h.

Referenced by FunctionEmitContext::AddElementOffset(), AddFunctionDeclaration(), AddFunctionDefinition(), AddGlobalVariable(), FunctionEmitContext::AllocaInst(), FunctionEmitContext::BinaryOperator(), FunctionEmitContext::BitCastInst(), FunctionEmitContext::BranchInst(), FunctionEmitContext::BroadcastValue(), FunctionEmitContext::CallInst(), FunctionEmitContext::CastInst(), FunctionEmitContext::CmpInst(), CompileAndOutput(), CompileFile(), Declaration::DeclareFunctions(), DeclStmt::EmitCode(), ForeachActiveStmt::EmitCode(), ForeachUniqueStmt::EmitCode(), SwitchStmt::EmitCode(), AssertStmt::EmitCode(), DeleteStmt::EmitCode(), Error(), PtrDerefExpr::EstimateCost(), FunctionEmitContext::ExtractInst(), FunctionEmitContext::FPCastInst(), FunctionEmitContext::FunctionEmitContext(), Function::GenerateIR(), ArrayType::GetAsConstType(), ReferenceType::GetAsConstType(), ArrayType::GetAsNonConstType(), ReferenceType::GetAsNonConstType(), ArrayType::GetAsSOAType(), ArrayType::GetAsUnboundVariabilityType(), ReferenceType::GetAsUnboundVariabilityType(), ArrayType::GetAsUniformType(), ReferenceType::GetAsUniformType(), ArrayType::GetAsUnsignedType(), VectorType::GetAsUnsignedType(), ArrayType::GetAsVaryingType(), ReferenceType::GetAsVaryingType(), ReferenceType::GetBaseType(), AtomicType::GetCDeclaration(), EnumType::GetCDeclaration(), PointerType::GetCDeclaration(), ArrayType::GetCDeclaration(), ReferenceType::GetCDeclaration(), AddressOfExpr::GetConstant(), NullPointerExpr::GetConstant(), PointerType::GetDIType(), ArrayType::GetDIType(), ReferenceType::GetDIType(), FunctionEmitContext::GetElementPtrInst(), StructType::GetElementType(), IndexExpr::GetLValue(), MemberExpr::GetLValue(), StructMemberExpr::GetLValueType(), VectorMemberExpr::GetLValueType(), PointerType::GetString(), ArrayType::GetString(), ReferenceType::GetString(), PtrDerefExpr::GetType(), RefDerefExpr::GetType(), AddressOfExpr::GetType(), StructMemberExpr::GetType(), BinaryExpr::GetValue(), AssignExpr::GetValue(), FunctionCallExpr::GetValue(), IndexExpr::GetValue(), MemberExpr::GetValue(), TypeCastExpr::GetValue(), ReferenceExpr::GetValue(), NewExpr::GetValue(), VectorMemberExpr::GetValue(), ReferenceType::GetVariability(), Declaration::GetVariableDeclarations(), FunctionEmitContext::I1VecToBoolVec(), Declarator::InitFromDeclSpecs(), Declarator::InitFromType(), InitSymbol(), FunctionEmitContext::InsertInst(), FunctionEmitContext::IntToPtrInst(), ReferenceType::IsBoolType(), ReferenceType::IsConstType(), ReferenceType::IsFloatType(), ReferenceType::IsIntType(), ReferenceType::IsUnsignedType(), FunctionEmitContext::LaunchInst(), lEmitLogicalOp(), lGetConstExprConstant(), lGetExprListConstant(), lGetVectorLLVMType(), FunctionType::LLVMFunctionType(), PointerType::LLVMType(), ArrayType::LLVMType(), StructType::LLVMType(), UndefinedStructType::LLVMType(), ReferenceType::LLVMType(), FunctionEmitContext::LoadInst(), lVaryingStructHasUniformMember(), PointerType::Mangle(), ArrayType::Mangle(), ReferenceType::Mangle(), FunctionType::Mangle(), FunctionEmitContext::maskedStore(), Module(), FunctionEmitContext::NotOperator(), PerformanceWarning(), FunctionEmitContext::PtrToIntInst(), PointerType::ResolveUnboundVariability(), ArrayType::ResolveUnboundVariability(), ReferenceType::ResolveUnboundVariability(), FunctionType::ResolveUnboundVariability(), FunctionEmitContext::SelectInst(), FunctionEmitContext::SExtInst(), FunctionEmitContext::ShuffleInst(), ArrayType::SizeUnsizedArrays(), FunctionEmitContext::SmearUniform(), FunctionEmitContext::StoreInst(), Target::StructOffset(), StructType::StructType(), FunctionEmitContext::SwitchBoolSize(), FunctionEmitContext::TruncInst(), AssignExpr::TypeCheck(), IndexExpr::TypeCheck(), SwitchStmt::TypeCheck(), PtrDerefExpr::TypeCheck(), RefDerefExpr::TypeCheck(), AddressOfExpr::TypeCheck(), NewExpr::TypeCheck(), Warning(), and FunctionEmitContext::ZExtInst().

◆ exportedTypes

std::vector<std::pair<const Type *, SourcePos> > Module::exportedTypes
private

Definition at line 162 of file module.h.

Referenced by AddExportedTypes(), writeDispatchHeader(), and writeHeader().

◆ filename

const char* Module::filename
private

Definition at line 159 of file module.h.

Referenced by CompileFile(), and Module().

◆ module

llvm::Module* Module::module

◆ symbolTable

SymbolTable* Module::symbolTable

The documentation for this class was generated from the following files: