Skip to content

Commit

Permalink
Synchronisation between branches.
Browse files Browse the repository at this point in the history
Change-Id: Iae7a99f21fe8a01cb794d634d961d14f58bab60d
  • Loading branch information
lwesiers committed Nov 26, 2018
1 parent a02a00f commit 67351f4
Show file tree
Hide file tree
Showing 240 changed files with 146,543 additions and 145,028 deletions.
4 changes: 2 additions & 2 deletions IGC/AdaptorCommon/AddImplicitArgs.cpp
Expand Up @@ -35,7 +35,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "common/LLVMWarningsPush.hpp"
#include "llvm/ADT/SCCIterator.h"
#include <llvm/IR/Module.h>
#include <llvmWrapper/IR/Function.h>
#include <llvmWrapper/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/DerivedTypes.h>
#include "llvm/IR/DIBuilder.h"
Expand Down Expand Up @@ -356,7 +356,7 @@ void AddImplicitArgs::replaceAllUsesWithNewOCLBuiltinFunction(CodeGenContext* ct
llvm::Function::arg_iterator new_arg_iter = new_func->arg_begin();
llvm::Function::arg_iterator new_arg_end = new_func->arg_end();

assert(IGCLLVM::GetFuncArgSize(new_func) >= numArgOperands);
assert(IGCLLVM::GetFuncArgSize(new_func) >= numArgOperands);

// basic arguments
for (unsigned int i = 0; i < numArgOperands; ++i, ++new_arg_iter)
Expand Down
4 changes: 2 additions & 2 deletions IGC/AdaptorCommon/IRUpgrader/IRUpgrader.hpp
Expand Up @@ -37,6 +37,6 @@ namespace IGC
/// Transform legacy resource access intrinsics taking an integer representation to
/// the new intrinsics taking pointer representation
llvm::Pass* CreateUpgradeResourceIntrinsic();
///Transfor legacy gen intrisics with prefix "@genx." => "@llvm.genx."
llvm::Pass* CreateUpgradeGenIntrinsicPrefix();
///Transfor legacy gen intrisics with prefix "@genx." => "@llvm.genx."
llvm::Pass* CreateUpgradeGenIntrinsicPrefix();
}
128 changes: 64 additions & 64 deletions IGC/AdaptorCommon/IRUpgrader/UpgraderResourceAccess.cpp
Expand Up @@ -150,14 +150,14 @@ void UpgradeResourceAccess::ChangeIntrinsic(CallInst& C, GenISAIntrinsic::ID ID)
types.push_back(args[resIndex]->getType());
}
break;
case GenISAIntrinsic::GenISA_ldmcsptr: {
types.push_back(C.getType());
types.push_back(C.getArgOperand(0)->getType());
unsigned int resIndex = C.getNumOperands() - 5;
args[resIndex] = GetResource(m, builder, args[resIndex]);
types.push_back(args[resIndex]->getType());
}
break;
case GenISAIntrinsic::GenISA_ldmcsptr: {
types.push_back(C.getType());
types.push_back(C.getArgOperand(0)->getType());
unsigned int resIndex = C.getNumOperands() - 5;
args[resIndex] = GetResource(m, builder, args[resIndex]);
types.push_back(args[resIndex]->getType());
}
break;
default:
assert("unhandled intrinsic upgrade" && 0);
break;
Expand All @@ -175,47 +175,47 @@ void UpgradeResourceAccess::visitCallInst(CallInst& C)
{
return;
}

//Note : This upgrader pass is handling legacy intrinsics as well,
// hence we might be dealing with intrinsics starting with @genx.
if(C.getCalledFunction()->getName().contains("genx.GenISA.sample."))

//Note : This upgrader pass is handling legacy intrinsics as well,
// hence we might be dealing with intrinsics starting with @genx.
if(C.getCalledFunction()->getName().contains("genx.GenISA.sample."))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_sampleptr);
}
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleB."))
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleB."))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_sampleBptr);
}
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleD."))
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleD."))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_sampleDptr);
}
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleC."))
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleC."))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_sampleCptr);
}
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleL."))
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleL."))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_sampleLptr);
}
else if(C.getCalledFunction()->getName().contains("genx.GenISA.gather4."))
else if(C.getCalledFunction()->getName().contains("genx.GenISA.gather4."))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_gather4ptr);
}
else if(C.getCalledFunction()->getName().contains("genx.GenISA.ldms."))
else if(C.getCalledFunction()->getName().contains("genx.GenISA.ldms."))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_ldmsptr);
}
else if(C.getCalledFunction()->getName().equals("llvm.genx.GenISA.ldmcs") ||
C.getCalledFunction()->getName().equals("genx.GenISA.ldmcs"))
else if(C.getCalledFunction()->getName().equals("llvm.genx.GenISA.ldmcs") ||
C.getCalledFunction()->getName().equals("genx.GenISA.ldmcs"))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_ldmcsptr);
}
else if(C.getCalledFunction()->getName().contains("genx.GenISA.ld."))
else if(C.getCalledFunction()->getName().contains("genx.GenISA.ld."))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_ldptr);
}
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleKill.legacy"))
else if(C.getCalledFunction()->getName().contains("genx.GenISA.sampleKill.legacy"))
{
ChangeIntrinsic(C, GenISAIntrinsic::GenISA_sampleKillPix);
}
Expand All @@ -228,52 +228,52 @@ void UpgradeResourceAccess::visitCallInst(CallInst& C)
}
}

class UpgradeGenIntrinsicPrefix : public ModulePass, public InstVisitor<UpgradeGenIntrinsicPrefix>
{
public:
UpgradeGenIntrinsicPrefix() : ModulePass(ID) {}

static char ID;
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override
{
AU.setPreservesCFG();
}
//bool runOnFunction(llvm::Function &F) override;
bool runOnModule(llvm::Module &M) override;

llvm::StringRef getPassName() const override
{
return "UpgradeGenIntrinsicPrefix";
}

private:
bool m_changed = false;
};
char UpgradeGenIntrinsicPrefix::ID = 0;

bool UpgradeGenIntrinsicPrefix::runOnModule(llvm::Module &M)
{
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
Function* pFunc = &(*I);
if (pFunc->getName().startswith("genx."))
pFunc->setName("llvm." + pFunc->getName());
}

return m_changed;
}

class UpgradeGenIntrinsicPrefix : public ModulePass, public InstVisitor<UpgradeGenIntrinsicPrefix>
{
public:
UpgradeGenIntrinsicPrefix() : ModulePass(ID) {}

static char ID;
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override
{
AU.setPreservesCFG();
}
//bool runOnFunction(llvm::Function &F) override;
bool runOnModule(llvm::Module &M) override;

llvm::StringRef getPassName() const override
{
return "UpgradeGenIntrinsicPrefix";
}

private:
bool m_changed = false;
};
char UpgradeGenIntrinsicPrefix::ID = 0;

bool UpgradeGenIntrinsicPrefix::runOnModule(llvm::Module &M)
{
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
Function* pFunc = &(*I);
if (pFunc->getName().startswith("genx."))
pFunc->setName("llvm." + pFunc->getName());
}

return m_changed;
}


namespace IGC
{
Pass* CreateUpgradeResourceIntrinsic()
{
return new UpgradeResourceAccess();
}

Pass* CreateUpgradeGenIntrinsicPrefix()
{
return new UpgradeGenIntrinsicPrefix();
}


}

Pass* CreateUpgradeGenIntrinsicPrefix()
{
return new UpgradeGenIntrinsicPrefix();
}


}
14 changes: 7 additions & 7 deletions IGC/AdaptorCommon/ImplicitArgs.cpp
Expand Up @@ -29,7 +29,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "common/LLVMWarningsPush.hpp"
#include <llvm/IR/DerivedTypes.h>
#include <llvmWrapper/IR/Function.h>
#include <llvmWrapper/IR/Function.h>
#include <llvm/IR/Metadata.h>
#include <llvm/IR/Module.h>
#include "common/LLVMWarningsPop.hpp"
Expand Down Expand Up @@ -389,7 +389,7 @@ void ImplicitArgs::addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils*
ImplicitArg::ArgMap OffsetArgs;
FunctionInfoMetaDataHandle funcInfoMD =
pMdUtils->getFunctionsInfoItem(const_cast<Function*>(&F));
for (auto& Arg : F.args() )
for (auto& Arg : F.args() )
{
Value* AV = &Arg;
PointerType* PTy = dyn_cast<PointerType>(AV->getType());
Expand Down Expand Up @@ -465,10 +465,10 @@ int32_t ImplicitArgs::getStructArgOffset(unsigned int index) const

TODO("Refactor code to avoid code triplication for getArgInFunc(), getImplicitArg() and WIFuncResolution::getImplicitArg()")
Argument* ImplicitArgs::getArgInFunc(llvm::Function& F, ImplicitArg::ArgType argType) {
assert(IGCLLVM::GetFuncArgSize(F) >= size() && "Invalid number of argumnents in the function!");
assert(IGCLLVM::GetFuncArgSize(F) >= size() && "Invalid number of argumnents in the function!");

unsigned int argIndex = getArgIndex(argType);
unsigned int argIndexInFunc = IGCLLVM::GetFuncArgSize(F) - size() + argIndex;
unsigned int argIndexInFunc = IGCLLVM::GetFuncArgSize(F) - size() + argIndex;
Function::arg_iterator arg = F.arg_begin();
for (unsigned int i = 0; i < argIndexInFunc; ++i, ++arg);

Expand All @@ -482,7 +482,7 @@ Argument* ImplicitArgs::getImplicitArg(llvm::Function& F, ImplicitArg::ArgType a
return nullptr;
unsigned int implicitArgIndex = this->getArgIndex(argType);

unsigned int implicitArgIndexInFunc = IGCLLVM::GetFuncArgSize(F) - numImplicitArgs + implicitArgIndex;
unsigned int implicitArgIndexInFunc = IGCLLVM::GetFuncArgSize(F) - numImplicitArgs + implicitArgIndex;

Function::arg_iterator arg = F.arg_begin();
for (unsigned int i = 0; i < implicitArgIndexInFunc; ++i, ++arg);
Expand All @@ -492,14 +492,14 @@ Argument* ImplicitArgs::getImplicitArg(llvm::Function& F, ImplicitArg::ArgType a

Argument* ImplicitArgs::getNumberedImplicitArg(llvm::Function& F, ImplicitArg::ArgType argType, int argNum)
{
assert(IGCLLVM::GetFuncArgSize(F) >= size() && "Invalid number of arguments in the function!");
assert(IGCLLVM::GetFuncArgSize(F) >= size() && "Invalid number of arguments in the function!");

unsigned int numImplicitArgs = size();
unsigned int implicitArgIndex = this->getNumberedArgIndex(argType, argNum);
if (implicitArgIndex == numImplicitArgs)
return nullptr;

unsigned int implicitArgIndexInFunc = IGCLLVM::GetFuncArgSize(F) - numImplicitArgs + implicitArgIndex;
unsigned int implicitArgIndexInFunc = IGCLLVM::GetFuncArgSize(F) - numImplicitArgs + implicitArgIndex;

Function::arg_iterator arg = F.arg_begin();
for (unsigned int i = 0; i < implicitArgIndexInFunc; ++i, ++arg);
Expand Down
10 changes: 5 additions & 5 deletions IGC/AdaptorCommon/ProcessFuncAttributes.cpp
Expand Up @@ -34,9 +34,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "SPIRV/SPIRVInternal.h"

#include "common/LLVMWarningsPush.hpp"

#include "llvmWrapper/IR/Attributes.h"


#include "llvmWrapper/IR/Attributes.h"

#include <llvm/Pass.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Function.h>
Expand Down Expand Up @@ -236,7 +236,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
for (auto I : F->users()) {
if (CallInst* callInst = dyn_cast<CallInst>(&*I)) {
if (callInst->hasFnAttr(llvm::Attribute::NoInline)) {
callInst->removeAttribute(IGCLLVM::AttributeSet::FunctionIndex, llvm::Attribute::NoInline);
callInst->removeAttribute(IGCLLVM::AttributeSet::FunctionIndex, llvm::Attribute::NoInline);
}
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)

if (!keepAlwaysInline)
{
for (auto &arg : F->args())
for (auto &arg : F->args())
{
// If argument contains an opaque type e.g. image, then always inline it.
// If argument is a pointer to GAS, always inline it for perf reason.
Expand Down
34 changes: 17 additions & 17 deletions IGC/AdaptorCommon/TypesLegalizationPass.cpp
Expand Up @@ -241,23 +241,23 @@ TypesLegalizationPass::ResolveValue( Instruction *ip,Value *val,SmallVector<unsi
break;
}
}
else if ((isa<Argument>(val) || isa<CallInst>(val)) &&
val->getType()->isStructTy()) {
// Handle struct arguments and structs returned by function calls.
IRBuilder<> builder(ip);
return builder.CreateExtractValue(val, indices);
}
else if (PHINode* phi = dyn_cast<PHINode>(val))
{
IRBuilder<> builder(&(*ip->getParent()->getFirstInsertionPt()));
PHINode* newPhi = builder.CreatePHI(ip->getType(), phi->getNumIncomingValues());
for (unsigned i = 0; i < phi->getNumIncomingValues(); i++)
{
Value* v = ResolveValue(ip, phi->getIncomingValue(i), indices);
newPhi->addIncoming(v, phi->getIncomingBlock(i));
}
return newPhi;
}
else if ((isa<Argument>(val) || isa<CallInst>(val)) &&
val->getType()->isStructTy()) {
// Handle struct arguments and structs returned by function calls.
IRBuilder<> builder(ip);
return builder.CreateExtractValue(val, indices);
}
else if (PHINode* phi = dyn_cast<PHINode>(val))
{
IRBuilder<> builder(&(*ip->getParent()->getFirstInsertionPt()));
PHINode* newPhi = builder.CreatePHI(ip->getType(), phi->getNumIncomingValues());
for (unsigned i = 0; i < phi->getNumIncomingValues(); i++)
{
Value* v = ResolveValue(ip, phi->getIncomingValue(i), indices);
newPhi->addIncoming(v, phi->getIncomingBlock(i));
}
return newPhi;
}

// What other kind of instruction can we have here?
assert( !"Unresolved instruction!" );
Expand Down

0 comments on commit 67351f4

Please sign in to comment.