Skip to content

handle wrapper #123795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "llvm/TargetParser/SubtargetFeature.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/HipStdPar/HipStdPar.h"
#include "llvm/Transforms/HLSL/DXILFinalizeLinkage.h"
#include "llvm/Transforms/IPO/EmbedBitcodePass.h"
#include "llvm/Transforms/IPO/LowerTypeTests.h"
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
Expand All @@ -82,6 +83,7 @@
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar/EarlyCSE.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/IPO/GlobalOpt.h"
#include "llvm/Transforms/Scalar/JumpThreading.h"
#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
Expand Down Expand Up @@ -1164,6 +1166,12 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
LangOpts.HIPStdParInterposeAlloc)
MPM.addPass(HipStdParAllocationInterpositionPass());

if (LangOpts.HLSL) {
// HLSL legalization passes
MPM.addPass(DXILFinalizeLinkage());
MPM.addPass(GlobalOptPass());
}

// Now that we have all of the passes ready, run them.
{
PrettyStackTraceString CrashInfo("Optimizer");
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(LLVM_LINK_COMPONENTS
FrontendOpenMP
FrontendOffloading
HIPStdPar
HLSL
IPO
IRPrinter
IRReader
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/DirectX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ add_llvm_target(DirectXCodeGen
DirectXTargetTransformInfo.cpp
DXContainerGlobals.cpp
DXILDataScalarization.cpp
DXILFinalizeLinkage.cpp
DXILFlattenArrays.cpp
DXILIntrinsicExpansion.cpp
DXILOpBuilder.cpp
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget() {
initializeDXILTranslateMetadataLegacyPass(*PR);
initializeDXILResourceMDWrapperPass(*PR);
initializeShaderFlagsAnalysisWrapperPass(*PR);
initializeDXILFinalizeLinkageLegacyPass(*PR);
}

class DXILTargetObjectFile : public TargetLoweringObjectFile {
Expand Down Expand Up @@ -91,7 +90,6 @@ class DirectXPassConfig : public TargetPassConfig {

FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; }
void addCodeGenPrepare() override {
addPass(createDXILFinalizeLinkageLegacyPass());
addPass(createDXILIntrinsicExpansionLegacyPass());
addPass(createDXILDataScalarizationLegacyPass());
addPass(createDXILFlattenArraysLegacyPass());
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "SPIRVTargetMachine.h"
#include "../DirectX/DirectX.h"
#include "SPIRV.h"
#include "SPIRVCallLowering.h"
#include "SPIRVGlobalRegistry.h"
Expand Down Expand Up @@ -224,6 +225,7 @@ void SPIRVPassConfig::addPreLegalizeMachineIR() {

// Use the default legalizer.
bool SPIRVPassConfig::addLegalizeMachineIR() {

addPass(new Legalizer());
addPass(createSPIRVPostLegalizerPass());
return false;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ add_subdirectory(ObjCARC)
add_subdirectory(Coroutines)
add_subdirectory(CFGuard)
add_subdirectory(HipStdPar)
add_subdirectory(HLSL)
18 changes: 18 additions & 0 deletions llvm/lib/Transforms/HLSL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
add_llvm_component_library(LLVMHlsl
DXILFinalizeLinkage.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms/HLSL

DEPENDS
intrinsics_gen
LLVMAnalysis

COMPONENT_NAME
HLSL

LINK_COMPONENTS
Analysis
Core
Support
TransformUtils)
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
//
//===----------------------------------------------------------------------===//

#include "DXILFinalizeLinkage.h"
#include "DirectX.h"
#include "llvm/Transforms/HLSL/DXILFinalizeLinkage.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"

#define DEBUG_TYPE "dxil-finalize-linkage"
Expand All @@ -20,6 +18,12 @@ using namespace llvm;
static bool finalizeLinkage(Module &M) {
SmallPtrSet<Function *, 8> Funcs;

for(auto &Var : M.globals()) {
if (Var.getLinkage() == GlobalValue::ExternalLinkage) {
Var.setLinkage(GlobalValue::InternalLinkage);
}
}

// Collect non-entry and non-exported functions to set to internal linkage.
for (Function &EF : M.functions()) {
if (EF.isIntrinsic())
Expand All @@ -44,19 +48,4 @@ PreservedAnalyses DXILFinalizeLinkage::run(Module &M,
if (finalizeLinkage(M))
return PreservedAnalyses::none();
return PreservedAnalyses::all();
}

bool DXILFinalizeLinkageLegacy::runOnModule(Module &M) {
return finalizeLinkage(M);
}

char DXILFinalizeLinkageLegacy::ID = 0;

INITIALIZE_PASS_BEGIN(DXILFinalizeLinkageLegacy, DEBUG_TYPE,
"DXIL Finalize Linkage", false, false)
INITIALIZE_PASS_END(DXILFinalizeLinkageLegacy, DEBUG_TYPE,
"DXIL Finalize Linkage", false, false)

ModulePass *llvm::createDXILFinalizeLinkageLegacyPass() {
return new DXILFinalizeLinkageLegacy();
}
}
Loading