mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-03 17:02:03 +00:00
Add intrinsic helper function
It simplifies getting generic argument types from intrinsics. Differential Revision: https://reviews.llvm.org/D81084
This commit is contained in:
parent
3a95e5caa2
commit
1d4b51e294
@ -222,6 +222,13 @@ namespace Intrinsic {
|
||||
/// This method returns true on error.
|
||||
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef<IITDescriptor> &Infos);
|
||||
|
||||
/// Gets the type arguments of an intrinsic call by matching type contraints
|
||||
/// specified by the .td file. The overloaded types are pushed into the
|
||||
/// AgTys vector.
|
||||
///
|
||||
/// Returns false if the given function is not a valid intrinsic call.
|
||||
bool getIntrinsicSignature(Function *F, SmallVectorImpl<Type *> &ArgTys);
|
||||
|
||||
// Checks if the intrinsic name matches with its signature and if not
|
||||
// returns the declaration with the same signature and remangled name.
|
||||
llvm::Optional<Function*> remangleIntrinsicFunction(Function *F);
|
||||
|
@ -1424,31 +1424,40 @@ Intrinsic::matchIntrinsicVarArg(bool isVarArg,
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<Function*> Intrinsic::remangleIntrinsicFunction(Function *F) {
|
||||
bool Intrinsic::getIntrinsicSignature(Function *F,
|
||||
SmallVectorImpl<Type *> &ArgTys) {
|
||||
Intrinsic::ID ID = F->getIntrinsicID();
|
||||
if (!ID)
|
||||
return false;
|
||||
|
||||
SmallVector<Intrinsic::IITDescriptor, 8> Table;
|
||||
getIntrinsicInfoTableEntries(ID, Table);
|
||||
ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
|
||||
|
||||
if (Intrinsic::matchIntrinsicSignature(F->getFunctionType(), TableRef,
|
||||
ArgTys) !=
|
||||
Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
|
||||
return false;
|
||||
}
|
||||
if (Intrinsic::matchIntrinsicVarArg(F->getFunctionType()->isVarArg(),
|
||||
TableRef))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
|
||||
SmallVector<Type *, 4> ArgTys;
|
||||
if (!getIntrinsicSignature(F, ArgTys))
|
||||
return None;
|
||||
|
||||
FunctionType *FTy = F->getFunctionType();
|
||||
// Accumulate an array of overloaded types for the given intrinsic
|
||||
SmallVector<Type *, 4> ArgTys;
|
||||
{
|
||||
SmallVector<Intrinsic::IITDescriptor, 8> Table;
|
||||
getIntrinsicInfoTableEntries(ID, Table);
|
||||
ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
|
||||
|
||||
if (Intrinsic::matchIntrinsicSignature(FTy, TableRef, ArgTys))
|
||||
return None;
|
||||
if (Intrinsic::matchIntrinsicVarArg(FTy->isVarArg(), TableRef))
|
||||
return None;
|
||||
}
|
||||
|
||||
Intrinsic::ID ID = F->getIntrinsicID();
|
||||
StringRef Name = F->getName();
|
||||
if (Name == Intrinsic::getName(ID, ArgTys))
|
||||
return None;
|
||||
|
||||
auto NewDecl = Intrinsic::getDeclaration(F->getParent(), ID, ArgTys);
|
||||
NewDecl->setCallingConv(F->getCallingConv());
|
||||
FunctionType *FTy = F->getFunctionType();
|
||||
assert(NewDecl->getFunctionType() == FTy && "Shouldn't change the signature");
|
||||
return NewDecl;
|
||||
}
|
||||
|
@ -1130,17 +1130,11 @@ Value *InstCombiner::simplifyAMDGCNMemoryIntrinsicDemanded(IntrinsicInst *II,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Determine the overload types of the original intrinsic.
|
||||
auto IID = II->getIntrinsicID();
|
||||
SmallVector<Intrinsic::IITDescriptor, 16> Table;
|
||||
getIntrinsicInfoTableEntries(IID, Table);
|
||||
ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
|
||||
|
||||
// Validate function argument and return types, extracting overloaded types
|
||||
// along the way.
|
||||
FunctionType *FTy = II->getCalledFunction()->getFunctionType();
|
||||
SmallVector<Type *, 6> OverloadTys;
|
||||
Intrinsic::matchIntrinsicSignature(FTy, TableRef, OverloadTys);
|
||||
if (!Intrinsic::getIntrinsicSignature(II->getCalledFunction(), OverloadTys))
|
||||
return nullptr;
|
||||
|
||||
Module *M = II->getParent()->getParent()->getParent();
|
||||
Type *EltTy = IIVTy->getElementType();
|
||||
@ -1148,7 +1142,8 @@ Value *InstCombiner::simplifyAMDGCNMemoryIntrinsicDemanded(IntrinsicInst *II,
|
||||
(NewNumElts == 1) ? EltTy : FixedVectorType::get(EltTy, NewNumElts);
|
||||
|
||||
OverloadTys[0] = NewTy;
|
||||
Function *NewIntrin = Intrinsic::getDeclaration(M, IID, OverloadTys);
|
||||
Function *NewIntrin =
|
||||
Intrinsic::getDeclaration(M, II->getIntrinsicID(), OverloadTys);
|
||||
|
||||
CallInst *NewCall = Builder.CreateCall(NewIntrin, Args);
|
||||
NewCall->takeName(II);
|
||||
|
Loading…
Reference in New Issue
Block a user