Intel® Implicit SPMD Program Compiler (Intel® ISPC)
1.13.0
|
#include <module.h>
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 |
SymbolTable * | symbolTable |
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 |
AST * | ast |
std::vector< std::pair< const Type *, SourcePos > > | exportedTypes |
enum Module::OutputFlags : int |
enum Module::OutputType |
After a source file has been compiled, output can be generated in a number of different formats.
Module::Module | ( | const char * | filename | ) |
The name of the source file being compiled should be passed as the module name.
Definition at line 131 of file module.cpp.
References ast, Globals::ctx, Globals::currentDirectory, diBuilder, diCompileUnit, Error(), errorCount, filename, g, Globals::generateDebuggingSymbols, Globals::generateDWARFVersion, Target::getDataLayout(), GetDirectoryAndFileName(), Target::GetTripleString(), InitLLVMUtil(), ISPC_VERSION, IsStdin(), lDeclareSizeAndPtrIntTypes(), Opt::level, module, Globals::opt, symbolTable, Globals::target, Globals::target_os, Warning(), windows, yyin, and yyparse().
Referenced by CompileAndOutput().
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.
void Module::AddFunctionDeclaration | ( | const std::string & | name, |
const FunctionType * | functionType, | ||
StorageClass | storageClass, | ||
bool | isInline, | ||
bool | isNoInline, | ||
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 549 of file module.cpp.
References SymbolTable::AddFunction(), Assert, Globals::ctx, Globals::dllExport, Type::Equal(), Error(), errorCount, SourcePos::first_line, Symbol::function, g, Target::GetISAString(), FunctionType::GetNumParameters(), FunctionType::GetParameterDefault(), FunctionType::GetParameterName(), FunctionType::GetParameterSourcePos(), FunctionType::GetParameterType(), FunctionType::GetReturnType(), FunctionType::GetReturnTypeString(), 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, Globals::target_os, Symbol::type, Warning(), and windows.
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 783 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 | ||
) |
Add a new global variable corresponding to the given Symbol to the module. If non-NULL, initExpr gives the initiailizer expression for the global's inital value.
Definition at line 272 of file module.cpp.
References SymbolTable::AddVariable(), Assert, Symbol::constValue, Globals::ctx, diBuilder, Type::Equal(), Error(), errorCount, SourcePos::first_line, g, SourcePos::GetDIFile(), Type::GetDIType(), Expr::GetStorageConstant(), Type::IsConstType(), Globals::isMultiTargetCompilation, Type::IsVoidType(), Type::LLVMStorageType(), SymbolTable::LookupFunction(), SymbolTable::LookupVariable(), module, Symbol::name, SourcePos::name, Optimize(), Symbol::pos, ASTNode::pos, SC_EXTERN, SC_EXTERN_C, SC_STATIC, ArrayType::SizeUnsizedArrays(), Symbol::storageClass, Symbol::storagePtr, symbolTable, ArrayType::TotalElementCount(), Symbol::type, TypeCheck(), TypeConvertExpr(), and Warning().
Add a named type definition to the module.
Definition at line 266 of file module.cpp.
References SymbolTable::AddType(), and symbolTable.
|
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.
srcFile | Pathname to ispc source file to compile |
arch | Target architecture (e.g. "x86-64") |
cpu | Target CPU (e.g. "core-i7") |
targets | Target 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. |
generatePIC | Indicates whether position-independent code should be generated. |
outputType | Type of output to generate (object files, assembly, LLVM bitcode.) |
outFileName | Base 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". |
headerFileName | If 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. |
includeFileName | If 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. |
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().
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().
|
private |
Definition at line 1907 of file module.cpp.
References Globals::cppArgs, Globals::debugPrint, Opt::disableAsserts, Opt::forceAlignedMemory, g, Target::getDataTypeWidth(), Target::GetISAString(), Target::getVectorWidth(), Target::hasHalf(), Target::hasRand(), Target::hasTranscendentals(), Globals::includePath, Globals::includeStdlib, Target::is32Bit(), ISPC_VERSION_MAJOR, ISPC_VERSION_MINOR, module, Globals::opt, and Globals::target.
Referenced by CompileFile().
|
staticprivate |
Definition at line 917 of file module.cpp.
References Bitcode, and BitcodeText.
Referenced by CompileAndOutput(), and writeOutput().
|
private |
Definition at line 1350 of file module.cpp.
References Globals::debugPrint, g, IsStdin(), lUnescapeStringInPlace(), and registeredDependencies.
Referenced by writeOutput().
|
private |
Definition at line 1422 of file module.cpp.
References Assert, emitOffloadParamStruct(), Error(), Type::GetAsNonConstType(), Type::GetCDeclaration(), SymbolTable::GetMatchingFunctions(), FunctionType::GetNumParameters(), FunctionType::GetParameterName(), FunctionType::GetParameterType(), ReferenceType::GetReferenceTarget(), FunctionType::GetReturnType(), Type::GetString(), Type::IsArrayType(), Type::IsConstType(), Type::IsPointerType(), Type::IsReferenceType(), Type::IsVoidType(), lEmitEnumDecls(), lEmitStructDecls(), lEmitVectorTypedefs(), lGetExportedParamTypes(), lIsExported(), lPrintFunctionDeclarations(), m, Symbol::name, Symbol::pos, symbolTable, Symbol::type, and Warning().
Referenced by writeOutput().
|
private |
Definition at line 1791 of file module.cpp.
References DispatchHeaderInfo::Emit16, DispatchHeaderInfo::Emit4, DispatchHeaderInfo::Emit8, DispatchHeaderInfo::EmitBackMatter, DispatchHeaderInfo::EmitFrontMatter, DispatchHeaderInfo::EmitFuncs, Globals::emitInstrumentation, DispatchHeaderInfo::EmitUnifs, exportedTypes, FATAL, DispatchHeaderInfo::file, DispatchHeaderInfo::fn, g, SymbolTable::GetMatchingFunctions(), Target::getVectorWidth(), lEmitEnumDecls(), lEmitStructDecls(), lEmitVectorTypedefs(), lGetExportedParamTypes(), lIsExported(), lIsExternC(), lPrintFunctionDeclarations(), m, Globals::noPragmaOnce, symbolTable, and Globals::target.
Referenced by writeOutput().
|
private |
Definition at line 1675 of file module.cpp.
References Globals::emitInstrumentation, exportedTypes, FATAL, g, SymbolTable::GetMatchingFunctions(), lEmitEnumDecls(), lEmitStructDecls(), lEmitVectorTypedefs(), lGetExportedParamTypes(), lIsExported(), lIsExternC(), lPrintFunctionDeclarations(), m, Globals::noPragmaOnce, and symbolTable.
Referenced by writeOutput().
|
private |
Definition at line 1557 of file module.cpp.
References Assert, emitOffloadParamStruct(), FunctionType::GetCDeclaration(), SymbolTable::GetMatchingFunctions(), FunctionType::GetNumParameters(), FunctionType::GetParameterName(), FunctionType::GetParameterType(), FunctionType::GetReturnType(), Type::IsArrayType(), Type::IsPointerType(), Type::IsVoidType(), lEmitEnumDecls(), lEmitStructDecls(), lEmitVectorTypedefs(), lGetExportedParamTypes(), lIsExported(), m, Symbol::name, Symbol::pos, symbolTable, Symbol::type, and Warning().
Referenced by writeOutput().
|
private |
Definition at line 950 of file module.cpp.
References g, Target::GetTargetMachine(), module, and Globals::target.
Referenced by CompileAndOutput(), and writeOutput().
|
staticprivate |
|
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().
|
private |
Definition at line 160 of file module.h.
Referenced by AddFunctionDefinition(), CompileFile(), and Module().
llvm::DIBuilder* Module::diBuilder |
The diBuilder manages generating debugging information
Definition at line 154 of file module.h.
Referenced by FunctionEmitContext::AddDebugPos(), AddGlobalVariable(), CompileFile(), FunctionEmitContext::EmitFunctionParameterDebugInfo(), FunctionEmitContext::EmitVariableDebugInfo(), FunctionEmitContext::EndScope(), FunctionEmitContext::FunctionEmitContext(), SourcePos::GetDIFile(), AtomicType::GetDIType(), EnumType::GetDIType(), PointerType::GetDIType(), VectorType::GetDIType(), StructType::GetDIType(), UndefinedStructType::GetDIType(), ReferenceType::GetDIType(), FunctionType::GetDIType(), lCreateDIArray(), lDefineConstantInt(), lDefineProgramIndex(), Module(), FunctionEmitContext::StartScope(), writeOutput(), and FunctionEmitContext::~FunctionEmitContext().
llvm::DICompileUnit* Module::diCompileUnit |
Definition at line 156 of file module.h.
Referenced by FunctionEmitContext::FunctionEmitContext(), lDefineConstantInt(), lDefineProgramIndex(), and Module().
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().
Definition at line 162 of file module.h.
Referenced by AddExportedTypes(), writeDispatchHeader(), and writeHeader().
|
private |
Definition at line 159 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 151 of file module.h.
Referenced by AddBitcodeToModule(), AddFunctionDeclaration(), AddGlobalVariable(), FunctionEmitContext::AddInstrumentationPoint(), FunctionEmitContext::CallInst(), CompileAndOutput(), CompileFile(), DeclStmt::EmitCode(), ForeachActiveStmt::EmitCode(), ForeachUniqueStmt::EmitCode(), PrintStmt::EmitCode(), AssertStmt::EmitCode(), DeleteStmt::EmitCode(), execPreprocessor(), FunctionEmitContext::FunctionEmitContext(), FunctionEmitContext::gather(), Function::GenerateIR(), StructType::GetDIType(), FunctionEmitContext::GetStringPtr(), NewExpr::GetValue(), InitSymbol(), FunctionEmitContext::LaunchInst(), lCreateDispatchFunction(), lGetBinaryIntrinsic(), lGetStringAsValue(), lGSBaseOffsetsGetMoreConst(), lGSToGSBaseOffsets(), lGSToLoadStore(), lImproveMaskedLoad(), lImproveMaskedStore(), lInitDispatchModule(), lReplacePseudoGS(), lReplacePseudoMaskedStore(), FunctionEmitContext::maskedStore(), FunctionEmitContext::MasksAllEqual(), FunctionEmitContext::MemcpyInst(), Module(), IntrinsicsOpt::runOnBasicBlock(), GatherCoalescePass::runOnBasicBlock(), IsCompileTimeConstantPass::runOnBasicBlock(), ReplaceStdlibShiftPass::runOnBasicBlock(), MakeInternalFuncsStaticPass::runOnModule(), FunctionEmitContext::scatter(), InstructionSimplifyPass::simplifyCall(), SourcePos::SourcePos(), FunctionEmitContext::SyncInst(), writeObjectFileOrAssembly(), and writeOutput().
SymbolTable* Module::symbolTable |
Symbol table to hold symbols visible in the current scope during compilation.
Definition at line 148 of file module.h.
Referenced by AddFunctionDeclaration(), AddFunctionDefinition(), AddGlobalVariable(), AddTypeDef(), FunctionEmitContext::All(), FunctionEmitContext::Any(), CompileAndOutput(), CompileFile(), DeclSpecs::DeclSpecs(), ForeachUniqueStmt::ForeachUniqueStmt(), Function::Function(), Declaration::GetVariableDeclarations(), FunctionEmitContext::LaneMask(), lCreateBinaryOperatorCall(), lExtractOrCheckGlobals(), FunctionEmitContext::LoadInst(), Module(), FunctionEmitContext::None(), BinaryExpr::Optimize(), writeDevStub(), writeDispatchHeader(), writeHeader(), and writeHostStub().