Skip to content

Commit

Permalink
Addressed feedback in #76903
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
aaupov committed Jan 12, 2024
2 parents a8c34ed + 1c8cb37 commit 134401e
Show file tree
Hide file tree
Showing 40 changed files with 1,481 additions and 915 deletions.
23 changes: 11 additions & 12 deletions bolt/include/bolt/Profile/BoltAddressTranslation.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,10 @@ class BoltAddressTranslation {

BoltAddressTranslation() {}

/// Write the serialized address translation table for a function.
template <bool Cold>
void writeMaps(std::map<uint64_t, MapTy> &Maps, uint64_t &PrevAddress,
raw_ostream &OS);

/// Write the serialized address translation tables for each reordered
/// function
void write(const BinaryContext &BC, raw_ostream &OS);

/// Read the serialized address translation table for a function.
/// Return a parse error if failed.
template <bool Cold>
void parseMaps(std::vector<uint64_t> &HotFuncs, uint64_t &PrevAddress,
DataExtractor &DE, uint64_t &Offset, Error &Err);

/// Read the serialized address translation tables and load them internally
/// in memory. Return a parse error if failed.
std::error_code parse(StringRef Buf);
Expand Down Expand Up @@ -133,6 +122,17 @@ class BoltAddressTranslation {
void writeEntriesForBB(MapTy &Map, const BinaryBasicBlock &BB,
uint64_t FuncAddress, uint64_t FuncInputAddress);

/// Write the serialized address translation table for a function.
template <bool Cold>
void writeMaps(std::map<uint64_t, MapTy> &Maps, uint64_t &PrevAddress,
raw_ostream &OS);

/// Read the serialized address translation table for a function.
/// Return a parse error if failed.
template <bool Cold>
void parseMaps(std::vector<uint64_t> &HotFuncs, uint64_t &PrevAddress,
DataExtractor &DE, uint64_t &Offset, Error &Err);

/// Returns the bitmask with set bits corresponding to indices of BRANCHENTRY
/// entries in function address translation map.
APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems);
Expand All @@ -142,7 +142,6 @@ class BoltAddressTranslation {
size_t getNumEqualOffsets(const MapTy &Map) const;

std::map<uint64_t, MapTy> Maps;
std::map<uint64_t, MapTy> ColdMaps;

using BBHashMap = std::unordered_map<uint32_t, size_t>;
std::unordered_map<uint64_t, std::pair<size_t, BBHashMap>> FuncHashes;
Expand Down
15 changes: 10 additions & 5 deletions bolt/lib/Profile/BoltAddressTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,17 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
for (const BinaryBasicBlock *const BB : FF)
writeEntriesForBB(Map, *BB, FF.getAddress(), Function.getAddress());

ColdMaps.emplace(FF.getAddress(), std::move(Map));
Maps.emplace(FF.getAddress(), std::move(Map));
ColdPartSource.emplace(FF.getAddress(), Function.getOutputAddress());
}
}

// Output addresses are delta-encoded
uint64_t PrevAddress = 0;
writeMaps</*Cold=*/false>(Maps, PrevAddress, OS);
writeMaps</*Cold=*/true>(ColdMaps, PrevAddress, OS);
writeMaps</*Cold=*/true>(Maps, PrevAddress, OS);

outs() << "BOLT-INFO: Wrote " << Maps.size() + ColdMaps.size()
<< " BAT maps\n";
outs() << "BOLT-INFO: Wrote " << Maps.size() << " BAT maps\n";
outs() << "BOLT-INFO: Wrote " << FuncHashes.size() << " function and "
<< std::accumulate(FuncHashes.begin(), FuncHashes.end(), 0ull,
[](size_t Acc, const auto &B) {
Expand Down Expand Up @@ -159,13 +158,19 @@ size_t BoltAddressTranslation::getNumEqualOffsets(const MapTy &Map) const {
template <bool Cold>
void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
uint64_t &PrevAddress, raw_ostream &OS) {
const uint32_t NumFuncs = Maps.size();
const uint32_t NumFuncs =
llvm::count_if(llvm::make_first_range(Maps), [&](const uint64_t Address) {
return Cold == ColdPartSource.count(Address);
});
encodeULEB128(NumFuncs, OS);
LLVM_DEBUG(dbgs() << "Writing " << NumFuncs << (Cold ? " cold" : "")
<< " functions for BAT.\n");
size_t PrevIndex = 0;
for (auto &MapEntry : Maps) {
const uint64_t Address = MapEntry.first;
// Only process cold fragments in cold mode, and vice versa.
if (Cold != ColdPartSource.count(Address))
continue;
const uint64_t HotInputAddress =
ReverseMap[Cold ? ColdPartSource[Address] : Address];
MapTy &Map = MapEntry.second;
Expand Down
16 changes: 16 additions & 0 deletions clang/cmake/caches/Fuchsia.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,25 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
CURL_ROOT
OpenSSL_ROOT
httplib_ROOT

# Deprecated
CursesAndPanel_ROOT

CURSES_INCLUDE_DIRS
CURSES_LIBRARIES
PANEL_LIBRARIES

# Deprecated
Terminfo_ROOT

Terminfo_LIBRARIES

# Deprecated
LibEdit_ROOT

LibEdit_INCLUDE_DIRS
LibEdit_LIBRARIES

FUCHSIA_ENABLE_LLDB
LLDB_ENABLE_CURSES
LLDB_ENABLE_LIBEDIT
Expand Down
4 changes: 4 additions & 0 deletions flang/include/flang/Common/Fortran.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ ENUM_CLASS(CUDASubprogramAttrs, Host, Device, HostDevice, Global, Grid_Global)
// CUDA data attributes; mutually exclusive
ENUM_CLASS(CUDADataAttr, Constant, Device, Managed, Pinned, Shared, Texture)

// OpenACC device types
ENUM_CLASS(
OpenACCDeviceType, Star, Default, Nvidia, Radeon, Host, Multicore, None)

// OpenMP atomic_default_mem_order clause allowed values
ENUM_CLASS(OmpAtomicDefaultMemOrderType, SeqCst, AcqRel, Relaxed)

Expand Down
3 changes: 2 additions & 1 deletion flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ParseTreeDumper {
NODE(std, uint64_t)
NODE_ENUM(common, CUDADataAttr)
NODE_ENUM(common, CUDASubprogramAttrs)
NODE_ENUM(common, OpenACCDeviceType)
NODE(format, ControlEditDesc)
NODE(format::ControlEditDesc, Kind)
NODE(format, DerivedTypeDataEditDesc)
Expand Down Expand Up @@ -101,7 +102,7 @@ class ParseTreeDumper {
NODE(parser, AccSelfClause)
NODE(parser, AccStandaloneDirective)
NODE(parser, AccDeviceTypeExpr)
NODE_ENUM(parser::AccDeviceTypeExpr, Device)

NODE(parser, AccDeviceTypeExprList)
NODE(parser, AccTileExpr)
NODE(parser, AccTileExprList)
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4072,8 +4072,8 @@ struct AccWaitArgument {
};

struct AccDeviceTypeExpr {
ENUM_CLASS(Device, Star, Default, Nvidia, Radeon, Host, Multicore)
WRAPPER_CLASS_BOILERPLATE(AccDeviceTypeExpr, Device);
WRAPPER_CLASS_BOILERPLATE(
AccDeviceTypeExpr, Fortran::common::OpenACCDeviceType);
CharBlock source;
};

Expand Down
31 changes: 27 additions & 4 deletions flang/include/flang/Semantics/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class WithBindName {
bool isExplicitBindName_{false};
};

class OpenACCRoutineInfo {
// Device type specific OpenACC routine information
class OpenACCRoutineDeviceTypeInfo {
public:
bool isSeq() const { return isSeq_; }
void set_isSeq(bool value = true) { isSeq_ = value; }
Expand All @@ -124,21 +125,43 @@ class OpenACCRoutineInfo {
void set_isGang(bool value = true) { isGang_ = value; }
unsigned gangDim() const { return gangDim_; }
void set_gangDim(unsigned value) { gangDim_ = value; }
bool isNohost() const { return isNohost_; }
void set_isNohost(bool value = true) { isNohost_ = value; }
const std::string *bindName() const {
return bindName_ ? &*bindName_ : nullptr;
}
void set_bindName(std::string &&name) { bindName_ = std::move(name); }
void set_dType(Fortran::common::OpenACCDeviceType dType) {
deviceType_ = dType;
}
Fortran::common::OpenACCDeviceType dType() const { return deviceType_; }

private:
bool isSeq_{false};
bool isVector_{false};
bool isWorker_{false};
bool isGang_{false};
unsigned gangDim_{0};
bool isNohost_{false};
std::optional<std::string> bindName_;
Fortran::common::OpenACCDeviceType deviceType_{
Fortran::common::OpenACCDeviceType::None};
};

// OpenACC routine information. Device independent info are stored on the
// OpenACCRoutineInfo instance while device dependent info are stored
// in as objects in the OpenACCRoutineDeviceTypeInfo list.
class OpenACCRoutineInfo : public OpenACCRoutineDeviceTypeInfo {
public:
bool isNohost() const { return isNohost_; }
void set_isNohost(bool value = true) { isNohost_ = value; }
std::list<OpenACCRoutineDeviceTypeInfo> &deviceTypeInfos() {
return deviceTypeInfos_;
}
void add_deviceTypeInfo(OpenACCRoutineDeviceTypeInfo &info) {
deviceTypeInfos_.push_back(info);
}

private:
std::list<OpenACCRoutineDeviceTypeInfo> deviceTypeInfos_;
bool isNohost_{false};
};

// A subroutine or function definition, or a subprogram interface defined
Expand Down
16 changes: 9 additions & 7 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,20 +1483,22 @@ genAsyncClause(Fortran::lower::AbstractConverter &converter,
}

static mlir::acc::DeviceType
getDeviceType(Fortran::parser::AccDeviceTypeExpr::Device device) {
getDeviceType(Fortran::common::OpenACCDeviceType device) {
switch (device) {
case Fortran::parser::AccDeviceTypeExpr::Device::Star:
case Fortran::common::OpenACCDeviceType::Star:
return mlir::acc::DeviceType::Star;
case Fortran::parser::AccDeviceTypeExpr::Device::Default:
case Fortran::common::OpenACCDeviceType::Default:
return mlir::acc::DeviceType::Default;
case Fortran::parser::AccDeviceTypeExpr::Device::Nvidia:
case Fortran::common::OpenACCDeviceType::Nvidia:
return mlir::acc::DeviceType::Nvidia;
case Fortran::parser::AccDeviceTypeExpr::Device::Radeon:
case Fortran::common::OpenACCDeviceType::Radeon:
return mlir::acc::DeviceType::Radeon;
case Fortran::parser::AccDeviceTypeExpr::Device::Host:
case Fortran::common::OpenACCDeviceType::Host:
return mlir::acc::DeviceType::Host;
case Fortran::parser::AccDeviceTypeExpr::Device::Multicore:
case Fortran::common::OpenACCDeviceType::Multicore:
return mlir::acc::DeviceType::Multicore;
case Fortran::common::OpenACCDeviceType::None:
return mlir::acc::DeviceType::None;
}
return mlir::acc::DeviceType::None;
}
Expand Down
1 change: 0 additions & 1 deletion flang/lib/Parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ add_flang_library(FortranParser
LINK_COMPONENTS
Support
FrontendOpenACC
FrontendOpenMP

DEPENDS
omp_gen
Expand Down
14 changes: 7 additions & 7 deletions flang/lib/Parser/openacc-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ TYPE_PARSER(construct<AccSizeExpr>(scalarIntExpr) ||
TYPE_PARSER(construct<AccSizeExprList>(nonemptyList(Parser<AccSizeExpr>{})))

TYPE_PARSER(sourced(construct<AccDeviceTypeExpr>(
first("*" >> pure(AccDeviceTypeExpr::Device::Star),
"DEFAULT" >> pure(AccDeviceTypeExpr::Device::Default),
"NVIDIA" >> pure(AccDeviceTypeExpr::Device::Nvidia),
"ACC_DEVICE_NVIDIA" >> pure(AccDeviceTypeExpr::Device::Nvidia),
"RADEON" >> pure(AccDeviceTypeExpr::Device::Radeon),
"HOST" >> pure(AccDeviceTypeExpr::Device::Host),
"MULTICORE" >> pure(AccDeviceTypeExpr::Device::Multicore)))))
first("*" >> pure(Fortran::common::OpenACCDeviceType::Star),
"DEFAULT" >> pure(Fortran::common::OpenACCDeviceType::Default),
"NVIDIA" >> pure(Fortran::common::OpenACCDeviceType::Nvidia),
"ACC_DEVICE_NVIDIA" >> pure(Fortran::common::OpenACCDeviceType::Nvidia),
"RADEON" >> pure(Fortran::common::OpenACCDeviceType::Radeon),
"HOST" >> pure(Fortran::common::OpenACCDeviceType::Host),
"MULTICORE" >> pure(Fortran::common::OpenACCDeviceType::Multicore)))))

TYPE_PARSER(
construct<AccDeviceTypeExprList>(nonemptyList(Parser<AccDeviceTypeExpr>{})))
Expand Down
75 changes: 61 additions & 14 deletions flang/lib/Semantics/check-acc-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ static constexpr inline AccClauseSet updateOnlyAllowedAfterDeviceTypeClauses{

static constexpr inline AccClauseSet routineOnlyAllowedAfterDeviceTypeClauses{
llvm::acc::Clause::ACCC_bind, llvm::acc::Clause::ACCC_gang,
llvm::acc::Clause::ACCC_vector, llvm::acc::Clause::ACCC_worker};
llvm::acc::Clause::ACCC_vector, llvm::acc::Clause::ACCC_worker,
llvm::acc::Clause::ACCC_seq};

static constexpr inline AccClauseSet routineMutuallyExclusiveClauses{
llvm::acc::Clause::ACCC_gang, llvm::acc::Clause::ACCC_worker,
llvm::acc::Clause::ACCC_vector, llvm::acc::Clause::ACCC_seq};

bool AccStructureChecker::CheckAllowedModifier(llvm::acc::Clause clause) {
if (GetContext().directive == llvm::acc::ACCD_enter_data ||
Expand Down Expand Up @@ -388,7 +393,6 @@ CHECK_SIMPLE_CLAUSE(NoCreate, ACCC_no_create)
CHECK_SIMPLE_CLAUSE(Nohost, ACCC_nohost)
CHECK_SIMPLE_CLAUSE(Private, ACCC_private)
CHECK_SIMPLE_CLAUSE(Read, ACCC_read)
CHECK_SIMPLE_CLAUSE(Seq, ACCC_seq)
CHECK_SIMPLE_CLAUSE(UseDevice, ACCC_use_device)
CHECK_SIMPLE_CLAUSE(Wait, ACCC_wait)
CHECK_SIMPLE_CLAUSE(Write, ACCC_write)
Expand Down Expand Up @@ -532,18 +536,40 @@ void AccStructureChecker::Enter(const parser::AccClause::DeviceType &d) {
.str()),
ContextDirectiveAsFortran());
}
ResetCrtGroup();
}

void AccStructureChecker::Enter(const parser::AccClause::Seq &g) {
llvm::acc::Clause crtClause = llvm::acc::Clause::ACCC_seq;
if (GetContext().directive == llvm::acc::Directive::ACCD_routine) {
CheckMutuallyExclusivePerGroup(crtClause,
llvm::acc::Clause::ACCC_device_type, routineMutuallyExclusiveClauses);
}
CheckAllowed(crtClause);
}

void AccStructureChecker::Enter(const parser::AccClause::Vector &g) {
CheckAllowed(llvm::acc::Clause::ACCC_vector);
CheckAllowedOncePerGroup(
llvm::acc::Clause::ACCC_vector, llvm::acc::Clause::ACCC_device_type);
llvm::acc::Clause crtClause = llvm::acc::Clause::ACCC_vector;
if (GetContext().directive == llvm::acc::Directive::ACCD_routine) {
CheckMutuallyExclusivePerGroup(crtClause,
llvm::acc::Clause::ACCC_device_type, routineMutuallyExclusiveClauses);
}
CheckAllowed(crtClause);
if (GetContext().directive != llvm::acc::Directive::ACCD_routine) {
CheckAllowedOncePerGroup(crtClause, llvm::acc::Clause::ACCC_device_type);
}
}

void AccStructureChecker::Enter(const parser::AccClause::Worker &g) {
CheckAllowed(llvm::acc::Clause::ACCC_worker);
CheckAllowedOncePerGroup(
llvm::acc::Clause::ACCC_worker, llvm::acc::Clause::ACCC_device_type);
llvm::acc::Clause crtClause = llvm::acc::Clause::ACCC_worker;
if (GetContext().directive == llvm::acc::Directive::ACCD_routine) {
CheckMutuallyExclusivePerGroup(crtClause,
llvm::acc::Clause::ACCC_device_type, routineMutuallyExclusiveClauses);
}
CheckAllowed(crtClause);
if (GetContext().directive != llvm::acc::Directive::ACCD_routine) {
CheckAllowedOncePerGroup(crtClause, llvm::acc::Clause::ACCC_device_type);
}
}

void AccStructureChecker::Enter(const parser::AccClause::Tile &g) {
Expand All @@ -553,24 +579,45 @@ void AccStructureChecker::Enter(const parser::AccClause::Tile &g) {
}

void AccStructureChecker::Enter(const parser::AccClause::Gang &g) {
CheckAllowed(llvm::acc::Clause::ACCC_gang);
CheckAllowedOncePerGroup(
llvm::acc::Clause::ACCC_gang, llvm::acc::Clause::ACCC_device_type);
llvm::acc::Clause crtClause = llvm::acc::Clause::ACCC_gang;
if (GetContext().directive == llvm::acc::Directive::ACCD_routine) {
CheckMutuallyExclusivePerGroup(crtClause,
llvm::acc::Clause::ACCC_device_type, routineMutuallyExclusiveClauses);
}
CheckAllowed(crtClause);
if (GetContext().directive != llvm::acc::Directive::ACCD_routine) {
CheckAllowedOncePerGroup(crtClause, llvm::acc::Clause::ACCC_device_type);
}

if (g.v) {
bool hasNum = false;
bool hasDim = false;
bool hasStatic = false;
const Fortran::parser::AccGangArgList &x = *g.v;
for (const Fortran::parser::AccGangArg &gangArg : x.v) {
if (std::get_if<Fortran::parser::AccGangArg::Num>(&gangArg.u))
if (std::get_if<Fortran::parser::AccGangArg::Num>(&gangArg.u)) {
hasNum = true;
else if (std::get_if<Fortran::parser::AccGangArg::Dim>(&gangArg.u))
} else if (std::get_if<Fortran::parser::AccGangArg::Dim>(&gangArg.u)) {
hasDim = true;
} else if (std::get_if<Fortran::parser::AccGangArg::Static>(&gangArg.u)) {
hasStatic = true;
}
}

if (hasDim && hasNum)
if (GetContext().directive == llvm::acc::Directive::ACCD_routine &&
(hasStatic || hasNum)) {
context_.Say(GetContext().clauseSource,
"Only the dim argument is allowed on the %s clause on the %s directive"_err_en_US,
parser::ToUpperCaseLetters(
llvm::acc::getOpenACCClauseName(llvm::acc::Clause::ACCC_gang)
.str()),
ContextDirectiveAsFortran());
}

if (hasDim && hasNum) {
context_.Say(GetContext().clauseSource,
"The num argument is not allowed when dim is specified"_err_en_US);
}
}
}

Expand Down
Loading

0 comments on commit 134401e

Please sign in to comment.