[PATCH] D85473: [Clang] Add option to allow marking pass-by-value args as noalias.
Florian Hahn via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 7 01:23:09 PDT 2020
fhahn updated this revision to Diff 283837.
fhahn added a comment.
Thanks for taking a look!
I adjusted the LangOpts description and added the flag to f_Group, as suggested.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85473/new/
https://reviews.llvm.org/D85473
Files:
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/pass-by-value-noalias.c
Index: clang/test/CodeGen/pass-by-value-noalias.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/pass-by-value-noalias.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fpass-by-value-is-noalias -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=WITH_NOALIAS %s
+// RUN: %clang_cc1 -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=NO_NOALIAS %s
+
+// A struct large enough so it is not passed in registers on ARM64.
+struct Foo {
+ int a;
+ int b;
+ int c;
+ int d;
+ int e;
+ int f;
+};
+
+// WITH_NOALIAS: define void @take(%struct.Foo* noalias %arg)
+// NO_NOALIAS: define void @take(%struct.Foo* %arg)
+void take(struct Foo arg) {}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3419,6 +3419,7 @@
Opts.PCHInstantiateTemplates = Args.hasArg(OPT_fpch_instantiate_templates);
Opts.MatrixTypes = Args.hasArg(OPT_fenable_matrix);
+ Opts.PassByValueIsNoAlias = Args.hasArg(OPT_fpass_by_value_is_noalias);
Opts.MaxTokens = getLastArgIntValue(Args, OPT_fmax_tokens_EQ, 0, Diags);
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2192,6 +2192,11 @@
if (AI.getIndirectByVal())
Attrs.addByValAttr(getTypes().ConvertTypeForMem(ParamType));
+ if (getLangOpts().PassByValueIsNoAlias)
+ // When calling the function, the pointer passed in will be the only
+ // reference to the underlying object. Mark it accordingly.
+ Attrs.addAttribute(llvm::Attribute::NoAlias);
+
// TODO: We could add the byref attribute if not byval, but it would
// require updating many testcases.
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4289,6 +4289,9 @@
def fcompatibility_qualified_id_block_param_type_checking : Flag<["-"], "fcompatibility-qualified-id-block-type-checking">,
HelpText<"Allow using blocks with parameters of more specific type than "
"the type system guarantees when a parameter is qualified id">;
+def fpass_by_value_is_noalias: Flag<["-"], "fpass-by-value-is-noalias">,
+ HelpText<"Allows assuming by-value parameters do not alias any other value."
+ "Note that this may not hold for C++.">, Group<f_Group>;
// FIXME: Remove these entirely once functionality/tests have been excised.
def fobjc_gc_only : Flag<["-"], "fobjc-gc-only">, Group<f_Group>,
Index: clang/include/clang/Basic/LangOptions.def
===================================================================
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -368,6 +368,8 @@
LANGOPT(RegisterStaticDestructors, 1, 1, "Register C++ static destructors")
LANGOPT(MatrixTypes, 1, 0, "Enable or disable the builtin matrix type")
+LANGOPT(PassByValueIsNoAlias, 1, 0, "assumption that by-value parameters do "
+ "not alias any other values")
COMPATIBLE_VALUE_LANGOPT(MaxTokens, 32, 0, "Max number of tokens per TU or 0")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85473.283837.patch
Type: text/x-patch
Size: 3462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200807/3b5e519d/attachment-0001.bin>
More information about the cfe-commits
mailing list