raw_fd_ostream OS(ImageName.str(), EC);
if (EC)
report_fatal_error("Error saving image : " + StringRef(EC.message()));
- OS << Image.getMemoryBuffer().getBuffer();
+ if (auto TgtImageBitcode = Image.getTgtImageBitcode()) {
+ size_t Size =
+ getPtrDiff(TgtImageBitcode->ImageEnd, TgtImageBitcode->ImageStart);
+ MemoryBufferRef MBR = MemoryBufferRef(
+ StringRef((const char *)TgtImageBitcode->ImageStart, Size), "");
+ OS << MBR.getBuffer();
+ } else {
+ OS << Image.getMemoryBuffer().getBuffer();
+ }
OS.close();
}
DeviceImageTy *Image = *ImageOrErr;
assert(Image != nullptr && "Invalid image");
+ if (InputTgtImage != PostJITImageOrErr.get())
+ Image->setTgtImageBitcode(InputTgtImage);
// Add the image to list.
LoadedImages.push_back(Image);
/// The pointer to the raw __tgt_device_image.
const __tgt_device_image *TgtImage;
+ const __tgt_device_image *TgtImageBitcode;
/// Table of offload entries.
OffloadEntryTableTy OffloadEntryTable;
public:
DeviceImageTy(int32_t Id, const __tgt_device_image *Image)
- : ImageId(Id), TgtImage(Image) {
+ : ImageId(Id), TgtImage(Image), TgtImageBitcode(nullptr) {
assert(TgtImage && "Invalid target image");
}
/// Get the pointer to the raw __tgt_device_image.
const __tgt_device_image *getTgtImage() const { return TgtImage; }
+ void setTgtImageBitcode(const __tgt_device_image *TgtImageBitcode) {
+ this->TgtImageBitcode = TgtImageBitcode;
+ }
+
+ const __tgt_device_image *getTgtImageBitcode() const {
+ return TgtImageBitcode;
+ }
+
/// Get the image starting address.
void *getStart() const { return TgtImage->ImageStart; }