https://github.com/shader-slang/slang
Tip revision: 0b46715bff7f047fefed303ae149d3de8eb6be4f authored by Yong He on 21 February 2024, 21:59:30 UTC
Fix parsing of literals in stdlib. (#3610)
Fix parsing of literals in stdlib. (#3610)
Tip revision: 0b46715
slang-ir-autodiff-region.h
// slang-ir-autodiff-region.h
#pragma once
#include "slang-ir.h"
#include "slang-ir-insts.h"
#include "slang-ir-autodiff.h"
namespace Slang
{
struct IndexedRegion : public RefObject
{
IRLoop* loop;
IndexedRegion* parent;
IndexedRegion(IRLoop* loop, IndexedRegion* parent) : loop(loop), parent(parent)
{ }
IRBlock* getInitializerBlock() { return as<IRBlock>(loop->getParent()); }
IRBlock* getConditionBlock()
{
auto condBlock = as<IRBlock>(loop->getTargetBlock());
SLANG_RELEASE_ASSERT(as<IRIfElse>(condBlock->getTerminator()));
return condBlock;
}
IRBlock* getBreakBlock() { return loop->getBreakBlock(); }
IRBlock* getUpdateBlock()
{
auto initBlock = getInitializerBlock();
auto condBlock = getConditionBlock();
IRBlock* lastLoopBlock = nullptr;
for (auto predecessor : condBlock->getPredecessors())
{
if (predecessor != initBlock)
lastLoopBlock = predecessor;
}
// Should find atleast one predecessor that is _not_ the
// init block (that contains the loop info). This
// predecessor would be the last block in the loop
// before looping back to the condition.
//
SLANG_RELEASE_ASSERT(lastLoopBlock);
return lastLoopBlock;
}
};
struct IndexedRegionMap : public RefObject
{
Dictionary<IRBlock*, IndexedRegion*> map;
List<RefPtr<IndexedRegion>> regions;
IndexedRegion* newRegion(IRLoop* loop, IndexedRegion* parent)
{
auto region = new IndexedRegion(loop, parent);
regions.add(region);
return region;
}
void mapBlock(IRBlock* block, IndexedRegion* region)
{
map.add(block, region);
}
bool hasMapping(IRBlock* block)
{
return map.containsKey(block);
}
IndexedRegion* getRegion(IRBlock* block)
{
return map[block];
}
List<IndexedRegion*> getAllAncestorRegions(IRBlock* block)
{
List<IndexedRegion*> regionList;
IndexedRegion* region = getRegion(block);
for (; region; region = region->parent)
regionList.add(region);
return regionList;
}
};
RefPtr<IndexedRegionMap> buildIndexedRegionMap(IRGlobalValueWithCode* func);
};