[llvm-branch-commits] [llvm] [llvm-exegesis] Switch from MCJIT to LLJIT (PR #72838)

2023-11-24 Thread Clement Courbet via llvm-branch-commits


@@ -324,66 +325,44 @@ object::OwningBinary 
getObjectFromFile(StringRef Filename) {
   return cantFail(object::ObjectFile::createObjectFile(Filename));
 }
 
-namespace {
-
-// Implementation of this class relies on the fact that a single object with a
-// single function will be loaded into memory.
-class TrackingSectionMemoryManager : public SectionMemoryManager {
-public:
-  explicit TrackingSectionMemoryManager(uintptr_t *CodeSize)
-  : CodeSize(CodeSize) {}
-
-  uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
-   unsigned SectionID,
-   StringRef SectionName) override {
-*CodeSize = Size;
-return SectionMemoryManager::allocateCodeSection(Size, Alignment, 
SectionID,
- SectionName);
-  }
-
-private:
-  uintptr_t *const CodeSize = nullptr;
-};
-
-} // namespace
-
 Expected ExecutableFunction::create(
 std::unique_ptr TM,
 object::OwningBinary &&ObjectFileHolder) {
   assert(ObjectFileHolder.getBinary() && "cannot create object file");
   std::unique_ptr Ctx = std::make_unique();
-  // Initializing the execution engine.
-  // We need to use the JIT EngineKind to be able to add an object file.
-  LLVMLinkInMCJIT();
-  uintptr_t CodeSize = 0;
-  std::string Error;
-  std::unique_ptr EE(
-  EngineBuilder(createModule(Ctx, TM->createDataLayout()))
-  .setErrorStr(&Error)
-  .setMCPU(TM->getTargetCPU())
-  .setEngineKind(EngineKind::JIT)
-  .setMCJITMemoryManager(
-  std::make_unique(&CodeSize))
-  .create(TM.release()));
-  if (!EE)
-return make_error(Twine(Error), inconvertibleErrorCode());
-  // Adding the generated object file containing the assembled function.
-  // The ExecutionEngine makes sure the object file is copied into an
-  // executable page.
-  EE->addObjectFile(std::move(ObjectFileHolder));
-  // Fetching function bytes.
-  const uint64_t FunctionAddress = EE->getFunctionAddress(FunctionID);
+
+  auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
+  assert(SymbolSizes.size() == 3);
+  uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);

legrosbuffle wrote:

Can you add a comment to explain which symbols we're expecting ?

https://github.com/llvm/llvm-project/pull/72838
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Switch from MCJIT to LLJIT (PR #72838)

2023-11-24 Thread Clement Courbet via llvm-branch-commits

https://github.com/legrosbuffle edited 
https://github.com/llvm/llvm-project/pull/72838
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Switch from MCJIT to LLJIT (PR #72838)

2023-11-24 Thread Clement Courbet via llvm-branch-commits

https://github.com/legrosbuffle approved this pull request.


https://github.com/llvm/llvm-project/pull/72838
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Add tablegen support for validation counters (PR #76652)

2024-01-05 Thread Clement Courbet via llvm-branch-commits


@@ -28,6 +28,22 @@ class PfmIssueCounter
   string ResourceName = resource_name;
 }
 
+class ValidationEvent  {

legrosbuffle wrote:

This needs doc to explain what a `ValidationEvent` and `PfmValidationCounter` 
are.

https://github.com/llvm/llvm-project/pull/76652
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Add tablegen support for validation counters (PR #76652)

2024-01-05 Thread Clement Courbet via llvm-branch-commits


@@ -59,6 +68,8 @@ struct PfmCountersInfo {
   const IssueCounter *IssueCounters;
   unsigned NumIssueCounters;
 
+  std::unordered_map ValidationCounters;

legrosbuffle wrote:

`unordered_map` means that:

 - We'll allocate on startup.
 - We don't have consistent ordering between runs, which might be a source of 
debugging pain.

Can we use a sorted array of `pair` instead ?

https://github.com/llvm/llvm-project/pull/76652
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-10 Thread Clement Courbet via llvm-branch-commits


@@ -112,9 +116,11 @@ class Counter {
   PerfEvent Event;
   int FileDescriptor = -1;
   bool IsDummyEvent;
+  std::vector ValidationEvents;

legrosbuffle wrote:

This is a bit weird, because the class `Counter` now holds several perf events. 
If we need several counters, we shoul dbe creating several `Counter` instances.

https://github.com/llvm/llvm-project/pull/76653
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-10 Thread Clement Courbet via llvm-branch-commits


@@ -87,6 +93,8 @@ struct BenchmarkMeasure {
   // This is the per-snippet value, i.e. measured quantity for one repetition 
of
   // the whole snippet.
   double PerSnippetValue;
+  // These are the validation counter values.
+  std::unordered_map ValidationCounters;

legrosbuffle wrote:

Can we make this an ordered map ? This will make the yaml output stable.

https://github.com/llvm/llvm-project/pull/76653
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [llvm-exegesis] Refactor individual counter data to ConfiguredEvent (PR #77900)

2024-01-12 Thread Clement Courbet via llvm-branch-commits

https://github.com/legrosbuffle approved this pull request.


https://github.com/llvm/llvm-project/pull/77900
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [llvm] [libc] [flang] [libcxxabi] [lld] [compiler-rt] [clang-tools-extra] [clang] [lldb] [llvm-exegesis] Add support for validation counters (PR #76653)

2024-01-16 Thread Clement Courbet via llvm-branch-commits

https://github.com/legrosbuffle approved this pull request.


https://github.com/llvm/llvm-project/pull/76653
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 735e6c8 - [MergeICmps] Fix missing split.

2020-12-01 Thread Clement Courbet via llvm-branch-commits

Author: Clement Courbet
Date: 2020-12-01T16:50:55+01:00
New Revision: 735e6c888ec8d647609d242a165e3631423a709d

URL: 
https://github.com/llvm/llvm-project/commit/735e6c888ec8d647609d242a165e3631423a709d
DIFF: 
https://github.com/llvm/llvm-project/commit/735e6c888ec8d647609d242a165e3631423a709d.diff

LOG: [MergeICmps] Fix missing split.

We were not correctly splitting a blocks for chains of length 1.

Before that change, additional instructions for blocks in chains of
length 1 were not split off from the block before removing (this was
done correctly for chains of longer size).
If this first block contained an instruction referenced elsewhere,
deleting the block, would result in invalidation of the produced value.

This caused a miscompile which motivated D92297 (before D17993,
nonnull and dereferenceable attributed were not added so MergeICmps were
not triggered.) The new test gep-references-bb.ll demonstrate the issue.

The regression was introduced in
rG0efadbbcdeb82f5c14f38fbc2826107063ca48b2.

This supersedes D92364.

Test case by MaskRay (Fangrui Song).

Differential Revision: https://reviews.llvm.org/D92375

Added: 
llvm/test/Transforms/MergeICmps/X86/gep-references-bb.ll

Modified: 
llvm/lib/Transforms/Scalar/MergeICmps.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp 
b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
index e3058af73c11..1559e7a41a7c 100644
--- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -624,6 +624,18 @@ static BasicBlock *mergeComparisons(ArrayRef 
Comparisons,
   Value *IsEqual = nullptr;
   LLVM_DEBUG(dbgs() << "Merging " << Comparisons.size() << " comparisons -> "
 << BB->getName() << "\n");
+
+  // If there is one block that requires splitting, we do it now, i.e.
+  // just before we know we will collapse the chain. The instructions
+  // can be executed before any of the instructions in the chain.
+  const auto ToSplit =
+  std::find_if(Comparisons.begin(), Comparisons.end(),
+   [](const BCECmpBlock &B) { return B.RequireSplit; });
+  if (ToSplit != Comparisons.end()) {
+LLVM_DEBUG(dbgs() << "Splitting non_BCE work to header\n");
+ToSplit->split(BB, AA);
+  }
+
   if (Comparisons.size() == 1) {
 LLVM_DEBUG(dbgs() << "Only one comparison, updating branches\n");
 Value *const LhsLoad =
@@ -633,17 +645,6 @@ static BasicBlock *mergeComparisons(ArrayRef 
Comparisons,
 // There are no blocks to merge, just do the comparison.
 IsEqual = Builder.CreateICmpEQ(LhsLoad, RhsLoad);
   } else {
-// If there is one block that requires splitting, we do it now, i.e.
-// just before we know we will collapse the chain. The instructions
-// can be executed before any of the instructions in the chain.
-const auto ToSplit =
-std::find_if(Comparisons.begin(), Comparisons.end(),
- [](const BCECmpBlock &B) { return B.RequireSplit; });
-if (ToSplit != Comparisons.end()) {
-  LLVM_DEBUG(dbgs() << "Splitting non_BCE work to header\n");
-  ToSplit->split(BB, AA);
-}
-
 const unsigned TotalSizeBits = std::accumulate(
 Comparisons.begin(), Comparisons.end(), 0u,
 [](int Size, const BCECmpBlock &C) { return Size + C.SizeBits(); });

diff  --git a/llvm/test/Transforms/MergeICmps/X86/gep-references-bb.ll 
b/llvm/test/Transforms/MergeICmps/X86/gep-references-bb.ll
new file mode 100644
index ..c42667da1df8
--- /dev/null
+++ b/llvm/test/Transforms/MergeICmps/X86/gep-references-bb.ll
@@ -0,0 +1,64 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -S -mergeicmps -verify-dom-info | FileCheck %s
+target triple = "x86_64"
+
+%Triple = type { i32, i32, i32, i32 }
+
+@g = external global i32
+
+; bb1 references a gep introduced in bb0. The gep must remain available after
+; the merge.
+define i1 @bug(%Triple* nonnull dereferenceable(16) %lhs, %Triple* nonnull 
dereferenceable(16) %rhs) {
+; CHECK-LABEL: @bug(
+; CHECK-NEXT:  bb0:
+; CHECK-NEXT:store i32 1, i32* @g, align 4
+; CHECK-NEXT:[[GEP:%.*]] = getelementptr [[TRIPLE:%.*]], %Triple* 
[[RHS:%.*]], i64 0, i32 0
+; CHECK-NEXT:[[L0_ADDR:%.*]] = getelementptr inbounds [[TRIPLE]], %Triple* 
[[LHS:%.*]], i64 0, i32 0
+; CHECK-NEXT:[[L0:%.*]] = load i32, i32* [[L0_ADDR]], align 4
+; CHECK-NEXT:[[R0_ADDR:%.*]] = getelementptr inbounds [[TRIPLE]], %Triple* 
[[RHS]], i64 0, i32 0
+; CHECK-NEXT:[[R0:%.*]] = load i32, i32* [[R0_ADDR]], align 4
+; CHECK-NEXT:[[CMP0:%.*]] = icmp eq i32 [[L0]], [[R0]]
+; CHECK-NEXT:br i1 [[CMP0]], label %"bb1+bb2", label [[FINAL:%.*]]
+; CHECK:   "bb1+bb2":
+; CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds [[TRIPLE]], %Triple* 
[[LHS]], i64 0, i32 2
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr inbounds i32, i32* [[GEP]], i64 2
+; CHECK-NEXT: 

[llvm-branch-commits] [llvm] be45a5a - [CodeGen][Tests] Fix b3cf70427eb1e97d9b89ba6e9298c280c8a32c74

2020-02-19 Thread Clement Courbet via llvm-branch-commits

Author: Clement Courbet
Date: 2020-02-19T13:32:46+01:00
New Revision: be45a5a4092d678c992ac5d32e4b41da9367989a

URL: 
https://github.com/llvm/llvm-project/commit/be45a5a4092d678c992ac5d32e4b41da9367989a
DIFF: 
https://github.com/llvm/llvm-project/commit/be45a5a4092d678c992ac5d32e4b41da9367989a.diff

LOG: [CodeGen][Tests] Fix b3cf70427eb1e97d9b89ba6e9298c280c8a32c74

Add missing lit.local.cfg in test/Transforms/CodeGenPrepare/PowerPC

Added: 
llvm/test/Transforms/CodeGenPrepare/PowerPC/lit.local.cfg

Modified: 


Removed: 




diff  --git a/llvm/test/Transforms/CodeGenPrepare/PowerPC/lit.local.cfg 
b/llvm/test/Transforms/CodeGenPrepare/PowerPC/lit.local.cfg
new file mode 100644
index ..091332439b18
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/PowerPC/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'PowerPC' in config.root.targets:
+config.unsupported = True



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 5b8c1ed - [llvm-exegesis] Fix D80610.

2020-06-02 Thread Clement Courbet via llvm-branch-commits

Author: Clement Courbet
Date: 2020-06-02T10:10:01+02:00
New Revision: 5b8c1ed2c802d3ae016363bab6d1e117b09ecdc9

URL: 
https://github.com/llvm/llvm-project/commit/5b8c1ed2c802d3ae016363bab6d1e117b09ecdc9
DIFF: 
https://github.com/llvm/llvm-project/commit/5b8c1ed2c802d3ae016363bab6d1e117b09ecdc9.diff

LOG: [llvm-exegesis] Fix D80610.

Summary:
Using a .data() member on a StringRef was discarding the StringRef
size, breaking llvm-exegesis on machines with counter sums (e.g.
Zen2).

Reviewers: oontvoo

Subscribers: mstojanovic, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80982

Added: 


Modified: 
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/Target.cpp
llvm/tools/llvm-exegesis/lib/Target.h

Removed: 




diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 522d4210245c..a5565bdfa723 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -55,7 +55,7 @@ class FunctionExecutorImpl : public 
BenchmarkRunner::FunctionExecutor {
 for (auto &CounterName : CounterNames) {
   CounterName = CounterName.trim();
   auto CounterOrError =
-  State.getExegesisTarget().createCounter(CounterName.data(), State);
+  State.getExegesisTarget().createCounter(CounterName, State);
 
   if (!CounterOrError)
 return CounterOrError.takeError();

diff  --git a/llvm/tools/llvm-exegesis/lib/Target.cpp 
b/llvm/tools/llvm-exegesis/lib/Target.cpp
index 61821bf4bb4d..6150c738dad8 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -30,8 +30,7 @@ const ExegesisTarget *ExegesisTarget::lookup(Triple TT) {
 }
 
 Expected>
-ExegesisTarget::createCounter(const char *CounterName,
-  const LLVMState &) const {
+ExegesisTarget::createCounter(StringRef CounterName, const LLVMState &) const {
   pfm::PerfEvent Event(CounterName);
   if (!Event.valid())
 return llvm::make_error(

diff  --git a/llvm/tools/llvm-exegesis/lib/Target.h 
b/llvm/tools/llvm-exegesis/lib/Target.h
index 937b88ddb4cc..bcc283ee8fe7 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.h
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -69,7 +69,7 @@ class ExegesisTarget {
 
   // Targets can use this to create target-specific perf counters.
   virtual Expected>
-  createCounter(const char *CounterName, const LLVMState &State) const;
+  createCounter(StringRef CounterName, const LLVMState &State) const;
 
   // Targets can use this to add target-specific passes in assembleToStream();
   virtual void addTargetSpecificPasses(PassManagerBase &PM) const {}



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits