|
@@ -3886,6 +3886,8 @@ public:
|
|
|
// Remove flattened functions.
|
|
|
for (auto Iter : funcMap) {
|
|
|
Function *F = Iter.first;
|
|
|
+ Function *flatF = Iter.second;
|
|
|
+ flatF->takeName(F);
|
|
|
F->eraseFromParent();
|
|
|
}
|
|
|
|
|
@@ -4978,9 +4980,11 @@ void SROA_Parameter_HLSL::flattenArgument(
|
|
|
|
|
|
Function *Entry = m_pHLModule->GetEntryFunction();
|
|
|
bool hasShaderInputOutput = F == Entry;
|
|
|
-
|
|
|
- if (m_pHLModule->HasHLFunctionProps(Entry)) {
|
|
|
- HLFunctionProps &funcProps = m_pHLModule->GetHLFunctionProps(Entry);
|
|
|
+ if (m_pHLModule->HasDxilFunctionProps(F)) {
|
|
|
+ hasShaderInputOutput = true;
|
|
|
+ }
|
|
|
+ if (m_pHLModule->HasDxilFunctionProps(Entry)) {
|
|
|
+ DxilFunctionProps &funcProps = m_pHLModule->GetDxilFunctionProps(Entry);
|
|
|
if (funcProps.shaderKind == DXIL::ShaderKind::Hull) {
|
|
|
Function *patchConstantFunc = funcProps.ShaderProps.HS.patchConstantFunc;
|
|
|
hasShaderInputOutput |= F == patchConstantFunc;
|
|
@@ -5536,7 +5540,13 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
|
|
|
DXASSERT(funcAnnotation, "must find annotation for function");
|
|
|
|
|
|
std::deque<Value *> WorkList;
|
|
|
-
|
|
|
+
|
|
|
+ LLVMContext &Ctx = m_pHLModule->GetCtx();
|
|
|
+ std::unique_ptr<BasicBlock> TmpBlockForFuncDecl;
|
|
|
+ if (F->isDeclaration()) {
|
|
|
+ TmpBlockForFuncDecl.reset(BasicBlock::Create(Ctx));
|
|
|
+ }
|
|
|
+
|
|
|
std::vector<Value *> FlatParamList;
|
|
|
std::vector<DxilParameterAnnotation> FlatParamAnnotationList;
|
|
|
const bool bForParamTrue = true;
|
|
@@ -5545,7 +5555,13 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
|
|
|
// merge GEP use for arg.
|
|
|
HLModule::MergeGepUse(&Arg);
|
|
|
// Insert point may be removed. So recreate builder every time.
|
|
|
- IRBuilder<> Builder(F->getEntryBlock().getFirstInsertionPt());
|
|
|
+ IRBuilder<> Builder(Ctx);
|
|
|
+ if (!F->isDeclaration()) {
|
|
|
+ Builder.SetInsertPoint(F->getEntryBlock().getFirstInsertionPt());
|
|
|
+ } else {
|
|
|
+ Builder.SetInsertPoint(TmpBlockForFuncDecl.get());
|
|
|
+ }
|
|
|
+
|
|
|
DxilParameterAnnotation ¶mAnnotation =
|
|
|
funcAnnotation->GetParameterAnnotation(Arg.getArgNo());
|
|
|
DbgDeclareInst *DDI = llvm::FindAllocaDbgDeclare(&Arg);
|
|
@@ -5558,8 +5574,12 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
|
|
|
std::vector<DxilParameterAnnotation> FlatRetAnnotationList;
|
|
|
// Split and change to out parameter.
|
|
|
if (!retType->isVoidTy()) {
|
|
|
- Instruction *InsertPt = F->getEntryBlock().getFirstInsertionPt();
|
|
|
- IRBuilder<> Builder(InsertPt);
|
|
|
+ IRBuilder<> Builder(Ctx);
|
|
|
+ if (!F->isDeclaration()) {
|
|
|
+ Builder.SetInsertPoint(F->getEntryBlock().getFirstInsertionPt());
|
|
|
+ } else {
|
|
|
+ Builder.SetInsertPoint(TmpBlockForFuncDecl.get());
|
|
|
+ }
|
|
|
Value *retValAddr = Builder.CreateAlloca(retType);
|
|
|
DxilParameterAnnotation &retAnnotation =
|
|
|
funcAnnotation->GetRetTypeAnnotation();
|
|
@@ -5640,8 +5660,8 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
|
|
|
}
|
|
|
|
|
|
unsigned extraParamSize = 0;
|
|
|
- if (m_pHLModule->HasHLFunctionProps(F)) {
|
|
|
- HLFunctionProps &funcProps = m_pHLModule->GetHLFunctionProps(F);
|
|
|
+ if (m_pHLModule->HasDxilFunctionProps(F)) {
|
|
|
+ DxilFunctionProps &funcProps = m_pHLModule->GetDxilFunctionProps(F);
|
|
|
if (funcProps.shaderKind == ShaderModel::Kind::Vertex) {
|
|
|
auto &VS = funcProps.ShaderProps.VS;
|
|
|
Type *outFloatTy = Type::getFloatPtrTy(F->getContext());
|
|
@@ -5698,12 +5718,12 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
|
|
|
}
|
|
|
DXASSERT(flatF->arg_size() == (extraParamSize + FlatParamAnnotationList.size()), "parameter count mismatch");
|
|
|
// ShaderProps.
|
|
|
- if (m_pHLModule->HasHLFunctionProps(F)) {
|
|
|
- HLFunctionProps &funcProps = m_pHLModule->GetHLFunctionProps(F);
|
|
|
- std::unique_ptr<HLFunctionProps> flatFuncProps = std::make_unique<HLFunctionProps>();
|
|
|
+ if (m_pHLModule->HasDxilFunctionProps(F)) {
|
|
|
+ DxilFunctionProps &funcProps = m_pHLModule->GetDxilFunctionProps(F);
|
|
|
+ std::unique_ptr<DxilFunctionProps> flatFuncProps = std::make_unique<DxilFunctionProps>();
|
|
|
flatFuncProps->shaderKind = funcProps.shaderKind;
|
|
|
flatFuncProps->ShaderProps = funcProps.ShaderProps;
|
|
|
- m_pHLModule->AddHLFunctionProps(flatF, flatFuncProps);
|
|
|
+ m_pHLModule->AddDxilFunctionProps(flatF, flatFuncProps);
|
|
|
if (funcProps.shaderKind == ShaderModel::Kind::Vertex) {
|
|
|
auto &VS = funcProps.ShaderProps.VS;
|
|
|
unsigned clipArgIndex = FlatParamAnnotationList.size();
|
|
@@ -5722,50 +5742,52 @@ void SROA_Parameter_HLSL::createFlattenedFunction(Function *F) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Move function body into flatF.
|
|
|
- moveFunctionBody(F, flatF);
|
|
|
+ if (!F->isDeclaration()) {
|
|
|
+ // Move function body into flatF.
|
|
|
+ moveFunctionBody(F, flatF);
|
|
|
|
|
|
- // Replace old parameters with flatF Arguments.
|
|
|
- auto argIter = flatF->arg_begin();
|
|
|
- auto flatArgIter = FlatParamList.begin();
|
|
|
- LLVMContext &Context = F->getContext();
|
|
|
+ // Replace old parameters with flatF Arguments.
|
|
|
+ auto argIter = flatF->arg_begin();
|
|
|
+ auto flatArgIter = FlatParamList.begin();
|
|
|
+ LLVMContext &Context = F->getContext();
|
|
|
|
|
|
- // Parameter cast come from begining of entry block.
|
|
|
- IRBuilder<> Builder(flatF->getEntryBlock().getFirstInsertionPt());
|
|
|
+ // Parameter cast come from begining of entry block.
|
|
|
+ IRBuilder<> Builder(flatF->getEntryBlock().getFirstInsertionPt());
|
|
|
|
|
|
- while (argIter != flatF->arg_end()) {
|
|
|
- Argument *Arg = argIter++;
|
|
|
- if (flatArgIter == FlatParamList.end()) {
|
|
|
- DXASSERT(extraParamSize>0, "parameter count mismatch");
|
|
|
- break;
|
|
|
- }
|
|
|
- Value *flatArg = *(flatArgIter++);
|
|
|
+ while (argIter != flatF->arg_end()) {
|
|
|
+ Argument *Arg = argIter++;
|
|
|
+ if (flatArgIter == FlatParamList.end()) {
|
|
|
+ DXASSERT(extraParamSize > 0, "parameter count mismatch");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Value *flatArg = *(flatArgIter++);
|
|
|
|
|
|
- if (castParamMap.count(flatArg)) {
|
|
|
- replaceCastParameter(flatArg, castParamMap[flatArg].first, *flatF, Arg,
|
|
|
- castParamMap[flatArg].second, Builder);
|
|
|
- }
|
|
|
+ if (castParamMap.count(flatArg)) {
|
|
|
+ replaceCastParameter(flatArg, castParamMap[flatArg].first, *flatF, Arg,
|
|
|
+ castParamMap[flatArg].second, Builder);
|
|
|
+ }
|
|
|
|
|
|
- flatArg->replaceAllUsesWith(Arg);
|
|
|
- // Update arg debug info.
|
|
|
- DbgDeclareInst *DDI = llvm::FindAllocaDbgDeclare(flatArg);
|
|
|
- if (DDI) {
|
|
|
- Value *VMD = MetadataAsValue::get(Context, ValueAsMetadata::get(Arg));
|
|
|
- DDI->setArgOperand(0, VMD);
|
|
|
- }
|
|
|
+ flatArg->replaceAllUsesWith(Arg);
|
|
|
+ // Update arg debug info.
|
|
|
+ DbgDeclareInst *DDI = llvm::FindAllocaDbgDeclare(flatArg);
|
|
|
+ if (DDI) {
|
|
|
+ Value *VMD = MetadataAsValue::get(Context, ValueAsMetadata::get(Arg));
|
|
|
+ DDI->setArgOperand(0, VMD);
|
|
|
+ }
|
|
|
|
|
|
- HLModule::MergeGepUse(Arg);
|
|
|
- // Flatten store of array parameter.
|
|
|
- if (Arg->getType()->isPointerTy()) {
|
|
|
- Type *Ty = Arg->getType()->getPointerElementType();
|
|
|
- if (Ty->isArrayTy())
|
|
|
- SplitArrayCopy(
|
|
|
- Arg, typeSys,
|
|
|
- &flatFuncAnnotation->GetParameterAnnotation(Arg->getArgNo()));
|
|
|
+ HLModule::MergeGepUse(Arg);
|
|
|
+ // Flatten store of array parameter.
|
|
|
+ if (Arg->getType()->isPointerTy()) {
|
|
|
+ Type *Ty = Arg->getType()->getPointerElementType();
|
|
|
+ if (Ty->isArrayTy())
|
|
|
+ SplitArrayCopy(
|
|
|
+ Arg, typeSys,
|
|
|
+ &flatFuncAnnotation->GetParameterAnnotation(Arg->getArgNo()));
|
|
|
+ }
|
|
|
}
|
|
|
+ // Support store to input and load from output.
|
|
|
+ LegalizeDxilInputOutputs(flatF, flatFuncAnnotation, typeSys);
|
|
|
}
|
|
|
- // Support store to input and load from output.
|
|
|
- LegalizeDxilInputOutputs(flatF, flatFuncAnnotation, typeSys);
|
|
|
}
|
|
|
|
|
|
void SROA_Parameter_HLSL::createFlattenedFunctionCall(Function *F, Function *flatF, CallInst *CI) {
|
|
@@ -5972,8 +5994,8 @@ void SROA_Parameter_HLSL::replaceCall(Function *F, Function *flatF) {
|
|
|
m_pHLModule->SetEntryFunction(flatF);
|
|
|
}
|
|
|
// Update patch constant function.
|
|
|
- if (m_pHLModule->HasHLFunctionProps(flatF)) {
|
|
|
- HLFunctionProps &funcProps = m_pHLModule->GetHLFunctionProps(flatF);
|
|
|
+ if (m_pHLModule->HasDxilFunctionProps(flatF)) {
|
|
|
+ DxilFunctionProps &funcProps = m_pHLModule->GetDxilFunctionProps(flatF);
|
|
|
if (funcProps.shaderKind == DXIL::ShaderKind::Hull) {
|
|
|
Function *oldPatchConstantFunc =
|
|
|
funcProps.ShaderProps.HS.patchConstantFunc;
|