-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync AFDO/Propeller with internal and enable Arm SPE support (#191)
Sync AFDO/Propeller with internal This change: 1. Updates necessary dependencies 2. Brings AutoFDO and Propeller core libraries up to date 3. Adds library functionality for SPE-driven Propeller and AutoFDO profile generation 4. Enables SPE-driven Propeller and AutoFDO profile generation in create_llvm_prof 5. Reapplies PR #134 and #156, which weren't synced internally
- Loading branch information
1 parent
1fe2d5f
commit 623c777
Showing
183 changed files
with
16,118 additions
and
5,495 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "addr2cu.h" | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
|
||
#include "base/logging.h" | ||
#include "third_party/abseil/absl/algorithm/container.h" | ||
#include "third_party/abseil/absl/status/status.h" | ||
#include "third_party/abseil/absl/status/statusor.h" | ||
#include "third_party/abseil/absl/strings/str_format.h" | ||
#include "third_party/abseil/absl/strings/string_view.h" | ||
#include "llvm/BinaryFormat/Dwarf.h" | ||
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" | ||
#include "llvm/DebugInfo/DWARF/DWARFContext.h" | ||
#include "llvm/DebugInfo/DWARF/DWARFDie.h" | ||
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h" | ||
#include "llvm/Object/ObjectFile.h" | ||
|
||
namespace devtools_crosstool_autofdo { | ||
|
||
absl::StatusOr<std::unique_ptr<llvm::DWARFContext>> CreateDWARFContext( | ||
const llvm::object::ObjectFile &obj, absl::string_view dwp_file) { | ||
std::unique_ptr<llvm::DWARFContext> dwarf_context = | ||
llvm::DWARFContext::create( | ||
obj, llvm::DWARFContext::ProcessDebugRelocations::Process, | ||
/*const LoadedObjectInfo *L=*/ nullptr, std::string(dwp_file)); | ||
CHECK(dwarf_context != nullptr); | ||
if (dwp_file.empty() && | ||
absl::c_any_of(dwarf_context->compile_units(), | ||
[](std::unique_ptr<llvm::DWARFUnit> &cu) { | ||
return cu->getUnitDIE().getTag() == | ||
llvm::dwarf::DW_TAG_skeleton_unit; | ||
})) { | ||
return absl::FailedPreconditionError( | ||
"skeleton unit found without a corresponding dwp file"); | ||
} | ||
if (!dwarf_context->getNumCompileUnits()) { | ||
return absl::FailedPreconditionError( | ||
"no compilation unit found, binary must be built with debuginfo"); | ||
} | ||
return dwarf_context; | ||
} | ||
|
||
absl::StatusOr<absl::string_view> Addr2Cu::GetCompileUnitFileNameForCodeAddress( | ||
uint64_t code_address) { | ||
llvm::DWARFCompileUnit *unit = | ||
dwarf_context_.getCompileUnitForCodeAddress(code_address); | ||
if (unit == nullptr) { | ||
return absl::FailedPreconditionError(absl::StrFormat( | ||
"no compile unit found on address 0x%x", code_address)); | ||
} | ||
llvm::DWARFDie die = unit->getNonSkeletonUnitDIE(); | ||
std::optional<llvm::DWARFFormValue> form_value = | ||
die.findRecursively({llvm::dwarf::DW_AT_name}); | ||
llvm::StringRef name = llvm::dwarf::toStringRef(form_value, ""); | ||
return absl::string_view(name.data(), name.size()); | ||
} | ||
} // namespace devtools_crosstool_autofdo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef AUTOFDOADDR2CU_H_ | ||
#define AUTOFDOADDR2CU_H_ | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
|
||
#include "third_party/abseil/absl/status/statusor.h" | ||
#include "third_party/abseil/absl/strings/string_view.h" | ||
#include "llvm/DebugInfo/DWARF/DWARFContext.h" | ||
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h" | ||
#include "llvm/Object/ObjectFile.h" | ||
|
||
namespace devtools_crosstool_autofdo { | ||
|
||
// Creates an `llvm::DWARFContext` instance, which can then be used to create | ||
// an `Addr2Cu` instance. | ||
absl::StatusOr<std::unique_ptr<llvm::DWARFContext>> CreateDWARFContext( | ||
const llvm::object::ObjectFile &obj, absl::string_view dwp_file = ""); | ||
|
||
// Utility class that gets the module name for a code address with | ||
// the help of debug information. | ||
class Addr2Cu { | ||
public: | ||
explicit Addr2Cu(llvm::DWARFContext &dwarf_context) | ||
: dwarf_context_(dwarf_context) {} | ||
|
||
Addr2Cu(const Addr2Cu&) = delete; | ||
Addr2Cu& operator=(const Addr2Cu&) = delete; | ||
|
||
Addr2Cu(Addr2Cu &&) = delete; | ||
Addr2Cu& operator=(Addr2Cu &&) = delete; | ||
|
||
// Returns the file name for the compile unit that contains the given code | ||
// address. Note: the returned string_view lives as long as `dwarf_context_`. | ||
absl::StatusOr<absl::string_view> GetCompileUnitFileNameForCodeAddress( | ||
uint64_t code_address); | ||
|
||
private: | ||
llvm::DWARFContext &dwarf_context_; | ||
}; | ||
} // namespace devtools_crosstool_autofdo | ||
#endif // AUTOFDOADDR2CU_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "addr2cu.h" | ||
|
||
#include <fstream> | ||
#include <ios> | ||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
|
||
#include "base/logging.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include "third_party/abseil/absl/status/statusor.h" | ||
#include "third_party/abseil/absl/strings/str_cat.h" | ||
#include "third_party/abseil/absl/strings/string_view.h" | ||
#include "llvm/DebugInfo/DWARF/DWARFContext.h" | ||
#include "llvm/Object/ObjectFile.h" | ||
#include "llvm/Support/ErrorOr.h" | ||
#include "llvm/Support/MemoryBuffer.h" | ||
#include "util/testing/status_matchers.h" | ||
|
||
namespace { | ||
|
||
using ::devtools_crosstool_autofdo::Addr2Cu; | ||
using ::devtools_crosstool_autofdo::CreateDWARFContext; | ||
using ::testing::HasSubstr; | ||
using ::testing::status::IsOkAndHolds; | ||
using ::testing::status::StatusIs; | ||
|
||
uint64_t GetSymbolAddress(const std::string &symmap, absl::string_view symbol) { | ||
std::ifstream fin(symmap.c_str()); | ||
int64_t addr; | ||
std::string sym_type; | ||
std::string sym_name; | ||
while (fin >> std::dec >> addr >> sym_type >> sym_name) | ||
if (sym_name == symbol) return addr; | ||
return -1; | ||
} | ||
|
||
struct BinaryData { | ||
std::unique_ptr<llvm::MemoryBuffer> mem_buf; | ||
std::unique_ptr<llvm::object::ObjectFile> object_file; | ||
}; | ||
|
||
// Primes `BinaryData` for test cases. | ||
absl::StatusOr<BinaryData> SetupBinaryData(absl::string_view binary) { | ||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> mem_buf = | ||
llvm::MemoryBuffer::getFile(binary); | ||
if (!mem_buf) { | ||
return absl::FailedPreconditionError(absl::StrCat( | ||
"failed creating MemoryBuffer: %s", mem_buf.getError().message())); | ||
} | ||
|
||
llvm::Expected<std::unique_ptr<llvm::object::ObjectFile>> object_file = | ||
llvm::object::ObjectFile::createELFObjectFile(**mem_buf); | ||
if (!object_file) { | ||
return absl::FailedPreconditionError( | ||
absl::StrFormat("failed creating ELFObjectFile: %s", | ||
llvm::toString(object_file.takeError()))); | ||
} | ||
|
||
return BinaryData{.mem_buf = std::move(*mem_buf), | ||
.object_file = std::move(*object_file)}; | ||
} | ||
|
||
TEST(Addr2CuTest, ComdatFuncHasNoDwp) { | ||
const std::string binary = | ||
absl::StrCat(::testing::SrcDir(), | ||
"/testdata/" | ||
"test_comdat_with_dwp.bin"); | ||
|
||
ASSERT_OK_AND_ASSIGN(BinaryData binary_data, SetupBinaryData(binary)); | ||
|
||
EXPECT_THAT(CreateDWARFContext(*binary_data.object_file), | ||
StatusIs(absl::StatusCode::kFailedPrecondition, | ||
HasSubstr("without a corresponding dwp file"))); | ||
} | ||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.