More places to be cautious about alloca vs. non-alloca insert locs.

- some builder name changes for consistency
This commit is contained in:
Tex Riddell 2018-03-29 18:05:38 -07:00
Родитель 81f8b8c3a2
Коммит 335ee949bb
10 изменённых файлов: 31 добавлений и 28 удалений

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

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

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

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

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

@ -13,6 +13,7 @@
#include "dxc/HLSL/DxilModule.h"
#include "dxc/HLSL/DxilOperations.h"
#include "dxc/HLSL/DxilPIXPasses.h"
#include "dxc/HLSL/DxilUtil.h"
#include "llvm/IR/Module.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).
//
Instruction* firstInsertionPt = DM.GetEntryFunction()->getEntryBlock().getFirstInsertionPt();
Instruction* firstInsertionPt = dxilutil::FirstNonAllocaInsertionPt(DM.GetEntryFunction());
IRBuilder<> Builder(firstInsertionPt);
BuilderContext BC{ M, DM, Ctx, HlslOP, Builder };

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

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

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

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

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

@ -86,15 +86,15 @@ public:
{
}
void CreateAlloca(IRBuilder<> &builder) {
LLVMContext &context = builder.getContext();
void CreateAlloca(IRBuilder<> &allocaBuilder) {
LLVMContext &context = allocaBuilder.getContext();
Type *elementType = m_OutputElement.GetCompType().GetLLVMType(context);
Type *allocaType = nullptr;
if (IsSingleElement())
allocaType = elementType;
else
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 {
@ -249,11 +249,11 @@ DxilPreserveAllOutputs::OutputMap DxilPreserveAllOutputs::generateOutputMap(cons
return map;
}
void DxilPreserveAllOutputs::createTempAllocas(OutputMap &outputMap, IRBuilder<> &builder)
void DxilPreserveAllOutputs::createTempAllocas(OutputMap &outputMap, IRBuilder<> &allocaBuilder)
{
for (auto &iter: outputMap) {
OutputElement &output = iter.second;
output.CreateAlloca(builder);
output.CreateAlloca(allocaBuilder);
}
}

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

@ -853,14 +853,14 @@ void HLMatrixLowerPass::lowerToVec(Instruction *matInst) {
Type *Ty = AI->getAllocatedType();
Type *matTy = Ty;
IRBuilder<> Builder(AI);
IRBuilder<> AllocaBuilder(AI);
if (Ty->isArrayTy()) {
Type *vecTy = HLMatrixLower::LowerMatrixArrayPointer(AI->getType());
vecTy = vecTy->getPointerElementType();
vecVal = Builder.CreateAlloca(vecTy, nullptr, AI->getName());
vecVal = AllocaBuilder.CreateAlloca(vecTy, nullptr, AI->getName());
} else {
Type *vecTy = HLMatrixLower::LowerMatrixType(matTy);
vecVal = Builder.CreateAlloca(vecTy, nullptr, AI->getName());
vecVal = AllocaBuilder.CreateAlloca(vecTy, nullptr, AI->getName());
}
// Update debug info.
DbgDeclareInst *DDI = llvm::FindAllocaDbgDeclare(AI);

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

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

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

@ -59,15 +59,15 @@ namespace {
return nullptr;
}
IRBuilder<> Builder(P);
IRBuilder<> AllocaBuilder(P);
if (!AllocaPoint) {
Function *F = P->getParent()->getParent();
AllocaPoint = F->getEntryBlock().begin();
}
Builder.SetInsertPoint(AllocaPoint);
AllocaBuilder.SetInsertPoint(AllocaPoint);
// 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.
BasicBlock::iterator InsertPt = P;
@ -123,23 +123,23 @@ namespace {
return nullptr;
}
IRBuilder<> Builder(&I);
IRBuilder<> AllocaBuilder(&I);
if (!AllocaPoint) {
Function *F = I.getParent()->getParent();
AllocaPoint = F->getEntryBlock().begin();
}
Builder.SetInsertPoint(AllocaPoint);
AllocaBuilder.SetInsertPoint(AllocaPoint);
if (AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
// 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.eraseFromParent();
return Slot;
}
// 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.
while (!I.use_empty()) {

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

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