-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[type] Add basic implementations of VectorType and PointerType #1948
Conversation
@@ -50,17 +50,17 @@ FunctionCreationGuard::FunctionCreationGuard( | |||
// emit into loop body function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in this file are mostly adding the llvm::
namespace.
if (stmt->is_ptr) { | ||
if (stmt->ret_type.is_pointer()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only substantial change in this file. Note that this part of the code is never used yet anyway.
@@ -10,8 +10,6 @@ | |||
|
|||
TLANG_NAMESPACE_BEGIN | |||
|
|||
using namespace llvm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing since llvm::PointerType
conflicts with taichi::lang::PointerType
.
// Note: these primitive types should never be freed. They are supposed to live | ||
// together with the process. This is a temporary solution. Later we should | ||
// manage its ownership more systematically. | ||
|
||
// This part doesn't look good, but we will remove it soon anyway. | ||
#define PER_TYPE(x) \ | ||
DataType PrimitiveType::x = \ | ||
DataType(Program::get_type_factory().get_primitive_type( \ | ||
PrimitiveType::primitive_type::x)); | ||
|
||
#include "taichi/inc/data_type.inc.h" | ||
#undef PER_TYPE | ||
|
||
DataType::DataType() : ptr_(PrimitiveType::unknown.ptr_) { | ||
} | ||
|
||
DataType PrimitiveType::get(PrimitiveType::primitive_type t) { | ||
if (false) { | ||
} | ||
#define PER_TYPE(x) else if (t == primitive_type::x) return PrimitiveType::x; | ||
#include "taichi/inc/data_type.inc.h" | ||
#undef PER_TYPE | ||
else { | ||
TI_NOT_IMPLEMENTED | ||
} | ||
} | ||
|
||
std::size_t DataType::hash() const { | ||
if (auto primitive = dynamic_cast<const PrimitiveType *>(ptr_)) { | ||
return (std::size_t)primitive->type; | ||
} else { | ||
TI_NOT_IMPLEMENTED | ||
} | ||
} | ||
|
||
std::string PrimitiveType::to_string() const { | ||
return data_type_name(DataType(this)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is completely copy-pasted from lang_util.cpp
.
class Type { | ||
public: | ||
virtual std::string to_string() const = 0; | ||
virtual ~Type() { | ||
} | ||
}; | ||
|
||
// A "Type" handle. This should be removed later. | ||
class DataType { | ||
public: | ||
DataType(); | ||
|
||
DataType(const Type *ptr) : ptr_(ptr) { | ||
} | ||
|
||
bool operator==(const DataType &o) const { | ||
return ptr_ == o.ptr_; | ||
} | ||
|
||
bool operator!=(const DataType &o) const { | ||
return !(*this == o); | ||
} | ||
|
||
std::size_t hash() const; | ||
|
||
std::string to_string() const { | ||
return ptr_->to_string(); | ||
}; | ||
|
||
// TODO: DataType itself should be a pointer in the future | ||
const Type *get_ptr() const { | ||
return ptr_; | ||
} | ||
|
||
private: | ||
const Type *ptr_; | ||
}; | ||
|
||
class PrimitiveType : public Type { | ||
public: | ||
enum class primitive_type : int { | ||
#define PER_TYPE(x) x, | ||
#include "taichi/inc/data_type.inc.h" | ||
#undef PER_TYPE | ||
}; | ||
|
||
#define PER_TYPE(x) static DataType x; | ||
#include "taichi/inc/data_type.inc.h" | ||
#undef PER_TYPE | ||
|
||
primitive_type type; | ||
|
||
PrimitiveType(primitive_type type) : type(type) { | ||
} | ||
|
||
std::string to_string() const override; | ||
|
||
static DataType get(primitive_type type); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-pasted from lang_util.h
.
@@ -19,66 +20,6 @@ struct Context; | |||
|
|||
using FunctionType = std::function<void(Context &)>; | |||
|
|||
class Type { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to type.cpp
@@ -30,45 +30,6 @@ real get_cpu_frequency() { | |||
|
|||
real default_measurement_time = 1; | |||
|
|||
// Note: these primitive types should never be freed. They are supposed to live |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to type.h
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM, I have only one minor comment about an attribute.
|
||
private: | ||
Type *pointee_{nullptr}; | ||
int addr_space_{0}; // TODO: make this an enum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about documenting this attribute(a comment would do the job)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we switch this part to an enum, the enum values will document themselves :-)
@@ -1,4 +1,5 @@ | |||
#include "taichi/ir/type_factory.h" | |||
#include "type_factory.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this line will cause some compilers to think "type_factory.h"
and "taichi/ir/type_factory.h"
are different files and include it twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The file will be included twice, which is fine since we have #pragma once
. But the second line is unnecessary so I'll remove it in a future PR :-)
Related issue = #1905
Changes:
VectorType
andPointerType
TypeFactor
to support creating the two new typesusing namespace llvm
incodegen_llvm.h
since nowtaichi::lang::PointerType
conflicts withllvm::PointerType
. Added some necessaryllvm::
prefixes to fix compilation.Stmt::is_ptr
toArgLoadStmt::is_ptr
since that's the only subclass that uses the member.Type-
related classes fromtaichi/lang_util.h/cpp
totaichi/ir/type.h/cpp
[Click here for the format server]