提交 ee5fb851 编写于 作者: F Foyzur Rahman 提交者: Karthikeyan Jambu Rajaraman

Renaming code_generator to codegen_utils and CodeGenerator to

CodegenUtils.
This closes #648
Signed-off-by: NFoyzur Rahman <frahman@gmail.com>
上级 7a457bd8
......@@ -113,7 +113,7 @@ include_directories(${CLANG_INCLUDE_DIRS})
# Core codegen library.
add_library(gpcodegen SHARED
utils/clang_compiler.cc
utils/code_generator.cc
utils/codegen_utils.cc
${codegen_tmpfile_sources})
if(APPLE)
set(WL_START_GROUP "")
......@@ -166,7 +166,7 @@ add_custom_target(unittest-check ${CMAKE_CTEST_COMMAND})
SET(TEST_SOURCES
tests/clang_compiler_unittest.cc
tests/code_generator_unittest.cc
tests/codegen_utils_unittest.cc
tests/instance_method_wrappers_unittest.cc)
# Googletest framework for tests.
......
......@@ -43,7 +43,7 @@ struct AnnotatedType {
*
* @tparam T A C++ scalar type.
* @param llvm_type The type's representation in LLVM, obtained by calling
* CodeGenerator::GetType<T>() or similar.
* CodegenUtils::GetType<T>() or similar.
* @return An AnnotatedType that includes additional information about T not
* captured by the llvm::Type.
**/
......@@ -67,7 +67,7 @@ struct AnnotatedType {
* @tparam T A C++ void pointer type with any combination of const and/or
* volatile qualifiers.
* @param llvm_type The type's representation in LLVM, obtained by calling
* CodeGenerator::GetType<T>() or similar.
* CodegenUtils::GetType<T>() or similar.
* @return An AnnotatedType that includes additional information about the
* void pointer type T not captured by the llvm::Type.
**/
......
......@@ -22,8 +22,8 @@
#include <string>
#include <type_traits>
#include "codegen/utils/code_generator.h"
#include "codegen/utils/macros.h"
#include "codegen/utils/codegen_utils.h"
namespace llvm { class Twine; }
......@@ -44,10 +44,10 @@ struct AnnotatedType;
* more user-friendly for programmers. The basic workflow for code generation
* from C++ is as follows:
*
* 1. Create a CodeGenerator object to manage the actual compilation and
* 1. Create a CodegenUtils object to manage the actual compilation and
* execution.
* 2. Create a ClangCompiler object to act as front-end for compiling C++
* source code for use with the CodeGenerator.
* source code for use with the CodegenUtils.
* 3. Build up C++ source code from in-memory strings as an llvm::Twine
* (llvm's Twine class is a string-like data type that allows for
* efficient concatenation). Note that any generated functions that we
......@@ -55,13 +55,13 @@ struct AnnotatedType;
* and can be refered to by an ordinary non-mangled name when they are
* compiled.
* 4. Call ClangCompiler::CompileCppSource() to compile C++ source code into
* an llvm Module managed by the CodeGenerator.
* 5. Call CodeGenerator::Optimize() and CodeGenerator::PrepareForExecution()
* an llvm Module managed by the CodegenUtils.
* 5. Call CodegenUtils::Optimize() and CodegenUtils::PrepareForExecution()
* to compile the code and get it ready to execute. Note that we would do
* the same thing to compile generated IR code, except that it makes sense
* to use higher levels of optimization when starting from C++ sources, as
* the initial output of the clang frontend is NOT well-optimized IR.
* 6. Call CodeGenerator::GetFunctionPointer() to get a callable function
* 6. Call CodegenUtils::GetFunctionPointer() to get a callable function
* pointer to any desired generated function.
**/
class ClangCompiler {
......@@ -69,23 +69,23 @@ class ClangCompiler {
/**
* @brief Constructor.
*
* @param code_generator The CodeGenerator instance to compile with. The
* specified CodeGenerator's LLVMContext will be used, and all
* @param codegen_utils The CodegenUtils instance to compile with. The
* specified CodegenUtils's LLVMContext will be used, and all
* successfully-compiled modules will be inserted into the
* CodeGenerator.
* CodegenUtils.
**/
explicit ClangCompiler(CodeGenerator* code_generator)
: code_generator_(code_generator) {
explicit ClangCompiler(CodegenUtils* codegen_utils)
: code_generator_(codegen_utils) {
}
/**
* @brief Compile a C++ source-code snippet (i.e. an in-memory translation
* unit) to an LLVM IR Module and place it in the CodeGenerator.
* unit) to an LLVM IR Module and place it in the CodegenUtils.
*
* @note It is recommended to mark any function you wish to call from outside
* of generated code as extern "C" so that its name will not be mangled
* and you can easily retrieve it by name from
* CodeGenerator::GetFunctionPointer().
* CodegenUtils::GetFunctionPointer().
*
* @param source_code The C++ source code to compile.
* @param debug If true, generate additional debugging information and dump
......@@ -115,7 +115,7 @@ class ClangCompiler {
* becomes a pointer, otherwise the distinction is preserved).
*
* @param annotated_type An AnnotatedType created by
* CodeGenerator::GetAnnotatedType().
* CodegenUtils::GetAnnotatedType().
* @return The equivalent of annotated_type as a C++ type (in string form).
**/
static std::string CppTypeFromAnnotatedType(
......@@ -123,17 +123,17 @@ class ClangCompiler {
/**
* @brief Generate forward-declarations for the named external functions
* registered in the CodeGenerator that this ClangCompiler is attached
* registered in the CodegenUtils that this ClangCompiler is attached
* to.
*
* This allows (named) external functions registered with
* CodeGenerator::RegisterExternalFunction() to be called from generated C++
* CodegenUtils::RegisterExternalFunction() to be called from generated C++
* code. The string returned by this method can be concatenated with other
* C++ source code that calls the external function(s) and passed to
* CompileCppSource() for compilation.
*
* @return A C++ source snippet with forward declarations (marked extern "C")
* for each named external function registered in the CodeGenerator.
* for each named external function registered in the CodegenUtils.
**/
std::string GenerateExternalFunctionDeclarations() const;
......@@ -154,7 +154,7 @@ class ClangCompiler {
std::string GetLiteralConstant(const CppType constant_value);
private:
CodeGenerator* code_generator_;
CodegenUtils* code_generator_;
DISALLOW_COPY_AND_ASSIGN(ClangCompiler);
};
......@@ -175,7 +175,7 @@ std::string HexDouble(const double value);
// ConstantPrinter has template specializations to handle different categories
// of C++ types. Specializations provide a static Print() method that takes a
// const CppType 'value' and a CodeGenerator* pointer (referring to the
// const CppType 'value' and a CodegenUtils* pointer (referring to the
// 'code_generator_' member of the calling ClangCompiler) and returns a string
// containing a C++ source snippet that parses to the original literal 'value'.
template <typename CppType, typename Enable = void>
......@@ -186,7 +186,7 @@ class ConstantPrinter {
template <>
class ConstantPrinter<bool> {
public:
static std::string Print(const bool value, CodeGenerator* code_generator) {
static std::string Print(const bool value, CodegenUtils* codegen_utils) {
return value ? "true" : "false";
}
};
......@@ -197,12 +197,12 @@ class ConstantPrinter<
IntType,
typename std::enable_if<std::is_integral<IntType>::value>::type> {
public:
static std::string Print(const IntType value, CodeGenerator* code_generator) {
static std::string Print(const IntType value, CodegenUtils* codegen_utils) {
// Enclose the literal in a static_cast that transforms it to the exact type
// expected.
std::string literal("static_cast<");
literal.append(ClangCompiler::CppTypeFromAnnotatedType(
code_generator->template GetAnnotatedType<IntType>()));
codegen_utils->template GetAnnotatedType<IntType>()));
literal.append(">(");
literal.append(std::to_string(value));
......@@ -231,7 +231,7 @@ class ConstantPrinter<
template <>
class ConstantPrinter<float> {
public:
static std::string Print(const float value, CodeGenerator* code_generator) {
static std::string Print(const float value, CodegenUtils* codegen_utils) {
// Get an unambiguously-rounded representation of the literal, then append
// an "f" to denote that the literal is a 32-bit float instead of a 64-bit
// double.
......@@ -245,7 +245,7 @@ class ConstantPrinter<float> {
template <>
class ConstantPrinter<double> {
public:
static std::string Print(const double value, CodeGenerator* code_generator) {
static std::string Print(const double value, CodegenUtils* codegen_utils) {
return HexDouble(value);
}
};
......@@ -258,11 +258,11 @@ class ConstantPrinter<
typename std::enable_if<std::is_enum<EnumType>::value>::type> {
public:
static std::string Print(const EnumType value,
CodeGenerator* code_generator) {
CodegenUtils* codegen_utils) {
return ConstantPrinter<typename std::underlying_type<EnumType>::type>
::Print(static_cast<typename std::underlying_type<EnumType>::type>(
value),
code_generator);
codegen_utils);
}
};
......@@ -271,18 +271,18 @@ template <typename PointedType>
class ConstantPrinter<PointedType*> {
public:
static std::string Print(PointedType* const value,
CodeGenerator* code_generator) {
CodegenUtils* codegen_utils) {
if (value == nullptr) {
std::string literal("static_cast<");
literal.append(ClangCompiler::CppTypeFromAnnotatedType(
code_generator->template GetAnnotatedType<PointedType*>()));
codegen_utils->template GetAnnotatedType<PointedType*>()));
literal.append(">(nullptr)");
return literal;
} else {
// Cast the literal address to the appropriate pointer type.
std::string literal("reinterpret_cast<");
literal.append(ClangCompiler::CppTypeFromAnnotatedType(
code_generator->template GetAnnotatedType<PointedType*>()));
codegen_utils->template GetAnnotatedType<PointedType*>()));
literal.append(">(");
// Write the literal address in integer form.
......@@ -298,7 +298,7 @@ template <>
class ConstantPrinter<std::nullptr_t> {
public:
static std::string Print(std::nullptr_t value,
CodeGenerator* code_generator) {
CodegenUtils* codegen_utils) {
return "nullptr";
}
};
......
......@@ -3,7 +3,7 @@
// Copyright 2016 Pivotal Software, Inc.
//
// @filename:
// code_generator.h
// codegen_utils.h
//
// @doc:
// Object that manages runtime code generation for a single LLVM module.
......@@ -13,8 +13,8 @@
//
//---------------------------------------------------------------------------
#ifndef GPCODEGEN_CODE_GENERATOR_H_
#define GPCODEGEN_CODE_GENERATOR_H_
#ifndef GPCODEGEN_CODEGEN_UTILS_H_
#define GPCODEGEN_CODEGEN_UTILS_H_
#include <cassert>
#include <cstddef>
......@@ -45,9 +45,9 @@
namespace gpcodegen {
// Forward declaration of helper class for friending purposes.
namespace code_generator_detail {
namespace codegen_utils_detail {
template <typename, typename> class ConstantMaker;
} // namespace code_generator_detail
} // namespace codegen_utils_detail
/** \addtogroup codegen
* @{
......@@ -56,7 +56,7 @@ template <typename, typename> class ConstantMaker;
/**
* @brief Object that manages runtime code generation for a single LLVM module.
**/
class CodeGenerator {
class CodegenUtils {
public:
enum class OptimizationLevel : unsigned {
kNone = 0, // -O0
......@@ -75,17 +75,17 @@ class CodeGenerator {
* @brief Constructor.
*
* @param module_name A human-readable name for the module that this
* CodeGenerator will manage.
* CodegenUtils will manage.
**/
explicit CodeGenerator(llvm::StringRef module_name);
explicit CodegenUtils(llvm::StringRef module_name);
~CodeGenerator() {
~CodegenUtils() {
}
/**
* @brief Initialize global LLVM state (in particular, information about the
* host machine which will be the target for code generation). Must be
* called at least once before creating CodeGenerator objects.
* called at least once before creating CodegenUtils objects.
*
* @return true if initilization was successful, false if some part of
* initialization failed.
......@@ -100,10 +100,10 @@ class CodeGenerator {
}
/**
* @return The LLVM Module that is managed by this CodeGenerator, or NULL if
* @return The LLVM Module that is managed by this CodegenUtils, or NULL if
* PrepareForExecution() has already been called.
*
* @note When a CodeGenerator is initially created, a Module is created with
* @note When a CodegenUtils is initially created, a Module is created with
* it and it is accessible via this method. The Module is mutable and
* new code can be inserted into it UNTIL PrepareForExecution() is
* called, at which point the Module's code is "frozen" and can no
......@@ -135,7 +135,7 @@ class CodeGenerator {
*
* @tparam CppType a C++ type to map to an LLVM type.
* @return A pointer to CppType's equivalent LLVM type in this
* CodeGenerator's context.
* CodegenUtils's context.
**/
template <typename CppType>
llvm::Type* GetType();
......@@ -162,7 +162,7 @@ class CodeGenerator {
* @tparam ReturnType The function's return type.
* @tparam ArgumentTypes The types of any number of arguments to the function.
* @return A pointer to the complete function type-signature's equivalent as
* an LLVM FunctionType in this CodeGenerator's context.
* an LLVM FunctionType in this CodegenUtils's context.
**/
template <typename ReturnType, typename... ArgumentTypes>
llvm::FunctionType* GetFunctionType();
......@@ -179,7 +179,7 @@ class CodeGenerator {
*
* @param constant_value A C++ value to map to an LLVM constant.
* @return A pointer to an llvm::Constant object with constant_value's value
* in this CodeGenerator's context.
* in this CodegenUtils's context.
**/
template <typename CppType>
llvm::Constant* GetConstant(const CppType constant_value);
......@@ -221,7 +221,7 @@ class CodeGenerator {
/**
* @brief Create an LLVM function in the module managed by this
* CodeGenerator.
* CodegenUtils.
*
* @note This method creates an empty Function object with no body. Caller
* can then create BasicBlocks inside the Function to implement its
......@@ -235,7 +235,7 @@ class CodeGenerator {
* ExternalLinkage, which makes the function visible and callable from
* anywhere.
* @return A pointer to a newly-created empty function in this
* CodeGenerator's module (object is owned by this CodeGenerator).
* CodegenUtils's module (object is owned by this CodegenUtils).
**/
template <typename ReturnType, typename... ArgumentTypes>
llvm::Function* CreateFunction(
......@@ -250,7 +250,7 @@ class CodeGenerator {
}
/**
* @brief Create a new BasicBlock inside a Function in this CodeGenerator's
* @brief Create a new BasicBlock inside a Function in this CodegenUtils's
* module.
*
* @param name The name of the BasicBlock. This is not required to be unique,
......@@ -294,9 +294,9 @@ class CodeGenerator {
* These do not need to be specified if external_function is not
* overloaded (they will be inferred automatically).
* @param external_function A function pointer to install for use in this
* CodeGenerator.
* CodegenUtils.
* @param name An optional name to refer to the external function by. If
* non-empty, this CodeGenerator will record additional information
* non-empty, this CodegenUtils will record additional information
* so that the registered function will also be callable by its name
* in C++ source code compiled by ClangCompiler (see
* ClangCompiler::GenerateExternalFunctionDeclarations()).
......@@ -320,7 +320,7 @@ class CodeGenerator {
}
/**
* @brief Optimize the code in the module managed by this CodeGenerator before
* @brief Optimize the code in the module managed by this CodegenUtils before
* execution.
*
* This method applies "generic" IR-to-IR optimization passes and is intended
......@@ -349,7 +349,7 @@ class CodeGenerator {
const bool optimize_for_host_cpu);
/**
* @brief Prepare code generated by this CodeGenerator for execution.
* @brief Prepare code generated by this CodegenUtils for execution.
*
* Internally, this creates an LLVM MCJIT ExecutionEngine and gives ownership
* of the Module to it. Actual compilation of functions may be deferred until
......@@ -372,7 +372,7 @@ class CodeGenerator {
/**
* @brief Get a pointer to the compiled machine-code version of a function
* generated by this CodeGenerator.
* generated by this CodegenUtils.
*
* @note PrepareForExecution() should be called before calling this method.
*
......@@ -404,7 +404,7 @@ class CodeGenerator {
friend class ClangCompiler;
template <typename, typename>
friend class code_generator_detail::ConstantMaker;
friend class codegen_utils_detail::ConstantMaker;
// Allow ClangCompilerTest to inspect 'auxiliary_modules_' to check if they
// have debugging information attached.
......@@ -471,7 +471,7 @@ class CodeGenerator {
llvm::LLVMContext context_;
llvm::IRBuilder<> ir_builder_;
// Primary module directly managed by this CodeGenerator.
// Primary module directly managed by this CodegenUtils.
std::unique_ptr<llvm::Module> module_;
// Additional modules to codegen from, generated by tools like ClangCompiler.
......@@ -495,26 +495,27 @@ class CodeGenerator {
std::vector<std::pair<const std::string, const std::uint64_t>>
external_global_variables_;
// Counters for external variables/functions registered in this CodeGenerator.
// Counters for external variables/functions registered in this CodegenUtils.
// Used by GenerateExternalVariableName() and GenerateExternalFunctionName(),
// respectively, to generate unique names for functions/globals.
unsigned external_variable_counter_;
unsigned external_function_counter_;
DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
DISALLOW_COPY_AND_ASSIGN(CodegenUtils);
};
/** @} */
// ----------------------------------------------------------------------------
// Implementation of CodeGenerator::GetType() and
// CodeGenerator::GetAnnotatedType().
// Implementation of CodegenUtils::GetType() and
// CodegenUtils::GetAnnotatedType().
// Because function template partial specialization is not allowed, we use
// helper classes to implement GetType() and GetAnnotatedType(). They are
// encapsulated in this nested namespace, which is not considered part of the
// public API.
namespace code_generator_detail {
namespace codegen_utils_detail {
// type_traits-style template that detects whether 'T' is bool, or a const
// and/or volatile qualified version of bool.
......@@ -708,28 +709,28 @@ class TypeMaker<ReferentType&> {
}
};
} // namespace code_generator_detail
} // namespace codegen_utils_detail
template <typename CppType>
llvm::Type* CodeGenerator::GetType() {
return code_generator_detail::TypeMaker<CppType>::Get(&context_);
llvm::Type* CodegenUtils::GetType() {
return codegen_utils_detail::TypeMaker<CppType>::Get(&context_);
}
template <typename CppType>
AnnotatedType CodeGenerator::GetAnnotatedType() {
return code_generator_detail::TypeMaker<CppType>::GetAnnotated(&context_);
AnnotatedType CodegenUtils::GetAnnotatedType() {
return codegen_utils_detail::TypeMaker<CppType>::GetAnnotated(&context_);
}
// ----------------------------------------------------------------------------
// Implementation of CodeGenerator::GetFunctionType().
// Implementation of CodegenUtils::GetFunctionType().
// Helper template classes are nested in this namespace and are not considered
// part of the public API.
namespace code_generator_detail {
namespace codegen_utils_detail {
// TypeVectorBuilder is a variadic template. Specializations of
// TypeVectorBuilder have a two static methods AppendTypes() and
// AppendAnnotatedTypes(). AppendTypes() takes a 'CodeGenerator*' pointer and a
// AppendAnnotatedTypes(). AppendTypes() takes a 'CodegenUtils*' pointer and a
// pointer to a vector of 'llvm::Type*' pointers.
// Calling TypeVectorBuilder<ArgumentTypes...>::AppendTypes() appends the
// equivalent llvm::Type for each of 'ArgumentTypes' to the vector. Similarly,
......@@ -742,12 +743,12 @@ class TypeVectorBuilder;
template <>
class TypeVectorBuilder<> {
public:
static void AppendTypes(CodeGenerator* generator,
static void AppendTypes(CodegenUtils* generator,
std::vector<llvm::Type*>* types) {
}
static void AppendAnnotatedTypes(
CodeGenerator* generator,
CodegenUtils* generator,
std::vector<AnnotatedType>* annotated_types) {
}
};
......@@ -759,16 +760,16 @@ class TypeVectorBuilder<HeadType, TailTypes...> {
public:
static_assert(!std::is_same<HeadType, void>::value,
"void is not allowed as an argument type for "
"gpcodegen::CodeGenerator::GetFunctionType()");
"gpcodegen::CodegenUtils::GetFunctionType()");
static void AppendTypes(CodeGenerator* generator,
static void AppendTypes(CodegenUtils* generator,
std::vector<llvm::Type*>* types) {
types->push_back(generator->GetType<HeadType>());
TypeVectorBuilder<TailTypes...>::AppendTypes(generator, types);
}
static void AppendAnnotatedTypes(
CodeGenerator* generator,
CodegenUtils* generator,
std::vector<AnnotatedType>* annotated_types) {
annotated_types->emplace_back(generator->GetAnnotatedType<HeadType>());
TypeVectorBuilder<TailTypes...>::AppendAnnotatedTypes(generator,
......@@ -776,29 +777,29 @@ class TypeVectorBuilder<HeadType, TailTypes...> {
}
};
} // namespace code_generator_detail
} // namespace codegen_utils_detail
template <typename ReturnType, typename... ArgumentTypes>
llvm::FunctionType* CodeGenerator::GetFunctionType() {
llvm::FunctionType* CodegenUtils::GetFunctionType() {
std::vector<llvm::Type*> argument_types;
code_generator_detail::TypeVectorBuilder<ArgumentTypes...>::AppendTypes(
codegen_utils_detail::TypeVectorBuilder<ArgumentTypes...>::AppendTypes(
this,
&argument_types);
return llvm::FunctionType::get(GetType<ReturnType>(), argument_types, false);
}
// ----------------------------------------------------------------------------
// Implementation of CodeGenerator::GetConstant().
// Implementation of CodegenUtils::GetConstant().
// Helper template classes are nested in this namespace and are not considered
// part of the public API.
namespace code_generator_detail {
namespace codegen_utils_detail {
// ConstantMaker has various template specializations to handle constants of
// different C++ types. The specialized versions have a static method Get()
// that takes a 'constant_value' of type 'const CppType' and a pointer to
// a CodeGenerator object, and returns a pointer to an llvm::Constant
// equivalent to 'constant_value' in the CodeGenerator's context.
// a CodegenUtils object, and returns a pointer to an llvm::Constant
// equivalent to 'constant_value' in the CodegenUtils's context.
template <typename CppType, typename Enable = void>
class ConstantMaker {
};
......@@ -815,7 +816,7 @@ class ConstantMaker<
"Unable to make an integer constant wider than 64 bits.");
static llvm::Constant* Get(const UnsignedIntType constant_value,
CodeGenerator* generator) {
CodegenUtils* generator) {
return llvm::ConstantInt::get(generator->GetType<UnsignedIntType>(),
constant_value);
}
......@@ -833,7 +834,7 @@ class ConstantMaker<
"Unable to make an integer constant wider than 64 bits.");
static llvm::Constant* Get(const SignedIntType constant_value,
CodeGenerator* generator) {
CodegenUtils* generator) {
return llvm::ConstantInt::getSigned(generator->GetType<SignedIntType>(),
constant_value);
}
......@@ -846,7 +847,7 @@ class ConstantMaker<
typename std::enable_if<std::is_enum<EnumType>::value>::type> {
public:
static llvm::Constant* Get(const EnumType constant_value,
CodeGenerator* generator) {
CodegenUtils* generator) {
typedef typename std::underlying_type<EnumType>::type EnumAsIntType;
return ConstantMaker<EnumAsIntType>::Get(
static_cast<EnumAsIntType>(constant_value),
......@@ -859,7 +860,7 @@ template <>
class ConstantMaker<float> {
public:
static llvm::Constant* Get(const float constant_value,
CodeGenerator* generator) {
CodegenUtils* generator) {
return llvm::ConstantFP::get(generator->GetType<float>(),
constant_value);
}
......@@ -870,7 +871,7 @@ template <>
class ConstantMaker<double> {
public:
static llvm::Constant* Get(const double constant_value,
CodeGenerator* generator) {
CodegenUtils* generator) {
return llvm::ConstantFP::get(generator->GetType<double>(),
constant_value);
}
......@@ -881,7 +882,7 @@ template <typename PointedType>
class ConstantMaker<PointedType*> {
public:
static llvm::Constant* Get(const PointedType* constant_value,
CodeGenerator* generator) {
CodegenUtils* generator) {
if (constant_value == nullptr) {
return llvm::ConstantPointerNull::get(
static_cast<llvm::PointerType*>(generator->GetType<PointedType*>()));
......@@ -895,22 +896,22 @@ class ConstantMaker<PointedType*> {
}
};
} // namespace code_generator_detail
} // namespace codegen_utils_detail
template <typename CppType>
llvm::Constant* CodeGenerator::GetConstant(const CppType constant_value) {
return code_generator_detail::ConstantMaker<CppType>::Get(constant_value,
llvm::Constant* CodegenUtils::GetConstant(const CppType constant_value) {
return codegen_utils_detail::ConstantMaker<CppType>::Get(constant_value,
this);
}
// ----------------------------------------------------------------------------
// Implementation of recursive variadic version of
// CodeGenerator::GetPointerToMemberImpl().
// CodegenUtils::GetPointerToMemberImpl().
template <typename StructType,
typename MemberType,
typename... TailPointerToMemberTypes>
llvm::Value* CodeGenerator::GetPointerToMemberImpl(
llvm::Value* CodegenUtils::GetPointerToMemberImpl(
llvm::Value* base_ptr,
llvm::Type* cast_type,
const std::size_t cumulative_offset,
......@@ -940,14 +941,14 @@ llvm::Value* CodeGenerator::GetPointerToMemberImpl(
}
// ----------------------------------------------------------------------------
// Implementation of CodeGenerator::RecordNamedExternalFunction()
// Implementation of CodegenUtils::RecordNamedExternalFunction()
template <typename ReturnType, typename... ArgumentTypes>
void CodeGenerator::RecordNamedExternalFunction(const std::string& name) {
void CodegenUtils::RecordNamedExternalFunction(const std::string& name) {
NamedExternalFunction named_external_fn{name,
GetAnnotatedType<ReturnType>(),
{}};
code_generator_detail::TypeVectorBuilder<ArgumentTypes...>
codegen_utils_detail::TypeVectorBuilder<ArgumentTypes...>
::AppendAnnotatedTypes(this,
&named_external_fn.argument_types);
......@@ -956,5 +957,5 @@ void CodeGenerator::RecordNamedExternalFunction(const std::string& name) {
} // namespace gpcodegen
#endif // GPCODEGEN_CODE_GENERATOR_H_
#endif // GPCODEGEN_CODEGEN_UTILS_H_
// EOF
......@@ -221,7 +221,7 @@ ClassType* WrapPlacementNew(void* place, ArgumentTypes... args) {
* @brief Templated wrapper function that invokes the 'new' operator with the
* move constructor for a class (if any) to move-from an existing object.
*
* @note This template works around the fact that CodeGenerator does not handle
* @note This template works around the fact that CodegenUtils does not handle
* rvalue-references. It takes a pointer which it dereferences and
* converts to an rvalue-reference that is moved-from.
*
......@@ -240,7 +240,7 @@ ClassType* WrapNewMove(ClassType* original) {
* 'new' operator with the move constructor for a class (if any) to
* move-from an existing object.
*
* @note This template works around the fact that CodeGenerator does not handle
* @note This template works around the fact that CodegenUtils does not handle
* rvalue-references. It takes a pointer which it dereferences and
* converts to an rvalue-reference that is moved-from.
* @warning All of the usual caveats about placement new also apply here, e.g.
......
......@@ -17,6 +17,7 @@
#define GPCODEGEN_UTILITY_H_
#include "llvm/IR/Function.h"
#include <utility>
namespace gpcodegen {
......@@ -32,7 +33,7 @@ namespace gpcodegen {
* @return A pointer to the specified argument, or NULL if the specified
* position was beyond the end of function's arguments.
**/
llvm::Argument* ArgumentByPosition(llvm::Function* function,
static llvm::Argument* ArgumentByPosition(llvm::Function* function,
const unsigned position) {
llvm::Function::arg_iterator it = function->arg_begin();
if (it == function->arg_end()) {
......
......@@ -12,8 +12,8 @@
#include "codegen/init_codegen.h"
#include "codegen/utils/code_generator.h"
#include "codegen/utils/codegen_utils.h"
extern "C" int InitCodeGen() {
return gpcodegen::CodeGenerator::InitializeGlobal() ? 0 : 1;
extern "C" int InitCodegen() {
return gpcodegen::CodegenUtils::InitializeGlobal() ? 0 : 1;
}
......@@ -18,7 +18,8 @@
#include <type_traits>
#include "codegen/utils/clang_compiler.h"
#include "codegen/utils/code_generator.h"
#include "codegen/utils/codegen_utils.h"
#include "codegen/utils/instance_method_wrappers.h"
#include "gtest/gtest.h"
#include "llvm/ADT/Twine.h"
......@@ -52,35 +53,35 @@ enum class UInt16Enum : std::uint16_t {
class ClangCompilerTestEnvironment : public ::testing::Environment {
public:
virtual void SetUp() {
ASSERT_TRUE(CodeGenerator::InitializeGlobal());
ASSERT_TRUE(CodegenUtils::InitializeGlobal());
}
};
class ClangCompilerTest : public ::testing::Test {
protected:
virtual void SetUp() {
code_generator_.reset(new CodeGenerator("test_module"));
clang_compiler_.reset(new ClangCompiler(code_generator_.get()));
codegen_utils_.reset(new CodegenUtils("test_module"));
clang_compiler_.reset(new ClangCompiler(codegen_utils_.get()));
}
// Check whether the auxiliary module specified by 'idx' in 'code_generator_'
// Check whether the auxiliary module specified by 'idx' in 'codegen_utils_'
// has debugging metadata attached.
bool AuxiliaryModuleHasDebugInfo(const std::size_t idx) {
// The "compile unit" (i.e. translation unit) level debugging info emitted
// by the clang frontend is called "llvm.dbg.cu".
return code_generator_->auxiliary_modules_.at(idx)->getNamedMetadata(
return codegen_utils_->auxiliary_modules_.at(idx)->getNamedMetadata(
"llvm.dbg.cu")
!= nullptr;
}
// Helper method for CppTypeFromAnnotatedTypeTest. Checks that invoking
// ClangCompiler::CppTypeFromAnnotatedType() on the AnnotatedType produced
// by CodeGenerator::GetType<T>() returns 'expected_cpp_type'.
// by CodegenUtils::GetType<T>() returns 'expected_cpp_type'.
template <typename T>
void CheckCppTypeFromAnnotatedType(const std::string& expected_cpp_type) {
EXPECT_EQ(expected_cpp_type,
ClangCompiler::CppTypeFromAnnotatedType(
code_generator_->GetAnnotatedType<T>()));
codegen_utils_->GetAnnotatedType<T>()));
}
template <typename T>
......@@ -90,7 +91,7 @@ class ClangCompilerTest : public ::testing::Test {
clang_compiler_->GetLiteralConstant(original_value));
}
std::unique_ptr<CodeGenerator> code_generator_;
std::unique_ptr<CodegenUtils> codegen_utils_;
std::unique_ptr<ClangCompiler> clang_compiler_;
};
......@@ -113,12 +114,12 @@ TEST_F(ClangCompilerTest, BasicCompilationTest) {
EXPECT_TRUE(clang_compiler_->CompileCppSource(kBasicCompilationSource));
// Now do actual codegen and try and call the function.
EXPECT_TRUE(code_generator_->PrepareForExecution(
CodeGenerator::OptimizationLevel::kNone,
EXPECT_TRUE(codegen_utils_->PrepareForExecution(
CodegenUtils::OptimizationLevel::kNone,
false));
unsigned (*binomial_coefficient)(const unsigned, const unsigned)
= code_generator_->GetFunctionPointer<unsigned,
= codegen_utils_->GetFunctionPointer<unsigned,
const unsigned,
const unsigned>(
"binomial_coefficient");
......@@ -159,12 +160,12 @@ TEST_F(ClangCompilerTest, MultiModuleCompilationTest) {
kMultiModuleBinomialCoeffecientSource));
// Now do actual codegen and try and call the function.
EXPECT_TRUE(code_generator_->PrepareForExecution(
CodeGenerator::OptimizationLevel::kNone,
EXPECT_TRUE(codegen_utils_->PrepareForExecution(
CodegenUtils::OptimizationLevel::kNone,
false));
unsigned (*binomial_coefficient)(const unsigned, const unsigned)
= code_generator_->GetFunctionPointer<unsigned,
= codegen_utils_->GetFunctionPointer<unsigned,
const unsigned,
const unsigned>(
"binomial_coefficient");
......@@ -375,17 +376,17 @@ static const char kExternalFunctionBinomialCoefficientSource[] =
} // namespace
TEST_F(ClangCompilerTest, ExternalFunctionTest) {
code_generator_->RegisterExternalFunction(&factorial, "factorial");
codegen_utils_->RegisterExternalFunction(&factorial, "factorial");
EXPECT_TRUE(clang_compiler_->CompileCppSource(
llvm::Twine(clang_compiler_->GenerateExternalFunctionDeclarations())
.concat(kExternalFunctionBinomialCoefficientSource)));
EXPECT_TRUE(code_generator_->PrepareForExecution(
CodeGenerator::OptimizationLevel::kNone,
EXPECT_TRUE(codegen_utils_->PrepareForExecution(
CodegenUtils::OptimizationLevel::kNone,
false));
unsigned (*binomial_coefficient)(const unsigned, const unsigned)
= code_generator_->GetFunctionPointer<unsigned,
= codegen_utils_->GetFunctionPointer<unsigned,
const unsigned,
const unsigned>(
"binomial_coefficient");
......@@ -434,16 +435,16 @@ static const char kExternalMethodInvocationSource[] =
} // namespace
TEST_F(ClangCompilerTest, ExternalMethodTest) {
code_generator_->RegisterExternalFunction(
codegen_utils_->RegisterExternalFunction(
&WrapNew<Accumulator<double>, double>,
"new_Accumulator");
code_generator_->RegisterExternalFunction(
codegen_utils_->RegisterExternalFunction(
&WrapDelete<Accumulator<double>>,
"delete_Accumulator");
code_generator_->RegisterExternalFunction(
codegen_utils_->RegisterExternalFunction(
&GPCODEGEN_WRAP_METHOD(&Accumulator<double>::Accumulate),
"Accumulator_Accumulate");
code_generator_->RegisterExternalFunction(
codegen_utils_->RegisterExternalFunction(
&GPCODEGEN_WRAP_METHOD(&Accumulator<double>::Get),
"Accumulator_Get");
......@@ -451,12 +452,12 @@ TEST_F(ClangCompilerTest, ExternalMethodTest) {
llvm::Twine(clang_compiler_->GenerateExternalFunctionDeclarations())
.concat(kExternalMethodInvocationSource)));
EXPECT_TRUE(code_generator_->PrepareForExecution(
CodeGenerator::OptimizationLevel::kNone,
EXPECT_TRUE(codegen_utils_->PrepareForExecution(
CodegenUtils::OptimizationLevel::kNone,
false));
double (*AddWithAccumulator)(const double, const double, const double)
= code_generator_->GetFunctionPointer<double,
= codegen_utils_->GetFunctionPointer<double,
const double,
const double,
const double>("AddWithAccumulator");
......
......@@ -26,14 +26,14 @@
#include <utility>
#include <vector>
#include "codegen/utils/codegen_utils.h"
#include "codegen/utils/annotated_type.h"
#include "codegen/utils/code_generator.h"
#ifdef CODEGEN_HAVE_TEMPORARY_FILE
#include "codegen/utils/temporary_file.h"
#endif
#include "clang/CodeGen/CodeGenAction.h"
#include "clang/Codegen/CodegenAction.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Module.h"
......@@ -255,7 +255,7 @@ std::string ClangCompiler::CppTypeFromAnnotatedType(
std::string ClangCompiler::GenerateExternalFunctionDeclarations() const {
std::string declarations;
for (const CodeGenerator::NamedExternalFunction& external_fn
for (const CodegenUtils::NamedExternalFunction& external_fn
: code_generator_->named_external_functions_) {
// Mark extern "C" to avoid name-mangling.
declarations.append("extern \"C\" ");
......
......@@ -3,7 +3,7 @@
// Copyright 2016 Pivotal Software, Inc.
//
// @filename:
// code_generator.cc
// codegen_utils.cc
//
// @doc:
// Object that manages runtime code generation for a single LLVM module.
......@@ -14,8 +14,6 @@
//
//---------------------------------------------------------------------------
#include "codegen/utils/code_generator.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
......@@ -25,6 +23,7 @@
#include <string>
#include <utility>
#include "codegen/utils/codegen_utils.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
......@@ -41,7 +40,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Codegen.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
......@@ -59,19 +58,19 @@ namespace {
// Almost-trivial conversion from Codegen enum for optimization level to the
// LLVM equivalent.
inline llvm::CodeGenOpt::Level OptLevelCodegenToLLVM(
const CodeGenerator::OptimizationLevel codegen_opt_level) {
const CodegenUtils::OptimizationLevel codegen_opt_level) {
switch (codegen_opt_level) {
case CodeGenerator::OptimizationLevel::kNone:
case CodegenUtils::OptimizationLevel::kNone:
return llvm::CodeGenOpt::None;
case CodeGenerator::OptimizationLevel::kLess:
case CodegenUtils::OptimizationLevel::kLess:
return llvm::CodeGenOpt::Less;
case CodeGenerator::OptimizationLevel::kDefault:
case CodegenUtils::OptimizationLevel::kDefault:
return llvm::CodeGenOpt::Default;
case CodeGenerator::OptimizationLevel::kAggressive:
case CodegenUtils::OptimizationLevel::kAggressive:
return llvm::CodeGenOpt::Aggressive;
default: {
std::fprintf(stderr,
"FATAL: Unrecognized CodeGenerator::OptimizationLevel\n");
"FATAL: Unrecognized CodegenUtils::OptimizationLevel\n");
std::exit(1);
}
}
......@@ -79,17 +78,17 @@ inline llvm::CodeGenOpt::Level OptLevelCodegenToLLVM(
} // namespace
constexpr char CodeGenerator::kExternalVariableNamePrefix[];
constexpr char CodeGenerator::kExternalFunctionNamePrefix[];
constexpr char CodegenUtils::kExternalVariableNamePrefix[];
constexpr char CodegenUtils::kExternalFunctionNamePrefix[];
CodeGenerator::CodeGenerator(llvm::StringRef module_name)
CodegenUtils::CodegenUtils(llvm::StringRef module_name)
: ir_builder_(context_),
module_(new llvm::Module(module_name, context_)),
external_variable_counter_(0),
external_function_counter_(0) {
}
bool CodeGenerator::InitializeGlobal() {
bool CodegenUtils::InitializeGlobal() {
// These LLVM initialization routines return true if there is no native
// target available, false if initialization was OK. So, if all 3 return
// false, then initialization is fine.
......@@ -98,7 +97,7 @@ bool CodeGenerator::InitializeGlobal() {
&& !llvm::InitializeNativeTargetAsmParser();
}
bool CodeGenerator::Optimize(const OptimizationLevel generic_opt_level,
bool CodegenUtils::Optimize(const OptimizationLevel generic_opt_level,
const SizeLevel size_level,
const bool optimize_for_host_cpu) {
// This method's implementation is loosely based on the LLVM "opt"
......@@ -201,7 +200,7 @@ bool CodeGenerator::Optimize(const OptimizationLevel generic_opt_level,
return true;
}
bool CodeGenerator::PrepareForExecution(const OptimizationLevel cpu_opt_level,
bool CodegenUtils::PrepareForExecution(const OptimizationLevel cpu_opt_level,
const bool optimize_for_host_cpu) {
if (engine_.get() != nullptr) {
// This method was already called successfully.
......@@ -264,7 +263,7 @@ bool CodeGenerator::PrepareForExecution(const OptimizationLevel cpu_opt_level,
return true;
}
llvm::GlobalVariable* CodeGenerator::AddExternalGlobalVariable(
llvm::GlobalVariable* CodegenUtils::AddExternalGlobalVariable(
llvm::Type* type,
const void* address) {
external_global_variables_.emplace_back(
......@@ -279,7 +278,7 @@ llvm::GlobalVariable* CodeGenerator::AddExternalGlobalVariable(
external_global_variables_.back().first);
}
void CodeGenerator::CheckFunctionType(
void CodegenUtils::CheckFunctionType(
const std::string& function_name,
const llvm::FunctionType* expected_function_type) {
// Look up function in the ExecutionEngine if PrepareForExecution() has
......@@ -293,7 +292,7 @@ void CodeGenerator::CheckFunctionType(
}
}
std::string CodeGenerator::GenerateExternalVariableName() {
std::string CodegenUtils::GenerateExternalVariableName() {
char print_buffer[sizeof(kExternalVariableNamePrefix)
+ (sizeof(unsigned) << 1) + 1] = {};
int chars_printed = std::snprintf(print_buffer,
......@@ -305,7 +304,7 @@ std::string CodeGenerator::GenerateExternalVariableName() {
return std::string(print_buffer);
}
std::string CodeGenerator::GenerateExternalFunctionName() {
std::string CodegenUtils::GenerateExternalFunctionName() {
// Prefix for generated names is only 10 chars. Up to 16 chars (including
// null-terminator) are typically stored inline for C++ standard library
// implementations that use the short-string optimization for std::string
......@@ -327,7 +326,7 @@ std::string CodeGenerator::GenerateExternalFunctionName() {
return std::string(print_buffer);
}
llvm::Value* CodeGenerator::GetPointerToMemberImpl(
llvm::Value* CodegenUtils::GetPointerToMemberImpl(
llvm::Value* base_ptr,
llvm::Type* cast_type,
const std::size_t cumulative_offset) {
......
......@@ -17,7 +17,7 @@
#include <cstdio>
#include "codegen/utils/code_generator.h"
#include "codegen/utils/codegen_utils.h"
#include "codegen/utils/utility.h"
#include "llvm/IR/Verifier.h"
......@@ -79,23 +79,23 @@ void materializeTuple(char *tuple) {
// external
//
MaterializeTupleFunction
GenerateCodeForMaterializeTuple(gpcodegen::CodeGenerator *code_generator) {
GenerateCodeForMaterializeTuple(gpcodegen::CodegenUtils *codegen_utils) {
auto irb = code_generator->ir_builder();
auto irb = codegen_utils->ir_builder();
llvm::Function *mt_function =
code_generator->CreateFunction<void, char *>("materializeTuple");
codegen_utils->CreateFunction<void, char *>("materializeTuple");
// "Constants"
llvm::Value *kNumSlots_value = code_generator->GetConstant(kNumSlots);
llvm::Value *kOffsets_array = code_generator->GetConstant(kOffsets);
llvm::Value *kTypes_array = code_generator->GetConstant(kTypes);
llvm::Value *bool_type = code_generator->GetConstant(Types::kBool);
llvm::Value *int_type = code_generator->GetConstant(Types::kInt);
llvm::Value *kNumSlots_value = codegen_utils->GetConstant(kNumSlots);
llvm::Value *kOffsets_array = codegen_utils->GetConstant(kOffsets);
llvm::Value *kTypes_array = codegen_utils->GetConstant(kTypes);
llvm::Value *bool_type = codegen_utils->GetConstant(Types::kBool);
llvm::Value *int_type = codegen_utils->GetConstant(Types::kInt);
// "External functions"
llvm::Function *parseInt_f =
code_generator->RegisterExternalFunction(ParseInt);
codegen_utils->RegisterExternalFunction(ParseInt);
llvm::Function *parseBool_f =
code_generator->RegisterExternalFunction(ParseBool);
codegen_utils->RegisterExternalFunction(ParseBool);
/*
*
......@@ -125,19 +125,19 @@ GenerateCodeForMaterializeTuple(gpcodegen::CodeGenerator *code_generator) {
// "Blocks"
llvm::BasicBlock *entry =
code_generator->CreateBasicBlock("entry", mt_function);
codegen_utils->CreateBasicBlock("entry", mt_function);
llvm::BasicBlock *loop_start =
code_generator->CreateBasicBlock("loop_start", mt_function);
codegen_utils->CreateBasicBlock("loop_start", mt_function);
llvm::BasicBlock *loop_main =
code_generator->CreateBasicBlock("loop_main", mt_function);
codegen_utils->CreateBasicBlock("loop_main", mt_function);
llvm::BasicBlock *switch_term =
code_generator->CreateBasicBlock("switch_term", mt_function);
codegen_utils->CreateBasicBlock("switch_term", mt_function);
llvm::BasicBlock *switch_bool =
code_generator->CreateBasicBlock("switch_bool", mt_function);
codegen_utils->CreateBasicBlock("switch_bool", mt_function);
llvm::BasicBlock *switch_int =
code_generator->CreateBasicBlock("switch_int", mt_function);
codegen_utils->CreateBasicBlock("switch_int", mt_function);
llvm::BasicBlock *loop_term =
code_generator->CreateBasicBlock("loop_term", mt_function);
codegen_utils->CreateBasicBlock("loop_term", mt_function);
// "Input Arguments"
llvm::Value *tuple_arg =
......@@ -149,9 +149,9 @@ GenerateCodeForMaterializeTuple(gpcodegen::CodeGenerator *code_generator) {
// loop-start block
irb->SetInsertPoint(loop_start);
llvm::PHINode *kOffsets_index = irb->CreatePHI(code_generator->GetType<int>(),
llvm::PHINode *kOffsets_index = irb->CreatePHI(codegen_utils->GetType<int>(),
2 /* num of incoming edges */);
kOffsets_index->addIncoming(code_generator->GetConstant(0), entry);
kOffsets_index->addIncoming(codegen_utils->GetConstant(0), entry);
// kOffsets_index == kNumSlots_value
irb->CreateCondBr(irb->CreateICmpEQ(kOffsets_index, kNumSlots_value),
......@@ -161,15 +161,15 @@ GenerateCodeForMaterializeTuple(gpcodegen::CodeGenerator *code_generator) {
irb->SetInsertPoint(loop_main);
// Type offset_value = kOffsets_array[kOffsets_index]
llvm::Value *offset_value =
irb->CreateLoad(code_generator->ir_builder()->CreateInBoundsGEP(
code_generator->GetType<int>(), kOffsets_array, kOffsets_index));
irb->CreateLoad(codegen_utils->ir_builder()->CreateInBoundsGEP(
codegen_utils->GetType<int>(), kOffsets_array, kOffsets_index));
// Type type_value = kTypes_array[kOffsets_index]
llvm::Value *type_value =
irb->CreateLoad(code_generator->ir_builder()->CreateInBoundsGEP(
code_generator->GetType<Types>(), kTypes_array, kOffsets_index));
irb->CreateLoad(codegen_utils->ir_builder()->CreateInBoundsGEP(
codegen_utils->GetType<Types>(), kTypes_array, kOffsets_index));
// char* slot_ptr = tuple_arg[offset_value]
llvm::Value *slot_ptr = irb->CreateInBoundsGEP(
code_generator->GetType<char>(), tuple_arg, offset_value);
codegen_utils->GetType<char>(), tuple_arg, offset_value);
// switch(type)
llvm::SwitchInst *switch_ins = irb->CreateSwitch(type_value, switch_term, 3);
......@@ -181,7 +181,7 @@ GenerateCodeForMaterializeTuple(gpcodegen::CodeGenerator *code_generator) {
// *slot_ptr = (char) parseBool_f()
llvm::Value *parsed_value = irb->CreateCall(parseBool_f, {});
irb->CreateStore(
irb->CreateZExt(parsed_value, code_generator->GetType<char>()),
irb->CreateZExt(parsed_value, codegen_utils->GetType<char>()),
slot_ptr);
irb->CreateBr(switch_term);
}
......@@ -192,7 +192,7 @@ GenerateCodeForMaterializeTuple(gpcodegen::CodeGenerator *code_generator) {
llvm::Value *parsed_value = irb->CreateCall(parseInt_f, {});
irb->CreateStore(
parsed_value,
irb->CreateBitCast(slot_ptr, code_generator->GetType<int *>()));
irb->CreateBitCast(slot_ptr, codegen_utils->GetType<int *>()));
irb->CreateBr(switch_term);
}
......@@ -201,7 +201,7 @@ GenerateCodeForMaterializeTuple(gpcodegen::CodeGenerator *code_generator) {
// kOffsets_index++
llvm::Value *next_kOffsets_index =
irb->CreateAdd(kOffsets_index, code_generator->GetConstant(1));
irb->CreateAdd(kOffsets_index, codegen_utils->GetConstant(1));
irb->CreateBr(loop_start);
kOffsets_index->addIncoming(next_kOffsets_index, switch_term);
......@@ -211,27 +211,27 @@ GenerateCodeForMaterializeTuple(gpcodegen::CodeGenerator *code_generator) {
// Verification
assert(!llvm::verifyFunction(*mt_function));
assert(!llvm::verifyModule(*code_generator->module()));
assert(!llvm::verifyModule(*codegen_utils->module()));
bool prepare_ok = code_generator->PrepareForExecution(
gpcodegen::CodeGenerator::OptimizationLevel::kDefault, true);
bool prepare_ok = codegen_utils->PrepareForExecution(
gpcodegen::CodegenUtils::OptimizationLevel::kDefault, true);
assert(prepare_ok);
return code_generator->GetFunctionPointer<void, char *>("materializeTuple");
return codegen_utils->GetFunctionPointer<void, char *>("materializeTuple");
}
}
int main() {
bool init_ok = gpcodegen::CodeGenerator::InitializeGlobal();
bool init_ok = gpcodegen::CodegenUtils::InitializeGlobal();
assert(init_ok);
std::printf("Testing static compiled version:\n");
gpcodegen::CodeGenerator code_generator("materializeTuple");
gpcodegen::CodegenUtils codegen_utils("materializeTuple");
testMaterializeTuple(materializeTuple);
std::printf("Testing JIT compiled version:\n");
auto materializeTupleCompiled =
GenerateCodeForMaterializeTuple(&code_generator);
GenerateCodeForMaterializeTuple(&codegen_utils);
testMaterializeTuple(materializeTupleCompiled);
return 0;
}
......@@ -18,7 +18,7 @@ extern "C" {
// Do one-time global initialization of Clang and LLVM libraries. Returns 0
// on success, nonzero on error.
int InitCodeGen();
int InitCodegen();
#ifdef __cplusplus
} // extern "C"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册