[llvm] 79c7d34 - Recommit: "[llvm-exegesis] Improve error reporting in Assembler.cpp"
Miloš Stojanović via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 19 05:41:53 PST 2020
Author: Miloš Stojanović
Date: 2020-02-19T14:40:28+01:00
New Revision: 79c7d34dccda441c1bcb7518613deb3202e9df87
URL: https://github.com/llvm/llvm-project/commit/79c7d34dccda441c1bcb7518613deb3202e9df87
DIFF: https://github.com/llvm/llvm-project/commit/79c7d34dccda441c1bcb7518613deb3202e9df87.diff
LOG: Recommit: "[llvm-exegesis] Improve error reporting in Assembler.cpp"
Summary: Commit 63bb9fee525f8f29fd9c2174fa7f15573c3d1fd7 was reverted in
7603bfb4b0a6a90137d47f0182a490fe54bf7ca3 because it broke builds that treat
warnings as errors.
This commit updates the calls to `assembleToStream()` in tests to check that
the return value is valid.
Original commit message:
Followup to D74084.
Replace the use of `report_fatal_error()` with returning the error to
`llvm-exegesis.cpp` and handling it there.
Differential Revision: https://reviews.llvm.org/D74325
Added:
Modified:
llvm/tools/llvm-exegesis/lib/Assembler.cpp
llvm/tools/llvm-exegesis/lib/Assembler.h
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h
Removed:
################################################################################
diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index bb89655435a8..523cb913885e 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -167,11 +167,11 @@ BitVector getFunctionReservedRegs(const TargetMachine &TM) {
return MF.getSubtarget().getRegisterInfo()->getReservedRegs(MF);
}
-void assembleToStream(const ExegesisTarget &ET,
- std::unique_ptr<LLVMTargetMachine> TM,
- ArrayRef<unsigned> LiveIns,
- ArrayRef<RegisterValue> RegisterInitialValues,
- const FillFunction &Fill, raw_pwrite_stream &AsmStream) {
+Error assembleToStream(const ExegesisTarget &ET,
+ std::unique_ptr<LLVMTargetMachine> TM,
+ ArrayRef<unsigned> LiveIns,
+ ArrayRef<RegisterValue> RegisterInitialValues,
+ const FillFunction &Fill, raw_pwrite_stream &AsmStream) {
auto Context = std::make_unique<LLVMContext>();
std::unique_ptr<Module> Module =
createModule(Context, TM->createDataLayout());
@@ -234,15 +234,15 @@ void assembleToStream(const ExegesisTarget &ET,
for (const char *PassName :
{"postrapseudos", "machineverifier", "prologepilog"})
if (addPass(PM, PassName, *TPC))
- report_fatal_error("Unable to add a mandatory pass");
+ return make_error<Failure>("Unable to add a mandatory pass");
TPC->setInitialized();
// AsmPrinter is responsible for generating the assembly into AsmBuffer.
- if (TM->addAsmPrinter(PM, AsmStream, nullptr, CGFT_ObjectFile,
- MCContext))
- report_fatal_error("Cannot add AsmPrinter passes");
+ if (TM->addAsmPrinter(PM, AsmStream, nullptr, CGFT_ObjectFile, MCContext))
+ return make_error<Failure>("Cannot add AsmPrinter passes");
PM.run(*Module); // Run all the passes
+ return Error::success();
}
object::OwningBinary<object::ObjectFile>
diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.h b/llvm/tools/llvm-exegesis/lib/Assembler.h
index 5d4204e4a50c..2a83344b751e 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.h
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.h
@@ -18,6 +18,7 @@
#include <memory>
#include "BenchmarkCode.h"
+#include "Error.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/CodeGen/MachineFunction.h"
@@ -86,11 +87,11 @@ using FillFunction = std::function<void(FunctionFiller &)>;
// Instructions. Runs a set of llvm Passes to provide correct prologue and
// epilogue. Once the MachineFunction is ready, it is assembled for TM to
// AsmStream, the temporary function is eventually discarded.
-void assembleToStream(const ExegesisTarget &ET,
- std::unique_ptr<LLVMTargetMachine> TM,
- ArrayRef<unsigned> LiveIns,
- ArrayRef<RegisterValue> RegisterInitialValues,
- const FillFunction &Fill, raw_pwrite_stream &AsmStream);
+Error assembleToStream(const ExegesisTarget &ET,
+ std::unique_ptr<LLVMTargetMachine> TM,
+ ArrayRef<unsigned> LiveIns,
+ ArrayRef<RegisterValue> RegisterInitialValues,
+ const FillFunction &Fill, raw_pwrite_stream &AsmStream);
// Creates an ObjectFile in the format understood by the host.
// Note: the resulting object keeps a copy of Buffer so it can be discarded once
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 6981aaa46cd9..5b15bc29c60d 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -101,10 +101,12 @@ Expected<InstructionBenchmark> BenchmarkRunner::runConfiguration(
{
SmallString<0> Buffer;
raw_svector_ostream OS(Buffer);
- assembleToStream(State.getExegesisTarget(), State.createTargetMachine(),
- BC.LiveIns, BC.Key.RegisterInitialValues,
- Repetitor.Repeat(Instructions, kMinInstructionsForSnippet),
- OS);
+ if (Error E = assembleToStream(
+ State.getExegesisTarget(), State.createTargetMachine(), BC.LiveIns,
+ BC.Key.RegisterInitialValues,
+ Repetitor.Repeat(Instructions, kMinInstructionsForSnippet), OS)) {
+ return std::move(E);
+ }
const ExecutableFunction EF(State.createTargetMachine(),
getObjectFromBuffer(OS.str()));
const auto FnBytes = EF.getFunctionBytes();
@@ -129,8 +131,11 @@ Expected<InstructionBenchmark> BenchmarkRunner::runConfiguration(
} else {
SmallString<0> Buffer;
raw_svector_ostream OS(Buffer);
- assembleToStream(State.getExegesisTarget(), State.createTargetMachine(),
- BC.LiveIns, BC.Key.RegisterInitialValues, Filler, OS);
+ if (Error E = assembleToStream(State.getExegesisTarget(),
+ State.createTargetMachine(), BC.LiveIns,
+ BC.Key.RegisterInitialValues, Filler, OS)) {
+ return std::move(E);
+ }
ObjectFile = getObjectFromBuffer(OS.str());
}
@@ -165,8 +170,11 @@ BenchmarkRunner::writeObjectFile(const BenchmarkCode &BC,
sys::fs::createTemporaryFile("snippet", "o", ResultFD, ResultPath)))
return std::move(E);
raw_fd_ostream OFS(ResultFD, true /*ShouldClose*/);
- assembleToStream(State.getExegesisTarget(), State.createTargetMachine(),
- BC.LiveIns, BC.Key.RegisterInitialValues, FillFunction, OFS);
+ if (Error E = assembleToStream(
+ State.getExegesisTarget(), State.createTargetMachine(), BC.LiveIns,
+ BC.Key.RegisterInitialValues, FillFunction, OFS)) {
+ return std::move(E);
+ }
return std::string(ResultPath.str());
}
diff --git a/llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h b/llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h
index 795b0d6ab64b..239685beb14e 100644
--- a/llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h
+++ b/llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h
@@ -77,8 +77,8 @@ class MachineFunctionGeneratorBaseTest : public ::testing::Test {
FillFunction Fill) {
SmallString<256> Buffer;
raw_svector_ostream AsmStream(Buffer);
- assembleToStream(*ET, createTargetMachine(), /*LiveIns=*/{},
- RegisterInitialValues, Fill, AsmStream);
+ EXPECT_FALSE(assembleToStream(*ET, createTargetMachine(), /*LiveIns=*/{},
+ RegisterInitialValues, Fill, AsmStream));
return ExecutableFunction(createTargetMachine(),
getObjectFromBuffer(AsmStream.str()));
}
More information about the llvm-commits
mailing list