Intel® Implicit SPMD Program Compiler (Intel® ISPC)
1.13.0
|
Impementation of the Module class, which collects the result of compiling a source file and then generates output (object files, etc.) More...
#include "module.h"
#include "builtins.h"
#include "ctx.h"
#include "expr.h"
#include "func.h"
#include "llvmutil.h"
#include "opt.h"
#include "stmt.h"
#include "sym.h"
#include "type.h"
#include "util.h"
#include <algorithm>
#include <ctype.h>
#include <fcntl.h>
#include <set>
#include <sstream>
#include <stdarg.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "llvm/IR/LegacyPassManager.h"
#include <clang/Basic/TargetInfo.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Frontend/Utils.h>
#include <clang/Lex/PreprocessorOptions.h>
#include <llvm/Analysis/TargetTransformInfo.h>
#include <llvm/Bitcode/BitcodeWriter.h>
#include <llvm/IR/CFG.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/IRPrintingPasses.h>
#include <llvm/IR/InstIterator.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Intrinsics.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/Verifier.h>
#include <llvm/PassRegistry.h>
#include <llvm/Support/FileUtilities.h>
#include <llvm/Support/FormattedStream.h>
#include <llvm/Support/Host.h>
#include <llvm/Support/ToolOutputFile.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/Utils/ValueMapper.h>
Go to the source code of this file.
Classes | |
struct | DispatchHeaderInfo |
struct | FunctionTargetVariants |
Macros | |
#define | UNESCAPE_SEQ(c, esc) |
Typedefs | |
typedef struct yy_buffer_state * | YY_BUFFER_STATE |
Functions | |
void | RegisterDependency (const std::string &fileName) |
static void | lDeclareSizeAndPtrIntTypes (SymbolTable *symbolTable) |
static void | lStripUnusedDebugInfo (llvm::Module *module) |
int | yyparse () |
void | yy_switch_to_buffer (YY_BUFFER_STATE) |
YY_BUFFER_STATE | yy_scan_string (const char *) |
YY_BUFFER_STATE | yy_create_buffer (FILE *, int) |
void | yy_delete_buffer (YY_BUFFER_STATE) |
static bool | lRecursiveCheckValidParamType (const Type *t, bool vectorOk) |
static void | lCheckExportedParameterTypes (const Type *type, const std::string &name, SourcePos pos) |
static void | lCheckForStructParameters (const FunctionType *ftype, SourcePos pos) |
static const StructType * | lGetElementStructType (const Type *t) |
static bool | lContainsPtrToVarying (const StructType *st) |
static void | lEmitStructDecl (const StructType *st, std::vector< const StructType *> *emittedStructs, FILE *file, bool emitUnifs=true) |
static void | lEmitStructDecls (std::vector< const StructType *> &structTypes, FILE *file, bool emitUnifs=true) |
static void | lEmitEnumDecls (const std::vector< const EnumType *> &enumTypes, FILE *file) |
static void | lEmitVectorTypedefs (const std::vector< const VectorType *> &types, FILE *file) |
template<typename T > | |
static void | lAddTypeIfNew (const Type *type, std::vector< const T *> *exportedTypes) |
static void | lGetExportedTypes (const Type *type, std::vector< const StructType *> *exportedStructTypes, std::vector< const EnumType *> *exportedEnumTypes, std::vector< const VectorType *> *exportedVectorTypes) |
static void | lGetExportedParamTypes (const std::vector< Symbol *> &funcs, std::vector< const StructType *> *exportedStructTypes, std::vector< const EnumType *> *exportedEnumTypes, std::vector< const VectorType *> *exportedVectorTypes) |
static void | lPrintFunctionDeclarations (FILE *file, const std::vector< Symbol *> &funcs, bool useExternC=1, bool rewriteForDispatch=false) |
static bool | lIsExported (const Symbol *sym) |
static bool | lIsExternC (const Symbol *sym) |
static void | lUnescapeStringInPlace (std::string &str) |
std::string | emitOffloadParamStruct (const std::string ¶mStructName, const Symbol *sym, const FunctionType *fct) |
static std::string | lGetTargetFileName (const char *outFileName, const char *isaString) |
static bool | lSymbolIsExported (const Symbol *s) |
static void | lGetExportedFunctions (SymbolTable *symbolTable, std::map< std::string, FunctionTargetVariants > &functions) |
static llvm::FunctionType * | lGetVaryingDispatchType (FunctionTargetVariants &funcs) |
static void | lCreateDispatchFunction (llvm::Module *module, llvm::Function *setISAFunc, llvm::Value *systemBestISAPtr, const std::string &name, FunctionTargetVariants &funcs) |
static llvm::Module * | lInitDispatchModule () |
static void | lEmitDispatchModule (llvm::Module *module, std::map< std::string, FunctionTargetVariants > &functions) |
static bool | lCompatibleTypes (llvm::Type *Ty1, llvm::Type *Ty2) |
static void | lExtractOrCheckGlobals (llvm::Module *msrc, llvm::Module *mdst, bool check) |
Variables | |
std::set< std::string > | registeredDependencies |
FILE * | yyin |
Impementation of the Module class, which collects the result of compiling a source file and then generates output (object files, etc.)
Definition in file module.cpp.
#define UNESCAPE_SEQ | ( | c, | |
esc | |||
) |
Referenced by lUnescapeStringInPlace().
typedef struct yy_buffer_state* YY_BUFFER_STATE |
Definition at line 197 of file module.cpp.
std::string emitOffloadParamStruct | ( | const std::string & | paramStructName, |
const Symbol * | sym, | ||
const FunctionType * | fct | ||
) |
Definition at line 1388 of file module.cpp.
References Error(), Type::GetAsNonConstType(), Type::GetCDeclaration(), FunctionType::GetNumParameters(), FunctionType::GetParameterName(), FunctionType::GetParameterType(), ReferenceType::GetReferenceTarget(), Type::GetString(), Type::IsArrayType(), Type::IsConstType(), Type::IsPointerType(), Type::IsReferenceType(), and Symbol::pos.
Referenced by Module::writeDevStub(), and Module::writeHostStub().
|
static |
Add the given type to the vector, if that type isn't already in there.
Definition at line 1208 of file module.cpp.
References Assert, Type::Equal(), and Type::GetAsNonConstType().
Referenced by lGetExportedTypes().
|
static |
Given a Symbol representing a function parameter, see if it or any contained types are varying. If so, issue an error. (This function should only be called for parameters to 'export'ed functions, where varying parameters is illegal.
Definition at line 505 of file module.cpp.
References Error(), Type::GetBaseType(), and lRecursiveCheckValidParamType().
Referenced by Module::AddFunctionDeclaration().
|
static |
Given a function type, loop through the function parameters and see if any are StructTypes. If so, issue an error; this is currently broken (https://github.com/ispc/ispc/issues/3).
Definition at line 531 of file module.cpp.
References Error(), FunctionType::GetNumParameters(), and FunctionType::GetParameterType().
Referenced by Module::AddFunctionDeclaration().
|
static |
Definition at line 2311 of file module.cpp.
Referenced by lExtractOrCheckGlobals().
|
static |
Definition at line 1019 of file module.cpp.
References StructType::GetElementCount(), StructType::GetElementType(), and Type::IsVaryingType().
Referenced by lEmitStructDecl().
|
static |
Create the dispatch function for an exported ispc function. This function checks to see which vector ISAs the system the code is running on supports and calls out to the best available variant that was generated at compile time.
module | Module in which to create the dispatch function. |
setISAFunc | Pointer to the __set_system_isa() function defined in builtins-dispatch.ll (which is linked into the given module before we get here.) |
systemBestISAPtr | Pointer to the module-local __system_best_isa variable, which holds a value of the Target::ISA enumerant giving the most capable ISA that the system supports. |
name | Name of the function for which we're generating a dispatch function |
funcs | Target-specific variants of the exported function. |
Definition at line 2157 of file module.cpp.
References Assert, Globals::ctx, FunctionTargetVariants::func, g, lGetVaryingDispatchType(), LLVMInt32(), Module::module, and Target::NUM_ISAS.
Referenced by lEmitDispatchModule().
|
static |
Definition at line 106 of file module.cpp.
References SymbolTable::AddType(), Opt::force32BitAddressing, g, Type::GetAsUnboundVariabilityType(), Type::GetAsUnsignedType(), Target::is32Bit(), Globals::opt, Globals::target, AtomicType::VaryingInt32, AtomicType::VaryingInt64, AtomicType::VaryingUInt32, and AtomicType::VaryingUInt64.
Referenced by Module::Module().
|
static |
Definition at line 2290 of file module.cpp.
References Assert, and lCreateDispatchFunction().
Referenced by Module::CompileAndOutput().
|
static |
Emit C declarations of enumerator types to the generated header file.
Definition at line 1133 of file module.cpp.
References Assert, Symbol::constValue, ConstExpr::GetValues(), and Symbol::name.
Referenced by Module::writeDevStub(), Module::writeDispatchHeader(), Module::writeHeader(), and Module::writeHostStub().
|
static |
Emits a declaration for the given struct to the given file. This function first makes sure that declarations for any structs that are (recursively) members of this struct are emitted first.
Definition at line 1036 of file module.cpp.
References Globals::ctx, Type::EqualIgnoringConst(), g, Type::GetAsNonConstType(), Type::GetCDeclaration(), StructType::GetCStructName(), Target::getDataLayout(), StructType::GetElementCount(), StructType::GetElementName(), StructType::GetElementType(), Type::GetSOAWidth(), Target::getVectorWidth(), Type::IsArrayType(), Type::IsPointerType(), Type::IsVaryingType(), lContainsPtrToVarying(), lGetElementStructType(), Type::LLVMType(), StructType::LLVMType(), and Globals::target.
Referenced by lEmitStructDecls().
|
static |
Given a set of structures that we want to print C declarations of in a header file, emit their declarations.
Definition at line 1112 of file module.cpp.
References lEmitStructDecl().
Referenced by Module::writeDevStub(), Module::writeDispatchHeader(), Module::writeHeader(), and Module::writeHostStub().
|
static |
Print declarations of VectorTypes used in 'export'ed parts of the program in the header file.
Definition at line 1171 of file module.cpp.
References Globals::ctx, g, VectorType::GetAsNonConstType(), VectorType::GetBaseType(), Type::GetCDeclaration(), Target::getDataLayout(), VectorType::GetElementCount(), Type::IsUniformType(), VectorType::LLVMType(), and Globals::target.
Referenced by Module::writeDevStub(), Module::writeDispatchHeader(), Module::writeHeader(), and Module::writeHostStub().
|
static |
Definition at line 2343 of file module.cpp.
References Assert, lCompatibleTypes(), SymbolTable::LookupVariable(), m, Symbol::pos, Module::symbolTable, and Warning().
Referenced by Module::CompileAndOutput().
|
static |
Given a pointer to an element of a structure, see if it is a struct type or an array of a struct type. If so, return a pointer to the underlying struct type.
Definition at line 1007 of file module.cpp.
References ArrayType::GetElementType().
Referenced by lEmitStructDecl().
|
static |
Definition at line 2086 of file module.cpp.
References FunctionTargetVariants::FTs, FunctionTargetVariants::func, g, Target::getISA(), SymbolTable::GetMatchingFunctions(), lSymbolIsExported(), and Globals::target.
Referenced by Module::CompileAndOutput().
|
static |
Given a set of functions, return the set of structure and vector types present in the parameters to them.
Definition at line 1265 of file module.cpp.
References Assert, FunctionType::GetNumParameters(), FunctionType::GetParameterType(), FunctionType::GetReturnType(), and lGetExportedTypes().
Referenced by Module::writeDevStub(), Module::writeDispatchHeader(), Module::writeHeader(), and Module::writeHostStub().
|
static |
Given an arbitrary type that appears in the app/ispc interface, add it to an appropriate vector if it is a struct, enum, or short vector type. Then, if it's a struct, recursively process its members to do the same.
Definition at line 1226 of file module.cpp.
References Assert, Type::GetBaseType(), ArrayType::GetElementType(), Type::GetReferenceTarget(), and lAddTypeIfNew().
Referenced by lGetExportedParamTypes().
|
static |
Definition at line 2039 of file module.cpp.
Referenced by Module::CompileAndOutput().
|
static |
Definition at line 2096 of file module.cpp.
References Assert, Globals::ctx, FunctionTargetVariants::FTs, FunctionTargetVariants::func, g, FunctionType::GetNumParameters(), FunctionType::GetParameterType(), Type::IsPointerType(), Type::IsVaryingType(), and Target::NUM_ISAS.
Referenced by lCreateDispatchFunction().
|
static |
Definition at line 2268 of file module.cpp.
References AddBitcodeToModule(), Assert, Globals::ctx, g, Target::getDataLayout(), TargetLibRegistry::getDispatchLib(), Target::GetTripleString(), Module::module, Globals::target, and Globals::target_registry.
Referenced by Module::CompileAndOutput().
|
static |
Definition at line 1307 of file module.cpp.
References Assert, FunctionType::isExported, and Symbol::type.
Referenced by Module::writeDevStub(), Module::writeDispatchHeader(), Module::writeHeader(), and Module::writeHostStub().
|
static |
Definition at line 1313 of file module.cpp.
References Assert, FunctionType::isExternC, and Symbol::type.
Referenced by Module::writeDispatchHeader(), and Module::writeHeader().
|
static |
Definition at line 1283 of file module.cpp.
References Assert, FunctionType::GetCDeclaration(), and FunctionType::GetCDeclarationForDispatch().
Referenced by Module::writeDevStub(), Module::writeDispatchHeader(), and Module::writeHeader().
|
static |
Given an arbitrary type, see if it or any of the leaf types contained in it has a type that's illegal to have exported to C/C++ code.
(Note that it's fine for the original struct or a contained struct to be varying, so long as all of its members have bound 'uniform' variability.)
This functions returns true and issues an error if are any illegal types are found and returns false otherwise.
Definition at line 465 of file module.cpp.
References StructType::GetElementCount(), SequentialType::GetElementType(), StructType::GetElementType(), and Type::IsVaryingType().
Referenced by Module::AddFunctionDeclaration(), and lCheckExportedParameterTypes().
|
static |
After compilation completes, there's often a lot of extra debugging metadata left around that isn't needed any more–for example, for static functions that weren't actually used, function information for functions that were inlined, etc. This function takes a llvm::Module and tries to strip out all of this extra stuff.
Definition at line 126 of file module.cpp.
Referenced by Module::writeOutput().
|
static |
Definition at line 2065 of file module.cpp.
References Symbol::exportedFunction.
Referenced by lGetExportedFunctions().
|
static |
Definition at line 1319 of file module.cpp.
References UNESCAPE_SEQ.
Referenced by Module::writeDeps().
void RegisterDependency | ( | const std::string & | fileName | ) |
this is where the parser tells us that it has seen the given file name in the CPP hash
Definition at line 101 of file module.cpp.
References registeredDependencies.
YY_BUFFER_STATE yy_create_buffer | ( | FILE * | , |
int | |||
) |
Referenced by Module::CompileFile().
void yy_delete_buffer | ( | YY_BUFFER_STATE | ) |
Referenced by Module::CompileFile().
YY_BUFFER_STATE yy_scan_string | ( | const char * | ) |
Referenced by Module::CompileFile().
void yy_switch_to_buffer | ( | YY_BUFFER_STATE | ) |
Referenced by Module::CompileFile().
int yyparse | ( | ) |
Referenced by Module::CompileFile(), and Module::Module().
std::set<std::string> registeredDependencies |
list of files encountered by the parser. this allows emitting of the module file's dependencies via the -MMM option
Definition at line 97 of file module.cpp.
Referenced by RegisterDependency(), and Module::writeDeps().
FILE* yyin |
Referenced by Module::CompileFile(), and Module::Module().