Lunderberg commented on a change in pull request #9727:
URL: https://github.com/apache/tvm/pull/9727#discussion_r770661440
##########
File path: src/target/llvm/codegen_llvm.cc
##########
@@ -931,15 +931,15 @@ llvm::Value* CodeGenLLVM::CreateIntrinsic(const CallNode*
op) {
} else if (op->op.same_as(builtin::tvm_storage_sync())) {
return CreateStorageSync(op);
} else if (op->op.same_as(builtin::address_of())) {
- const LoadNode* l = op->args[0].as<LoadNode>();
- ICHECK(op->args.size() == 1 && l);
- TypedPointer buffer_ptr;
- if (const RampNode* r = l->index.as<RampNode>()) {
- PrimExpr index = r->base / make_const(DataType::Int(32), r->lanes);
- buffer_ptr = CreateBufferPtr(l->dtype, MakeValue(l->buffer_var),
MakeValue(index));
- } else {
- buffer_ptr = CreateBufferPtr(l->dtype, MakeValue(l->buffer_var),
MakeValue(l->index));
+ const BufferLoadNode* load = op->args[0].as<BufferLoadNode>();
+ ICHECK(op->args.size() == 1 && load);
+ ICHECK_EQ(load->indices.size(), 0) << "LLVM only supports flat memory
allocations.";
+ PrimExpr index = load->indices[0];
Review comment:
I think `index` needs to be `PrimExpr` here, since conditionally
changing it to a `RampNode` in the next few lines wouldn't be possible with a
`const PrimExpr&`. The alternative would be to have everything through the
call to `CreateBufferPtr` be duplicated on both sides of a conditional (as
below), but I felt that the decrease in readability wouldn't be worth avoiding
the copy.
```c++
const PrimExpr& index = load->indices[0];
TypedPointer buffer_ptr;
if (const RampNode* r = index.as<RampNode>()) {
PrimExpr ramp_index = r->base / make_const(DataType::Int(32), r->lanes);
CreateBufferPtr(load->dtype, MakeValue(load->buffer->data),
MakeValue(ramp_index));
} else {
CreateBufferPtr(load->dtype, MakeValue(load->buffer->data),
MakeValue(index));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]