Commit 0fe6b544 by David Sehr

Fix race condition in jump table list creation

BUG= R=stichnot@chromium.org Review URL: https://codereview.chromium.org/1460003003 .
parent f4d0a7a5
...@@ -966,12 +966,13 @@ void Cfg::emitJumpTables() { ...@@ -966,12 +966,13 @@ void Cfg::emitJumpTables() {
IceString MangledName = Ctx->mangleName(getFunctionName()); IceString MangledName = Ctx->mangleName(getFunctionName());
for (const InstJumpTable *JumpTable : JumpTables) { for (const InstJumpTable *JumpTable : JumpTables) {
SizeT NumTargets = JumpTable->getNumTargets(); SizeT NumTargets = JumpTable->getNumTargets();
JumpTableData &JT = JumpTableData::TargetList TargetList;
Ctx->addJumpTable(MangledName, JumpTable->getId(), NumTargets);
for (SizeT I = 0; I < NumTargets; ++I) { for (SizeT I = 0; I < NumTargets; ++I) {
SizeT Index = JumpTable->getTarget(I)->getIndex(); SizeT Index = JumpTable->getTarget(I)->getIndex();
JT.pushTarget(getAssembler()->getCfgNodeLabel(Index)->getPosition()); TargetList.emplace_back(
getAssembler()->getCfgNodeLabel(Index)->getPosition());
} }
Ctx->addJumpTable(MangledName, JumpTable->getId(), TargetList);
} }
} break; } break;
case FT_Asm: { case FT_Asm: {
......
...@@ -895,10 +895,11 @@ JumpTableDataList GlobalContext::getJumpTables() { ...@@ -895,10 +895,11 @@ JumpTableDataList GlobalContext::getJumpTables() {
return JumpTables; return JumpTables;
} }
JumpTableData &GlobalContext::addJumpTable(IceString FuncName, SizeT Id, JumpTableData &
SizeT NumTargets) { GlobalContext::addJumpTable(IceString FuncName, SizeT Id,
const JumpTableData::TargetList &TargetList) {
auto JumpTableList = getJumpTableList(); auto JumpTableList = getJumpTableList();
JumpTableList->emplace_back(FuncName, Id, NumTargets); JumpTableList->emplace_back(FuncName, Id, TargetList);
return JumpTableList->back(); return JumpTableList->back();
} }
......
...@@ -217,7 +217,8 @@ public: ...@@ -217,7 +217,8 @@ public:
/// Return a locked pointer to the registered jump tables. /// Return a locked pointer to the registered jump tables.
JumpTableDataList getJumpTables(); JumpTableDataList getJumpTables();
/// Create a new jump table entry and return a reference to it. /// Create a new jump table entry and return a reference to it.
JumpTableData &addJumpTable(IceString FuncName, SizeT Id, SizeT NumTargets); JumpTableData &addJumpTable(IceString FuncName, SizeT Id,
const JumpTableData::TargetList &TargetList);
const ClFlags &getFlags() const { return Flags; } const ClFlags &getFlags() const { return Flags; }
......
...@@ -81,26 +81,23 @@ class JumpTableData { ...@@ -81,26 +81,23 @@ class JumpTableData {
JumpTableData &operator=(const JumpTableData &) = delete; JumpTableData &operator=(const JumpTableData &) = delete;
public: public:
JumpTableData(IceString FuncName, SizeT Id, SizeT NumTargets) using TargetList = std::vector<intptr_t>;
: FuncName(FuncName), Id(Id) {
TargetOffsets.reserve(NumTargets); JumpTableData(const IceString &FuncName, SizeT Id,
} const TargetList &TargetOffsets)
: FuncName(FuncName), Id(Id), TargetOffsets(TargetOffsets) {}
JumpTableData(const JumpTableData &) = default; JumpTableData(const JumpTableData &) = default;
JumpTableData(JumpTableData &&) = default; JumpTableData(JumpTableData &&) = default;
JumpTableData &operator=(JumpTableData &&) = default; JumpTableData &operator=(JumpTableData &&) = default;
void pushTarget(intptr_t Offset) { TargetOffsets.emplace_back(Offset); }
const IceString &getFunctionName() const { return FuncName; } const IceString &getFunctionName() const { return FuncName; }
SizeT getId() const { return Id; } SizeT getId() const { return Id; }
const std::vector<intptr_t> &getTargetOffsets() const { const TargetList &getTargetOffsets() const { return TargetOffsets; }
return TargetOffsets;
}
private: private:
IceString FuncName; IceString FuncName;
SizeT Id; SizeT Id;
std::vector<intptr_t> TargetOffsets; TargetList TargetOffsets;
}; };
using JumpTableDataList = std::vector<JumpTableData>; using JumpTableDataList = std::vector<JumpTableData>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment