|
14 | 14 |
|
15 | 15 | #include "CGHLSLRuntime.h" |
16 | 16 | #include "CGDebugInfo.h" |
| 17 | +#include "CodeGenFunction.h" |
17 | 18 | #include "CodeGenModule.h" |
18 | 19 | #include "TargetInfo.h" |
19 | 20 | #include "clang/AST/Decl.h" |
| 21 | +#include "clang/AST/RecursiveASTVisitor.h" |
20 | 22 | #include "clang/Basic/TargetOptions.h" |
21 | 23 | #include "llvm/IR/GlobalVariable.h" |
22 | 24 | #include "llvm/IR/LLVMContext.h" |
@@ -617,3 +619,33 @@ llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) { |
617 | 619 | llvm_unreachable("Convergence token should have been emitted."); |
618 | 620 | return nullptr; |
619 | 621 | } |
| 622 | + |
| 623 | +class OpaqueValueVisitor : public RecursiveASTVisitor<OpaqueValueVisitor> { |
| 624 | +public: |
| 625 | + llvm::SmallPtrSet<OpaqueValueExpr *, 8> OVEs; |
| 626 | + OpaqueValueVisitor() {} |
| 627 | + |
| 628 | + bool VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 629 | + OVEs.insert(E); |
| 630 | + return true; |
| 631 | + } |
| 632 | +}; |
| 633 | + |
| 634 | +void CGHLSLRuntime::emitInitListOpaqueValues(CodeGenFunction &CGF, |
| 635 | + InitListExpr *E) { |
| 636 | + |
| 637 | + typedef CodeGenFunction::OpaqueValueMappingData OpaqueValueMappingData; |
| 638 | + OpaqueValueVisitor Visitor; |
| 639 | + Visitor.TraverseStmt(E); |
| 640 | + for (auto *OVE : Visitor.OVEs) { |
| 641 | + if (CGF.isOpaqueValueEmitted(OVE)) |
| 642 | + continue; |
| 643 | + if (OpaqueValueMappingData::shouldBindAsLValue(OVE)) { |
| 644 | + LValue LV = CGF.EmitLValue(OVE->getSourceExpr()); |
| 645 | + OpaqueValueMappingData::bind(CGF, OVE, LV); |
| 646 | + } else { |
| 647 | + RValue RV = CGF.EmitAnyExpr(OVE->getSourceExpr()); |
| 648 | + OpaqueValueMappingData::bind(CGF, OVE, RV); |
| 649 | + } |
| 650 | + } |
| 651 | +} |
0 commit comments