Skip to content

Commit 8785813

Browse files
emit Alignment decoration for alloca's
1 parent 2fea1cc commit 8785813

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ let TargetPrefix = "spv" in {
3636
def int_spv_selection_merge : Intrinsic<[], [llvm_vararg_ty]>;
3737
def int_spv_cmpxchg : Intrinsic<[llvm_i32_ty], [llvm_any_ty, llvm_vararg_ty]>;
3838
def int_spv_unreachable : Intrinsic<[], []>;
39-
def int_spv_alloca : Intrinsic<[llvm_any_ty], []>;
40-
def int_spv_alloca_array : Intrinsic<[llvm_any_ty], [llvm_anyint_ty]>;
39+
def int_spv_alloca : Intrinsic<[llvm_any_ty], [llvm_i8_ty], [ImmArg<ArgIndex<0>>]>;
40+
def int_spv_alloca_array : Intrinsic<[llvm_any_ty], [llvm_anyint_ty, llvm_i8_ty], [ImmArg<ArgIndex<1>>]>;
4141
def int_spv_undef : Intrinsic<[llvm_i32_ty], []>;
4242
def int_spv_inline_asm : Intrinsic<[], [llvm_metadata_ty, llvm_metadata_ty, llvm_vararg_ty]>;
4343

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,9 +1713,12 @@ Instruction *SPIRVEmitIntrinsics::visitAllocaInst(AllocaInst &I) {
17131713
TrackConstants = false;
17141714
Type *PtrTy = I.getType();
17151715
auto *NewI =
1716-
ArraySize ? B.CreateIntrinsic(Intrinsic::spv_alloca_array,
1717-
{PtrTy, ArraySize->getType()}, {ArraySize})
1718-
: B.CreateIntrinsic(Intrinsic::spv_alloca, {PtrTy}, {});
1716+
ArraySize
1717+
? B.CreateIntrinsic(Intrinsic::spv_alloca_array,
1718+
{PtrTy, ArraySize->getType()},
1719+
{ArraySize, B.getInt8(I.getAlign().value())})
1720+
: B.CreateIntrinsic(Intrinsic::spv_alloca, {PtrTy},
1721+
{B.getInt8(I.getAlign().value())});
17191722
replaceAllUsesWithAndErase(B, &I, NewI);
17201723
return NewI;
17211724
}

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,12 +3298,17 @@ bool SPIRVInstructionSelector::selectAllocaArray(Register ResVReg,
32983298
// there was an allocation size parameter to the allocation instruction
32993299
// that is not 1
33003300
MachineBasicBlock &BB = *I.getParent();
3301-
return BuildMI(BB, I, I.getDebugLoc(),
3302-
TII.get(SPIRV::OpVariableLengthArrayINTEL))
3303-
.addDef(ResVReg)
3304-
.addUse(GR.getSPIRVTypeID(ResType))
3305-
.addUse(I.getOperand(2).getReg())
3306-
.constrainAllUses(TII, TRI, RBI);
3301+
bool Res = BuildMI(BB, I, I.getDebugLoc(),
3302+
TII.get(SPIRV::OpVariableLengthArrayINTEL))
3303+
.addDef(ResVReg)
3304+
.addUse(GR.getSPIRVTypeID(ResType))
3305+
.addUse(I.getOperand(2).getReg())
3306+
.constrainAllUses(TII, TRI, RBI);
3307+
if (!STI.isVulkanEnv()) {
3308+
unsigned Alignment = I.getOperand(3).getImm();
3309+
buildOpDecorate(ResVReg, I, TII, SPIRV::Decoration::Alignment, {Alignment});
3310+
}
3311+
return Res;
33073312
}
33083313

33093314
bool SPIRVInstructionSelector::selectFrameIndex(Register ResVReg,
@@ -3312,12 +3317,18 @@ bool SPIRVInstructionSelector::selectFrameIndex(Register ResVReg,
33123317
// Change order of instructions if needed: all OpVariable instructions in a
33133318
// function must be the first instructions in the first block
33143319
auto It = getOpVariableMBBIt(I);
3315-
return BuildMI(*It->getParent(), It, It->getDebugLoc(),
3316-
TII.get(SPIRV::OpVariable))
3317-
.addDef(ResVReg)
3318-
.addUse(GR.getSPIRVTypeID(ResType))
3319-
.addImm(static_cast<uint32_t>(SPIRV::StorageClass::Function))
3320-
.constrainAllUses(TII, TRI, RBI);
3320+
bool Res = BuildMI(*It->getParent(), It, It->getDebugLoc(),
3321+
TII.get(SPIRV::OpVariable))
3322+
.addDef(ResVReg)
3323+
.addUse(GR.getSPIRVTypeID(ResType))
3324+
.addImm(static_cast<uint32_t>(SPIRV::StorageClass::Function))
3325+
.constrainAllUses(TII, TRI, RBI);
3326+
if (!STI.isVulkanEnv()) {
3327+
unsigned Alignment = I.getOperand(2).getImm();
3328+
buildOpDecorate(ResVReg, *It, TII, SPIRV::Decoration::Alignment,
3329+
{Alignment});
3330+
}
3331+
return Res;
33213332
}
33223333

33233334
bool SPIRVInstructionSelector::selectBranch(MachineInstr &I) const {

0 commit comments

Comments
 (0)