Repository navigation
add unaligned memory access flags - #162
Merged
Merged
Conversation
Coverage
Diff CoverageDiff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
jitir.hppLines 1765-1773 1765 Value* value() const { return arg(1); }
1766 StoreFlags flags() const { return _flags; }
1767 AliasingGroup aliasing() const { return _aliasing; }
1768 uint64_t offset() const { return _offset; }
! 1769 void set_flags(StoreFlags flags) { _flags = flags; }
1770 void set_aliasing(AliasingGroup aliasing) { _aliasing = aliasing; }
1771 void set_offset(uint64_t offset) { _offset = offset; }
1772 void write(metajit::PrettyStream& stream) const override {
1773 stream << Highlight::Keyword << "Store" << Highlight::None;Lines 1774-1783 1774 stream << ' ';
1775 bool is_first = true;
1776 write_args(stream, is_first);
1777 if ((uint32_t) _flags != StoreFlags::None) {
! 1778 stream << ", "; stream << Highlight::ArgName << "flags=" << Highlight::None; stream << _flags;
! 1779 }
1780 stream << ", "; stream << Highlight::ArgName << "aliasing=" << Highlight::None; stream << Highlight::Constant << _aliasing << Highlight::None;
1781 stream << ", "; stream << Highlight::ArgName << "offset=" << Highlight::None; stream << Highlight::Constant << _offset << Highlight::None;
1782 }
1783 void write_json(std::ostream& stream) const override {Lines 1793-1803 1793 stream << ", ";
1794 stream << "\"type\": ";
1795 stream << "\"" << type() << "\"";
1796 stream << ", ";
! 1797 stream << "\"flags\": ";
! 1798 _flags.write_json(stream);
! 1799 stream << ", ";
1800 stream << "\"aliasing\": ";
1801 stream << _aliasing;
1802 stream << ", ";
1803 stream << "\"offset\": ";Lines 1811-1819 1811 if (arg_count() != other_inst->arg_count()) { return false; }
1812 for (size_t it = 0; it < arg_count(); it++) {
1813 if (arg(it) != other_inst->arg(it)) { return false; }
1814 }
! 1815 if (_flags != other_inst->_flags) { return false; }
1816 if (_aliasing != other_inst->_aliasing) { return false; }
1817 if (_offset != other_inst->_offset) { return false; }
1818 return true;
1819 }Lines 1822-1830 1822 hash ^= std::hash<size_t>()(arg_count());
1823 for (size_t it = 0; it < arg_count(); it++) {
1824 hash ^= std::hash<Value*>()(arg(it));
1825 }
! 1826 hash ^= std::hash<StoreFlags>()(_flags);
1827 hash ^= std::hash<AliasingGroup>()(_aliasing);
1828 hash ^= std::hash<uint64_t>()(_offset);
1829 return hash;
1830 }Lines 4245-4254 4245 return build_load(ptr, type, flags, aliasing, offset);
4246 }
4247
4248 Value* fold_store(Value* ptr, Value* value, AliasingGroup aliasing, uint64_t offset) {
! 4249 return fold_store(ptr, value, StoreFlags::None, aliasing, offset);
! 4250 }
4251
4252 Value* fold_store(Value* ptr, Value* value, StoreFlags flags, AliasingGroup aliasing, uint64_t offset) {
4253 if (dynmatch(AddPtrInst, add_ptr, ptr)) {
4254 if (dynmatch(Const, const_offset, add_ptr->offset())) {Lines 5382-5394 5382 Value* value = read_value_arg();
5383 expect_char(','); skip_whitespace();
5384 StoreFlags flags = StoreFlags::None;
5385 if (_stream.peek() == 'f') {
! 5386 expect_word("flags");
! 5387 expect_char('=');
! 5388 flags = read_flags<StoreFlags>();
! 5389 expect_char(',');
! 5390 }
5391 expect_word("aliasing");
5392 expect_char('=');
5393 AliasingGroup aliasing = read_int32();
5394 expect_char(','); skip_whitespace();Lines 6834-6843 6834 assert(!is_poison);
6835 size_t size = type_size(type);
6836 assert(size > 0);
6837 uint64_t bits = value;
! 6838 if constexpr (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) {
! 6839 bits <<= (sizeof(bits) - size) * 8;
6840 }
6841 std::memcpy(ptr, &bits, size);
6842 }Lines 6845-6854 6845 uint64_t value = 0;
6846 size_t size = type_size(type);
6847 assert(size > 0);
6848 std::memcpy(&value, ptr, size);
! 6849 if constexpr (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) {
! 6850 value >>= (sizeof(value) - size) * 8;
6851 }
6852 return Bits::constant(type, value);
6853 }jitir_llvmapi.hppLines 702-713 702 std::vector<llvm::Value*> build_args;
703 build_args.push_back(jitir_builder);
704 build_args.push_back(args[0]);
705 build_args.push_back(args[1]);
! 706 build_args.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), (uint64_t)i->flags(), false));
707 build_args.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), (uint64_t)i->aliasing(), false));
708 build_args.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(context), (uint64_t)i->offset(), false));
! 709 assert(build_args.size() == 6);
710 llvm::Value* built = builder.CreateCall(api.build_store, build_args);
711 return built;
712 }
713 if (AllocaInst* i = dynamic_cast<AllocaInst*>(inst)) {llvmgen.hppLines 248-257 248 emit_type(load->type()),
249 emit_add_offset(emit_arg(load->arg(0)), load->offset())
250 );
251 if (load->flags().has(LoadFlags::Unaligned)) {
! 252 result->setAlignment(llvm::Align(1));
! 253 }
254 if (load->flags().has(LoadFlags::Pure)) {
255 result->setMetadata(llvm::LLVMContext::MD_invariant_load, llvm::MDNode::get(_context, {}));
256 }
257 return result;Lines 260-269 260 emit_arg(store->value()),
261 emit_add_offset(emit_arg(store->ptr()), store->offset())
262 );
263 if (store->flags().has(StoreFlags::Unaligned)) {
! 264 result->setAlignment(llvm::Align(1));
! 265 }
266 return result;
267 } else if (dynmatch(AllocaInst, alloca, inst)) {
268 llvm::AllocaInst* llvm_alloca;
269 if (_alloca_types.find(alloca) != _alloca_types.end() && _alloca_types.at(alloca) != Type::Void) {lowerllvm.hppLines 193-202 193 Value* ptr = lower_operand(load->getPointerOperand());
194 Type type = lower_type(load->getType());
195 LoadFlags flags = LoadFlags::None;
196 if (load->getAlign().value() < type_size(type)) {
! 197 flags = LoadFlags::Unaligned;
! 198 }
199 return _builder.fold_load(ptr, type, flags, AliasingGroup(0), 0);
200 } else if (llvm::StoreInst* store = llvm::dyn_cast<llvm::StoreInst>(inst)) {
201 Value* ptr = lower_operand(store->getPointerOperand());
202 Value* value = lower_operand(store->getValueOperand());Lines 201-210 201 Value* ptr = lower_operand(store->getPointerOperand());
202 Value* value = lower_operand(store->getValueOperand());
203 StoreFlags flags = StoreFlags::None;
204 if (store->getAlign().value() < type_size(value->type())) {
! 205 flags = StoreFlags::Unaligned;
! 206 }
207 return _builder.fold_store(ptr, value, flags, AliasingGroup(0), 0);
208 } else if (llvm::GetElementPtrInst* gep = llvm::dyn_cast<llvm::GetElementPtrInst>(inst)) {
209 Value* ptr = lower_operand(gep->getPointerOperand());
210 assert(ptr->type() == Type::Ptr); |
Coverage
Diff CoverageDiff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
jitir.hppLines 1765-1773 1765 Value* value() const { return arg(1); }
1766
8000
StoreFlags flags() const { return _flags; }
1767 AliasingGroup aliasing() const { return _aliasing; }
1768 uint64_t offset() const { return _offset; }
! 1769 void set_flags(StoreFlags flags) { _flags = flags; }
1770 void set_aliasing(AliasingGroup aliasing) { _aliasing = aliasing; }
1771 void set_offset(uint64_t offset) { _offset = offset; }
1772 void write(metajit::PrettyStream& stream) const override {
1773 stream << Highlight::Keyword << "Store" << Highlight::None;;Lines 1794-1804 1794 stream << ", ";
1795 stream << "\"type\": ";
1796 stream << "\"" << type() << "\"";
1797 stream << ", ";
! 1798 stream << "\"flags\": ";
! 1799 _flags.write_json(stream);
! 1800 stream << ", ";
1801 stream << "\"aliasing\": ";
1802 stream << _aliasing;
1803 stream << ", ";
1804 stream << "\"offset\": ";Lines 1812-1820 1812 if (arg_count() != other_inst->arg_count()) { return false; }
1813 for (size_t it = 0; it < arg_count(); it++) {
1814 if (arg(it) != other_inst->arg(it)) { return false; }
1815 }
! 1816 if (_flags != other_inst->_flags) { return false; }
1817 if (_aliasing != other_inst->_aliasing) { return false; }
1818 if (_offset != other_inst->_offset) { return false; }
1819 return true;
1820 }Lines 1823-1831 1823 hash ^= std::hash<size_t>()(arg_count());
1824 for (size_t it = 0; it < arg_count(); it++) {
1825 hash ^= std::hash<Value*>()(arg(it));
1826 }
! 1827 hash ^= std::hash<StoreFlags>()(_flags);
1828 hash ^= std::hash<AliasingGroup>()(_aliasing);
1829 hash ^= std::hash<uint64_t>()(_offset);
1830 return hash;
1831 }Lines 4246-4255 4246 return build_load(ptr, type, flags, aliasing, offset);
4247 }
4248
4249 Value* fold_store(Value* ptr, Value* value, AliasingGroup aliasing, uint64_t offset) {
! 4250 return fold_store(ptr, value, StoreFlags::None, aliasing, offset);
! 4251 }
4252
4253 Value* fold_store(Value* ptr, Value* value, StoreFlags flags, AliasingGroup aliasing, uint64_t offset) {
4254 if (dynmatch(AddPtrInst, add_ptr, ptr)) {
4255 if (dynmatch(Const, const_offset, add_ptr->offset())) {Lines 6822-6831 6822 assert(!is_poison);
6823 size_t size = type_size(type);
6824 assert(size > 0);
6825 uint64_t bits = value;
! 6826 if constexpr (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) {
! 6827 bits <<= (sizeof(bits) - size) * 8;
6828 }
6829 std::memcpy(ptr, &bits, size);
6830 }Lines 6833-6842 6833 uint64_t value = 0;
6834 size_t size = type_size(type);
6835 assert(size > 0);
6836 std::memcpy(&value, ptr, size);
! 6837 if constexpr (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) {
! 6838 value >>= (sizeof(value) - size) * 8;
6839 }
6840 return Bits::constant(type, value);
6841 }jitir_llvmapi.hppLines 702-713 702 std::vector<llvm::Value*> build_args;
703 build_args.push_back(jitir_builder);
704 build_args.push_back(args[0]);
705 build_args.push_back(args[1]);
! 706 build_args.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), (uint64_t)i->flags(), false));
707 build_args.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), (uint64_t)i->aliasing(), false));
708 build_args.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(context), (uint64_t)i->offset(), false));
! 709 assert(build_args.size() == 6);
710 llvm::Value* built = builder.CreateCall(api.build_store, build_args);
711 return built;
712 }
713 if (AllocaInst* i = dynamic_cast<AllocaInst*>(inst)) {llvmgen.hppLines 248-257 248 emit_type(load->type()),
249 emit_add_offset(emit_arg(load->arg(0)), load->offset())
250 );
251 if (load->flags().has(LoadFlags::Unaligned)) {
! 252 result->setAlignment(llvm::Align(1));
! 253 }
254 if (load->flags().has(LoadFlags::Pure)) {
255 result->setMetadata(llvm::LLVMContext::MD_invariant_load, llvm::MDNode::get(_context, {}));
256 }
257 return result;Lines 260-269 260 emit_arg(store->value()),
261 emit_add_offset(emit_arg(store->ptr()), store->offset())
262 );
263 if (store->flags().has(StoreFlags::Unaligned)) {
! 264 result->setAlignment(llvm::Align(1));
! 265 }
266 return result;
267 } else if (dynmatch(AllocaInst, alloca, inst)) {
268 llvm::AllocaInst* llvm_alloca;
269 if (_alloca_types.find(alloca) != _alloca_types.end() && _alloca_types.at(alloca) != Type::Void) {lowerllvm.hppLines 193-202 193 Value* ptr = lower_operand(load->getPointerOperand());
194 Type type = lower_type(load->getType());
195 LoadFlags flags = LoadFlags::None;
196 if (load->getAlign().value() < type_size(type)) {
! 197 flags = LoadFlags::Unaligned;
! 198 }
199 return _builder.fold_load(ptr, type, flags, AliasingGroup(0), 0);
200 } else if (llvm::StoreInst* store = llvm::dyn_cast<llvm::StoreInst>(inst)) {
201 Value* ptr = lower_operand(store->getPointerOperand());
202 Value* value = lower_operand(store->getValueOperand());Lines 201-210 201 Value* ptr = lower_operand(store->getPointerOperand());
202 Value* value = lower_operand(store->getValueOperand());
203 StoreFlags flags = StoreFlags::None;
204 if (store->getAlign().value() < type_size(value->type())) {
! 205 flags = StoreFlags::Unaligned;
! 206 }
207 return _builder.fold_store(ptr, value, flags, AliasingGroup(0), 0);
208 } else if (llvm::GetElementPtrInst* gep = llvm::dyn_cast<llvm::GetElementPtrInst>(inst)) {
209 Value* ptr = lower_operand(gep->getPointerOperand());
210 assert(ptr->type() == Type::Ptr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.