-
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 CustomFloatType #2062
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2062 +/- ##
==========================================
- Coverage 43.56% 43.53% -0.03%
==========================================
Files 45 45
Lines 6267 6264 -3
Branches 1110 1110
==========================================
- Hits 2730 2727 -3
Misses 3366 3366
Partials 171 171
Continue to review full report at Codecov.
|
if (stmt->ptr->ret_type->as<PointerType>()->is_bit_pointer()) { | ||
auto cit = stmt->ret_type->as<CustomIntType>(); | ||
// 1. load bit pointer | ||
llvm::Value *byte_ptr, *bit_offset; | ||
read_bit_pointer(llvm_val[stmt->ptr], byte_ptr, bit_offset); | ||
|
||
auto bit_level_container = builder->CreateLoad(builder->CreateBitCast( | ||
byte_ptr, llvm_ptr_type(cit->get_physical_type()))); | ||
// 2. bit shifting | ||
// first left shift `physical_type - (offset + num_bits)` | ||
// then right shift `physical_type - num_bits` | ||
auto bit_end = builder->CreateAdd(bit_offset, | ||
tlctx->get_constant(cit->get_num_bits())); | ||
auto left = builder->CreateSub( | ||
tlctx->get_constant(data_type_bits(cit->get_physical_type())), bit_end); | ||
auto right = builder->CreateSub( | ||
tlctx->get_constant(data_type_bits(cit->get_physical_type())), | ||
tlctx->get_constant(cit->get_num_bits())); | ||
left = builder->CreateIntCast(left, bit_level_container->getType(), false); | ||
right = | ||
builder->CreateIntCast(right, bit_level_container->getType(), false); | ||
auto step1 = builder->CreateShl(bit_level_container, left); | ||
llvm::Value *step2 = nullptr; | ||
if (cit->get_is_signed()) | ||
step2 = builder->CreateAShr(step1, right); | ||
else | ||
step2 = builder->CreateLShr(step1, right); | ||
|
||
llvm_val[stmt] = builder->CreateIntCast( | ||
step2, llvm_type(cit->get_compute_type()), cit->get_is_signed()); |
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 moved without change into load_as_custom_int
.
llvm::Value *CodeGenLLVM::load_as_custom_int(Stmt *ptr, Type *load_type) { | ||
auto *cit = load_type->as<CustomIntType>(); | ||
// 1. load bit pointer | ||
llvm::Value *byte_ptr, *bit_offset; | ||
read_bit_pointer(llvm_val[ptr], byte_ptr, bit_offset); | ||
|
||
auto bit_level_container = builder->CreateLoad(builder->CreateBitCast( | ||
byte_ptr, llvm_ptr_type(cit->get_physical_type()))); | ||
// 2. bit shifting | ||
// first left shift `physical_type - (offset + num_bits)` | ||
// then right shift `physical_type - num_bits` | ||
auto bit_end = | ||
builder->CreateAdd(bit_offset, tlctx->get_constant(cit->get_num_bits())); | ||
auto left = builder->CreateSub( | ||
tlctx->get_constant(data_type_bits(cit->get_physical_type())), bit_end); | ||
auto right = builder->CreateSub( | ||
tlctx->get_constant(data_type_bits(cit->get_physical_type())), | ||
tlctx->get_constant(cit->get_num_bits())); | ||
left = builder->CreateIntCast(left, bit_level_container->getType(), false); | ||
right = builder->CreateIntCast(right, bit_level_container->getType(), false); | ||
auto step1 = builder->CreateShl(bit_level_container, left); | ||
llvm::Value *step2 = nullptr; | ||
|
||
if (cit->get_is_signed()) | ||
step2 = builder->CreateAShr(step1, right); | ||
else | ||
step2 = builder->CreateLShr(step1, right); | ||
|
||
return builder->CreateIntCast(step2, llvm_type(cit->get_compute_type()), | ||
cit->get_is_signed()); | ||
} |
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.
Extracted from CodeGenLLVM::visit(GlobalLoadStmt *stmt)
.
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.
Thanks! Looks great! Left one minor comment
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.
Cool! Looks great to me! Thanks!
Related issue = #1905
Sorry about the large changes.
CustomFloatType
CustomFloatType
(atomid_add
will be done later.)KernelReturnStmt
/ArgLoadStmt
ctor no longer takes data type. Their return data types are inferred bytype_check
get_compute_type
is now part ofType
API. Overriden in derived classesCustomFloatType
,CustomIntType
,PrimitiveType
.GlobalPtrStmt
is now a pointer type (used to be only the pointee type)CustomFloat/IntType
is_real(DataType)
GlobalStoreStmt
no longer has a return data type[Click here for the format server]