|
@@ -20,10 +20,12 @@
|
|
|
#include "TargetInfo.h"
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
+#include "clang/AST/HlslTypes.h"
|
|
|
#include "clang/AST/RecordLayout.h"
|
|
|
#include "clang/AST/StmtVisitor.h"
|
|
|
#include "clang/Basic/TargetInfo.h"
|
|
|
#include "clang/Frontend/CodeGenOptions.h"
|
|
|
+#include "dxc/DXIL/DxilUtil.h" // HLSL Change
|
|
|
#include "llvm/IR/CFG.h"
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
@@ -3701,7 +3703,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
|
|
|
}
|
|
|
// HLSL Change Starts
|
|
|
if (CGF.getLangOpts().HLSL && !CGF.getLangOpts().EnableShortCircuit) {
|
|
|
- // HLSL does not short circuit by default.
|
|
|
+ // HLSL does not short circuit by default before HLSL 2021
|
|
|
if (hlsl::IsHLSLVecType(E->getType()) || E->getType()->isArithmeticType()) {
|
|
|
llvm::Value *CondV = CGF.EmitScalarExpr(condExpr);
|
|
|
llvm::Value *LHS = Visit(lhsExpr);
|
|
@@ -3729,6 +3731,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
|
|
|
CGF, E, LHS->getType(), {Cond, LHS, RHS});
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// HLSL Change Ends
|
|
|
|
|
|
// If this is a really simple expression (like x ? 4 : 5), emit this as a
|
|
@@ -3749,6 +3752,17 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
|
|
|
return Builder.CreateSelect(CondV, LHS, RHS, "cond");
|
|
|
}
|
|
|
|
|
|
+ // HLSL Change Begins
|
|
|
+ llvm::Instruction *ResultAlloca = nullptr;
|
|
|
+ if (CGF.getLangOpts().HLSL && CGF.getLangOpts().EnableShortCircuit &&
|
|
|
+ hlsl::IsHLSLMatType(E->getType())) {
|
|
|
+ llvm::Type *MatTy = CGF.ConvertTypeForMem(E->getType());
|
|
|
+ ResultAlloca = CGF.CreateTempAlloca(MatTy);
|
|
|
+ ResultAlloca->moveBefore(hlsl::dxilutil::FindAllocaInsertionPt(
|
|
|
+ Builder.GetInsertBlock()->getParent()));
|
|
|
+ }
|
|
|
+ // HLSL Change Ends
|
|
|
+
|
|
|
llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.true");
|
|
|
llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.false");
|
|
|
llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.end");
|
|
@@ -3761,6 +3775,11 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
|
|
|
CGF.incrementProfileCounter(E);
|
|
|
eval.begin(CGF);
|
|
|
Value *LHS = Visit(lhsExpr);
|
|
|
+ // HLSL Change Begin - Handle matrix ternary
|
|
|
+ if (ResultAlloca)
|
|
|
+ CGF.CGM.getHLSLRuntime().EmitHLSLMatrixStore(CGF, LHS, ResultAlloca,
|
|
|
+ E->getType());
|
|
|
+ // HLSL Change End
|
|
|
eval.end(CGF);
|
|
|
|
|
|
LHSBlock = Builder.GetInsertBlock();
|
|
@@ -3769,11 +3788,22 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
|
|
|
CGF.EmitBlock(RHSBlock);
|
|
|
eval.begin(CGF);
|
|
|
Value *RHS = Visit(rhsExpr);
|
|
|
+ // HLSL Change Begin - Handle matrix ternary
|
|
|
+ if (ResultAlloca)
|
|
|
+ CGF.CGM.getHLSLRuntime().EmitHLSLMatrixStore(CGF, RHS, ResultAlloca,
|
|
|
+ E->getType());
|
|
|
+ // HLSL Change End
|
|
|
eval.end(CGF);
|
|
|
|
|
|
RHSBlock = Builder.GetInsertBlock();
|
|
|
CGF.EmitBlock(ContBlock);
|
|
|
|
|
|
+ // HLSL Change Begin - Handle matrix ternary
|
|
|
+ if (ResultAlloca)
|
|
|
+ return CGF.CGM.getHLSLRuntime().EmitHLSLMatrixLoad(CGF, ResultAlloca,
|
|
|
+ E->getType());
|
|
|
+ // HLSL Change End
|
|
|
+
|
|
|
// If the LHS or RHS is a throw expression, it will be legitimately null.
|
|
|
if (!LHS)
|
|
|
return RHS;
|