Skip to content

Commit b66f6b2

Browse files
authored
1 parent 81898ac commit b66f6b2

File tree

14 files changed

+19
-516
lines changed

14 files changed

+19
-516
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4335,16 +4335,6 @@ def HLSLLoopHint: StmtAttr {
43354335
let Documentation = [HLSLLoopHintDocs, HLSLUnrollHintDocs];
43364336
}
43374337

4338-
def HLSLControlFlowHint: StmtAttr {
4339-
/// [branch]
4340-
/// [flatten]
4341-
let Spellings = [Microsoft<"branch">, Microsoft<"flatten">];
4342-
let Subjects = SubjectList<[IfStmt],
4343-
ErrorDiag, "'if' statements">;
4344-
let LangOpts = [HLSL];
4345-
let Documentation = [InternalOnly];
4346-
}
4347-
43484338
def CapturedRecord : InheritableAttr {
43494339
// This attribute has no spellings as it is only ever created implicitly.
43504340
let Spellings = [];

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,6 @@ void CodeGenFunction::EmitAttributedStmt(const AttributedStmt &S) {
757757
bool noinline = false;
758758
bool alwaysinline = false;
759759
bool noconvergent = false;
760-
HLSLControlFlowHintAttr::Spelling flattenOrBranch =
761-
HLSLControlFlowHintAttr::SpellingNotCalculated;
762760
const CallExpr *musttail = nullptr;
763761

764762
for (const auto *A : S.getAttrs()) {
@@ -790,17 +788,13 @@ void CodeGenFunction::EmitAttributedStmt(const AttributedStmt &S) {
790788
Builder.CreateAssumption(AssumptionVal);
791789
}
792790
} break;
793-
case attr::HLSLControlFlowHint: {
794-
flattenOrBranch = cast<HLSLControlFlowHintAttr>(A)->getSemanticSpelling();
795-
} break;
796791
}
797792
}
798793
SaveAndRestore save_nomerge(InNoMergeAttributedStmt, nomerge);
799794
SaveAndRestore save_noinline(InNoInlineAttributedStmt, noinline);
800795
SaveAndRestore save_alwaysinline(InAlwaysInlineAttributedStmt, alwaysinline);
801796
SaveAndRestore save_noconvergent(InNoConvergentAttributedStmt, noconvergent);
802797
SaveAndRestore save_musttail(MustTailCall, musttail);
803-
SaveAndRestore save_flattenOrBranch(HLSLControlFlowAttr, flattenOrBranch);
804798
EmitStmt(S.getSubStmt(), S.getAttrs());
805799
}
806800

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "llvm/IR/DataLayout.h"
4141
#include "llvm/IR/Dominators.h"
4242
#include "llvm/IR/FPEnv.h"
43-
#include "llvm/IR/Instruction.h"
4443
#include "llvm/IR/IntrinsicInst.h"
4544
#include "llvm/IR/Intrinsics.h"
4645
#include "llvm/IR/MDBuilder.h"
@@ -2084,29 +2083,7 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
20842083
Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
20852084
}
20862085

2087-
llvm::Instruction *BrInst = Builder.CreateCondBr(CondV, TrueBlock, FalseBlock,
2088-
Weights, Unpredictable);
2089-
switch (HLSLControlFlowAttr) {
2090-
case HLSLControlFlowHintAttr::Microsoft_branch:
2091-
case HLSLControlFlowHintAttr::Microsoft_flatten: {
2092-
llvm::MDBuilder MDHelper(CGM.getLLVMContext());
2093-
2094-
llvm::ConstantInt *BranchHintConstant =
2095-
HLSLControlFlowAttr ==
2096-
HLSLControlFlowHintAttr::Spelling::Microsoft_branch
2097-
? llvm::ConstantInt::get(CGM.Int32Ty, 1)
2098-
: llvm::ConstantInt::get(CGM.Int32Ty, 2);
2099-
2100-
SmallVector<llvm::Metadata *, 2> Vals(
2101-
{MDHelper.createString("hlsl.controlflow.hint"),
2102-
MDHelper.createConstant(BranchHintConstant)});
2103-
BrInst->setMetadata("hlsl.controlflow.hint",
2104-
llvm::MDNode::get(CGM.getLLVMContext(), Vals));
2105-
break;
2106-
}
2107-
case HLSLControlFlowHintAttr::SpellingNotCalculated:
2108-
break;
2109-
}
2086+
Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);
21102087
}
21112088

21122089
/// ErrorUnsupported - Print out an error that codegen doesn't support the

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,6 @@ class CodeGenFunction : public CodeGenTypeCache {
615615
/// True if the current statement has noconvergent attribute.
616616
bool InNoConvergentAttributedStmt = false;
617617

618-
/// HLSL Branch attribute.
619-
HLSLControlFlowHintAttr::Spelling HLSLControlFlowAttr =
620-
HLSLControlFlowHintAttr::SpellingNotCalculated;
621-
622618
// The CallExpr within the current statement that the musttail attribute
623619
// applies to. nullptr if there is no 'musttail' on the current statement.
624620
const CallExpr *MustTailCall = nullptr;

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,6 @@ static Attr *handleHLSLLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
619619
return ::new (S.Context) HLSLLoopHintAttr(S.Context, A, UnrollFactor);
620620
}
621621

622-
static Attr *handleHLSLControlFlowHint(Sema &S, Stmt *St, const ParsedAttr &A,
623-
SourceRange Range) {
624-
625-
return ::new (S.Context) HLSLControlFlowHintAttr(S.Context, A);
626-
}
627-
628622
static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
629623
SourceRange Range) {
630624
if (A.isInvalid() || A.getKind() == ParsedAttr::IgnoredAttribute)
@@ -661,8 +655,6 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
661655
return handleLoopHintAttr(S, St, A, Range);
662656
case ParsedAttr::AT_HLSLLoopHint:
663657
return handleHLSLLoopHintAttr(S, St, A, Range);
664-
case ParsedAttr::AT_HLSLControlFlowHint:
665-
return handleHLSLControlFlowHint(S, St, A, Range);
666658
case ParsedAttr::AT_OpenCLUnrollHint:
667659
return handleOpenCLUnrollHint(S, St, A, Range);
668660
case ParsedAttr::AT_Suppress:

clang/test/AST/HLSL/HLSLControlFlowHint.hlsl

Lines changed: 0 additions & 43 deletions
This file was deleted.

clang/test/CodeGenHLSL/HLSLControlFlowHint.hlsl

Lines changed: 0 additions & 48 deletions
This file was deleted.

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let TargetPrefix = "spv" in {
3333
def int_spv_ptrcast : Intrinsic<[llvm_any_ty], [llvm_any_ty, llvm_metadata_ty, llvm_i32_ty], [ImmArg<ArgIndex<2>>]>;
3434
def int_spv_switch : Intrinsic<[], [llvm_any_ty, llvm_vararg_ty]>;
3535
def int_spv_loop_merge : Intrinsic<[], [llvm_vararg_ty]>;
36-
def int_spv_selection_merge : Intrinsic<[], [llvm_any_ty, llvm_i32_ty], [ImmArg<ArgIndex<1>>]>;
36+
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<[], []>;
3939
def int_spv_alloca : Intrinsic<[llvm_any_ty], [llvm_i8_ty], [ImmArg<ArgIndex<0>>]>;

llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
#include "llvm/ADT/Twine.h"
1616
#include "llvm/Analysis/DXILMetadataAnalysis.h"
1717
#include "llvm/Analysis/DXILResource.h"
18-
#include "llvm/IR/BasicBlock.h"
1918
#include "llvm/IR/Constants.h"
2019
#include "llvm/IR/DiagnosticInfo.h"
2120
#include "llvm/IR/DiagnosticPrinter.h"
2221
#include "llvm/IR/Function.h"
2322
#include "llvm/IR/IRBuilder.h"
2423
#include "llvm/IR/LLVMContext.h"
25-
#include "llvm/IR/MDBuilder.h"
2624
#include "llvm/IR/Metadata.h"
2725
#include "llvm/IR/Module.h"
2826
#include "llvm/InitializePasses.h"
@@ -302,39 +300,6 @@ static MDTuple *emitTopLevelLibraryNode(Module &M, MDNode *RMD,
302300
return constructEntryMetadata(nullptr, nullptr, RMD, Properties, Ctx);
303301
}
304302

305-
// TODO: We might need to refactor this to be more generic,
306-
// in case we need more metadata to be replaced.
307-
static void translateBranchMetadata(Module &M) {
308-
for (Function &F : M) {
309-
for (BasicBlock &BB : F) {
310-
Instruction *BBTerminatorInst = BB.getTerminator();
311-
312-
MDNode *HlslControlFlowMD =
313-
BBTerminatorInst->getMetadata("hlsl.controlflow.hint");
314-
315-
if (!HlslControlFlowMD)
316-
continue;
317-
318-
assert(HlslControlFlowMD->getNumOperands() == 2 &&
319-
"invalid operands for hlsl.controlflow.hint");
320-
321-
MDBuilder MDHelper(M.getContext());
322-
ConstantInt *Op1 =
323-
mdconst::extract<ConstantInt>(HlslControlFlowMD->getOperand(1));
324-
325-
SmallVector<llvm::Metadata *, 2> Vals(
326-
ArrayRef<Metadata *>{MDHelper.createString("dx.controlflow.hints"),
327-
MDHelper.createConstant(Op1)});
328-
329-
MDNode *MDNode = llvm::MDNode::get(M.getContext(), Vals);
330-
331-
BBTerminatorInst->setMetadata("dx.controlflow.hints", MDNode);
332-
BBTerminatorInst->setMetadata("hlsl.controlflow.hint", nullptr);
333-
}
334-
F.clearMetadata();
335-
}
336-
}
337-
338303
static void translateMetadata(Module &M, DXILBindingMap &DBM,
339304
DXILResourceTypeMap &DRTM,
340305
const Resources &MDResources,
@@ -407,7 +372,6 @@ PreservedAnalyses DXILTranslateMetadata::run(Module &M,
407372
const dxil::ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M);
408373

409374
translateMetadata(M, DBM, DRTM, MDResources, ShaderFlags, MMDI);
410-
translateBranchMetadata(M);
411375

412376
return PreservedAnalyses::all();
413377
}
@@ -445,7 +409,6 @@ class DXILTranslateMetadataLegacy : public ModulePass {
445409
getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
446410

447411
translateMetadata(M, DBM, DRTM, MDResources, ShaderFlags, MMDI);
448-
translateBranchMetadata(M);
449412
return true;
450413
}
451414
};

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "llvm/CodeGen/TargetOpcodes.h"
3434
#include "llvm/IR/IntrinsicsSPIRV.h"
3535
#include "llvm/Support/Debug.h"
36-
#include "llvm/Support/ErrorHandling.h"
3736

3837
#define DEBUG_TYPE "spirv-isel"
3938

@@ -46,17 +45,6 @@ using ExtInstList =
4645

4746
namespace {
4847

49-
llvm::SPIRV::SelectionControl::SelectionControl
50-
getSelectionOperandForImm(int Imm) {
51-
if (Imm == 2)
52-
return SPIRV::SelectionControl::Flatten;
53-
if (Imm == 1)
54-
return SPIRV::SelectionControl::DontFlatten;
55-
if (Imm == 0)
56-
return SPIRV::SelectionControl::None;
57-
llvm_unreachable("Invalid immediate");
58-
}
59-
6048
#define GET_GLOBALISEL_PREDICATE_BITSET
6149
#include "SPIRVGenGlobalISel.inc"
6250
#undef GET_GLOBALISEL_PREDICATE_BITSET
@@ -2830,24 +2818,19 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
28302818
}
28312819
return MIB.constrainAllUses(TII, TRI, RBI);
28322820
}
2833-
case Intrinsic::spv_loop_merge: {
2834-
auto MIB = BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpLoopMerge));
2821+
case Intrinsic::spv_loop_merge:
2822+
case Intrinsic::spv_selection_merge: {
2823+
const auto Opcode = IID == Intrinsic::spv_selection_merge
2824+
? SPIRV::OpSelectionMerge
2825+
: SPIRV::OpLoopMerge;
2826+
auto MIB = BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode));
28352827
for (unsigned i = 1; i < I.getNumExplicitOperands(); ++i) {
28362828
assert(I.getOperand(i).isMBB());
28372829
MIB.addMBB(I.getOperand(i).getMBB());
28382830
}
28392831
MIB.addImm(SPIRV::SelectionControl::None);
28402832
return MIB.constrainAllUses(TII, TRI, RBI);
28412833
}
2842-
case Intrinsic::spv_selection_merge: {
2843-
auto MIB =
2844-
BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpSelectionMerge));
2845-
assert(I.getOperand(1).isMBB() &&
2846-
"operand 1 to spv_selection_merge must be a basic block");
2847-
MIB.addMBB(I.getOperand(1).getMBB());
2848-
MIB.addImm(getSelectionOperandForImm(I.getOperand(2).getImm()));
2849-
return MIB.constrainAllUses(TII, TRI, RBI);
2850-
}
28512834
case Intrinsic::spv_cmpxchg:
28522835
return selectAtomicCmpXchg(ResVReg, ResType, I);
28532836
case Intrinsic::spv_unreachable:

0 commit comments

Comments
 (0)