Fix GCC warning on enum class bitfield. NFC.

This commit is contained in:
Michael Liao 2020-03-28 10:12:58 -04:00
parent d2dd0fac48
commit cb6389360b
2 changed files with 31 additions and 17 deletions

View File

@ -466,18 +466,19 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
for (auto &&Info : DeviceVars) {
llvm::GlobalVariable *Var = Info.Var;
llvm::Constant *VarName = makeConstantString(getDeviceSideName(Info.D));
switch (Info.Flags.Kind) {
switch (Info.Flags.getKind()) {
case DeviceVarFlags::Variable: {
uint64_t VarSize =
CGM.getDataLayout().getTypeAllocSize(Var->getValueType());
llvm::Value *Args[] = {&GpuBinaryHandlePtr,
Builder.CreateBitCast(Var, VoidPtrTy),
VarName,
VarName,
llvm::ConstantInt::get(IntTy, Info.Flags.Extern),
llvm::ConstantInt::get(IntTy, VarSize),
llvm::ConstantInt::get(IntTy, Info.Flags.Constant),
llvm::ConstantInt::get(IntTy, 0)};
llvm::Value *Args[] = {
&GpuBinaryHandlePtr,
Builder.CreateBitCast(Var, VoidPtrTy),
VarName,
VarName,
llvm::ConstantInt::get(IntTy, Info.Flags.isExtern()),
llvm::ConstantInt::get(IntTy, VarSize),
llvm::ConstantInt::get(IntTy, Info.Flags.isConstant()),
llvm::ConstantInt::get(IntTy, 0)};
Builder.CreateCall(RegisterVar, Args);
break;
}
@ -485,16 +486,16 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
Builder.CreateCall(
RegisterSurf,
{&GpuBinaryHandlePtr, Builder.CreateBitCast(Var, VoidPtrTy), VarName,
VarName, llvm::ConstantInt::get(IntTy, Info.Flags.SurfTexType),
llvm::ConstantInt::get(IntTy, Info.Flags.Extern)});
VarName, llvm::ConstantInt::get(IntTy, Info.Flags.getSurfTexType()),
llvm::ConstantInt::get(IntTy, Info.Flags.isExtern())});
break;
case DeviceVarFlags::Texture:
Builder.CreateCall(
RegisterTex,
{&GpuBinaryHandlePtr, Builder.CreateBitCast(Var, VoidPtrTy), VarName,
VarName, llvm::ConstantInt::get(IntTy, Info.Flags.SurfTexType),
llvm::ConstantInt::get(IntTy, Info.Flags.Normalized),
llvm::ConstantInt::get(IntTy, Info.Flags.Extern)});
VarName, llvm::ConstantInt::get(IntTy, Info.Flags.getSurfTexType()),
llvm::ConstantInt::get(IntTy, Info.Flags.isNormalized()),
llvm::ConstantInt::get(IntTy, Info.Flags.isExtern())});
break;
}
}

View File

@ -42,17 +42,30 @@ protected:
public:
// Global variable properties that must be passed to CUDA runtime.
struct DeviceVarFlags {
enum DeviceVarKind : unsigned {
class DeviceVarFlags {
public:
enum DeviceVarKind {
Variable, // Variable
Surface, // Builtin surface
Texture, // Builtin texture
};
DeviceVarKind Kind : 2;
private:
unsigned Kind : 2;
unsigned Extern : 1;
unsigned Constant : 1; // Constant variable.
unsigned Normalized : 1; // Normalized texture.
int SurfTexType; // Type of surface/texutre.
public:
DeviceVarFlags(DeviceVarKind K, bool E, bool C, bool N, int T)
: Kind(K), Extern(E), Constant(C), Normalized(N), SurfTexType(T) {}
DeviceVarKind getKind() const { return static_cast<DeviceVarKind>(Kind); }
bool isExtern() const { return Extern; }
bool isConstant() const { return Constant; }
bool isNormalized() const { return Normalized; }
int getSurfTexType() const { return SurfTexType; }
};
CGCUDARuntime(CodeGenModule &CGM) : CGM(CGM) {}