|
30 | 30 | #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
|
31 | 31 | #include "llvm/IR/DebugInfoMetadata.h"
|
32 | 32 | #include "llvm/IR/IRBuilder.h"
|
| 33 | +#include "llvm/IR/ReplaceConstant.h" |
33 | 34 | #include "llvm/Support/FileSystem.h"
|
34 | 35 | #include "llvm/TargetParser/Triple.h"
|
35 | 36 | #include "llvm/Transforms/Utils/ModuleUtils.h"
|
@@ -2913,10 +2914,14 @@ handleDeclareTargetMapVar(MapInfoData &mapData,
|
2913 | 2914 | // reference pointer and the pointer are assigned in the kernel argument
|
2914 | 2915 | // structure for the host.
|
2915 | 2916 | if (mapData.IsDeclareTarget[i]) {
|
2916 |
| - |
2917 |
| - moduleTranslation.getOpenMPBuilder() |
2918 |
| - ->replaceConstantValueUsesInFuncWithInstr(mapData.OriginalValue[i], |
2919 |
| - func); |
| 2917 | + // If the original map value is a constant, then we have to make sure all |
| 2918 | + // of it's uses within the current kernel/function that we are going to |
| 2919 | + // rewrite are converted to instructions, as we will be altering the old |
| 2920 | + // use (OriginalValue) from a constant to an instruction, which will be |
| 2921 | + // illegal and ICE the compiler if the user is a constant expression of |
| 2922 | + // some kind e.g. a constant GEP. |
| 2923 | + if (auto *constant = dyn_cast<llvm::Constant>(mapData.OriginalValue[i])) |
| 2924 | + convertUsersOfConstantsToInstructions(constant, func, false); |
2920 | 2925 |
|
2921 | 2926 | // The users iterator will get invalidated if we modify an element,
|
2922 | 2927 | // so we populate this vector of uses to alter each user on an
|
|
0 commit comments