20
20
#include " TargetInfo.h"
21
21
#include " clang/AST/ASTContext.h"
22
22
#include " clang/AST/DeclObjC.h"
23
+ #include " clang/AST/HlslTypes.h"
23
24
#include " clang/AST/RecordLayout.h"
24
25
#include " clang/AST/StmtVisitor.h"
25
26
#include " clang/Basic/TargetInfo.h"
26
27
#include " clang/Frontend/CodeGenOptions.h"
28
+ #include " dxc/DXIL/DxilUtil.h" // HLSL Change
27
29
#include " llvm/IR/CFG.h"
28
30
#include " llvm/IR/Constants.h"
29
31
#include " llvm/IR/DataLayout.h"
@@ -3701,7 +3703,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
3701
3703
}
3702
3704
// HLSL Change Starts
3703
3705
if (CGF.getLangOpts ().HLSL && !CGF.getLangOpts ().EnableShortCircuit ) {
3704
- // HLSL does not short circuit by default.
3706
+ // HLSL does not short circuit by default before HLSL 2021
3705
3707
if (hlsl::IsHLSLVecType (E->getType ()) || E->getType ()->isArithmeticType ()) {
3706
3708
llvm::Value *CondV = CGF.EmitScalarExpr (condExpr);
3707
3709
llvm::Value *LHS = Visit (lhsExpr);
@@ -3729,6 +3731,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
3729
3731
CGF, E, LHS->getType (), {Cond, LHS, RHS});
3730
3732
}
3731
3733
}
3734
+
3732
3735
// HLSL Change Ends
3733
3736
3734
3737
// If this is a really simple expression (like x ? 4 : 5), emit this as a
@@ -3749,6 +3752,17 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
3749
3752
return Builder.CreateSelect (CondV, LHS, RHS, " cond" );
3750
3753
}
3751
3754
3755
+ // HLSL Change Begins
3756
+ llvm::Instruction *ResultAlloca = nullptr ;
3757
+ if (CGF.getLangOpts ().HLSL && CGF.getLangOpts ().EnableShortCircuit &&
3758
+ hlsl::IsHLSLMatType (E->getType ())) {
3759
+ llvm::Type *MatTy = CGF.ConvertTypeForMem (E->getType ());
3760
+ ResultAlloca = CGF.CreateTempAlloca (MatTy);
3761
+ ResultAlloca->moveBefore (hlsl::dxilutil::FindAllocaInsertionPt (
3762
+ Builder.GetInsertBlock ()->getParent ()));
3763
+ }
3764
+ // HLSL Change Ends
3765
+
3752
3766
llvm::BasicBlock *LHSBlock = CGF.createBasicBlock (" cond.true" );
3753
3767
llvm::BasicBlock *RHSBlock = CGF.createBasicBlock (" cond.false" );
3754
3768
llvm::BasicBlock *ContBlock = CGF.createBasicBlock (" cond.end" );
@@ -3761,6 +3775,11 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
3761
3775
CGF.incrementProfileCounter (E);
3762
3776
eval.begin (CGF);
3763
3777
Value *LHS = Visit (lhsExpr);
3778
+ // HLSL Change Begin - Handle matrix ternary
3779
+ if (ResultAlloca)
3780
+ CGF.CGM .getHLSLRuntime ().EmitHLSLMatrixStore (CGF, LHS, ResultAlloca,
3781
+ E->getType ());
3782
+ // HLSL Change End
3764
3783
eval.end (CGF);
3765
3784
3766
3785
LHSBlock = Builder.GetInsertBlock ();
@@ -3769,11 +3788,22 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
3769
3788
CGF.EmitBlock (RHSBlock);
3770
3789
eval.begin (CGF);
3771
3790
Value *RHS = Visit (rhsExpr);
3791
+ // HLSL Change Begin - Handle matrix ternary
3792
+ if (ResultAlloca)
3793
+ CGF.CGM .getHLSLRuntime ().EmitHLSLMatrixStore (CGF, RHS, ResultAlloca,
3794
+ E->getType ());
3795
+ // HLSL Change End
3772
3796
eval.end (CGF);
3773
3797
3774
3798
RHSBlock = Builder.GetInsertBlock ();
3775
3799
CGF.EmitBlock (ContBlock);
3776
3800
3801
+ // HLSL Change Begin - Handle matrix ternary
3802
+ if (ResultAlloca)
3803
+ return CGF.CGM .getHLSLRuntime ().EmitHLSLMatrixLoad (CGF, ResultAlloca,
3804
+ E->getType ());
3805
+ // HLSL Change End
3806
+
3777
3807
// If the LHS or RHS is a throw expression, it will be legitimately null.
3778
3808
if (!LHS)
3779
3809
return RHS;
0 commit comments