zequanwu created this revision.
zequanwu added reviewers: aaron.ballman, rnk.
Herald added subscribers: dexonsmith, jdoerfert.
zequanwu requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This adds `disable-merge` function attribute which is similar to `nomerge` 
statement attribute introduced at https://reviews.llvm.org/D79121.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92800

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-disable-merge.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-disable-merge.c
  clang/test/SemaCXX/attr-disable-merge.cpp
  llvm/include/llvm/IR/Attributes.td

Index: llvm/include/llvm/IR/Attributes.td
===================================================================
--- llvm/include/llvm/IR/Attributes.td
+++ llvm/include/llvm/IR/Attributes.td
@@ -121,7 +121,7 @@
 /// Function is called early and/or often, so lazy binding isn't worthwhile.
 def NonLazyBind : EnumAttr<"nonlazybind">;
 
-/// Disable merging for call sites
+/// Disable merging for specified function or call sites.
 def NoMerge : EnumAttr<"nomerge">;
 
 /// Pointer is known to be not null.
Index: clang/test/SemaCXX/attr-disable-merge.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/attr-disable-merge.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+class A {
+public:
+  [[clang::disable_merge]] virtual int foo1() { return 1; }
+  [[clang::disable_merge]] int foo2() { return 2; }
+};
\ No newline at end of file
Index: clang/test/Sema/attr-disable-merge.c
===================================================================
--- /dev/null
+++ clang/test/Sema/attr-disable-merge.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int foo __attribute__((disable_merge)); // expected-warning {{'disable_merge' attribute only applies to functions}}
+
+int bar(int a) __attribute__((disable_merge("abc"))); // expected-error {{'disable_merge' attribute takes no arguments}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===================================================================
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -54,6 +54,7 @@
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, SubjectMatchRule_variable, SubjectMatchRule_record, SubjectMatchRule_objc_interface)
 // CHECK-NEXT: Destructor (SubjectMatchRule_function)
+// CHECK-NEXT: DisableMerge (SubjectMatchRule_function)
 // CHECK-NEXT: DisableTailCalls (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: EnableIf (SubjectMatchRule_function)
 // CHECK-NEXT: EnumExtensibility (SubjectMatchRule_enum)
Index: clang/test/CodeGen/attr-disable-merge.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGen/attr-disable-merge.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -S -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
+
+[[clang::disable_merge]] void bar();
+
+void foo(int i) {
+  bar();
+}
+
+// CHECK: call void  @_Z3barv() #[[NOMERGEATTR2:[0-9]+]]
+// CHECK: declare void @_Z3barv() #[[NOMERGEATTR:[0-9]+]]
+// CHECK: attributes #[[NOMERGEATTR]] = { nomerge {{.*}}}
+// CHECK: attributes #[[NOMERGEATTR2]] = { nomerge }
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7743,6 +7743,9 @@
     handleSimpleAttributeWithExclusions<DisableTailCallsAttr, NakedAttr>(S, D,
                                                                          AL);
     break;
+  case ParsedAttr::AT_DisableMerge:
+    handleSimpleAttribute<DisableMergeAttr>(S, D, AL);
+    break;
   case ParsedAttr::AT_Visibility:
     handleVisibilityAttr(S, D, AL, false);
     break;
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1946,6 +1946,8 @@
       FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
     if (TargetDecl->hasAttr<ConvergentAttr>())
       FuncAttrs.addAttribute(llvm::Attribute::Convergent);
+    if (TargetDecl->hasAttr<DisableMergeAttr>())
+      FuncAttrs.addAttribute(llvm::Attribute::NoMerge);
 
     if (const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
       AddAttributesFromFunctionProtoType(
Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -4123,6 +4123,14 @@
   }];
 }
 
+def DisableMergeDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use this attribute to prevent multiple calls to the specified function from 
+merging during optimization.
+  }];
+}
+
 def AnyX86NoCallerSavedRegistersDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1646,6 +1646,13 @@
   let SimpleHandler = 1;
 }
 
+def DisableMerge : InheritableAttr {
+  let Spellings = [Clang<"disable_merge">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [DisableMergeDocs];
+  let SimpleHandler = 1;
+}
+
 def NoMips16 : InheritableAttr, TargetSpecificAttr<TargetMips32> {
   let Spellings = [GCC<"nomips16">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D92800: [Clang] Add disa... Zequan Wu via Phabricator via cfe-commits

Reply via email to