Merged PR 56: Avoid inserting other insts before allocas in several passes.

Avoid inserting other insts before allocas in several passes.

- Improve code that creates allocas/non-allocas to keep allocas first
- Add helper functions to dxilutil
- Use name AllocaBuilder for CreateAlloca for clarity
This commit is contained in:
Tex Riddell 2018-04-10 23:33:41 +00:00 коммит произвёл Young Kim
Родитель 0bc25bd790 335ee949bb
Коммит 0021e993a2
15 изменённых файлов: 127 добавлений и 81 удалений

Просмотреть файл

@ -22,6 +22,7 @@ class LLVMContext;
class DiagnosticInfo; class DiagnosticInfo;
class Value; class Value;
class Instruction; class Instruction;
class BasicBlock;
class StringRef; class StringRef;
} }
@ -37,6 +38,15 @@ namespace dxilutil {
llvm::Type *GetArrayEltTy(llvm::Type *Ty); llvm::Type *GetArrayEltTy(llvm::Type *Ty);
bool HasDynamicIndexing(llvm::Value *V); bool HasDynamicIndexing(llvm::Value *V);
// Find alloca insertion point, given instruction
llvm::Instruction *FindAllocaInsertionPt(llvm::Instruction* I);
llvm::Instruction *FindAllocaInsertionPt(llvm::Function* F);
llvm::Instruction *SkipAllocas(llvm::Instruction *I);
// Get first non-alloca insertion point, to avoid inserting non-allocas before alloca
llvm::Instruction *FirstNonAllocaInsertionPt(llvm::Instruction* I);
llvm::Instruction *FirstNonAllocaInsertionPt(llvm::BasicBlock* BB);
llvm::Instruction *FirstNonAllocaInsertionPt(llvm::Function* F);
bool IsStaticGlobal(llvm::GlobalVariable *GV); bool IsStaticGlobal(llvm::GlobalVariable *GV);
bool IsSharedMemoryGlobal(llvm::GlobalVariable *GV); bool IsSharedMemoryGlobal(llvm::GlobalVariable *GV);
bool RemoveUnusedFunctions(llvm::Module &M, llvm::Function *EntryFunc, bool RemoveUnusedFunctions(llvm::Module &M, llvm::Function *EntryFunc,

Просмотреть файл

@ -15,6 +15,7 @@
#include "dxc/HLSL/DxilInstructions.h" #include "dxc/HLSL/DxilInstructions.h"
#include "dxc/HLSL/DxilModule.h" #include "dxc/HLSL/DxilModule.h"
#include "dxc/HLSL/DxilPIXPasses.h" #include "dxc/HLSL/DxilPIXPasses.h"
#include "dxc/HLSL/DxilUtil.h"
#include "llvm/IR/PassManager.h" #include "llvm/IR/PassManager.h"
#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/Local.h"
@ -93,7 +94,7 @@ bool DxilAddPixelHitInstrumentation::runOnModule(Module &M)
CallInst *HandleForUAV; CallInst *HandleForUAV;
{ {
IRBuilder<> Builder(DM.GetEntryFunction()->getEntryBlock().getFirstInsertionPt()); IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(DM.GetEntryFunction()));
unsigned int UAVResourceHandle = static_cast<unsigned int>(DM.GetUAVs().size()); unsigned int UAVResourceHandle = static_cast<unsigned int>(DM.GetUAVs().size());

Просмотреть файл

@ -804,7 +804,7 @@ void DxilLowerCreateHandleForLib::TranslateDxilResourceUses(
for (iplist<Function>::iterator F : pM->getFunctionList()) { for (iplist<Function>::iterator F : pM->getFunctionList()) {
if (!F->isDeclaration()) { if (!F->isDeclaration()) {
if (!isResArray) { if (!isResArray) {
IRBuilder<> Builder(F->getEntryBlock().getFirstInsertionPt()); IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(F));
if (m_HasDbgInfo) { if (m_HasDbgInfo) {
// TODO: set debug info. // TODO: set debug info.
// Builder.SetCurrentDebugLocation(DL); // Builder.SetCurrentDebugLocation(DL);

Просмотреть файл

@ -13,6 +13,7 @@
#include "dxc/HLSL/DxilModule.h" #include "dxc/HLSL/DxilModule.h"
#include "dxc/HLSL/DxilOperations.h" #include "dxc/HLSL/DxilOperations.h"
#include "dxc/HLSL/DxilPIXPasses.h" #include "dxc/HLSL/DxilPIXPasses.h"
#include "dxc/HLSL/DxilUtil.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/Constants.h" #include "llvm/IR/Constants.h"
@ -728,7 +729,7 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
// value at (UAVSize) - (Small Amount) * 2 (which is actually a conservative definition of overflow). // value at (UAVSize) - (Small Amount) * 2 (which is actually a conservative definition of overflow).
// //
Instruction* firstInsertionPt = DM.GetEntryFunction()->getEntryBlock().getFirstInsertionPt(); Instruction* firstInsertionPt = dxilutil::FirstNonAllocaInsertionPt(DM.GetEntryFunction());
IRBuilder<> Builder(firstInsertionPt); IRBuilder<> Builder(firstInsertionPt);
BuilderContext BC{ M, DM, Ctx, HlslOP, Builder }; BuilderContext BC{ M, DM, Ctx, HlslOP, Builder };

Просмотреть файл

@ -13,6 +13,7 @@
#include "dxc/HLSL/DxilOperations.h" #include "dxc/HLSL/DxilOperations.h"
#include "dxc/HLSL/DxilSignatureElement.h" #include "dxc/HLSL/DxilSignatureElement.h"
#include "dxc/HLSL/DxilModule.h" #include "dxc/HLSL/DxilModule.h"
#include "dxc/HLSL/DxilUtil.h"
#include "dxc/Support/Global.h" #include "dxc/Support/Global.h"
#include "dxc/HLSL/DxilInstructions.h" #include "dxc/HLSL/DxilInstructions.h"
@ -123,10 +124,10 @@ bool DxilEliminateOutputDynamicIndexing::EliminateDynamicOutput(
if (dynamicSigSet.empty()) if (dynamicSigSet.empty())
return false; return false;
IRBuilder<> Builder(Entry->getEntryBlock().getFirstInsertionPt()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(Entry));
Value *opcodeV = Builder.getInt32(static_cast<unsigned>(opcode)); Value *opcodeV = AllocaBuilder.getInt32(static_cast<unsigned>(opcode));
Value *zero = Builder.getInt32(0); Value *zero = AllocaBuilder.getInt32(0);
for (auto sig : dynamicSigSet) { for (auto sig : dynamicSigSet) {
Value *sigID = sig.first; Value *sigID = sig.first;
@ -139,7 +140,7 @@ bool DxilEliminateOutputDynamicIndexing::EliminateDynamicOutput(
std::vector<Value *> tmpSigElts(col); std::vector<Value *> tmpSigElts(col);
for (unsigned c = 0; c < col; c++) { for (unsigned c = 0; c < col; c++) {
Value *newCol = Builder.CreateAlloca(AT); Value *newCol = AllocaBuilder.CreateAlloca(AT);
tmpSigElts[c] = newCol; tmpSigElts[c] = newCol;
} }

Просмотреть файл

@ -100,7 +100,7 @@ void SimplifyGlobalSymbol(GlobalVariable *GV) {
for (auto it : handleMapOnFunction) { for (auto it : handleMapOnFunction) {
Function *F = it.first; Function *F = it.first;
Instruction *I = it.second; Instruction *I = it.second;
IRBuilder<> Builder(F->getEntryBlock().getFirstInsertionPt()); IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(F));
Value *headLI = Builder.CreateLoad(GV); Value *headLI = Builder.CreateLoad(GV);
I->replaceAllUsesWith(headLI); I->replaceAllUsesWith(headLI);
} }
@ -613,11 +613,10 @@ void DxilGenerationPass::RemoveLocalDxilResourceAllocas(Function *F) {
Insts.clear(); Insts.clear();
} }
} }
void DxilGenerationPass::TranslateParamDxilResourceHandles(Function *F, std::unordered_map<Instruction *, Value *> &handleMap) { void DxilGenerationPass::TranslateParamDxilResourceHandles(Function *F, std::unordered_map<Instruction *, Value *> &handleMap) {
Type *handleTy = m_pHLModule->GetOP()->GetHandleType(); Type *handleTy = m_pHLModule->GetOP()->GetHandleType();
IRBuilder<> Builder(F->getEntryBlock().getFirstInsertionPt()); IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(F));
for (Argument &arg : F->args()) { for (Argument &arg : F->args()) {
Type *Ty = arg.getType(); Type *Ty = arg.getType();
@ -770,9 +769,7 @@ void DxilGenerationPass::GenerateDxilCBufferHandles(
// Must HLCreateHandle. // Must HLCreateHandle.
CallInst *CI = cast<CallInst>(*(U++)); CallInst *CI = cast<CallInst>(*(U++));
// Put createHandle to entry block. // Put createHandle to entry block.
auto InsertPt = IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(CI));
CI->getParent()->getParent()->getEntryBlock().getFirstInsertionPt();
IRBuilder<> Builder(InsertPt);
Value *V = Builder.CreateLoad(GV); Value *V = Builder.CreateLoad(GV);
CallInst *handle = Builder.CreateCall(createHandle, {opArg, V}, handleName); CallInst *handle = Builder.CreateCall(createHandle, {opArg, V}, handleName);
if (m_HasDbgInfo) { if (m_HasDbgInfo) {
@ -796,11 +793,7 @@ void DxilGenerationPass::GenerateDxilCBufferHandles(
Value *CBIndex = CI->getArgOperand(HLOperandIndex::kCreateHandleIndexOpIdx); Value *CBIndex = CI->getArgOperand(HLOperandIndex::kCreateHandleIndexOpIdx);
if (isa<ConstantInt>(CBIndex)) { if (isa<ConstantInt>(CBIndex)) {
// Put createHandle to entry block for const index. // Put createHandle to entry block for const index.
auto InsertPt = CI->getParent() Builder.SetInsertPoint(dxilutil::FirstNonAllocaInsertionPt(CI));
->getParent()
->getEntryBlock()
.getFirstInsertionPt();
Builder.SetInsertPoint(InsertPt);
} }
// Add GEP for cbv array use. // Add GEP for cbv array use.
Value *GEP = Builder.CreateGEP(GV, {zeroIdx, CBIndex}); Value *GEP = Builder.CreateGEP(GV, {zeroIdx, CBIndex});

Просмотреть файл

@ -754,8 +754,7 @@ DxilLinkJob::Link(std::pair<DxilFunctionLinkInfo *, DxilLib *> &entryLinkPair,
CloneFunctions(vmap); CloneFunctions(vmap);
// Call global constrctor. // Call global constrctor.
IRBuilder<> Builder( IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(DM.GetEntryFunction()));
DM.GetEntryFunction()->getEntryBlock().getFirstInsertionPt());
for (auto &it : m_functionDefs) { for (auto &it : m_functionDefs) {
DxilFunctionLinkInfo *linkInfo = it.first; DxilFunctionLinkInfo *linkInfo = it.first;
DxilLib *pLib = it.second; DxilLib *pLib = it.second;

Просмотреть файл

@ -86,15 +86,15 @@ public:
{ {
} }
void CreateAlloca(IRBuilder<> &builder) { void CreateAlloca(IRBuilder<> &allocaBuilder) {
LLVMContext &context = builder.getContext(); LLVMContext &context = allocaBuilder.getContext();
Type *elementType = m_OutputElement.GetCompType().GetLLVMType(context); Type *elementType = m_OutputElement.GetCompType().GetLLVMType(context);
Type *allocaType = nullptr; Type *allocaType = nullptr;
if (IsSingleElement()) if (IsSingleElement())
allocaType = elementType; allocaType = elementType;
else else
allocaType = ArrayType::get(elementType, NumElements()); allocaType = ArrayType::get(elementType, NumElements());
m_Alloca = builder.CreateAlloca(allocaType, nullptr, m_OutputElement.GetName()); m_Alloca = allocaBuilder.CreateAlloca(allocaType, nullptr, m_OutputElement.GetName());
} }
void StoreTemp(IRBuilder<> &builder, Value *row, Value *col, Value *value) const { void StoreTemp(IRBuilder<> &builder, Value *row, Value *col, Value *value) const {
@ -249,11 +249,11 @@ DxilPreserveAllOutputs::OutputMap DxilPreserveAllOutputs::generateOutputMap(cons
return map; return map;
} }
void DxilPreserveAllOutputs::createTempAllocas(OutputMap &outputMap, IRBuilder<> &builder) void DxilPreserveAllOutputs::createTempAllocas(OutputMap &outputMap, IRBuilder<> &allocaBuilder)
{ {
for (auto &iter: outputMap) { for (auto &iter: outputMap) {
OutputElement &output = iter.second; OutputElement &output = iter.second;
output.CreateAlloca(builder); output.CreateAlloca(allocaBuilder);
} }
} }

Просмотреть файл

@ -265,5 +265,33 @@ Value *SelectOnOperation(llvm::Instruction *Inst, unsigned operandIdx) {
} }
return nullptr; return nullptr;
} }
llvm::Instruction *SkipAllocas(llvm::Instruction *I) {
// Step past any allocas:
while (I && isa<AllocaInst>(I))
I = I->getNextNode();
return I;
}
llvm::Instruction *FindAllocaInsertionPt(llvm::Instruction* I) {
Function *F = I->getParent()->getParent();
if (F)
return F->getEntryBlock().getFirstInsertionPt();
else // BB with no parent function
return I->getParent()->getFirstInsertionPt();
}
llvm::Instruction *FindAllocaInsertionPt(llvm::Function* F) {
return F->getEntryBlock().getFirstInsertionPt();
}
llvm::Instruction *FirstNonAllocaInsertionPt(llvm::Instruction* I) {
return SkipAllocas(FindAllocaInsertionPt(I));
}
llvm::Instruction *FirstNonAllocaInsertionPt(llvm::BasicBlock* BB) {
return SkipAllocas(
BB->getFirstInsertionPt());
}
llvm::Instruction *FirstNonAllocaInsertionPt(llvm::Function* F) {
return SkipAllocas(
F->getEntryBlock().getFirstInsertionPt());
}
} }
} }

Просмотреть файл

@ -789,18 +789,16 @@ Instruction *HLMatrixLowerPass::TrivialMatBinOpToVec(CallInst *CI) {
// Create BitCast if ptr, otherwise, create alloca of new type, write to bitcast of alloca, and return load from alloca // Create BitCast if ptr, otherwise, create alloca of new type, write to bitcast of alloca, and return load from alloca
// If bOrigAllocaTy is true: create alloca of old type instead, write to alloca, and return load from bitcast of alloca // If bOrigAllocaTy is true: create alloca of old type instead, write to alloca, and return load from bitcast of alloca
static Instruction *BitCastValueOrPtr(Value* V, Instruction *Insert, Type *Ty, bool bOrigAllocaTy = false, const Twine &Name = "") { static Instruction *BitCastValueOrPtr(Value* V, Instruction *Insert, Type *Ty, bool bOrigAllocaTy = false, const Twine &Name = "") {
IRBuilder<> Builder(Insert);
if (Ty->isPointerTy()) { if (Ty->isPointerTy()) {
// If pointer, we can bitcast directly // If pointer, we can bitcast directly
IRBuilder<> Builder(Insert);
return cast<Instruction>(Builder.CreateBitCast(V, Ty, Name)); return cast<Instruction>(Builder.CreateBitCast(V, Ty, Name));
} } else {
else {
// If value, we have to alloca, store to bitcast ptr, and load // If value, we have to alloca, store to bitcast ptr, and load
IRBuilder<> EntryBuilder(Insert->getParent()->getParent()->getEntryBlock().begin()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(Insert));
Type *allocaTy = bOrigAllocaTy ? V->getType() : Ty; Type *allocaTy = bOrigAllocaTy ? V->getType() : Ty;
Type *otherTy = bOrigAllocaTy ? Ty : V->getType(); Type *otherTy = bOrigAllocaTy ? Ty : V->getType();
Instruction *allocaInst = EntryBuilder.CreateAlloca(allocaTy); Instruction *allocaInst = AllocaBuilder.CreateAlloca(allocaTy);
IRBuilder<> Builder(Insert);
Instruction *bitCast = cast<Instruction>(Builder.CreateBitCast(allocaInst, otherTy->getPointerTo())); Instruction *bitCast = cast<Instruction>(Builder.CreateBitCast(allocaInst, otherTy->getPointerTo()));
Builder.CreateStore(V, bOrigAllocaTy ? allocaInst : bitCast); Builder.CreateStore(V, bOrigAllocaTy ? allocaInst : bitCast);
return Builder.CreateLoad(bOrigAllocaTy ? bitCast : allocaInst, Name); return Builder.CreateLoad(bOrigAllocaTy ? bitCast : allocaInst, Name);
@ -855,14 +853,14 @@ void HLMatrixLowerPass::lowerToVec(Instruction *matInst) {
Type *Ty = AI->getAllocatedType(); Type *Ty = AI->getAllocatedType();
Type *matTy = Ty; Type *matTy = Ty;
IRBuilder<> Builder(AI); IRBuilder<> AllocaBuilder(AI);
if (Ty->isArrayTy()) { if (Ty->isArrayTy()) {
Type *vecTy = HLMatrixLower::LowerMatrixArrayPointer(AI->getType()); Type *vecTy = HLMatrixLower::LowerMatrixArrayPointer(AI->getType());
vecTy = vecTy->getPointerElementType(); vecTy = vecTy->getPointerElementType();
vecVal = Builder.CreateAlloca(vecTy, nullptr, AI->getName()); vecVal = AllocaBuilder.CreateAlloca(vecTy, nullptr, AI->getName());
} else { } else {
Type *vecTy = HLMatrixLower::LowerMatrixType(matTy); Type *vecTy = HLMatrixLower::LowerMatrixType(matTy);
vecVal = Builder.CreateAlloca(vecTy, nullptr, AI->getName()); vecVal = AllocaBuilder.CreateAlloca(vecTy, nullptr, AI->getName());
} }
// Update debug info. // Update debug info.
DbgDeclareInst *DDI = llvm::FindAllocaDbgDeclare(AI); DbgDeclareInst *DDI = llvm::FindAllocaDbgDeclare(AI);

Просмотреть файл

@ -6727,18 +6727,16 @@ void TranslateSubscriptOperation(Function *F, HLOperationLowerHelper &helper, H
// Create BitCast if ptr, otherwise, create alloca of new type, write to bitcast of alloca, and return load from alloca // Create BitCast if ptr, otherwise, create alloca of new type, write to bitcast of alloca, and return load from alloca
// If bOrigAllocaTy is true: create alloca of old type instead, write to alloca, and return load from bitcast of alloca // If bOrigAllocaTy is true: create alloca of old type instead, write to alloca, and return load from bitcast of alloca
static Instruction *BitCastValueOrPtr(Value* V, Instruction *Insert, Type *Ty, bool bOrigAllocaTy = false, const Twine &Name = "") { static Instruction *BitCastValueOrPtr(Value* V, Instruction *Insert, Type *Ty, bool bOrigAllocaTy = false, const Twine &Name = "") {
IRBuilder<> Builder(Insert);
if (Ty->isPointerTy()) { if (Ty->isPointerTy()) {
// If pointer, we can bitcast directly // If pointer, we can bitcast directly
IRBuilder<> Builder(Insert);
return cast<Instruction>(Builder.CreateBitCast(V, Ty, Name)); return cast<Instruction>(Builder.CreateBitCast(V, Ty, Name));
} } else {
else {
// If value, we have to alloca, store to bitcast ptr, and load // If value, we have to alloca, store to bitcast ptr, and load
IRBuilder<> EntryBuilder(Insert->getParent()->getParent()->getEntryBlock().begin()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(Insert));
Type *allocaTy = bOrigAllocaTy ? V->getType() : Ty; Type *allocaTy = bOrigAllocaTy ? V->getType() : Ty;
Type *otherTy = bOrigAllocaTy ? Ty : V->getType(); Type *otherTy = bOrigAllocaTy ? Ty : V->getType();
Instruction *allocaInst = EntryBuilder.CreateAlloca(allocaTy); Instruction *allocaInst = AllocaBuilder.CreateAlloca(allocaTy);
IRBuilder<> Builder(Insert);
Instruction *bitCast = cast<Instruction>(Builder.CreateBitCast(allocaInst, otherTy->getPointerTo())); Instruction *bitCast = cast<Instruction>(Builder.CreateBitCast(allocaInst, otherTy->getPointerTo()));
Builder.CreateStore(V, bOrigAllocaTy ? allocaInst : bitCast); Builder.CreateStore(V, bOrigAllocaTy ? allocaInst : bitCast);
return Builder.CreateLoad(bOrigAllocaTy ? bitCast : allocaInst, Name); return Builder.CreateLoad(bOrigAllocaTy ? bitCast : allocaInst, Name);

Просмотреть файл

@ -19,6 +19,7 @@
#include "dxc/HLSL/HLModule.h" #include "dxc/HLSL/HLModule.h"
#include "dxc/HLSL/HLMatrixLowerHelper.h" #include "dxc/HLSL/HLMatrixLowerHelper.h"
#include "dxc/HlslIntrinsicOp.h" #include "dxc/HlslIntrinsicOp.h"
#include "dxc/HLSL/DxilUtil.h"
#include "llvm/IR/IRBuilder.h" #include "llvm/IR/IRBuilder.h"
#include "llvm/IR/DebugInfo.h" #include "llvm/IR/DebugInfo.h"
@ -530,6 +531,7 @@ Value *replaceLdWithLdInput(Function *loadInput, LoadInst *ldInst,
unsigned cols, MutableArrayRef<Value *> args, unsigned cols, MutableArrayRef<Value *> args,
bool bCast) { bool bCast) {
IRBuilder<> Builder(ldInst); IRBuilder<> Builder(ldInst);
IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(ldInst));
Type *Ty = ldInst->getType(); Type *Ty = ldInst->getType();
Type *EltTy = Ty->getScalarType(); Type *EltTy = Ty->getScalarType();
// Change i1 to i32 for load input. // Change i1 to i32 for load input.
@ -570,7 +572,7 @@ Value *replaceLdWithLdInput(Function *loadInput, LoadInst *ldInst,
// Vector indexing. // Vector indexing.
// Load to array. // Load to array.
ArrayType *AT = ArrayType::get(ldInst->getType(), cols); ArrayType *AT = ArrayType::get(ldInst->getType(), cols);
Value *arrayVec = Builder.CreateAlloca(AT); Value *arrayVec = AllocaBuilder.CreateAlloca(AT);
Value *zeroIdx = Builder.getInt32(0); Value *zeroIdx = Builder.getInt32(0);
for (unsigned col = 0; col < cols; col++) { for (unsigned col = 0; col < cols; col++) {

Просмотреть файл

@ -59,15 +59,15 @@ namespace {
return nullptr; return nullptr;
} }
IRBuilder<> Builder(P); IRBuilder<> AllocaBuilder(P);
if (!AllocaPoint) { if (!AllocaPoint) {
Function *F = P->getParent()->getParent(); Function *F = P->getParent()->getParent();
AllocaPoint = F->getEntryBlock().begin(); AllocaPoint = F->getEntryBlock().begin();
} }
Builder.SetInsertPoint(AllocaPoint); AllocaBuilder.SetInsertPoint(AllocaPoint);
// Create a stack slot to hold the value. // Create a stack slot to hold the value.
AllocaInst *Slot = Builder.CreateAlloca(P->getType(), nullptr, P->getName() + ".reg2mem"); AllocaInst *Slot = AllocaBuilder.CreateAlloca(P->getType(), nullptr, P->getName() + ".reg2mem");
// Insert a load in place of the PHI and replace all uses. // Insert a load in place of the PHI and replace all uses.
BasicBlock::iterator InsertPt = P; BasicBlock::iterator InsertPt = P;
@ -123,23 +123,23 @@ namespace {
return nullptr; return nullptr;
} }
IRBuilder<> Builder(&I); IRBuilder<> AllocaBuilder(&I);
if (!AllocaPoint) { if (!AllocaPoint) {
Function *F = I.getParent()->getParent(); Function *F = I.getParent()->getParent();
AllocaPoint = F->getEntryBlock().begin(); AllocaPoint = F->getEntryBlock().begin();
} }
Builder.SetInsertPoint(AllocaPoint); AllocaBuilder.SetInsertPoint(AllocaPoint);
if (AllocaInst *AI = dyn_cast<AllocaInst>(&I)) { if (AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
// Create a stack slot to hold the value. // Create a stack slot to hold the value.
AllocaInst *Slot = Builder.CreateAlloca(AI->getAllocatedType(), nullptr, I.getName() + ".reg2mem"); AllocaInst *Slot = AllocaBuilder.CreateAlloca(AI->getAllocatedType(), nullptr, I.getName() + ".reg2mem");
I.replaceAllUsesWith(Slot); I.replaceAllUsesWith(Slot);
I.eraseFromParent(); I.eraseFromParent();
return Slot; return Slot;
} }
// Create a stack slot to hold the value. // Create a stack slot to hold the value.
AllocaInst *Slot = Builder.CreateAlloca(I.getType(), nullptr, I.getName() + ".reg2mem");; AllocaInst *Slot = AllocaBuilder.CreateAlloca(I.getType(), nullptr, I.getName() + ".reg2mem");;
// Change all of the users of the instruction to read from the stack slot. // Change all of the users of the instruction to read from the stack slot.
while (!I.use_empty()) { while (!I.use_empty()) {

Просмотреть файл

@ -1605,7 +1605,7 @@ bool SROA_HLSL::performScalarRepl(Function &F, DxilTypeSystem &typeSys) {
// separate elements. // separate elements.
if (ShouldAttemptScalarRepl(AI) && isSafeAllocaToScalarRepl(AI)) { if (ShouldAttemptScalarRepl(AI) && isSafeAllocaToScalarRepl(AI)) {
std::vector<Value *> Elts; std::vector<Value *> Elts;
IRBuilder<> Builder(AI); IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(AI));
bool hasPrecise = HLModule::HasPreciseAttributeWithMetadata(AI); bool hasPrecise = HLModule::HasPreciseAttributeWithMetadata(AI);
bool SROAed = SROA_Helper::DoScalarReplacement( bool SROAed = SROA_Helper::DoScalarReplacement(
@ -3068,7 +3068,7 @@ void SROA_Helper::RewriteBitCast(BitCastInst *BCI) {
void SROA_Helper::RewriteCallArg(CallInst *CI, unsigned ArgIdx, bool bIn, void SROA_Helper::RewriteCallArg(CallInst *CI, unsigned ArgIdx, bool bIn,
bool bOut) { bool bOut) {
Function *F = CI->getParent()->getParent(); Function *F = CI->getParent()->getParent();
IRBuilder<> AllocaBuilder(F->getEntryBlock().getFirstInsertionPt()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(F));
const DataLayout &DL = F->getParent()->getDataLayout(); const DataLayout &DL = F->getParent()->getDataLayout();
Value *userTyV = CI->getArgOperand(ArgIdx); Value *userTyV = CI->getArgOperand(ArgIdx);
@ -3269,7 +3269,9 @@ bool SROA_Helper::DoScalarReplacement(Value *V, std::vector<Value *> &Elts,
// Skip matrix types. // Skip matrix types.
if (HLMatrixLower::IsMatrixType(Ty)) if (HLMatrixLower::IsMatrixType(Ty))
return false; return false;
IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(Builder.GetInsertPoint()));
if (StructType *ST = dyn_cast<StructType>(Ty)) { if (StructType *ST = dyn_cast<StructType>(Ty)) {
// Skip HLSL object types. // Skip HLSL object types.
if (HLModule::IsHLSLObjectType(ST)) { if (HLModule::IsHLSLObjectType(ST)) {
@ -3283,7 +3285,7 @@ bool SROA_Helper::DoScalarReplacement(Value *V, std::vector<Value *> &Elts,
if (SA && SA->IsEmptyStruct()) if (SA && SA->IsEmptyStruct())
return true; return true;
for (int i = 0, e = numTypes; i != e; ++i) { for (int i = 0, e = numTypes; i != e; ++i) {
AllocaInst *NA = Builder.CreateAlloca(ST->getContainedType(i), nullptr, V->getName() + "." + Twine(i)); AllocaInst *NA = AllocaBuilder.CreateAlloca(ST->getContainedType(i), nullptr, V->getName() + "." + Twine(i));
bool markPrecise = hasPrecise; bool markPrecise = hasPrecise;
if (SA) { if (SA) {
DxilFieldAnnotation &FA = SA->GetFieldAnnotation(i); DxilFieldAnnotation &FA = SA->GetFieldAnnotation(i);
@ -3324,7 +3326,7 @@ bool SROA_Helper::DoScalarReplacement(Value *V, std::vector<Value *> &Elts,
if (SA && SA->IsEmptyStruct()) if (SA && SA->IsEmptyStruct())
return true; return true;
for (int i = 0, e = numTypes; i != e; ++i) { for (int i = 0, e = numTypes; i != e; ++i) {
AllocaInst *NA = Builder.CreateAlloca( AllocaInst *NA = AllocaBuilder.CreateAlloca(
CreateNestArrayTy(ElST->getContainedType(i), nestArrayTys), CreateNestArrayTy(ElST->getContainedType(i), nestArrayTys),
nullptr, V->getName() + "." + Twine(i)); nullptr, V->getName() + "." + Twine(i));
bool markPrecise = hasPrecise; bool markPrecise = hasPrecise;
@ -3344,7 +3346,7 @@ bool SROA_Helper::DoScalarReplacement(Value *V, std::vector<Value *> &Elts,
nestArrayTys.size() > 1) nestArrayTys.size() > 1)
return false; return false;
for (int i = 0, e = AT->getNumElements(); i != e; ++i) { for (int i = 0, e = AT->getNumElements(); i != e; ++i) {
AllocaInst *NA = Builder.CreateAlloca(ElTy, nullptr, AllocaInst *NA = AllocaBuilder.CreateAlloca(ElTy, nullptr,
V->getName() + "." + Twine(i)); V->getName() + "." + Twine(i));
Elts.push_back(NA); Elts.push_back(NA);
} }
@ -3362,7 +3364,7 @@ bool SROA_Helper::DoScalarReplacement(Value *V, std::vector<Value *> &Elts,
ArrayType *scalarArrayTy = CreateNestArrayTy(ElVT->getElementType(), nestArrayTys); ArrayType *scalarArrayTy = CreateNestArrayTy(ElVT->getElementType(), nestArrayTys);
for (int i = 0, e = ElVT->getNumElements(); i != e; ++i) { for (int i = 0, e = ElVT->getNumElements(); i != e; ++i) {
AllocaInst *NA = Builder.CreateAlloca(scalarArrayTy, nullptr, AllocaInst *NA = AllocaBuilder.CreateAlloca(scalarArrayTy, nullptr,
V->getName() + "." + Twine(i)); V->getName() + "." + Twine(i));
if (hasPrecise) if (hasPrecise)
HLModule::MarkPreciseAttributeWithMetadata(NA); HLModule::MarkPreciseAttributeWithMetadata(NA);
@ -4784,7 +4786,8 @@ void SROA_Parameter_HLSL::replaceCastParameter(
if (isa<Argument>(OldParam) && OldTy->isPointerTy()) { if (isa<Argument>(OldParam) && OldTy->isPointerTy()) {
// OldParam will be removed with Old function. // OldParam will be removed with Old function.
// Create alloca to replace it. // Create alloca to replace it.
Value *AllocParam = Builder.CreateAlloca(OldTy->getPointerElementType()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(&F));
Value *AllocParam = AllocaBuilder.CreateAlloca(OldTy->getPointerElementType());
OldParam->replaceAllUsesWith(AllocParam); OldParam->replaceAllUsesWith(AllocParam);
OldParam = AllocParam; OldParam = AllocParam;
} }
@ -4880,6 +4883,8 @@ Value *SROA_Parameter_HLSL::castResourceArgIfRequired(
IRBuilder<> &Builder) { IRBuilder<> &Builder) {
Type *HandleTy = m_pHLModule->GetOP()->GetHandleType(); Type *HandleTy = m_pHLModule->GetOP()->GetHandleType();
Module &M = *m_pHLModule->GetModule(); Module &M = *m_pHLModule->GetModule();
IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(Builder.GetInsertPoint()));
// Lower resource type to handle ty. // Lower resource type to handle ty.
if (HLModule::IsHLSLObjectType(Ty) && if (HLModule::IsHLSLObjectType(Ty) &&
!HLModule::IsStreamOutputPtrType(V->getType())) { !HLModule::IsStreamOutputPtrType(V->getType())) {
@ -4891,7 +4896,7 @@ Value *SROA_Parameter_HLSL::castResourceArgIfRequired(
/*opcode*/ 0, HandleTy, { LdRes }, M); /*opcode*/ 0, HandleTy, { LdRes }, M);
} }
else { else {
V = Builder.CreateAlloca(HandleTy); V = AllocaBuilder.CreateAlloca(HandleTy);
} }
castParamMap[V] = std::make_pair(Res, inputQual); castParamMap[V] = std::make_pair(Res, inputQual);
} }
@ -4905,7 +4910,7 @@ Value *SROA_Parameter_HLSL::castResourceArgIfRequired(
if (HLModule::IsHLSLObjectType(AT)) { if (HLModule::IsHLSLObjectType(AT)) {
Value *Res = V; Value *Res = V;
Type *Ty = ArrayType::get(HandleTy, arraySize); Type *Ty = ArrayType::get(HandleTy, arraySize);
V = Builder.CreateAlloca(Ty); V = AllocaBuilder.CreateAlloca(Ty);
castParamMap[V] = std::make_pair(Res, inputQual); castParamMap[V] = std::make_pair(Res, inputQual);
} }
} }
@ -4917,9 +4922,11 @@ Value *SROA_Parameter_HLSL::castArgumentIfRequired(
DxilParamInputQual inputQual, DxilFieldAnnotation &annotation, DxilParamInputQual inputQual, DxilFieldAnnotation &annotation,
std::deque<Value *> &WorkList, IRBuilder<> &Builder) { std::deque<Value *> &WorkList, IRBuilder<> &Builder) {
Module &M = *m_pHLModule->GetModule(); Module &M = *m_pHLModule->GetModule();
IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(Builder.GetInsertPoint()));
// Remove pointer for vector/scalar which is not out. // Remove pointer for vector/scalar which is not out.
if (V->getType()->isPointerTy() && !Ty->isAggregateType() && !bOut) { if (V->getType()->isPointerTy() && !Ty->isAggregateType() && !bOut) {
Value *Ptr = Builder.CreateAlloca(Ty); Value *Ptr = AllocaBuilder.CreateAlloca(Ty);
V->replaceAllUsesWith(Ptr); V->replaceAllUsesWith(Ptr);
// Create load here to make correct type. // Create load here to make correct type.
// The Ptr will be store with correct value in replaceCastParameter. // The Ptr will be store with correct value in replaceCastParameter.
@ -5005,6 +5012,7 @@ void SROA_Parameter_HLSL::flattenArgument(
std::vector<Value *> &FlatParamList, std::vector<Value *> &FlatParamList,
std::vector<DxilParameterAnnotation> &FlatAnnotationList, std::vector<DxilParameterAnnotation> &FlatAnnotationList,
IRBuilder<> &Builder, DbgDeclareInst *DDI) { IRBuilder<> &Builder, DbgDeclareInst *DDI) {
IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(Builder.GetInsertPoint()));
std::deque<Value *> WorkList; std::deque<Value *> WorkList;
WorkList.push_back(Arg); WorkList.push_back(Arg);
@ -5140,7 +5148,7 @@ void SROA_Parameter_HLSL::flattenArgument(
unsigned targetIndex; unsigned targetIndex;
Semantic::DecomposeNameAndIndex(semanticStr, &targetStr, &targetIndex); Semantic::DecomposeNameAndIndex(semanticStr, &targetStr, &targetIndex);
// Replace target parameter with local target. // Replace target parameter with local target.
AllocaInst *localTarget = Builder.CreateAlloca(Ty); AllocaInst *localTarget = AllocaBuilder.CreateAlloca(Ty);
V->replaceAllUsesWith(localTarget); V->replaceAllUsesWith(localTarget);
unsigned arraySize = 1; unsigned arraySize = 1;
std::vector<unsigned> arraySizeList; std::vector<unsigned> arraySizeList;
@ -5157,7 +5165,7 @@ void SROA_Parameter_HLSL::flattenArgument(
// Create flattened target. // Create flattened target.
DxilFieldAnnotation EltAnnotation = annotation; DxilFieldAnnotation EltAnnotation = annotation;
for (unsigned i=0;i<arraySize;i++) { for (unsigned i=0;i<arraySize;i++) {
Value *Elt = Builder.CreateAlloca(Ty); Value *Elt = AllocaBuilder.CreateAlloca(Ty);
EltAnnotation.SetSemanticString(targetStr.str()+std::to_string(targetIndex+i)); EltAnnotation.SetSemanticString(targetStr.str()+std::to_string(targetIndex+i));
// Add semantic type. // Add semantic type.
@ -5251,7 +5259,7 @@ void SROA_Parameter_HLSL::flattenArgument(
// For stream output objects. // For stream output objects.
// Create a value as output value. // Create a value as output value.
Type *outputType = V->getType()->getPointerElementType()->getStructElementType(0); Type *outputType = V->getType()->getPointerElementType()->getStructElementType(0);
Value *outputVal = Builder.CreateAlloca(outputType); Value *outputVal = AllocaBuilder.CreateAlloca(outputType);
// For each stream.Append(data) // For each stream.Append(data)
// transform into // transform into
// d = load data // d = load data
@ -5372,7 +5380,8 @@ void SROA_Parameter_HLSL::preprocessArgUsedInCall(Function *F) {
DxilFunctionAnnotation *pFuncAnnot = typeSys.GetFunctionAnnotation(F); DxilFunctionAnnotation *pFuncAnnot = typeSys.GetFunctionAnnotation(F);
DXASSERT(pFuncAnnot, "else invalid function"); DXASSERT(pFuncAnnot, "else invalid function");
IRBuilder<> AllocaBuilder(F->getEntryBlock().getFirstInsertionPt()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(F));
IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(F));
SmallVector<ReturnInst*, 2> retList; SmallVector<ReturnInst*, 2> retList;
for (BasicBlock &bb : F->getBasicBlockList()) { for (BasicBlock &bb : F->getBasicBlockList()) {
@ -5407,7 +5416,7 @@ void SROA_Parameter_HLSL::preprocessArgUsedInCall(Function *F) {
if (inputQual == DxilParamInputQual::In || if (inputQual == DxilParamInputQual::In ||
inputQual == DxilParamInputQual::Inout) { inputQual == DxilParamInputQual::Inout) {
// copy arg to tmp. // copy arg to tmp.
CallInst *argToTmp = AllocaBuilder.CreateMemCpy(TmpArg, &arg, size, 0); CallInst *argToTmp = Builder.CreateMemCpy(TmpArg, &arg, size, 0);
// Split the memcpy. // Split the memcpy.
MemcpySplitter::SplitMemCpy(cast<MemCpyInst>(argToTmp), DL, nullptr, MemcpySplitter::SplitMemCpy(cast<MemCpyInst>(argToTmp), DL, nullptr,
typeSys); typeSys);
@ -5525,7 +5534,7 @@ static void LegalizeDxilInputOutputs(Function *F,
// DxilGenerationPass. // DxilGenerationPass.
isColMajor = paramAnnotation.GetMatrixAnnotation().Orientation == isColMajor = paramAnnotation.GetMatrixAnnotation().Orientation ==
MatrixOrientation::ColumnMajor; MatrixOrientation::ColumnMajor;
IRBuilder<> Builder(EntryBlk.getFirstInsertionPt()); IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(F));
HLCastOpcode opcode = isColMajor ? HLCastOpcode::ColMatrixToVecCast HLCastOpcode opcode = isColMajor ? HLCastOpcode::ColMatrixToVecCast
: HLCastOpcode::RowMatrixToVecCast; : HLCastOpcode::RowMatrixToVecCast;
@ -5591,9 +5600,10 @@ static void LegalizeDxilInputOutputs(Function *F,
} }
if (bNeedTemp) { if (bNeedTemp) {
IRBuilder<> Builder(EntryBlk.getFirstInsertionPt()); IRBuilder<> AllocaBuilder(EntryBlk.getFirstInsertionPt());
IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(&EntryBlk));
AllocaInst *temp = Builder.CreateAlloca(Ty); AllocaInst *temp = AllocaBuilder.CreateAlloca(Ty);
// Replace all uses with temp. // Replace all uses with temp.
arg.replaceAllUsesWith(temp); arg.replaceAllUsesWith(temp);
@ -5684,9 +5694,9 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
// Insert point may be removed. So recreate builder every time. // Insert point may be removed. So recreate builder every time.
IRBuilder<> Builder(Ctx); IRBuilder<> Builder(Ctx);
if (!F->isDeclaration()) { if (!F->isDeclaration()) {
Builder.SetInsertPoint(F->getEntryBlock().getFirstInsertionPt()); Builder.SetInsertPoint(dxilutil::FirstNonAllocaInsertionPt(F));
} else { } else {
Builder.SetInsertPoint(TmpBlockForFuncDecl->getFirstInsertionPt()); Builder.SetInsertPoint(dxilutil::FirstNonAllocaInsertionPt(TmpBlockForFuncDecl.get()));
} }
unsigned prevFlatParamCount = FlatParamList.size(); unsigned prevFlatParamCount = FlatParamList.size();
@ -5710,12 +5720,15 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
// Split and change to out parameter. // Split and change to out parameter.
if (!retType->isVoidTy()) { if (!retType->isVoidTy()) {
IRBuilder<> Builder(Ctx); IRBuilder<> Builder(Ctx);
IRBuilder<> AllocaBuilder(Ctx);
if (!F->isDeclaration()) { if (!F->isDeclaration()) {
Builder.SetInsertPoint(F->getEntryBlock().getFirstInsertionPt()); Builder.SetInsertPoint(dxilutil::FirstNonAllocaInsertionPt(F));
AllocaBuilder.SetInsertPoint(dxilutil::FindAllocaInsertionPt(F));
} else { } else {
Builder.SetInsertPoint(TmpBlockForFuncDecl->getFirstInsertionPt()); Builder.SetInsertPoint(dxilutil::FirstNonAllocaInsertionPt(TmpBlockForFuncDecl.get()));
AllocaBuilder.SetInsertPoint(TmpBlockForFuncDecl->getFirstInsertionPt());
} }
Value *retValAddr = Builder.CreateAlloca(retType); Value *retValAddr = AllocaBuilder.CreateAlloca(retType);
DxilParameterAnnotation &retAnnotation = DxilParameterAnnotation &retAnnotation =
funcAnnotation->GetRetTypeAnnotation(); funcAnnotation->GetRetTypeAnnotation();
Module &M = *m_pHLModule->GetModule(); Module &M = *m_pHLModule->GetModule();
@ -5925,7 +5938,8 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
LLVMContext &Context = F->getContext(); LLVMContext &Context = F->getContext();
// Parameter cast come from begining of entry block. // Parameter cast come from begining of entry block.
IRBuilder<> Builder(flatF->getEntryBlock().getFirstInsertionPt()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(flatF));
IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(flatF));
while (argIter != flatF->arg_end()) { while (argIter != flatF->arg_end()) {
Argument *Arg = argIter++; Argument *Arg = argIter++;
@ -5950,7 +5964,7 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
StoreInst *SI = cast<StoreInst>(*flatArg->user_begin()); StoreInst *SI = cast<StoreInst>(*flatArg->user_begin());
allocaArg = SI->getPointerOperand(); allocaArg = SI->getPointerOperand();
} else { } else {
allocaArg = Builder.CreateAlloca(flatArg->getType()); allocaArg = AllocaBuilder.CreateAlloca(flatArg->getType());
StoreInst *initArg = Builder.CreateStore(flatArg, allocaArg); StoreInst *initArg = Builder.CreateStore(flatArg, allocaArg);
Value *ldArg = Builder.CreateLoad(allocaArg); Value *ldArg = Builder.CreateLoad(allocaArg);
flatArg->replaceAllUsesWith(ldArg); flatArg->replaceAllUsesWith(ldArg);
@ -6062,8 +6076,10 @@ bool LowerStaticGlobalIntoAlloca::lowerStaticGlobalIntoAlloca(GlobalVariable *GV
return false; return false;
Function *F = const_cast<Function*>(PS.AccessingFunction); Function *F = const_cast<Function*>(PS.AccessingFunction);
IRBuilder<> Builder(F->getEntryBlock().getFirstInsertionPt()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(F));
AllocaInst *AI = Builder.CreateAlloca(GV->getType()->getElementType()); AllocaInst *AI = AllocaBuilder.CreateAlloca(GV->getType()->getElementType());
IRBuilder<> Builder(dxilutil::FirstNonAllocaInsertionPt(F));
// Store initializer is exist. // Store initializer is exist.
if (GV->hasInitializer() && !isa<UndefValue>(GV->getInitializer())) { if (GV->hasInitializer() && !isa<UndefValue>(GV->getInitializer())) {
@ -6110,9 +6126,9 @@ protected:
}; };
AllocaInst *LowerTypePass::lowerAlloca(AllocaInst *A) { AllocaInst *LowerTypePass::lowerAlloca(AllocaInst *A) {
IRBuilder<> Builder(A); IRBuilder<> AllocaBuilder(A);
Type *NewTy = lowerType(A->getAllocatedType()); Type *NewTy = lowerType(A->getAllocatedType());
return Builder.CreateAlloca(NewTy); return AllocaBuilder.CreateAlloca(NewTy);
} }
GlobalVariable *LowerTypePass::lowerInternalGlobal(GlobalVariable *GV) { GlobalVariable *LowerTypePass::lowerInternalGlobal(GlobalVariable *GV) {

Просмотреть файл

@ -6502,15 +6502,14 @@ void CGMSHLSLRuntime::EmitHLSLOutParamConversionInit(
Value *tmpArgAddr = nullptr; Value *tmpArgAddr = nullptr;
BasicBlock *InsertBlock = CGF.Builder.GetInsertBlock(); BasicBlock *InsertBlock = CGF.Builder.GetInsertBlock();
Function *F = InsertBlock->getParent(); Function *F = InsertBlock->getParent();
BasicBlock *EntryBlock = &F->getEntryBlock();
if (ParamTy->isBooleanType()) { if (ParamTy->isBooleanType()) {
// Create i32 for bool. // Create i32 for bool.
ParamTy = CGM.getContext().IntTy; ParamTy = CGM.getContext().IntTy;
} }
// Make sure the alloca is in entry block to stop inline create stacksave. // Make sure the alloca is in entry block to stop inline create stacksave.
IRBuilder<> Builder(EntryBlock->getFirstInsertionPt()); IRBuilder<> AllocaBuilder(dxilutil::FindAllocaInsertionPt(F));
tmpArgAddr = Builder.CreateAlloca(CGF.ConvertType(ParamTy)); tmpArgAddr = AllocaBuilder.CreateAlloca(CGF.ConvertType(ParamTy));
// add it to local decl map // add it to local decl map