\r
Query for this feature with ``__has_extension(attribute_overloadable)``.\r
\r
+noduplicate\r
+-----------\r
+.. csv-table:: Supported Syntaxes\r
+ :header: "GNU", "C++11", "__declspec", "Keyword"\r
+\r
+ "X","X","",""\r
+\r
+The ``noduplicate`` attribute can be placed on function declarations to control\r
+whether function calls to this function can be duplicated \r
+or not as a result of optimizations. This is required for the implementation\r
+of functions with certain special requirements, like the OpenCL "barrier", \r
+function that, depending on the hardware, might require to be run concurrently\r
+by all the threads that are currently executing in lockstep on the hardware.\r
+For example this attribute applied on the function "nodupfunc" \r
+avoids that this code:\r
+\r
+.. code-block:: c\r
+\r
+ void nodupfunc() __attribute__((noduplicate));\r
+ // Setting it as a C++11 attribute is also valid\r
+ // void nodupfunc() [[clang::noduplicate]];\r
+ void foo();\r
+ void bar();\r
+\r
+ nodupfunc();\r
+ if (a > n) {\r
+ foo();\r
+ } else {\r
+ bar();\r
+ }\r
+\r
+gets possibly modified by some optimization into code similar to this:\r
+\r
+.. code-block:: c\r
+\r
+ if (a > n) {\r
+ nodupfunc();\r
+ foo();\r
+ } else {\r
+ nodupfunc();\r
+ bar();\r
+ }\r
+\r
+where the barrier call is duplicated and sunk into the two branches of the condition.\r
\r
Variable Attributes\r
===================\r
let Documentation = [Undocumented];
}
+def NoDuplicate : InheritableAttr {
+ let Spellings = [GNU<"noduplicate">, CXX11<"clang", "noduplicate">];
+ let Subjects = SubjectList<[Function]>;
+ let Documentation = [NoDuplicateDocs];
+}
+
def NoInline : InheritableAttr {
let Spellings = [GCC<"noinline">, Declspec<"noinline">];
let Subjects = SubjectList<[Function]>;
}];
}
+def NoDuplicateDocs : Documentation {
+ let Category = DocCatFunction;
+ let Content = [{
+The ``noduplicate`` attribute can be placed on function declarations to control
+whether function calls to this function can be duplicated
+or not as a result of optimizations. This is required for the implementation
+of functions with certain special requirements, like the OpenCL "barrier",
+function that, depending on the hardware, might require to be run concurrently
+by all the threads that are currently executing in lockstep on the hardware.
+For example this attribute applied on the function "nodupfunc"
+avoids that this code:
+
+.. code-block:: c
+
+ void nodupfunc() __attribute__((noduplicate));
+ // Setting it as a C++11 attribute is also valid
+ // void nodupfunc() [[clang::noduplicate]];
+ void foo();
+ void bar();
+
+ nodupfunc();
+ if (a > n) {
+ foo();
+ } else {
+ bar();
+ }
+
+gets possibly modified by some optimization into code similar to this:
+
+.. code-block:: c
+
+ if (a > n) {
+ nodupfunc();
+ foo();
+ } else {
+ nodupfunc();
+ bar();
+ }
+
+where the barrier call is duplicated and sunk into the two branches of the condition.
+ }];
+}
+
def ObjCRequiresSuperDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
the corresponding arguments are annotated. If the arguments are
incorrect, the caller of ``foo`` will receive a warning.
}];
-}
\ No newline at end of file
+}
FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
if (TargetDecl->hasAttr<NoReturnAttr>())
FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
+ if (TargetDecl->hasAttr<NoDuplicateAttr>())
+ FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
if (const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
const FunctionProtoType *FPT = Fn->getType()->getAs<FunctionProtoType>();
// Naked implies noinline: we should not be inlining such functions.
B.addAttribute(llvm::Attribute::Naked);
B.addAttribute(llvm::Attribute::NoInline);
+ } else if (D->hasAttr<NoDuplicateAttr>()) {
+ B.addAttribute(llvm::Attribute::NoDuplicate);
} else if (D->hasAttr<NoInlineAttr>()) {
B.addAttribute(llvm::Attribute::NoInline);
} else if ((D->hasAttr<AlwaysInlineAttr>() ||
handleSimpleAttribute<PureAttr>(S, D, Attr); break;
case AttributeList::AT_Cleanup: handleCleanupAttr (S, D, Attr); break;
case AttributeList::AT_NoDebug: handleNoDebugAttr (S, D, Attr); break;
+ case AttributeList::AT_NoDuplicate:
+ handleSimpleAttribute<NoDuplicateAttr>(S, D, Attr); break;
case AttributeList::AT_NoInline:
handleSimpleAttribute<NoInlineAttr>(S, D, Attr); break;
case AttributeList::AT_NoInstrumentFunction: // Interacts with -pg.
--- /dev/null
+// RUN: %clang_cc1 -triple=i686-pc-unknown -std=c++11 %s -emit-llvm -o - | FileCheck %s
+
+// This was a problem in Sema, but only shows up as noinline missing
+// in CodeGen.
+
+// CHECK: define i32 @_Z15noduplicatedfuni(i32 %a) [[NI:#[0-9]+]]
+
+int noduplicatedfun [[clang::noduplicate]] (int a) {
+
+ return a+1;
+
+}
+
+int main() {
+
+ return noduplicatedfun(5);
+
+}
+
+// CHECK: attributes [[NI]] = { noduplicate nounwind{{.*}} }
--- /dev/null
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int a __attribute__((noduplicate)); // expected-warning {{'noduplicate' attribute only applies to functions}}
+
+void t1() __attribute__((noduplicate));
+
+void t2() __attribute__((noduplicate(2))); // expected-error {{'noduplicate' attribute takes no arguments}}
+