[PATCH] D138496: [OpenMP][OMPContext] Move SIMD alignment calculation to LLVM Frontend
Dominik Adamski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 16 04:33:06 PST 2022
domada added inline comments.
================
Comment at: llvm/lib/Frontend/OpenMP/OMPContext.cpp:587
+ if (!TargetsIter->getValue())
+ return 0;
+
----------------
jdoerfert wrote:
> You lookup Key in Targets 3 times. Maybe we can reduce that a little. Can the pointer ever be nullptr (the one returned by `createTargetMachine`?
`createTargetMachine` can return nullptr. Test scenario:
# build clang without support of one target arch (for example build only x86 target: `cmake "-DLLVM_TARGETS_TO_BUILD="X86;")
# try to generate LLVM IR and specify target which hasn't been mentioned in cmake configuration: (for example: clang --target=arm -S -emit-llvm -fopenmp test.c)
We can reduce number of lookups in the best scenario (given Key has been inserted earlier):
```
// find the corresponding target
auto TargetsIter = Targets.find(Key);
//if not found - insert it and update TargetsIter
if (TargetsIter==Targets.end()) {
// some initialization code
Targets[Key] = TheTarget->createTargetMachine(..);
TargetsIter = Targets.find(Key);
}
//check if TargetMachine is not nullptr:
if (!TargetsIter->getValue())
return 0;
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138496/new/
https://reviews.llvm.org/D138496
More information about the llvm-commits
mailing list