-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[IPO] Optimise variadic functions #92850
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature | ||
|
||
// Simple calls to known variadic functions that are completely elided when optimisations are on | ||
// This is a functional check that the expand-variadic pass is consistent with clang's va_arg handling | ||
|
||
// -Wno-varargs avoids warning second argument to 'va_start' is not the last named parameter | ||
|
||
// RUN: %clang_cc1 -triple aarch64-linux-gnu -Wno-varargs -O1 -emit-llvm -o - %s | FileCheck %s | ||
|
||
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -Wno-varargs -O1 -emit-llvm -o - %s | FileCheck %s | ||
|
||
// x64 needs O2 to remove the extra SROA layer | ||
// RUN: %clang_cc1 -triple x86_64-linux-gnu -Wno-varargs -O2 -emit-llvm -o - %s | FileCheck %s | ||
|
||
|
||
#include <stdarg.h> | ||
#include <stdint.h> | ||
|
||
template <typename X, typename Y> | ||
static X first(...) { | ||
va_list va; | ||
__builtin_va_start(va, 0); | ||
X r = va_arg(va, X); | ||
va_end(va); | ||
return r; | ||
} | ||
|
||
template <typename X, typename Y> | ||
static Y second(...) { | ||
va_list va; | ||
__builtin_va_start(va, 0); | ||
va_arg(va, X); | ||
Y r = va_arg(va, Y); | ||
va_end(va); | ||
return r; | ||
} | ||
|
||
|
||
extern "C" | ||
{ | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@first_pair_i32 | ||
// CHECK-SAME: (i32 noundef returned [[X:%.*]], i32 noundef [[Y:%.*]]) | ||
// CHECK-LABEL:{{.}}: | ||
// CHECK-NEXT: ret i32 [[X]] | ||
// | ||
int first_pair_i32(int x, int y) | ||
{ | ||
return first<int,int>(x, y); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@second_pair_i32 | ||
// CHECK-SAME: (i32 noundef [[X:%.*]], i32 noundef returned [[Y:%.*]]) | ||
// CHECK-LABEL:{{.}}: | ||
// CHECK-NEXT: ret i32 [[Y]] | ||
// | ||
int second_pair_i32(int x, int y) | ||
{ | ||
return second<int,int>(x, y); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@first_pair_f64 | ||
// CHECK-SAME: (double noundef returned [[X:%.*]], double noundef [[Y:%.*]]) | ||
// CHECK-LABEL:{{.}}: | ||
// CHECK-NEXT: ret double [[X]] | ||
// | ||
double first_pair_f64(double x, double y) | ||
{ | ||
return first<double,double>(x, y); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@second_pair_f64 | ||
// CHECK-SAME: (double noundef [[X:%.*]], double noundef returned [[Y:%.*]]) | ||
// CHECK-LABEL:{{.}}: | ||
// CHECK-NEXT: ret double [[Y]] | ||
// | ||
double second_pair_f64(double x, double y) | ||
{ | ||
return second<double,double>(x, y); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
extern "C" | ||
{ | ||
// CHECK-LABEL: define {{[^@]+}}@first_i32_f64 | ||
// CHECK-SAME: (i32 noundef returned [[X:%.*]], double noundef [[Y:%.*]]) | ||
// CHECK-LABEL:{{.}}: | ||
// CHECK-NEXT: ret i32 [[X]] | ||
// | ||
int first_i32_f64(int x, double y) | ||
{ | ||
return first<int,double>(x, y); | ||
} | ||
|
||
|
||
// CHECK-LABEL: define {{[^@]+}}@second_i32_f64 | ||
// CHECK-SAME: (i32 noundef [[X:%.*]], double noundef returned [[Y:%.*]]) | ||
// CHECK-LABEL:{{.}}: | ||
// CHECK-NEXT: ret double [[Y]] | ||
// | ||
double second_i32_f64(int x, double y) | ||
{ | ||
return second<int,double>(x, y); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@first_f64_i32 | ||
// CHECK-SAME: (double noundef returned [[X:%.*]], i32 noundef [[Y:%.*]]) | ||
// CHECK-LABEL:{{.}}: | ||
// CHECK-NEXT: ret double [[X]] | ||
// | ||
double first_f64_i32(double x, int y) | ||
{ | ||
return first<double,int>(x, y); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@second_f64_i32 | ||
// CHECK-SAME: (double noundef [[X:%.*]], i32 noundef returned [[Y:%.*]]) | ||
// CHECK-LABEL:{{.}}: | ||
// CHECK-NEXT: ret i32 [[Y]] | ||
// | ||
int second_f64_i32(double x, int y) | ||
{ | ||
return second<double,int>(x, y); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===- ExpandVariadics.h - expand variadic functions ------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_TRANSFORMS_IPO_EXPANDVARIADICS_H | ||
#define LLVM_TRANSFORMS_IPO_EXPANDVARIADICS_H | ||
|
||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
|
||
class Module; | ||
class ModulePass; | ||
class OptimizationLevel; | ||
|
||
enum class ExpandVariadicsMode { | ||
Unspecified, // Use the implementation defaults | ||
Disable, // Disable the pass entirely | ||
Optimize, // Optimise without changing ABI | ||
Lowering, // Change variadic calling convention | ||
}; | ||
|
||
class ExpandVariadicsPass : public PassInfoMixin<ExpandVariadicsPass> { | ||
const ExpandVariadicsMode Mode; | ||
|
||
public: | ||
// Operates under passed mode unless overridden on commandline | ||
ExpandVariadicsPass(ExpandVariadicsMode Mode); | ||
|
||
// Chooses disable or optimize based on optimization level | ||
ExpandVariadicsPass(OptimizationLevel Level); | ||
|
||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); | ||
}; | ||
|
||
ModulePass *createExpandVariadicsPass(ExpandVariadicsMode); | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_TRANSFORMS_IPO_EXPANDVARIADICS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
^this disable shouldn't be necessary, having trouble working out what the filecheck regex are complaining about