Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SPIRV/libSPIRV/SPIRVFnVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bool specializeFnVariants(SPIRVModule *BM, std::string &ErrMsg) {
for (const auto &CondCap : BM->getConditionalCapabilities()) {
const SPIRVId Condition = CondCap.first.first;
const Capability Cap = CondCap.first.second;
const SPIRVConditionalCapabilityINTEL *Entry = CondCap.second;
const SPIRVConditionalCapabilityINTEL *Entry = CondCap.second.get();
bool ShouldKeep = false;
if (!evaluateConstant(BM, Entry->getCondition(), ShouldKeep, ErrMsg)) {
return false;
Expand Down
30 changes: 14 additions & 16 deletions lib/SPIRV/libSPIRV/SPIRVModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,6 @@ SPIRVModuleImpl::~SPIRVModuleImpl() {
for (auto I : IdEntryMap)
delete I.second;

for (auto C : CapMap)
delete C.second;

for (auto C : ConditionalCapMap)
delete C.second;

for (auto *M : ModuleProcessedVec)
delete M;
}
Expand Down Expand Up @@ -789,10 +783,12 @@ void SPIRVModuleImpl::addCapability(SPIRVCapabilityKind Cap) {
addCapabilities(SPIRV::getCapability(Cap));
SPIRVDBG(spvdbgs() << "addCapability: " << SPIRVCapabilityNameMap::map(Cap)
<< '\n');
if (hasCapability(Cap))

auto [It, Inserted] = CapMap.try_emplace(Cap);
if (!Inserted)
return;

auto *CapObj = new SPIRVCapability(this, Cap);
auto CapObj = std::make_unique<SPIRVCapability>(this, Cap);
if (AutoAddExtensions) {
// While we are reading existing SPIR-V we need to read it as-is and don't
// add required extensions for each entry automatically
Expand All @@ -801,15 +797,16 @@ void SPIRVModuleImpl::addCapability(SPIRVCapabilityKind Cap) {
addExtension(Ext.value());
}

CapMap.insert(std::make_pair(Cap, CapObj));
It->second = std::move(CapObj);
}

void SPIRVModuleImpl::addCapabilityInternal(SPIRVCapabilityKind Cap) {
if (AutoAddCapability) {
if (hasCapability(Cap))
auto [It, Inserted] = CapMap.try_emplace(Cap);
if (!Inserted)
return;

CapMap.insert(std::make_pair(Cap, new SPIRVCapability(this, Cap)));
It->second = std::make_unique<SPIRVCapability>(this, Cap);
}
}

Expand All @@ -818,18 +815,19 @@ void SPIRVModuleImpl::addConditionalCapability(SPIRVId Condition,
SPIRVDBG(spvdbgs() << "addConditionalCapability: "
<< SPIRVCapabilityNameMap::map(Cap)
<< ", condition: " << Condition << '\n');
if (ConditionalCapMap.find(std::make_pair(Condition, Cap)) !=
ConditionalCapMap.end()) {
auto Key = std::make_pair(Condition, Cap);
auto [It, Inserted] = ConditionalCapMap.try_emplace(Key);
if (!Inserted) {
return;
}

auto *CapObj = new SPIRVConditionalCapabilityINTEL(this, Condition, Cap);
auto CapObj =
std::make_unique<SPIRVConditionalCapabilityINTEL>(this, Condition, Cap);
if (AutoAddExtensions) {
assert(false && "Auto adding conditional extensions is not supported.");
}

ConditionalCapMap.insert(
std::make_pair(std::make_pair(Condition, Cap), CapObj));
It->second = std::move(CapObj);
}

void SPIRVModuleImpl::eraseConditionalCapability(SPIRVId Condition,
Expand Down
5 changes: 3 additions & 2 deletions lib/SPIRV/libSPIRV/SPIRVModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ struct SPIRVTypeImageDescriptor;

class SPIRVModule {
public:
typedef std::map<SPIRVCapabilityKind, SPIRVCapability *> SPIRVCapMap;
typedef std::map<SPIRVCapabilityKind, std::unique_ptr<SPIRVCapability>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, do we really need to keep the order here? Could this be made std::unordered_map? That would probably give us better performance. Anyway, I know this is offtopic, so feel free to ignore or address in a different patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it to my TODO list and do it in a separate PR. It's a low hanging fruit so it's worth checking.

I'll also see if I can remove the rest of the manual memory management from the class, such that the destructor becomes trivial.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gave it a try and I know now why std::map is used: If we want to use the unordered containers on these two maps we have to define std::hash(const SPIRVCapabilityKind&).

SPIRVCapMap;
typedef std::map<std::pair<SPIRVId, SPIRVCapabilityKind>,
SPIRVConditionalCapabilityINTEL *>
std::unique_ptr<SPIRVConditionalCapabilityINTEL>>
SPIRVConditionalCapMap;
typedef std::vector<SPIRVConditionalEntryPointINTEL *>
SPIRVConditionalEntryPointVec;
Expand Down
Loading