[PATCH] D73072: [Driver][CodeGen] Support -fpatchable-function-entry=N,M where M>0

2020-01-21 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon times-circle color=red} Unit tests: fail. 62081 tests passed, 2 failed 
and 784 were skipped.

  failed: Clang.Driver/cc-print-options.c
  failed: Clang.Driver/fpatchable-function-entry.c

{icon question-circle color=gray} clang-tidy: unknown.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73072/new/

https://reviews.llvm.org/D73072



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73072: [Driver][CodeGen] Support -fpatchable-function-entry=N,M where M>0

2020-01-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 239400.
MaskRay added a comment.

Improve tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73072/new/

https://reviews.llvm.org/D73072

Files:
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/patchable-function-entry.c
  clang/test/Sema/patchable-function-entry-attr.c

Index: clang/test/Sema/patchable-function-entry-attr.c
===
--- clang/test/Sema/patchable-function-entry-attr.c
+++ clang/test/Sema/patchable-function-entry-attr.c
@@ -13,5 +13,5 @@
 // expected-error@+1 {{'patchable_function_entry' attribute requires parameter 0 to be an integer constant}}
 __attribute__((patchable_function_entry(i))) void f();
 
-// expected-error@+1 {{'patchable_function_entry' attribute requires integer constant between 0 and 0 inclusive}}
-__attribute__((patchable_function_entry(1, 1))) void f();
+// expected-error@+1 {{'patchable_function_entry' attribute requires integer constant between 0 and 2 inclusive}}
+__attribute__((patchable_function_entry(2, 3))) void f();
Index: clang/test/CodeGen/patchable-function-entry.c
===
--- clang/test/CodeGen/patchable-function-entry.c
+++ clang/test/CodeGen/patchable-function-entry.c
@@ -17,10 +17,20 @@
 __attribute__((patchable_function_entry(2, 0))) void f20decl();
 void f20decl() {}
 
-// OPT: define void @f() #2
+// CHECK: define void @f44() #2
+__attribute__((patchable_function_entry(4, 4))) void f44() {}
+
+// CHECK: define void @f52() #3
+__attribute__((patchable_function_entry(5, 2))) void f52() {}
+
+// OPT: define void @f() #4
 void f() {}
 
-/// M in patchable_function_entry(N,M) is currently ignored.
-// CHECK: attributes #0 = { {{.*}} "patchable-function-entry"="0"
+/// No need to emit "patchable-function-entry"="0"
+// CHECK: attributes #0 = { {{.*}}
+// CHECK-NOT: "patchable-function-entry"
+
 // CHECK: attributes #1 = { {{.*}} "patchable-function-entry"="2"
-// OPT:   attributes #2 = { {{.*}} "patchable-function-entry"="1"
+// CHECK: attributes #2 = { {{.*}} "patchable-function-entry"="0" "patchable-function-prefix"="4"
+// CHECK: attributes #3 = { {{.*}} "patchable-function-entry"="3" "patchable-function-prefix"="2"
+// OPT:   attributes #4 = { {{.*}} "patchable-function-entry"="1"
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -4924,9 +4924,9 @@
 Expr *Arg = AL.getArgAsExpr(1);
 if (!checkUInt32Argument(S, AL, Arg, Offset, 1, true))
   return;
-if (Offset) {
+if (Count < Offset) {
   S.Diag(getAttrLoc(AL), diag::err_attribute_argument_out_of_range)
-  << &AL << 0 << 0 << Arg->getBeginLoc();
+  << &AL << 0 << Count << Arg->getBeginLoc();
   return;
 }
   }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1102,6 +1102,8 @@
 
   Opts.PatchableFunctionEntryCount =
   getLastArgIntValue(Args, OPT_fpatchable_function_entry_EQ, 0, Diags);
+  Opts.PatchableFunctionEntryOffset = getLastArgIntValue(
+  Args, OPT_fpatchable_function_entry_offset_EQ, 0, Diags);
   Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
   Opts.CallFEntry = Args.hasArg(OPT_mfentry);
   Opts.MNopMCount = Args.hasArg(OPT_mnop_mcount);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5111,20 +5111,23 @@
 
   if (Arg *A = Args.getLastArg(options::OPT_fpatchable_function_entry_EQ)) {
 StringRef S0 = A->getValue(), S = S0;
-unsigned Size, Start = 0;
+unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && Triple.getArch() != llvm::Triple::x86 &&
 Triple.getArch() != llvm::Triple::x86_64)
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 else if (S.consumeInteger(10, Size) ||
  (!S.empty() && (!S.consume_front(",") ||
- S.consumeInteger(10, Start) || !S.empty(
+ S.consumeInteger(10, Offset) || !S.empty(
   D.Diag(diag::err_drv_invalid_argument_to_option)
   << S0 << A->getOption().getName();
-else if (Start)
+else if (Size < Offset)
   D.Diag(diag::err_drv_unsupported_fp

[PATCH] D73072: [Driver][CodeGen] Support -fpatchable-function-entry=N,M where M>0

2020-01-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the patch!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73072/new/

https://reviews.llvm.org/D73072



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73072: [Driver][CodeGen] Support -fpatchable-function-entry=N,M where M>0

2020-01-20 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon times-circle color=red} Unit tests: fail. 62040 tests passed, 2 failed 
and 783 were skipped.

  failed: Clang.CodeGen/patchable-function-entry.c
  failed: Clang.Driver/fpatchable-function-entry.c

{icon question-circle color=gray} clang-tidy: unknown.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73072/new/

https://reviews.llvm.org/D73072



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73072: [Driver][CodeGen] Support -fpatchable-function-entry=N,M where M>0

2020-01-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: aaron.ballman, craig.topper, nickdesaulniers, nsz, 
ostannard, peter.smith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
MaskRay added a parent revision: D73071: [X86] Support 
-fpatchable-function-entry=N,M where M>0.
MaskRay retitled this revision from "[Driver][CodeGen] Support 
-fpatchable-function-prefix=N,M where M>0" to "[Driver][CodeGen] Support 
-fpatchable-function-entry=N,M where M>0".

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73072

Files:
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/patchable-function-entry.c
  clang/test/Sema/patchable-function-entry-attr.c

Index: clang/test/Sema/patchable-function-entry-attr.c
===
--- clang/test/Sema/patchable-function-entry-attr.c
+++ clang/test/Sema/patchable-function-entry-attr.c
@@ -13,5 +13,5 @@
 // expected-error@+1 {{'patchable_function_entry' attribute requires parameter 0 to be an integer constant}}
 __attribute__((patchable_function_entry(i))) void f();
 
-// expected-error@+1 {{'patchable_function_entry' attribute requires integer constant between 0 and 0 inclusive}}
-__attribute__((patchable_function_entry(1, 1))) void f();
+// expected-error@+1 {{'patchable_function_entry' attribute requires integer constant between 0 and 2 inclusive}}
+__attribute__((patchable_function_entry(2, 3))) void f();
Index: clang/test/CodeGen/patchable-function-entry.c
===
--- clang/test/CodeGen/patchable-function-entry.c
+++ clang/test/CodeGen/patchable-function-entry.c
@@ -17,10 +17,14 @@
 __attribute__((patchable_function_entry(2, 0))) void f20decl();
 void f20decl() {}
 
-// OPT: define void @f() #2
+// CHECK: define void @f52() #2
+__attribute__((patchable_function_entry(5, 2))) void f52() {}
+
+// OPT: define void @f() #3
 void f() {}
 
 /// M in patchable_function_entry(N,M) is currently ignored.
 // CHECK: attributes #0 = { {{.*}} "patchable-function-entry"="0"
 // CHECK: attributes #1 = { {{.*}} "patchable-function-entry"="2"
-// OPT:   attributes #2 = { {{.*}} "patchable-function-entry"="1"
+// CHECK: attributes #2 = { {{.*}} "patchable-function-entry"="3" "patchable-function-prefix"="2"
+// OPT:   attributes #3 = { {{.*}} "patchable-function-entry"="1"
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -4924,9 +4924,9 @@
 Expr *Arg = AL.getArgAsExpr(1);
 if (!checkUInt32Argument(S, AL, Arg, Offset, 1, true))
   return;
-if (Offset) {
+if (Count < Offset) {
   S.Diag(getAttrLoc(AL), diag::err_attribute_argument_out_of_range)
-  << &AL << 0 << 0 << Arg->getBeginLoc();
+  << &AL << 0 << Count << Arg->getBeginLoc();
   return;
 }
   }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1102,6 +1102,8 @@
 
   Opts.PatchableFunctionEntryCount =
   getLastArgIntValue(Args, OPT_fpatchable_function_entry_EQ, 0, Diags);
+  Opts.PatchableFunctionEntryOffset = getLastArgIntValue(
+  Args, OPT_fpatchable_function_entry_offset_EQ, 0, Diags);
   Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
   Opts.CallFEntry = Args.hasArg(OPT_mfentry);
   Opts.MNopMCount = Args.hasArg(OPT_mnop_mcount);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5111,20 +5111,23 @@
 
   if (Arg *A = Args.getLastArg(options::OPT_fpatchable_function_entry_EQ)) {
 StringRef S0 = A->getValue(), S = S0;
-unsigned Size, Start = 0;
+unsigned Size, Offset = 0;
 if (!Triple.isAArch64() && Triple.getArch() != llvm::Triple::x86 &&
 Triple.getArch() != llvm::Triple::x86_64)
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 else if (S.consumeInteger(10, Size) ||
  (!S.empty() && (!S.consume_front(",") ||
- S.consumeInteger(10, Start) || !S.empty(
+ S.consumeInteger(10, Offset) || !S.empty(
   D.Diag(diag::err_drv_invalid_argument_to_option)
   << S0 << A->getOption().getName();
-else if (Start)
+else if (Size < Offset)
   D.Diag(diag::err_drv_unsupported_fp