|
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"
|
@@ -2862,10 +2863,14 @@ handleDeclareTargetMapVar(MapInfoData &mapData,
|
2862 | 2863 | // reference pointer and the pointer are assigned in the kernel argument
|
2863 | 2864 | // structure for the host.
|
2864 | 2865 | if (mapData.IsDeclareTarget[i]) {
|
2865 |
| - |
2866 |
| - moduleTranslation.getOpenMPBuilder() |
2867 |
| - ->replaceConstantValueUsesInFuncWithInstr(mapData.OriginalValue[i], |
2868 |
| - func); |
| 2866 | + // If the original map value is a constant, then we have to make sure all |
| 2867 | + // of it's uses within the current kernel/function that we are going to |
| 2868 | + // rewrite are converted to instructions, as we will be altering the old |
| 2869 | + // use (OriginalValue) from a constant to an instruction, which will be |
| 2870 | + // illegal and ICE the compiler if the user is a constant expression of |
| 2871 | + // some kind e.g. a constant GEP. |
| 2872 | + if (auto *constant = dyn_cast<llvm::Constant>(mapData.OriginalValue[i])) |
| 2873 | + convertUsersOfConstantsToInstructions(constant, func, false); |
2869 | 2874 |
|
2870 | 2875 | // The users iterator will get invalidated if we modify an element,
|
2871 | 2876 | // so we populate this vector of uses to alter each user on an
|
|
0 commit comments