-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[VFABI] Refactor try demangle for vfabi to use only the vector abi mangled names #67430
Conversation
JolantaJensen
commented
Sep 26, 2023
•
edited
Loading
edited
@@ -27,15 +27,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | |||
// present. We need to make sure we can even invoke | |||
// `getOrInsertFunction` because such method asserts on strings with | |||
// zeroes. |
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 about this test. The comment is definitely wrong now but does the test still make sense?
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.
Resolved.
return std::nullopt; | ||
const ElementCount EC = getECFromSignature(F->getFunctionType()); |
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.
What about keeping getECFromSignature
but passing it the ISA
and the FunctionType
of the CallInst
?
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.
But to get the FunctionType, I need the Function itself, and to get the Function I need the Module. And what about an Instruction that isn't a CallInstruction and won't give me a Function? Or do you mean passing FunctionType instead of the vector with Operand Types? Or passing the Instruction itself as argument?
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.
Resolved.
llvm/lib/Analysis/VectorUtils.cpp
Outdated
LLVM_DEBUG(dbgs() << "VFABI: adding mapping '" << S << "'\n"); | ||
std::optional<VFInfo> Info = | ||
VFABI::tryDemangleForVFABI(S, *(CI.getModule())); | ||
std::optional<VFInfo> Info = VFABI::tryDemangleForVFABI(S, OpTys); |
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.
You previously identified the operands might not be enough so perhaps just pass in the call instruction itself rather than spend time pulling the operands into a separate vector.
…ed names and the call's argument types to construct the VFInfo. Currently the tryDemangleForVFABI is incorrectly making assumptions that when the mangled name has __LLVM__ set as ISA and _vlen_ is set to scalable/VLA the module can be queried to identify the correct VF. This works currently only by chance rather than by design and limits the ability to maximise the use for the Vector ABI. This behaviour is changed by llvm#66656 and llvm#67308 and means demangling can be implemented as expected based solely on the rules as documented within the VFABI.
a0754c9
to
4ab245f
Compare
FunctionType *FTy = | ||
FunctionType::get(Type::getVoidTy(M->getContext()), false); | ||
FunctionCallee F = M->getOrInsertFunction(MangledName, FTy); | ||
// Fake the arguments to the CallInst. | ||
SmallVector<Value *> Args; | ||
for (Type *ParamTy : FTy->params()) { | ||
Args.push_back(Constant::getNullValue(ParamTy)); | ||
} | ||
std::unique_ptr<CallInst> CI(CallInst::Create(F, Args)); | ||
const auto Info = VFABI::tryDemangleForVFABI(MangledName, *(CI.get())); | ||
|
||
// Do not optimize away the return value. Inspired by | ||
// https://github.com/google/benchmark/blob/main/include/benchmark/benchmark.h#L307-L345 | ||
asm volatile("" : : "r,m"(Info) : "memory"); | ||
// Do not optimize away the return value. Inspired by | ||
// https://github.com/google/benchmark/blob/main/include/benchmark/benchmark.h#L307-L345 | ||
asm volatile("" : : "r,m"(Info) : "memory"); | ||
|
||
return 0; | ||
return 0; |
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.
Here, I'm only returning a value if the if condition is true but it does not make a sense to me to try to call VFABI::tryDemangleForVFABI
if we do not have a CI. Grateful for suggestions how to rewrite this part.
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.
Resolved
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.
Given my current comments I've not reviewed the tools
and unittests
changes but broadly this is looking like a nice cleanup, you just need to firm up which type is used to calculate the ElemetCount.
/// name. At the moment, this parameter is needed only to retrieve the | ||
/// Vectorization Factor of scalable vector functions from their | ||
/// respective IR declarations. | ||
/// \param CI -> the call instruction. |
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.
It's worth being a little more verbose here and say something like "the call instruction to the scalar function to which MangledName is being linked and whose return and parameter types are required to calculate the expected ElementCount for the matching vector function".
assert(verifyAllVectorsHaveSameWidth(Signature) && | ||
"Invalid vector signature."); |
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 this makes much sense because isn't CI
the call to the scalar function? I'm thinking verifyAllVectorsHaveSameWidth
only existed due to the bogus way EC
was previously calculated.
ArrayRef<Type *> ParamTys = Signature->params(); | ||
if (ParamTys.empty()) { | ||
return ParseRet::Error; | ||
} |
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.
It's likely more complicated than this because I believe we support the case where there's a return value but no parameters.
Also, now I can see the code, I think I've given you an incomplete steer because in order to support things like "uniform" and "linear" we cannot pick just any parameter, we first need to know which of the parameters are required to be vector types. This means tryParseVLEN
likely needs to be called last after we construct the VFParameter
's.
Superseded by #72260 that landed last week. |