-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spirv] Add bare bone code for SPIR-V codegen (#233)
* [spirv] Add libclangSPIRV and skeleton FrontendAction for SPIR-V * [spirv] Add -spirv into dxc for invoking EmitSPIRVAction * [spirv] Build SPIR-V codegen conditionally Added ENABLE_SPIRV_CODEGEN in CMake config to control the building of SPIR-V component and wrap up SPIR-V code using it. Also add -spirv to hctbuild to turn it on.
- Loading branch information
1 parent
47d21ad
commit 2c7a3fc
Showing
14 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===-- EmitSPIRVAction.h - FrontendAction for Emitting SPIR-V --*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_CLANG_SPIRV_EMITSPIRVACTION_H | ||
#define LLVM_CLANG_SPIRV_EMITSPIRVACTION_H | ||
|
||
#include "clang/Frontend/FrontendAction.h" | ||
|
||
namespace clang { | ||
|
||
class EmitSPIRVAction : public ASTFrontendAction { | ||
protected: | ||
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, | ||
StringRef InFile) override; | ||
}; | ||
|
||
} // end namespace clang | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===-- SPIRVBuilder.h - SPIR-V builder --*- C++ -*------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_CLANG_SPIRV_SPIRVBUILDER_H | ||
#define LLVM_CLANG_SPIRV_SPIRVBUILDER_H | ||
|
||
namespace clang { | ||
namespace spirv { | ||
|
||
class SPIRVBuilder { | ||
public: | ||
SPIRVBuilder() : NextID(0) {} | ||
|
||
private: | ||
uint32_t NextID; | ||
}; | ||
|
||
} // end namespace spirv | ||
} // end namespace clang | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
set(LLVM_LINK_COMPONENTS | ||
Support | ||
) | ||
|
||
add_clang_library(clangSPIRV | ||
EmitSPIRVAction.cpp | ||
SPIRVBuilder.cpp | ||
|
||
LINK_LIBS | ||
clangAST | ||
clangBasic | ||
clangFrontend | ||
clangLex | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===--- EmitSPIRVAction.cpp - EmitSPIRVAction implementation -------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "clang/SPIRV/EmitSPIRVAction.h" | ||
#include "clang/AST/AST.h" | ||
#include "clang/AST/ASTConsumer.h" | ||
#include "clang/AST/ASTContext.h" | ||
#include "clang/AST/RecordLayout.h" | ||
#include "clang/AST/RecursiveASTVisitor.h" | ||
#include "clang/Basic/Diagnostic.h" | ||
#include "clang/Basic/FileManager.h" | ||
#include "clang/Basic/SourceManager.h" | ||
#include "clang/Frontend/CompilerInstance.h" | ||
#include "llvm/Support/Path.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
namespace clang { | ||
namespace { | ||
class SPIRVEmitter : public ASTConsumer, | ||
public RecursiveASTVisitor<SPIRVEmitter> { | ||
public: | ||
explicit SPIRVEmitter(raw_ostream *Out) : OutStream(*Out) {} | ||
|
||
void HandleTranslationUnit(ASTContext &Context) override { | ||
OutStream << "SPIR-V"; | ||
} | ||
|
||
private: | ||
raw_ostream &OutStream; | ||
}; | ||
} | ||
|
||
std::unique_ptr<ASTConsumer> | ||
EmitSPIRVAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { | ||
return llvm::make_unique<SPIRVEmitter>(CI.getOutStream()); | ||
} | ||
} // end namespace clang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//===--- SPIRVBuilder.cpp - SPIR-V builder implementation -----------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
namespace clang { | ||
namespace spirv {} // end namespace spirv | ||
} // end namespace clang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters