forked from OSchip/llvm-project
Introduce std.varargs attribute to mark variadic arguments functions
This is only teaching the LLVM converter to propagate the attribute onto the function type. MLIR will not recognize this arguments, so it would only be useful when calling for example `printf` with the same arguments across a module. Since varargs is part of the ABI lowering, this is not NFC. -- PiperOrigin-RevId: 242382427
This commit is contained in:
parent
f9c4c60320
commit
7286d43920
|
@ -83,8 +83,8 @@ private:
|
|||
// MLIR LLVM IR dialect types. Use `loc` as a location when reporting errors.
|
||||
// Return nullptr on errors.
|
||||
static llvm::FunctionType *convertFunctionType(llvm::LLVMContext &llvmContext,
|
||||
FunctionType type,
|
||||
Location loc) {
|
||||
FunctionType type, Location loc,
|
||||
bool isVarArgs) {
|
||||
assert(type && "expected non-null type");
|
||||
|
||||
auto context = type.getContext();
|
||||
|
@ -105,14 +105,14 @@ static llvm::FunctionType *convertFunctionType(llvm::LLVMContext &llvmContext,
|
|||
|
||||
if (type.getNumResults() == 0)
|
||||
return llvm::FunctionType::get(llvm::Type::getVoidTy(llvmContext), argTypes,
|
||||
/*isVarArg=*/false);
|
||||
isVarArgs);
|
||||
|
||||
auto wrappedResultType = type.getResult(0).dyn_cast<LLVM::LLVMType>();
|
||||
if (!wrappedResultType)
|
||||
return context->emitError(loc, "non-LLVM function result"), nullptr;
|
||||
|
||||
return llvm::FunctionType::get(wrappedResultType.getUnderlyingType(),
|
||||
argTypes, /*isVarArg=*/false);
|
||||
argTypes, isVarArgs);
|
||||
}
|
||||
|
||||
// Create an LLVM IR constant of `llvmType` from the MLIR attribute `attr`.
|
||||
|
@ -417,8 +417,12 @@ bool ModuleTranslation::convertFunctions() {
|
|||
// call graph with cycles.
|
||||
for (Function &function : mlirModule) {
|
||||
Function *functionPtr = &function;
|
||||
llvm::FunctionType *functionType = convertFunctionType(
|
||||
llvmModule->getContext(), function.getType(), function.getLoc());
|
||||
mlir::BoolAttr isVarArgsAttr =
|
||||
function.getAttrOfType<BoolAttr>("std.varargs");
|
||||
bool isVarArgs = isVarArgsAttr && isVarArgsAttr.getValue();
|
||||
llvm::FunctionType *functionType =
|
||||
convertFunctionType(llvmModule->getContext(), function.getType(),
|
||||
function.getLoc(), isVarArgs);
|
||||
if (!functionType)
|
||||
return true;
|
||||
llvm::FunctionCallee llvmFuncCst =
|
||||
|
|
|
@ -793,3 +793,7 @@ func @cond_br_arguments(%arg0: !llvm.i1, %arg1: !llvm.i1) {
|
|||
func @llvm_noalias(%arg0: !llvm<"float*"> {llvm.noalias: true}) {
|
||||
llvm.return
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @llvm_varargs(...)
|
||||
func @llvm_varargs()
|
||||
attributes {std.varargs: true}
|
||||
|
|
Loading…
Reference in New Issue