Ignore:
Timestamp:
Apr 23, 2017, 12:44:04 PM (2 years ago)
Author:
nmedfort
Message:

Bug fixes for 32-bit systems

Location:
icGREP/icgrep-devel/icgrep/IR_Gen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5418 r5419  
    250250}
    251251
    252 /*
    253     MADV_NORMAL
    254         No special treatment. This is the default.
    255     MADV_RANDOM
    256         Expect page references in random order. (Hence, read ahead may be less useful than normally.)
    257     MADV_SEQUENTIAL
    258         Expect page references in sequential order. (Hence, pages in the given range can be aggressively read ahead, and may be freed
    259         soon after they are accessed.)
    260     MADV_WILLNEED
    261         Expect access in the near future. (Hence, it might be a good idea to read some pages ahead.)
    262     MADV_DONTNEED
    263         Do not expect access in the near future. (For the time being, the application is finished with the given range, so the kernel
    264         can free resources associated with it.) Subsequent accesses of pages in this range will succeed, but will result either in
    265         reloading of the memory contents from the underlying mapped file (see mmap(2)) or zero-fill-on-demand pages for mappings
    266         without an underlying file.
    267 */
    268 
    269 Value * CBuilder::CreateMAdvise(Value * addr, Value * length, std::initializer_list<MAdviceFlags> advice) {
     252/**
     253 * @brief CBuilder::CreateMAdvise
     254 * @param addr
     255 * @param length
     256 * @param advice
     257 *
     258 * Note: intermittent failures are possible. Test if this is more than a simple hint and handle accordingly.
     259 *
     260 *  ADVICE_NORMAL
     261 *      No special treatment. This is the default.
     262 *  ADVICE_RANDOM
     263 *      Expect page references in random order. (Hence, read ahead may be less useful than normally.)
     264 *  ADVICE_SEQUENTIAL
     265 *      Expect page references in sequential order. (Hence, pages in the given range can be aggressively read ahead, and may be freed
     266 *      soon after they are accessed.)
     267 *  ADVICE_WILLNEED
     268 *      Expect access in the near future. (Hence, it might be a good idea to read some pages ahead.)
     269 *  ADVICE_DONTNEED
     270 *      Do not expect access in the near future. (For the time being, the application is finished with the given range, so the kernel
     271 *      can free resources associated with it.) Subsequent accesses of pages in this range will succeed, but will result either in
     272 *      reloading of the memory contents from the underlying mapped file (see mmap(2)) or zero-fill-on-demand pages for mappings
     273 *      without an underlying file.
     274 *
     275 * @return Value indicating success (0) or failure (non-zero).
     276 */
     277Value * CBuilder::CreateMAdvise(Value * addr, Value * length, Advice advice) {
    270278    Triple T(mMod->getTargetTriple());
    271279    Value * result = nullptr;
    272     if (T.isOSLinux()) {
     280    if (T.isOSLinux() || T.isOSDarwin()) {
    273281        DataLayout DL(mMod);
    274282        IntegerType * const intTy = getIntPtrTy(DL);
     
    282290        addr = CreatePointerCast(addr, voidPtrTy);
    283291        length = CreateZExtOrTrunc(length, sizeTy);
    284         int adviceFlags = 0;
    285         for (const MAdviceFlags adv : advice) {
    286             switch (adv) {
    287                 case MAdviceFlags::MMAP_NORMAL: adviceFlags |= MADV_NORMAL; break;
    288                 case MAdviceFlags::MMAP_RANDOM: adviceFlags |= MADV_RANDOM; break;
    289                 case MAdviceFlags::MMAP_SEQUENTIAL: adviceFlags |= MADV_SEQUENTIAL; break;
    290                 case MAdviceFlags::MMAP_DONTNEED: adviceFlags |= MADV_DONTNEED; break;
    291                 case MAdviceFlags::MMAP_WILLNEED: adviceFlags |= MADV_WILLNEED; break;
    292 //                case MADV::REMOVE: adviceFlags |= MADV_REMOVE; break;
    293 //                case MADV::DONTFORK: adviceFlags |= MADV_DONTFORK; break;
    294 //                case MADV::DOFORK: adviceFlags |= MADV_DOFORK; break;
    295 //                case MADV::HWPOISON: adviceFlags |= MADV_HWPOISON; break;
    296 //                case MADV::MERGEABLE: adviceFlags |= MADV_MERGEABLE; break;
    297 //                case MADV::UNMERGEABLE: adviceFlags |= MADV_UNMERGEABLE; break;
    298 //                case MADV::HUGEPAGE: adviceFlags |= MADV_HUGEPAGE; break;
    299 //                case MADV::NOHUGEPAGE: adviceFlags |= MADV_NOHUGEPAGE; break;
    300 //                case MADV::DONTDUMP: adviceFlags |= MADV_DONTDUMP; break;
    301 //                case MADV::DODUMP: adviceFlags |= MADV_DODUMP; break;
    302             }
     292        int madv_flag = 0;
     293        switch (advice) {
     294            case Advice::ADVICE_NORMAL:
     295                madv_flag = MADV_NORMAL; break;
     296            case Advice::ADVICE_RANDOM:
     297                madv_flag = MADV_RANDOM; break;
     298            case Advice::ADVICE_SEQUENTIAL:
     299                madv_flag = MADV_SEQUENTIAL; break;
     300            case Advice::ADVICE_WILLNEED:
     301                madv_flag = MADV_WILLNEED; break;
     302            case Advice::ADVICE_DONTNEED:
     303                madv_flag = MADV_DONTNEED; break;
    303304        }
    304         result = CreateCall(MAdviseFunc, {addr, length, ConstantInt::get(intTy, adviceFlags)});
    305         if (codegen::EnableAsserts) {
    306             CreateAssert(CreateICmpEQ(result, ConstantInt::getNullValue(result->getType())), "CreateMMapAdvise: failed");
    307         }
     305        result = CreateCall(MAdviseFunc, {addr, length, ConstantInt::get(intTy, madv_flag)});
    308306    }
    309307    return result;
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5418 r5419  
    9797    llvm::Value * CreateFileSourceMMap(llvm::Value * fd, llvm::Value * size);
    9898
    99     enum MAdviceFlags {
    100         MMAP_NORMAL
    101         , MMAP_RANDOM
    102         , MMAP_SEQUENTIAL
    103         , MMAP_WILLNEED
    104         , MMAP_DONTNEED
     99    enum Advice {
     100        ADVICE_NORMAL
     101        , ADVICE_RANDOM
     102        , ADVICE_SEQUENTIAL
     103        , ADVICE_WILLNEED
     104        , ADVICE_DONTNEED
    105105    };
    106106
    107     llvm::Value * CreateMAdvise(llvm::Value * addr, llvm::Value * length, MAdviceFlags advice) {
    108         return CreateMAdvise(addr, length, { advice });
    109     }
    110 
    111     llvm::Value * CreateMAdvise(llvm::Value * addr, llvm::Value * length, std::initializer_list<MAdviceFlags> advice);
     107    llvm::Value * CreateMAdvise(llvm::Value * addr, llvm::Value * length, Advice advice);
    112108
    113109    llvm::Value * CreateMMap(llvm::Value * const addr, llvm::Value * size, llvm::Value * const prot, llvm::Value * const flags, llvm::Value * const fd, llvm::Value * const offset);
Note: See TracChangeset for help on using the changeset viewer.