Add a type arg

This commit is contained in:
Daniel Thornburgh 2025-07-22 13:29:09 -07:00
parent 68761d9bf3
commit b7f8a9c8b4
2 changed files with 9 additions and 7 deletions

View File

@ -2635,7 +2635,7 @@ For example:
This attribute indicates that outlining passes should not modify the
function.
``"modular-format"="<string_idx>,<first_idx_to_check>,<modular_impl_fn>,<impl_name>,<aspects...>"``
``"modular-format"="<type>,<string_idx>,<first_idx_to_check>,<modular_impl_fn>,<impl_name>,<aspects...>"``
This attribute indicates that the implementation is modular on a particular
format string argument . When the argument for a given call is constant, the
compiler may redirect the call to a modular implementation function
@ -2648,13 +2648,15 @@ For example:
brought into the link to satisfy weak references in the modular
implemenation function.
The first two arguments have the same semantics as the arguments to the C
The first three arguments have the same semantics as the arguments to the C
``format`` attribute.
The following aspects are currently supported:
- ``float``: The call has a floating point argument
Call Site Attributes
----------------------

View File

@ -4008,18 +4008,18 @@ static Value *optimizeModularFormat(CallInst *CI, IRBuilderBase &B) {
SmallVector<StringRef> Args(
llvm::split(CI->getFnAttr("modular-format").getValueAsString(), ','));
// TODO: Examine the format argument in Args[0].
// TODO: Make use of the first two arguments
// TODO: Error handling
unsigned FirstArgIdx;
if (!llvm::to_integer(Args[1], FirstArgIdx))
if (!llvm::to_integer(Args[2], FirstArgIdx))
return nullptr;
if (FirstArgIdx == 0)
return nullptr;
--FirstArgIdx;
StringRef FnName = Args[2];
StringRef ImplName = Args[3];
StringRef FnName = Args[3];
StringRef ImplName = Args[4];
DenseSet<StringRef> Aspects(llvm::from_range,
ArrayRef<StringRef>(Args).drop_front(4));
ArrayRef<StringRef>(Args).drop_front(5));
Module *M = CI->getModule();
LLVMContext &Ctx = M->getContext();
Function *Callee = CI->getCalledFunction();