Intel SPMD Program Compiler  1.10.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

Public Types

enum  OutputType {
  Asm, Bitcode, 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, 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, const char *arch, const char *cpu, const char *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
llvm::Module * module
llvm::DIBuilder * diBuilder

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)

Private Attributes

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

Detailed Description

Definition at line 57 of file module.h.

Member Enumeration Documentation

enum Module::OutputFlags : int

Dependencies will be output as a flat list.


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

Definition at line 109 of file module.h.

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


Generate text assembly language output


Generate LLVM IR bitcode output


Generate a native object file


Generate a C++ file


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


generate dependencies


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

Definition at line 97 of file module.h.

Constructor & Destructor Documentation

Module::Module ( const char *  filename)

Member Function Documentation

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 1212 of file module.cpp.

References Error(), and exportedTypes.

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

Add a declaration of the function defined by the given function symbol to the module.

We've got a declaration for a function to process. This function does all the work of creating the corresponding llvm::Function instance, adding the symbol for the function to the symbol table and doing various sanity checks. This function returns true upon success and false if any errors were encountered.

Definition at line 924 of file module.cpp.

References SymbolTable::AddFunction(), Assert, Globals::ctx, Globals::dllExport, Type::Equal(), Error(), errorCount, SourcePos::first_line, Symbol::function, g, Target::GENERIC, Target::getISA(), Target::GetISAString(), FunctionType::GetNumParameters(), FunctionType::GetParameterDefault(), FunctionType::GetParameterName(), FunctionType::GetParameterSourcePos(), FunctionType::GetParameterType(), FunctionType::GetReturnType(), FunctionType::GetReturnTypeString(), Target::getTreatGenericAsSmth(), FunctionType::isExported, FunctionType::isExternC, FunctionType::isTask, Type::IsUniformType(), Type::IsVoidType(), lCheckExportedParameterTypes(), lCheckForStructParameters(), FunctionType::LLVMFunctionType(), SymbolTable::LookupFunction(), SymbolTable::LookupVariable(), lRecursiveCheckValidParamType(), m, FunctionType::Mangle(), Globals::mangleFunctionsWithTarget, Target::markFuncWithTargetAttr(), module, SourcePos::name, Symbol::pos, RoundUpPow2(), SC_EXTERN_C, SC_STATIC, symbolTable, Globals::target, Symbol::type, AtomicType::Void, and Warning().

Referenced by Declaration::DeclareFunctions().

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 1190 of file module.cpp.

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

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

Add a named type definition to the module.

Definition at line 556 of file module.cpp.

References SymbolTable::AddType(), and symbolTable.

int Module::CompileAndOutput ( const char *  srcFile,
const char *  arch,
const char *  cpu,
const char *  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 

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.

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.
Number of errors encountered when compiling srcFile.

Definition at line 3171 of file module.cpp.

References Asm, Assert, Bitcode, 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::GENERIC, Target::getISA(), Target::GetISAString(), Target::GetTargetMachine(), Target::getTreatGenericAsSmth(), Header, HostStub, Target::ISAToTargetString(), Target::isValid(), lEmitDispatchModule(), lExtractOrCheckGlobals(), lExtractTargets(), lGetExportedFunctions(), lGetTargetFileName(), lInitDispatchModule(), m, Globals::mangleFunctionsWithTarget, Module(), module, Target::NUM_ISAS, Object, OutputDepsToStdout, Globals::printTarget, symbolTable, Globals::target, writeBitcode(), writeObjectFileOrAssembly(), and writeOutput().

Referenced by main().

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 489 of file module.cpp.

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

Referenced by CompileAndOutput().

void Module::execPreprocessor ( const char *  infilename,
llvm::raw_string_ostream *  ostream 
) const
bool Module::writeBitcode ( llvm::Module *  module,
const char *  outFileName 

Definition at line 1436 of file module.cpp.

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

Referenced by CompileAndOutput(), and writeOutput().

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

Definition at line 1991 of file module.cpp.

References lUnescapeStringInPlace(), and registeredDependencies.

Referenced by writeOutput().

bool Module::writeDevStub ( const char *  filename)
bool Module::writeDispatchHeader ( DispatchHeaderInfo DHI)
bool Module::writeHeader ( const char *  filename)
bool Module::writeHostStub ( const char *  filename)
bool Module::writeObjectFileOrAssembly ( OutputType  outputType,
const char *  filename 

Definition at line 1508 of file module.cpp.

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

Referenced by CompileAndOutput(), and writeOutput().

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

Definition at line 1516 of file module.cpp.

References g, Target::getDataLayout(), Object, and Globals::target.

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

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 1228 of file module.cpp.

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

Referenced by CompileAndOutput().

Member Data Documentation

AST* Module::ast

Definition at line 179 of file module.h.

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

llvm::DIBuilder* Module::diBuilder
int Module::errorCount

Total number of errors encountered during compilation.

Definition at line 159 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(), ExprList::GetConstant(), ConstExpr::GetConstant(), 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(), FunctionType::LLVMFunctionType(), PointerType::LLVMType(), ArrayType::LLVMType(), VectorType::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::TruncInst(), AssignExpr::TypeCheck(), IndexExpr::TypeCheck(), SwitchStmt::TypeCheck(), PtrDerefExpr::TypeCheck(), RefDerefExpr::TypeCheck(), AddressOfExpr::TypeCheck(), NewExpr::TypeCheck(), Warning(), and FunctionEmitContext::ZExtInst().

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

Definition at line 181 of file module.h.

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

const char* Module::filename

Definition at line 178 of file module.h.

Referenced by CompileFile(), and Module().

llvm::Module* Module::module

llvm Module object into which globals and functions are added.

Definition at line 166 of file module.h.

Referenced by AddBitcodeToModule(), AddFunctionDeclaration(), FunctionEmitContext::AddInstrumentationPoint(), FunctionEmitContext::CallInst(), CompileAndOutput(), CreateFixBooleanSelectPass(), Function::emitCode(), DeclStmt::EmitCode(), ForeachActiveStmt::EmitCode(), ForeachUniqueStmt::EmitCode(), PrintStmt::EmitCode(), AssertStmt::EmitCode(), DeleteStmt::EmitCode(), FunctionEmitContext::FunctionEmitContext(), FunctionEmitContext::gather(), Function::GenerateIR(), StructType::GetDIType(), FunctionEmitContext::GetStringPtr(), NewExpr::GetValue(), InitSymbol(), FunctionEmitContext::LaneMask(), FunctionEmitContext::LaunchInst(), lCreateDispatchFunction(), lGetStringAsValue(), lGSBaseOffsetsGetMoreConst(), lGSToGSBaseOffsets(), lGSToLoadStore(), lHasUnsizedArrays(), lImproveMaskedLoad(), lImproveMaskedStore(), lInitDispatchModule(), lReplacePseudoGS(), lReplacePseudoMaskedStore(), lUpdateVaryingCounter(), FunctionEmitContext::maskedStore(), FunctionEmitContext::MemcpyInst(), PeepholePass::PeepholePass(), FunctionEmitContext::ProgramIndexVector(), IntrinsicsOpt::runOnBasicBlock(), GatherCoalescePass::runOnBasicBlock(), IsCompileTimeConstantPass::runOnBasicBlock(), ReplaceStdlibShiftPass::runOnBasicBlock(), MakeInternalFuncsStaticPass::runOnModule(), FunctionEmitContext::scatter(), InstructionSimplifyPass::simplifyCall(), SourcePos::SourcePos(), and FunctionEmitContext::SyncInst().

SymbolTable* Module::symbolTable

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