Skip to content

Commit

Permalink
Abort on calls to funcs with non-std type args
Browse files Browse the repository at this point in the history
  • Loading branch information
pvelesko committed Jan 30, 2025
1 parent 17f4f4b commit 85f5553
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions llvm_passes/HipPromoteInts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,30 @@ void processInstruction(Instruction *I, Type *NonStdType, Type *PromotedTy, std:
Replacements.push_back(Replacement(I, NewInst));
}
else if (isa<CallInst>(I)) {
CallInst* Call = cast<CallInst>(I);
CallInst* OldCall = cast<CallInst>(I);
// Create a new call with the same operands, but use promoted values where available
SmallVector<Value*, 8> NewArgs;
for (unsigned i = 0; i < Call->arg_size(); ++i) {
Value* Arg = Call->getArgOperand(i);
Value* NewArg = PromotedValues.count(Arg) ? PromotedValues[Arg] : Arg;
for (unsigned i = 0; i < OldCall->arg_size(); ++i) {
Value* OldArg = OldCall->getArgOperand(i);
Value* NewArg = PromotedValues.count(OldArg) ? PromotedValues[OldArg] : OldArg;

// If the argument needs to match the original type, truncate it
if (NewArg->getType() != Call->getArgOperand(i)->getType())
NewArg = Builder.CreateTrunc(NewArg, Call->getArgOperand(i)->getType());
// if the function expects a non-standard type, abort for now.
// TODO: if this assert is hit, we need to handle this case in the future
// by promoting the function arguments as well.
if (OldArg->getType() != NewArg->getType())
assert(false && "HipPromoteIntsPass: Function expects non-standard type");

NewArgs.push_back(NewArg);
}

CallInst* NewCall = CallInst::Create(Call->getFunctionType(),
Call->getCalledOperand(),
CallInst* NewCall = CallInst::Create(OldCall->getFunctionType(),
OldCall->getCalledOperand(),
NewArgs,
Call->getName(),
Call);
NewCall->setCallingConv(Call->getCallingConv());
NewCall->setAttributes(Call->getAttributes());
OldCall->getName(),
OldCall);
NewCall->setCallingConv(OldCall->getCallingConv());
NewCall->setAttributes(OldCall->getAttributes());


errs() << Indent << " " << *I << " ============> " << *NewCall << "\n";
PromotedValues[I] = NewCall;
Expand Down

0 comments on commit 85f5553

Please sign in to comment.