[clang] [llvm] [HLSL] Adding Flatten and Branch if attributes (PR #116331)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 2 12:16:04 PST 2024
================
@@ -2076,7 +2076,28 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
}
- Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);
+ auto *BrInst = Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights,
+ Unpredictable);
+ switch (HLSLControlFlowAttr) {
+ case HLSLControlFlowHintAttr::Microsoft_branch:
+ case HLSLControlFlowHintAttr::Microsoft_flatten: {
+ llvm::MDBuilder MDHelper(CGM.getLLVMContext());
+
+ llvm::ConstantInt *BranchHintConstant =
+ HLSLControlFlowAttr ==
+ HLSLControlFlowHintAttr::Spelling::Microsoft_branch
+ ? llvm::ConstantInt::get(CGM.Int32Ty, 1)
+ : llvm::ConstantInt::get(CGM.Int32Ty, 2);
+
+ SmallVector<llvm::Metadata *, 2> Vals(
+ {MDHelper.createString("hlsl.controlflow.hint"),
+ MDHelper.createConstant(BranchHintConstant)});
+ BrInst->setMetadata("hlsl.controlflow.hint",
+ llvm::MDNode::get(CGM.getLLVMContext(), Vals));
+ } break;
+ case HLSLControlFlowHintAttr::SpellingNotCalculated:
----------------
llvm-beanz wrote:
Can this occur? Seems like it probably can't, so maybe this should be a default case with an unreachable?
https://github.com/llvm/llvm-project/pull/116331
More information about the cfe-commits
mailing list