diff options
author | Tom Stellard <[email protected]> | 2012-07-13 15:52:37 +0000 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2012-07-13 16:29:46 +0000 |
commit | f323c6260d54357d2408f1993a21e08f091b1e27 (patch) | |
tree | ac1af2d6562b7f30eb291feb37b71ba262fc4a6d /src/gallium/drivers/radeon/R600KernelParameters.cpp | |
parent | 39d82a1b2028a7fe83a885478c9224669ea9f18a (diff) |
radeon/llvm: Coding style fixes
Diffstat (limited to 'src/gallium/drivers/radeon/R600KernelParameters.cpp')
-rw-r--r-- | src/gallium/drivers/radeon/R600KernelParameters.cpp | 496 |
1 files changed, 206 insertions, 290 deletions
diff --git a/src/gallium/drivers/radeon/R600KernelParameters.cpp b/src/gallium/drivers/radeon/R600KernelParameters.cpp index e810023b651..e86ebbcabcf 100644 --- a/src/gallium/drivers/radeon/R600KernelParameters.cpp +++ b/src/gallium/drivers/radeon/R600KernelParameters.cpp @@ -36,49 +36,47 @@ namespace { #define CONSTANT_CACHE_SIZE_DW 127 -class R600KernelParameters : public FunctionPass -{ - const TargetData * TD; +class R600KernelParameters : public FunctionPass { + const TargetData *TD; LLVMContext* Context; - Module *mod; + Module *Mod; - struct param - { - param() : val(NULL), ptr_val(NULL), offset_in_dw(0), size_in_dw(0), - indirect(true), specialID(0) {} + struct Param { + Param() : Val(NULL), PtrVal(NULL), OffsetInDW(0), SizeInDW(0), + IsIndirect(true), SpecialID(0) {} - Value* val; - Value* ptr_val; - int offset_in_dw; - int size_in_dw; + Value* Val; + Value* PtrVal; + int OffsetInDW; + int SizeInDW; - bool indirect; + bool IsIndirect; - std::string specialType; - int specialID; + std::string SpecialType; + int SpecialID; - int end() { return offset_in_dw + size_in_dw; } + int End() { return OffsetInDW + SizeInDW; } // The first 9 dwords are reserved for the grid sizes. - int get_rat_offset() { return 9 + offset_in_dw; } + int getRatOffset() { return 9 + OffsetInDW; } }; - std::vector<param> params; + std::vector<Param> Params; - bool isOpenCLKernel(const Function* fun); + bool IsOpenCLKernel(const Function *Fun); int getLastSpecialID(const std::string& TypeName); int getListSize(); - void AddParam(Argument* arg); - int calculateArgumentSize(Argument* arg); - void RunAna(Function* fun); - void Replace(Function* fun); - bool isIndirect(Value* val, std::set<Value*>& visited); - void Propagate(Function* fun); - void Propagate(Value* v, const Twine& name, bool indirect = true); - Value* ConstantRead(Function* fun, param& p); - Value* handleSpecial(Function* fun, param& p); - bool isSpecialType(Type*); - std::string getSpecialTypeName(Type*); + void AddParam(Argument *Arg); + int CalculateArgumentSize(Argument *Arg); + void RunAna(Function *Fun); + void Replace(Function *Fun); + bool IsIndirect(Value *Val, std::set<Value*> &Visited); + void Propagate(Function* Fun); + void Propagate(Value *V, const Twine &Name, bool IsIndirect = true); + Value* ConstantRead(Function *Fun, Param &P); + Value* handleSpecial(Function *Fun, Param &P); + bool IsSpecialType(Type *T); + std::string getSpecialTypeName(Type *T); public: static char ID; R600KernelParameters() : FunctionPass(ID) {}; @@ -95,27 +93,22 @@ char R600KernelParameters::ID = 0; static RegisterPass<R600KernelParameters> X("kerparam", "OpenCL Kernel Parameter conversion", false, false); -bool R600KernelParameters::isOpenCLKernel(const Function* fun) -{ - Module *mod = const_cast<Function*>(fun)->getParent(); - NamedMDNode * md = mod->getOrInsertNamedMetadata("opencl.kernels"); +bool R600KernelParameters::IsOpenCLKernel(const Function* Fun) { + Module *Mod = const_cast<Function*>(Fun)->getParent(); + NamedMDNode * MD = Mod->getOrInsertNamedMetadata("opencl.kernels"); - if (!md or !md->getNumOperands()) - { + if (!MD or !MD->getNumOperands()) { return false; } - for (int i = 0; i < int(md->getNumOperands()); i++) - { - if (!md->getOperand(i) or !md->getOperand(i)->getOperand(0)) - { + for (int i = 0; i < int(MD->getNumOperands()); i++) { + if (!MD->getOperand(i) or !MD->getOperand(i)->getOperand(0)) { continue; } - - assert(md->getOperand(i)->getNumOperands() == 1); - if (md->getOperand(i)->getOperand(0)->getName() == fun->getName()) - { + assert(MD->getOperand(i)->getNumOperands() == 1); + + if (MD->getOperand(i)->getOperand(0)->getName() == Fun->getName()) { return true; } } @@ -123,76 +116,61 @@ bool R600KernelParameters::isOpenCLKernel(const Function* fun) return false; } -int R600KernelParameters::getLastSpecialID(const std::string& TypeName) -{ - int lastID = -1; +int R600KernelParameters::getLastSpecialID(const std::string &TypeName) { + int LastID = -1; - for (std::vector<param>::iterator i = params.begin(); i != params.end(); i++) - { - if (i->specialType == TypeName) - { - lastID = i->specialID; + for (std::vector<Param>::iterator i = Params.begin(); i != Params.end(); i++) { + if (i->SpecialType == TypeName) { + LastID = i->SpecialID; } } - return lastID; + return LastID; } -int R600KernelParameters::getListSize() -{ - if (params.size() == 0) - { +int R600KernelParameters::getListSize() { + if (Params.size() == 0) { return 0; } - return params.back().end(); + return Params.back().End(); } -bool R600KernelParameters::isIndirect(Value* val, std::set<Value*>& visited) -{ +bool R600KernelParameters::IsIndirect(Value *Val, std::set<Value*> &Visited) { //XXX Direct parameters are not supported yet, so return true here. return true; #if 0 - if (isa<LoadInst>(val)) - { + if (isa<LoadInst>(Val)) { return false; } - if (isa<IntegerType>(val->getType())) - { + if (isa<IntegerType>(Val->getType())) { assert(0 and "Internal error"); return false; } - if (visited.count(val)) - { + if (Visited.count(Val)) { return false; } - visited.insert(val); + Visited.insert(Val); - if (isa<GetElementPtrInst>(val)) - { - GetElementPtrInst* GEP = dyn_cast<GetElementPtrInst>(val); - GetElementPtrInst::op_iterator i = GEP->op_begin(); + if (isa<getElementPtrInst>(Val)) { + getElementPtrInst* GEP = dyn_cast<getElementPtrInst>(Val); + getElementPtrInst::op_iterator I = GEP->op_begin(); - for (i++; i != GEP->op_end(); i++) - { - if (!isa<Constant>(*i)) - { + for (++I; I != GEP->op_end(); ++I) { + if (!isa<Constant>(*I)) { return true; } } } - for (Value::use_iterator i = val->use_begin(); i != val->use_end(); i++) - { - Value* v2 = dyn_cast<Value>(*i); + for (Value::use_iterator I = Val->use_begin(); i != Val->use_end(); ++I) { + Value* V2 = dyn_cast<Value>(*I); - if (v2) - { - if (isIndirect(v2, visited)) - { + if (V2) { + if (IsIndirect(V2, Visited)) { return true; } } @@ -202,293 +180,242 @@ bool R600KernelParameters::isIndirect(Value* val, std::set<Value*>& visited) #endif } -void R600KernelParameters::AddParam(Argument* arg) -{ - param p; +void R600KernelParameters::AddParam(Argument *Arg) { + Param P; - p.val = dyn_cast<Value>(arg); - p.offset_in_dw = getListSize(); - p.size_in_dw = calculateArgumentSize(arg); + P.Val = dyn_cast<Value>(Arg); + P.OffsetInDW = getListSize(); + P.SizeInDW = CalculateArgumentSize(Arg); - if (isa<PointerType>(arg->getType()) and arg->hasByValAttr()) - { - std::set<Value*> visited; - p.indirect = isIndirect(p.val, visited); + if (isa<PointerType>(Arg->getType()) and Arg->hasByValAttr()) { + std::set<Value*> Visited; + P.IsIndirect = IsIndirect(P.Val, Visited); } - params.push_back(p); + Params.push_back(P); } -int R600KernelParameters::calculateArgumentSize(Argument* arg) -{ - Type* t = arg->getType(); +int R600KernelParameters::CalculateArgumentSize(Argument *Arg) { + Type* T = Arg->getType(); - if (arg->hasByValAttr() and dyn_cast<PointerType>(t)) - { - t = dyn_cast<PointerType>(t)->getElementType(); + if (Arg->hasByValAttr() and dyn_cast<PointerType>(T)) { + T = dyn_cast<PointerType>(T)->getElementType(); } - int store_size_in_dw = (TD->getTypeStoreSize(t) + 3)/4; + int StoreSizeInDW = (TD->getTypeStoreSize(T) + 3)/4; - assert(store_size_in_dw); + assert(StoreSizeInDW); - return store_size_in_dw; + return StoreSizeInDW; } -void R600KernelParameters::RunAna(Function* fun) -{ - assert(isOpenCLKernel(fun)); +void R600KernelParameters::RunAna(Function* Fun) { + assert(IsOpenCLKernel(Fun)); - for (Function::arg_iterator i = fun->arg_begin(); i != fun->arg_end(); i++) - { - AddParam(i); + for (Function::arg_iterator I = Fun->arg_begin(); I != Fun->arg_end(); ++I) { + AddParam(I); } } -void R600KernelParameters::Replace(Function* fun) -{ - for (std::vector<param>::iterator i = params.begin(); i != params.end(); i++) - { - Value *new_val; +void R600KernelParameters::Replace(Function* Fun) { + for (std::vector<Param>::iterator I = Params.begin(); I != Params.end(); ++I) { + Value *NewVal; - if (isSpecialType(i->val->getType())) - { - new_val = handleSpecial(fun, *i); - } - else - { - new_val = ConstantRead(fun, *i); + if (IsSpecialType(I->Val->getType())) { + NewVal = handleSpecial(Fun, *I); + } else { + NewVal = ConstantRead(Fun, *I); } - if (new_val) - { - i->val->replaceAllUsesWith(new_val); + if (NewVal) { + I->Val->replaceAllUsesWith(NewVal); } } } -void R600KernelParameters::Propagate(Function* fun) -{ - for (std::vector<param>::iterator i = params.begin(); i != params.end(); i++) - { - if (i->ptr_val) - { - Propagate(i->ptr_val, i->val->getName(), i->indirect); - } +void R600KernelParameters::Propagate(Function* Fun) { + for (std::vector<Param>::iterator I = Params.begin(); I != Params.end(); ++I) { + if (I->PtrVal) { + Propagate(I->PtrVal, I->Val->getName(), I->IsIndirect); + } } } -void R600KernelParameters::Propagate(Value* v, const Twine& name, bool indirect) -{ - LoadInst* load = dyn_cast<LoadInst>(v); - GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(v); +void R600KernelParameters::Propagate(Value* V, const Twine& Name, bool IsIndirect) { + LoadInst* Load = dyn_cast<LoadInst>(V); + GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V); - unsigned addrspace; + unsigned Addrspace; - if (indirect) - { - addrspace = AMDILAS::PARAM_I_ADDRESS; - } - else - { - addrspace = AMDILAS::PARAM_D_ADDRESS; + if (IsIndirect) { + Addrspace = AMDILAS::PARAM_I_ADDRESS; + } else { + Addrspace = AMDILAS::PARAM_D_ADDRESS; } - if (GEP and GEP->getType()->getAddressSpace() != addrspace) - { - Value* op = GEP->getPointerOperand(); + if (GEP and GEP->getType()->getAddressSpace() != Addrspace) { + Value *Op = GEP->getPointerOperand(); - if (dyn_cast<PointerType>(op->getType())->getAddressSpace() != addrspace) - { - op = new BitCastInst(op, PointerType::get(dyn_cast<PointerType>( - op->getType())->getElementType(), addrspace), - name, dyn_cast<Instruction>(v)); + if (dyn_cast<PointerType>(Op->getType())->getAddressSpace() != Addrspace) { + Op = new BitCastInst(Op, PointerType::get(dyn_cast<PointerType>( + Op->getType())->getElementType(), Addrspace), + Name, dyn_cast<Instruction>(V)); } - std::vector<Value*> params(GEP->idx_begin(), GEP->idx_end()); + std::vector<Value*> Params(GEP->idx_begin(), GEP->idx_end()); - GetElementPtrInst* GEP2 = GetElementPtrInst::Create(op, params, name, - dyn_cast<Instruction>(v)); + GetElementPtrInst* GEP2 = GetElementPtrInst::Create(Op, Params, Name, + dyn_cast<Instruction>(V)); GEP2->setIsInBounds(GEP->isInBounds()); - v = dyn_cast<Value>(GEP2); + V = dyn_cast<Value>(GEP2); GEP->replaceAllUsesWith(GEP2); GEP->eraseFromParent(); - load = NULL; + Load = NULL; } - if (load) - { + if (Load) { ///normally at this point we have the right address space - if (load->getPointerAddressSpace() != addrspace) - { - Value *orig_ptr = load->getPointerOperand(); - PointerType *orig_ptr_type = dyn_cast<PointerType>(orig_ptr->getType()); + if (Load->getPointerAddressSpace() != Addrspace) { + Value *OrigPtr = Load->getPointerOperand(); + PointerType *OrigPtrType = dyn_cast<PointerType>(OrigPtr->getType()); - Type* new_ptr_type = PointerType::get(orig_ptr_type->getElementType(), - addrspace); + Type* NewPtrType = PointerType::get(OrigPtrType->getElementType(), + Addrspace); - Value* new_ptr = orig_ptr; + Value* NewPtr = OrigPtr; - if (orig_ptr->getType() != new_ptr_type) - { - new_ptr = new BitCastInst(orig_ptr, new_ptr_type, "prop_cast", load); + if (OrigPtr->getType() != NewPtrType) { + NewPtr = new BitCastInst(OrigPtr, NewPtrType, "prop_cast", Load); } - Value* new_load = new LoadInst(new_ptr, name, load); - load->replaceAllUsesWith(new_load); - load->eraseFromParent(); + Value* new_Load = new LoadInst(NewPtr, Name, Load); + Load->replaceAllUsesWith(new_Load); + Load->eraseFromParent(); } return; } - std::vector<User*> users(v->use_begin(), v->use_end()); + std::vector<User*> Users(V->use_begin(), V->use_end()); - for (int i = 0; i < int(users.size()); i++) - { - Value* v2 = dyn_cast<Value>(users[i]); + for (int i = 0; i < int(Users.size()); i++) { + Value* V2 = dyn_cast<Value>(Users[i]); - if (v2) - { - Propagate(v2, name, indirect); + if (V2) { + Propagate(V2, Name, IsIndirect); } } } -Value* R600KernelParameters::ConstantRead(Function* fun, param& p) -{ - assert(fun->front().begin() != fun->front().end()); +Value* R600KernelParameters::ConstantRead(Function *Fun, Param &P) { + assert(Fun->front().begin() != Fun->front().end()); - Instruction *first_inst = fun->front().begin(); - IRBuilder <> builder (first_inst); + Instruction *FirstInst = Fun->front().begin(); + IRBuilder <> Builder (FirstInst); /* First 3 dwords are reserved for the dimmension info */ - if (!p.val->hasNUsesOrMore(1)) - { + if (!P.Val->hasNUsesOrMore(1)) { return NULL; } - unsigned addrspace; + unsigned Addrspace; - if (p.indirect) - { - addrspace = AMDILAS::PARAM_I_ADDRESS; - } - else - { - addrspace = AMDILAS::PARAM_D_ADDRESS; + if (P.IsIndirect) { + Addrspace = AMDILAS::PARAM_I_ADDRESS; + } else { + Addrspace = AMDILAS::PARAM_D_ADDRESS; } - Argument *arg = dyn_cast<Argument>(p.val); - Type * argType = p.val->getType(); - PointerType * argPtrType = dyn_cast<PointerType>(p.val->getType()); + Argument *Arg = dyn_cast<Argument>(P.Val); + Type * ArgType = P.Val->getType(); + PointerType * ArgPtrType = dyn_cast<PointerType>(P.Val->getType()); - if (argPtrType and arg->hasByValAttr()) - { - Value* param_addr_space_ptr = ConstantPointerNull::get( + if (ArgPtrType and Arg->hasByValAttr()) { + Value* ParamAddrSpacePtr = ConstantPointerNull::get( PointerType::get(Type::getInt32Ty(*Context), - addrspace)); - Value* param_ptr = GetElementPtrInst::Create(param_addr_space_ptr, + Addrspace)); + Value* ParamPtr = GetElementPtrInst::Create(ParamAddrSpacePtr, ConstantInt::get(Type::getInt32Ty(*Context), - p.get_rat_offset()), arg->getName(), - first_inst); - param_ptr = new BitCastInst(param_ptr, - PointerType::get(argPtrType->getElementType(), - addrspace), - arg->getName(), first_inst); - p.ptr_val = param_ptr; - return param_ptr; - } - else - { - Value* param_addr_space_ptr = ConstantPointerNull::get(PointerType::get( - argType, addrspace)); - - Value* param_ptr = builder.CreateGEP(param_addr_space_ptr, - ConstantInt::get(Type::getInt32Ty(*Context), p.get_rat_offset()), - arg->getName()); - - Value* param_value = builder.CreateLoad(param_ptr, arg->getName()); - - return param_value; + P.getRatOffset()), Arg->getName(), + FirstInst); + ParamPtr = new BitCastInst(ParamPtr, + PointerType::get(ArgPtrType->getElementType(), + Addrspace), + Arg->getName(), FirstInst); + P.PtrVal = ParamPtr; + return ParamPtr; + } else { + Value *ParamAddrSpacePtr = ConstantPointerNull::get(PointerType::get( + ArgType, Addrspace)); + + Value *ParamPtr = Builder.CreateGEP(ParamAddrSpacePtr, + ConstantInt::get(Type::getInt32Ty(*Context), P.getRatOffset()), + Arg->getName()); + + Value *Param_Value = Builder.CreateLoad(ParamPtr, Arg->getName()); + + return Param_Value; } } -Value* R600KernelParameters::handleSpecial(Function* fun, param& p) -{ - std::string name = getSpecialTypeName(p.val->getType()); +Value* R600KernelParameters::handleSpecial(Function* Fun, Param& P) { + std::string Name = getSpecialTypeName(P.Val->getType()); int ID; - assert(!name.empty()); + assert(!Name.empty()); - if (name == "image2d_t" or name == "image3d_t") - { - int lastID = std::max(getLastSpecialID("image2d_t"), + if (Name == "image2d_t" or Name == "image3d_t") { + int LastID = std::max(getLastSpecialID("image2d_t"), getLastSpecialID("image3d_t")); - if (lastID == -1) - { + if (LastID == -1) { ID = 2; ///ID0 and ID1 are used internally by the driver + } else { + ID = LastID + 1; } - else - { - ID = lastID + 1; - } - } - else if (name == "sampler_t") - { - int lastID = getLastSpecialID("sampler_t"); + } else if (Name == "sampler_t") { + int LastID = getLastSpecialID("sampler_t"); - if (lastID == -1) - { + if (LastID == -1) { ID = 0; + } else { + ID = LastID + 1; } - else - { - ID = lastID + 1; - } - } - else - { + } else { ///TODO: give some error message return NULL; } - p.specialType = name; - p.specialID = ID; + P.SpecialType = Name; + P.SpecialID = ID; - Instruction *first_inst = fun->front().begin(); + Instruction *FirstInst = Fun->front().begin(); return new IntToPtrInst(ConstantInt::get(Type::getInt32Ty(*Context), - p.specialID), p.val->getType(), - "resourceID", first_inst); + P.SpecialID), P.Val->getType(), + "resourceID", FirstInst); } -bool R600KernelParameters::isSpecialType(Type* t) -{ - return !getSpecialTypeName(t).empty(); +bool R600KernelParameters::IsSpecialType(Type* T) { + return !getSpecialTypeName(T).empty(); } -std::string R600KernelParameters::getSpecialTypeName(Type* t) -{ - PointerType *pt = dyn_cast<PointerType>(t); - StructType *st = NULL; +std::string R600KernelParameters::getSpecialTypeName(Type* T) { + PointerType *PT = dyn_cast<PointerType>(T); + StructType *ST = NULL; - if (pt) - { - st = dyn_cast<StructType>(pt->getElementType()); + if (PT) { + ST = dyn_cast<StructType>(PT->getElementType()); } - if (st) - { - std::string prefix = "struct.opencl_builtin_type_"; + if (ST) { + std::string Prefix = "struct.opencl_builtin_type_"; - std::string name = st->getName().str(); + std::string Name = ST->getName().str(); - if (name.substr(0, prefix.length()) == prefix) - { - return name.substr(prefix.length(), name.length()); + if (Name.substr(0, Prefix.length()) == Prefix) { + return Name.substr(Prefix.length(), Name.length()); } } @@ -496,10 +423,8 @@ std::string R600KernelParameters::getSpecialTypeName(Type* t) } -bool R600KernelParameters::runOnFunction (Function &F) -{ - if (!isOpenCLKernel(&F)) - { +bool R600KernelParameters::runOnFunction (Function &F) { + if (!IsOpenCLKernel(&F)) { return false; } @@ -510,37 +435,28 @@ bool R600KernelParameters::runOnFunction (Function &F) return false; } -void R600KernelParameters::getAnalysisUsage(AnalysisUsage &AU) const -{ +void R600KernelParameters::getAnalysisUsage(AnalysisUsage &AU) const { FunctionPass::getAnalysisUsage(AU); AU.setPreservesAll(); } -const char *R600KernelParameters::getPassName() const -{ +const char *R600KernelParameters::getPassName() const { return "OpenCL Kernel parameter conversion to memory"; } -bool R600KernelParameters::doInitialization(Module &M) -{ +bool R600KernelParameters::doInitialization(Module &M) { Context = &M.getContext(); - mod = &M; + Mod = &M; return false; } -bool R600KernelParameters::doFinalization(Module &M) -{ +bool R600KernelParameters::doFinalization(Module &M) { return false; } } // End anonymous namespace -FunctionPass* llvm::createR600KernelParametersPass(const TargetData* TD) -{ - FunctionPass *p = new R600KernelParameters(TD); - - return p; +FunctionPass* llvm::createR600KernelParametersPass(const TargetData* TD) { + return new R600KernelParameters(TD); } - - |