Skip to content

Commit 4b9ab3e

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents cdabc42 + 8149957 commit 4b9ab3e

27 files changed

+153
-39
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8651,10 +8651,8 @@ void Sema::ProcessDeclAttributeList(Scope *S, Decl *D,
86518651
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
86528652
D->setInvalidDecl();
86538653
} else if (const auto *A = D->getAttr<IntelReqdSubGroupSizeAttr>()) {
8654-
if (!getLangOpts().SYCLIsDevice) {
8655-
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
8656-
D->setInvalidDecl();
8657-
}
8654+
Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
8655+
D->setInvalidDecl();
86588656
} else if (!D->hasAttr<CUDAGlobalAttr>()) {
86598657
if (const auto *A = D->getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
86608658
Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "SPIRVWriter.h"
4040

4141
#include "llvm/IR/DebugInfo.h"
42+
#include "llvm/IR/DebugInfoMetadata.h"
4243

4344
using namespace SPIRV;
4445

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
#include "llvm/IR/DebugInfo.h"
4444
#include "llvm/IR/Module.h"
4545

46-
#include <memory>
47-
4846
using namespace llvm;
4947

5048
namespace SPIRV {

llvm-spirv/lib/SPIRV/Mangler/Mangler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "ManglingUtils.h"
1515
#include "NameMangleAPI.h"
1616
#include "ParameterType.h"
17-
#include "SPIRVInternal.h"
1817
#include <algorithm>
1918
#include <map>
2019
#include <sstream>

llvm-spirv/lib/SPIRV/OCL20ToSPIRV.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "llvm/IR/Instruction.h"
5050
#include "llvm/IR/Instructions.h"
5151
#include "llvm/Pass.h"
52+
#include "llvm/Support/Debug.h"
5253

5354
#include <algorithm>
5455
#include <set>
@@ -329,7 +330,7 @@ bool OCL20ToSPIRV::runOnModule(Module &Module) {
329330
return false;
330331

331332
CLVer = std::get<1>(Src);
332-
if (CLVer > kOCLVer::CL20)
333+
if (CLVer == kOCLVer::CL21)
333334
return false;
334335

335336
LLVM_DEBUG(dbgs() << "Enter OCL20ToSPIRV:\n");
@@ -406,7 +407,8 @@ void OCL20ToSPIRV::visitCallInst(CallInst &CI) {
406407
DemangledName == kOCLBuiltinName::AtomicCmpXchgStrong ||
407408
DemangledName == kOCLBuiltinName::AtomicCmpXchgWeakExplicit ||
408409
DemangledName == kOCLBuiltinName::AtomicCmpXchgStrongExplicit) {
409-
assert(CLVer == kOCLVer::CL20 && "Wrong version of OpenCL");
410+
assert((CLVer == kOCLVer::CL20 || CLVer == kOCLVer::CL30) &&
411+
"Wrong version of OpenCL");
410412
PCI = visitCallAtomicCmpXchg(PCI);
411413
}
412414
visitCallAtomicLegacy(PCI, MangledName, DemangledName);

llvm-spirv/lib/SPIRV/OCL21ToSPIRV.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "llvm/IR/InstVisitor.h"
4747
#include "llvm/IR/Instructions.h"
4848
#include "llvm/Pass.h"
49+
#include "llvm/Support/Debug.h"
4950

5051
#include <set>
5152

@@ -107,7 +108,7 @@ bool OCL21ToSPIRV::runOnModule(Module &Module) {
107108
return false;
108109

109110
CLVer = std::get<1>(Src);
110-
if (CLVer < kOCLVer::CL21)
111+
if (CLVer != kOCLVer::CL21)
111112
return false;
112113

113114
LLVM_DEBUG(dbgs() << "Enter OCL21ToSPIRV:\n");

llvm-spirv/lib/SPIRV/OCLUtil.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141

4242
#include "SPIRVInternal.h"
4343
#include "llvm/ADT/SmallString.h"
44-
#include "llvm/ADT/SmallString.h"
45-
#include "llvm/IR/DebugInfoMetadata.h"
4644
#include "llvm/IR/IRBuilder.h"
4745
#include "llvm/IR/Instructions.h"
4846
#include "llvm/Support/Path.h"
@@ -321,6 +319,7 @@ namespace kOCLVer {
321319
const unsigned CL12 = 102000;
322320
const unsigned CL20 = 200000;
323321
const unsigned CL21 = 201000;
322+
const unsigned CL30 = 300000;
324323
} // namespace kOCLVer
325324

326325
namespace OclExt {

llvm-spirv/lib/SPIRV/PreprocessMetadata.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "llvm/IR/IRBuilder.h"
5050
#include "llvm/IR/InstVisitor.h"
5151
#include "llvm/Pass.h"
52+
#include "llvm/Support/CommandLine.h"
5253

5354
using namespace llvm;
5455
using namespace SPIRV;
@@ -207,8 +208,8 @@ void PreprocessMetadata::preprocessOCLMetadata(Module *M, SPIRVMDBuilder *B,
207208
// !{x} = !{i32 3, i32 102000}
208209
B->addNamedMD(kSPIRVMD::Source)
209210
.addOp()
210-
.add(CLVer < kOCLVer::CL21 ? spv::SourceLanguageOpenCL_C
211-
: spv::SourceLanguageOpenCL_CPP)
211+
.add(CLVer == kOCLVer::CL21 ? spv::SourceLanguageOpenCL_CPP
212+
: spv::SourceLanguageOpenCL_C)
212213
.add(CLVer)
213214
.done();
214215
if (EraseOCLMD)

llvm-spirv/lib/SPIRV/SPIRVLowerConstExpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "llvm/IR/InstVisitor.h"
5050
#include "llvm/IR/Instructions.h"
5151
#include "llvm/Pass.h"
52+
#include "llvm/Support/CommandLine.h"
5253

5354
#include <list>
5455
#include <set>

llvm-spirv/lib/SPIRV/SPIRVLowerSaddWithOverflow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "llvm/IRReader/IRReader.h"
5252
#include "llvm/Linker/Linker.h"
5353
#include "llvm/Pass.h"
54+
#include "llvm/Support/SourceMgr.h"
5455

5556
using namespace llvm;
5657
using namespace SPIRV;

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,6 +3309,8 @@ bool SPIRVToLLVM::translate() {
33093309
auto BV = BM->getVariable(I);
33103310
if (BV->getStorageClass() != StorageClassFunction)
33113311
transValue(BV, nullptr, nullptr);
3312+
else
3313+
transGlobalCtorDtors(BV);
33123314
}
33133315

33143316
// Compile unit might be needed during translation of debug intrinsics.
@@ -3651,6 +3653,15 @@ bool SPIRVToLLVM::transDecoration(SPIRVValue *BV, Value *V) {
36513653
return true;
36523654
}
36533655

3656+
void SPIRVToLLVM::transGlobalCtorDtors(SPIRVVariable *BV) {
3657+
if (BV->getName() != "llvm.global_ctors" &&
3658+
BV->getName() != "llvm.global_dtors")
3659+
return;
3660+
3661+
Value *V = transValue(BV, nullptr, nullptr);
3662+
cast<GlobalValue>(V)->setLinkage(GlobalValue::AppendingLinkage);
3663+
}
3664+
36543665
bool SPIRVToLLVM::transFPContractMetadata() {
36553666
bool ContractOff = false;
36563667
for (unsigned I = 0, E = BM->getNumFunctions(); I != E; ++I) {

llvm-spirv/lib/SPIRV/SPIRVReader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545

4646
#include "llvm/ADT/DenseMap.h"
4747
#include "llvm/IR/GlobalValue.h" // llvm::GlobalValue::LinkageTypes
48-
#include "llvm/IR/Metadata.h" // llvm::Metadata
4948

5049
namespace llvm {
50+
class Metadata;
5151
class Module;
5252
class Type;
5353
class Instruction;
@@ -270,6 +270,7 @@ class SPIRVToLLVM {
270270

271271
void transUserSemantic(SPIRV::SPIRVFunction *Fun);
272272
void transGlobalAnnotations();
273+
void transGlobalCtorDtors(SPIRVVariable *BV);
273274
void transIntelFPGADecorations(SPIRVValue *BV, Value *V);
274275
}; // class SPIRVToLLVM
275276

llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/IR/Instructions.h"
4646
#include "llvm/IR/Operator.h"
4747
#include "llvm/Pass.h"
48+
#include "llvm/Support/Debug.h"
4849

4950
#include <set>
5051
#include <vector>

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#define SPIRVTOLLVMDBGTRAN_H
4141

4242
#include "SPIRVInstruction.h"
43-
#include "SPIRVModule.h"
4443

4544
#include "llvm/IR/DIBuilder.h"
4645
#include "llvm/IR/DebugLoc.h"

llvm-spirv/lib/SPIRV/SPIRVToOCL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "llvm/IR/InstVisitor.h"
4444
#include "llvm/Pass.h"
4545

46-
#include <cstring>
46+
#include <string>
4747

4848
namespace SPIRV {
4949
class SPIRVToOCL : public ModulePass, public InstVisitor<SPIRVToOCL> {

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ SPIRVValue *LLVMToSPIRV::transConstant(Value *V) {
759759
}
760760
std::vector<SPIRVValue *> BV;
761761
for (auto I = ConstV->op_begin(), E = ConstV->op_end(); I != E; ++I)
762-
BV.push_back(transValue(*I, nullptr));
762+
BV.push_back(transValue(*I, nullptr, true, FuncTransMode::Pointer));
763763
return BM->addCompositeConstant(transType(V->getType()), BV);
764764
}
765765

@@ -2861,9 +2861,17 @@ void LLVMToSPIRV::transFunction(Function *I) {
28612861
}
28622862
}
28632863

2864+
bool isEmptyLLVMModule(Module *M) {
2865+
return M->empty() && // No functions
2866+
M->global_empty(); // No global variables
2867+
}
2868+
28642869
bool LLVMToSPIRV::translate() {
28652870
BM->setGeneratorVer(KTranslatorVer);
28662871

2872+
if (isEmptyLLVMModule(M))
2873+
BM->addCapability(CapabilityLinkage);
2874+
28672875
if (!transSourceLanguage())
28682876
return false;
28692877
if (!transExtension())
@@ -3599,6 +3607,9 @@ bool isValidLLVMModule(Module *M, SPIRVErrorLog &ErrorLog) {
35993607
if (!M)
36003608
return false;
36013609

3610+
if (isEmptyLLVMModule(M))
3611+
return true;
3612+
36023613
Triple TT(M->getTargetTriple());
36033614
if (!ErrorLog.checkError(isSupportedTriple(TT), SPIRVEC_InvalidTargetTriple,
36043615
"Actual target triple is " + M->getTargetTriple()))

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "SPIRVDebug.h"
4141

4242
#include "llvm/IR/Verifier.h"
43+
#include "llvm/Support/CommandLine.h"
4344
#include "llvm/Support/raw_ostream.h"
4445

4546
#define DEBUG_TYPE "spirv-regularization"
@@ -51,12 +52,12 @@ SPIRV::SPIRVDbgErrorHandlingKinds SPIRV::SPIRVDbgError =
5152
SPIRVDbgErrorHandlingKinds::Exit;
5253
bool SPIRV::SPIRVDbgErrorMsgIncludesSourceInfo = true;
5354

54-
llvm::cl::opt<bool> SPIRV::VerifyRegularizationPasses(
55+
namespace SPIRV {
56+
llvm::cl::opt<bool> VerifyRegularizationPasses(
5557
"spirv-verify-regularize-passes", llvm::cl::init(_SPIRVDBG),
5658
llvm::cl::desc(
5759
"Verify module after each pass in LLVM regularization phase"));
5860

59-
namespace SPIRV {
6061
void verifyRegularizationPass(llvm::Module &M, const std::string &PassName) {
6162
if (VerifyRegularizationPasses) {
6263
std::string Err;

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDebug.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@
4141
#define SPIRV_LIBSPIRV_SPIRVDEBUG_H
4242

4343
#include "SPIRVUtil.h"
44-
#include "llvm/IR/Module.h"
45-
#include "llvm/Support/CommandLine.h"
46-
#include "llvm/Support/Debug.h"
4744

4845
#include <iostream>
4946
#include <string>
5047

51-
namespace SPIRV {
48+
namespace llvm {
49+
class Module;
50+
}
5251

53-
extern llvm::cl::opt<bool> VerifyRegularizationPasses;
52+
namespace SPIRV {
5453

5554
// Include source file and line number in error message.
5655
extern bool SPIRVDbgErrorMsgIncludesSourceInfo;

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@
4848
#include "SPIRVValue.h"
4949

5050
#include <cassert>
51-
#include <cstdint>
5251
#include <functional>
5352
#include <iostream>
54-
#include <map>
5553
#include <unordered_set>
5654
#include <utility>
5755
#include <vector>

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVModule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
#include <iostream>
4747
#include <set>
4848
#include <string>
49-
#include <unordered_map>
50-
#include <unordered_set>
5149
#include <vector>
5250

5351
namespace SPIRV {

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVStream.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@
4343
#include "SPIRVDebug.h"
4444
#include "SPIRVExtInst.h"
4545
#include "SPIRVModule.h"
46-
#include <algorithm>
4746
#include <cctype>
4847
#include <cstdint>
4948
#include <iostream>
50-
#include <iterator>
5149
#include <string>
5250
#include <vector>
5351

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVType.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
#include "SPIRVStream.h"
4949

5050
#include <cassert>
51-
#include <iostream>
52-
#include <map>
5351
#include <tuple>
5452
#include <vector>
5553

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
#include "SPIRVType.h"
4949

5050
#include <iostream>
51-
#include <map>
52-
#include <memory>
5351

5452
namespace SPIRV {
5553

llvm-spirv/test/empty-module.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s
3+
; RUN: llvm-spirv %t.bc -o %t.spv
4+
; RUN: spirv-val %t.spv
5+
6+
; CHECK: 119734787 {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} 0
7+
; CHECK: Capability Addresses
8+
; CHECK: Capability Linkage
9+
; CHECK: Capability Kernel
10+
; CHECK: ExtInstImport 1 "OpenCL.std"
11+
; CHECK: MemoryModel 2 2
12+
; CHECK: Source 0 0

0 commit comments

Comments
 (0)