if (ConstantInt *Const = dyn_cast<ConstantInt>(C)) {
Inst.addOperand(MCOperand::createImm(Const->getZExtValue()));
} else if (auto *CE = dyn_cast<Function>(C)) {
- Register FuncReg = MAI->getFuncReg(CE->getName().str());
+ Register FuncReg = MAI->getFuncReg(CE);
assert(FuncReg.isValid());
Inst.addOperand(MCOperand::createReg(FuncReg));
}
const Function &F = *FI;
if (F.isDeclaration())
continue;
- Register FReg = MAI->getFuncReg(F.getGlobalIdentifier());
+ Register FReg = MAI->getFuncReg(&F);
assert(FReg.isValid());
if (MDNode *Node = F.getMetadata("reqd_work_group_size"))
outputExecutionModeFromMDNode(FReg, Node,
// the annotated variable.
Value *AnnotatedVar = CS->getOperand(0)->stripPointerCasts();
if (!isa<Function>(AnnotatedVar))
- llvm_unreachable("Unsupported value in llvm.global.annotations");
+ report_fatal_error("Unsupported value in llvm.global.annotations");
Function *Func = cast<Function>(AnnotatedVar);
- Register Reg = MAI->getFuncReg(Func->getGlobalIdentifier());
+ Register Reg = MAI->getFuncReg(Func);
// The second field contains a pointer to a global annotation string.
GlobalVariable *GV =
Register ResVReg =
Info.OrigRet.Regs.empty() ? Register(0) : Info.OrigRet.Regs[0];
- std::string FuncName = Info.Callee.getGlobal()->getGlobalIdentifier();
+ std::string FuncName = Info.Callee.getGlobal()->getName().str();
std::string DemangledName = getOclOrSpirvBuiltinDemangledName(FuncName);
const auto *ST = static_cast<const SPIRVSubtarget *>(&MF.getSubtarget());
// TODO: check that it's OCL builtin, then apply OpenCL_std.
default:
llvm_unreachable("unknown operand type");
case MachineOperand::MO_GlobalAddress: {
- Register FuncReg = MAI->getFuncReg(MO.getGlobal()->getGlobalIdentifier());
+ Register FuncReg = MAI->getFuncReg(dyn_cast<Function>(MO.getGlobal()));
assert(FuncReg.isValid() && "Cannot find function Id");
MCOp = MCOperand::createReg(FuncReg);
break;
Register GlobalReg = MAI.getRegisterAlias(MI.getMF(), Reg);
assert(GlobalReg.isValid());
// TODO: check that it does not conflict with existing entries.
- MAI.FuncNameMap[F.getGlobalIdentifier()] = GlobalReg;
+ MAI.FuncNameMap[getFunctionGlobalIdentifier(&F)] = GlobalReg;
}
}
#include "MCTargetDesc/SPIRVBaseInfo.h"
#include "SPIRVGlobalRegistry.h"
+#include "SPIRVUtils.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallSet.h"
// The table maps MBB number to SPIR-V unique ID register.
DenseMap<int, Register> BBNumToRegMap;
- Register getFuncReg(std::string FuncName) {
- auto FuncReg = FuncNameMap.find(FuncName);
+ Register getFuncReg(const Function *F) {
+ assert(F && "Function is null");
+ auto FuncReg = FuncNameMap.find(getFunctionGlobalIdentifier(F));
assert(FuncReg != FuncNameMap.end() && "Cannot find function Id");
return FuncReg->second;
}
return isOpenCLBuiltinType(SType) || isSPIRVBuiltinType(SType);
return false;
}
+
+std::string getFunctionGlobalIdentifier(const Function *F) {
+ StringRef Name = F->hasName() ? F->getName() : ".anonymous";
+ GlobalValue::LinkageTypes Linkage = F->getLinkage();
+ StringRef ModuleFileName = F->getParent()->getSourceFileName();
+ return GlobalValue::getGlobalIdentifier(Name, Linkage, ModuleFileName);
+}
} // namespace llvm
// Check if given LLVM type is a special opaque builtin type.
bool isSpecialOpaqueType(const Type *Ty);
+
+std::string getFunctionGlobalIdentifier(const Function *F);
} // namespace llvm
#endif // LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
--- /dev/null
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+
+;; Types:
+; CHECK-DAG: %[[#F32:]] = OpTypeFloat 32
+; CHECK-DAG: %[[#FNF32:]] = OpTypeFunction %[[#F32]] %[[#F32]]
+;; Function decl:
+; CHECK: %[[#ANON:]] = OpFunction %[[#F32]] None %[[#FNF32]]
+; CHECK-NEXT: OpFunctionParameter %[[#F32]]
+; CHECK-NEXT: OpLabel
+; CHECK-NEXT: OpReturnValue
+; CHECK-NEXT: OpFunctionEnd
+define internal spir_func float @0(float %a) {
+ ret float %a
+}
+
+; CHECK: OpFunctionCall %[[#F32]] %[[#ANON]]
+define spir_kernel void @foo(float %a) {
+ %1 = call spir_func float @0(float %a)
+ ret void
+}