LLVM front end register class error OpenCL — GPU t

2019-08-30 01:47发布

问题:

I've recently been encountering this error when compiling OpenCL kernel files with my LLVM_IR pass:

aoc: ../../../TargetRegisterInfo.cpp:89: const llvm::TargetRegisterClass* llvm::TargetRegisterInfo::getMinimalPhysRegClass(unsigned int, llvm::EVT) const: Assertion `BestRC && "Couldn't find the register class"' failed.

I'm not sure what this means. What I've read from the documention doesn't make a lot of sense. Basically it means the backend doesn't know what type to place into the register?

Does anyone know what the error means?

It occurs in various kernels and doesn't seem to have a definitive pattern I can show as an example. I can post more details if needed, but really I'd just like to know what the error is telling me.

Thanks ahead of time for any help.

UPDATE: It seems this command in LLVM is causing the issue:

AllocaInst* llvm::IRBuilder< preserveNames, T, Inserter >::CreateAlloca(Type * Ty, Value * ArraySize = 0,const Twine &  Name = "")

It creates this error when I do a nonspecific allocation in this manner. The reason I use this command is that sometimes in a kernel there will be a store value that is a Constant. Since LLVM often requires a Value I needed a way of converting it. So I do a an allocation with an immediate store and load. This was suggested by another SOF user. Does anyone know an alternate method of converting a Constant to a Value in LLVM?

Thanks all.

Ok it seems a conventional:

Value *new_val = dyn_cast<Value>(old_val);

Works perfectly fine. Hopefully this knowledge will help someone else.

UPDATE3: Scratch that. Dynamic cast doesn't convert Constant to a Value type. So if anyone knows how to do that, please let me know.

回答1:

I admit I don't understand the assertion error you get. However:

The reason I use this command is that sometimes in a kernel there will be a store value that is a Constant. Since LLVM often requires a Value I needed a way of converting it. So I do a an allocation with an immediate store and load.

That doesn't make sense to me:

  1. Any llvm::Constant is already an llvm::Value
  2. Storing a value and then loading it back seems like an expensive nop...